Implement MSI v2 (mTLS PoP with KeyGuard Attestation) for Java Managed Identity#1014
Draft
Implement MSI v2 (mTLS PoP with KeyGuard Attestation) for Java Managed Identity#1014
Conversation
…Identity Co-authored-by: gladjohn <90415114+gladjohn@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Implement MSI v2 for Java with mTLS PoP and KeyGuard
Implement MSI v2 (mTLS PoP with KeyGuard Attestation) for Java Managed Identity
Mar 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds the MSI v2 token acquisition flow for Azure Managed Identity on Java: mTLS Proof-of-Possession tokens bound to VBS-isolated KeyGuard RSA keys, attested via Windows AttestationClientLib. Feature is opt-in only and Windows-specific.
Gating logic
Both flags must be set; attestation alone is rejected:
MSI v2 failures always throw
MsiV2Exception— no silent fallback to MSI v1.New parameters (
ManagedIdentityParameters)mtlsProofOfPossession(boolean)— requestsmtls_poptoken typewithAttestationSupport(boolean)— enables KeyGuard attestation (requires PoP)New classes
MsiV2— orchestrates the 7-step flow: IMDS platform metadata → KeyGuard RSA key (JNI) → PKCS#10 CSR → attestation JWT (JNI) → IMDS/issuecredential→ X.509 cert parse → mTLS token acquisitionMsiV2Exception— non-recoverable MSI v2 failure; never triggers fallbackCsrGenerator— manual DER encoding of PKCS#10 with RSA-PSS/SHA-256 and Microsoft cuId OID1.3.6.1.4.1.311.90.2.10WindowsKeyGuardJNI— JNI bridge toMsalJNIBridge.dllfor NCrypt KeyGuard key ops, signing, and native mTLSCsrMetadata,IssueCertificateRequest,IssueCertificateResponse— DTOs for the IMDS metadata and credential issuance endpointsNative stubs (
src/main/cpp/)MsalJNIBridge.h/.cppdefine the JNI contract and NCrypt/WinHTTP implementation pattern. Full compilation requires MSVC + Windows SDK + AttestationClientLib.dll; stub methods throwMsiV2Exceptionuntil the native DLL is provided.Routing change (
AcquireTokenByManagedIdentitySupplier)fetchNewTokenMsiV2()when both flags set — bypasses token cache (tokens are short-lived and hardware-bound)New error codes
MSI_V2_ATTESTATION_REQUIRES_POP,MSI_V2_KEYGUARD_UNAVAILABLE,MSI_V2_ERRORWarning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
build.shibboleth.net/usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --enable-native-access=ALL-UNNAMED -classpath /usr/share/apache-maven-3.9.12/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/usr/share/apache-maven-3.9.12/bin/m2.conf -Dmaven.home=/usr/share/apache-maven-3.9.12 -Dlibrary.jansi.path=/usr/share/apache-maven-3.9.12/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/microsoft-authentication-library-for-java/microsoft-authentication-library-for-java org.codehaus.plexus.classworlds.launcher.Launcher -f pom.xml -B -V -e -Dfindbugs.skip -Dcheckstyle.skip -Dpmd.skip=true -Dspotbugs.skip -Denforcer.skip -Dmaven.javadoc.skip(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
Implement MSI v2 (mTLS PoP with KeyGuard Attestation) for Java Managed Identity
Overview
Implement MSI v2 token acquisition flow for Azure Managed Identity on Java, adding support for mTLS Proof-of-Possession (PoP) tokens bound to KeyGuard-protected certificates. This feature enables secure, short-lived token acquisition with hardware-backed key protection on Windows.
Architecture
Key Design Pattern (from Python PR #882)
mtlsProofOfPossession=trueANDwithAttestationSupport=truewith_attestation_supportrequiresmtls_proof_of_possession(error if attestation alone)MsiV2Error(never fall back to v1)7-Step MSI v2 Flow
/metadata/identity/getPlatformMetadata→ get clientId, tenantId, cuId, attestationEndpoint/metadata/identity/issuecredentialwith CSR + attestation JWTtoken_type=mtls_popFiles to Create/Modify
Modify Existing
mtlsProofOfPossessionandwithAttestationSupportparameters toacquireTokenForClient()MsiV2.obtainToken()when both flags trueNew Files - Core Java Implementation
msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/MsiV2Exception.java
msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/MsiV2.java
msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/CsrMetadata.java
/getPlatformMetadataresponsemsal4j-sdk/src/main/java/com/microsoft/aad/msal4j/CsrGenerator.java
msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/IssueCertificateRequest.java
/issuecredentialmsal4j-sdk/src/main/java/com/microsoft/aad/msal4j/IssueCertificateResponse.java
/issuecredentialNew Files - JNI Wrapper (Windows KeyGuard + Attestation)
msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/WindowsKeyGuardJNI.java
createKeyGuardRsaKeyNative(String keyName, int keySizeBits)→ returns native key handlegetAttestationTokenNative(String endpoint, byte[] keyHandle)→ returns JWT from AttestationClientLib.dllPlatformNotSupportedExceptionif VBS unavailablemsal4j-sdk/src/main/cpp/MsalJNIBridge.cpp (C++ implementation)
NCryptUseVirtualIsolationFlag | NCryptUsePerBootKeyFlagmsal4j-sdk/src/main/cpp/MsalJNIBridge.h (C++ header)
New Files - Build & Native Library Packaging
pom.xml (modifications)
README.md (update)
Implementation Details
Gating Logic (ManagedIdentityClient)