Support intermediate certs in keyvault jca - #41303
Conversation
|
/azp run java - keyvault - tests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
API change check APIView has identified API level changes in this PR and created following API reviews. |
|
The failure of Screenshot: Hi, Vinay Gera (@g2vinay) . |
|
The whole process of verify:
$ keytool -import -alias rootCA -keystore "C:\Program Files\Microsoft\jdk-17.0.11.9-hotspot\lib\security\cacerts" -file myCA/rootCA/certs/ca.cert.pem
Warning: use -cacerts option to access cacerts keystore
Enter keystore password: xxx
Owner: CN=Root CA, OU=IT Department, O=Example Corp, L=Sam Francisco, ST=California, C=US
Issuer: CN=Root CA, OU=IT Department, O=Example Corp, L=Sam Francisco, ST=California, C=US
Serial number: 24bb2a6692662129063fd2cf572da11c634ee489
Valid from: Wed Jul 24 21:02:30 CST 2024 until: Tue Jul 19 21:02:30 CST 2044
Certificate fingerprints:
SHA1: CD:46:CB:C0:8C:A6:D0:CF:AB:C1:31:11:FA:67:24:37:70:B7:8D:A2
SHA256: DC:F8:58:89:0B:9D:AE:7A:0F:33:AD:03:85:C9:F4:BC:9C:F0:8E:69:2E:98:D5:C7:43:31:09:DF:B1:8D:55:7D
Signature algorithm name: SHA256withRSA
Subject Public Key Algorithm: 4096-bit RSA key
Version: 3
Extensions:
#1: ObjectId: 2.5.29.35 Criticality=false
AuthorityKeyIdentifier [
KeyIdentifier [
0000: 0C C7 9E BC D0 DE EE 00 99 2C F8 20 5D 94 35 14 .........,. ].5.
0010: BE 63 88 52 .c.R
]
]
#2: ObjectId: 2.5.29.19 Criticality=true
BasicConstraints:[
CA:true
PathLen: no limit
]
#3: ObjectId: 2.5.29.15 Criticality=true
KeyUsage [
Key_CertSign
Crl_Sign
]
#4: ObjectId: 2.5.29.14 Criticality=false
SubjectKeyIdentifier [
KeyIdentifier [
0000: 0C C7 9E BC D0 DE EE 00 99 2C F8 20 5D 94 35 14 .........,. ].5.
0010: BE 63 88 52 .c.R
]
]
Trust this certificate? [no]: yes
Certificate was added to keystore
$ jarsigner \
-keystore NONE \
-storetype AzureKeyVault \
-signedjar signedjar.jar \
unsigned.jar pfxchain \
-verbose \
-storepass "" \
-providerName AzureKeyVault \
-providerClass com.azure.security.keyvault.jca.KeyVaultJcaProvider \
-J--module-path="." \
-J--add-modules="com.azure.security.keyvault.jca" \
-J-Dazure.keyvault.uri=https://rujchekeyvault.vault.azure.net/ \
-J-Dazure.keyvault.tenant-id=xxx \
-J-Dazure.keyvault.client-id=xxx \
-J-Dazure.keyvault.client-secret=xxx
Jul 30, 2024 10:01:55 AM com.azure.security.keyvault.jca.implementation.KeyVaultClient <init>
INFO: Using Azure Key Vault: https://rujchekeyvault.vault.azure.net/
Jul 30, 2024 10:01:55 AM com.azure.security.keyvault.jca.implementation.utils.AccessTokenUtil getLoginUri
INFO: Getting login URI using: https://rujchekeyvault.vault.azure.net/certificates?api-version=7.1
Jul 30, 2024 10:01:57 AM com.azure.security.keyvault.jca.implementation.utils.AccessTokenUtil getLoginUri
INFO: Obtained login URI: https://login.microsoftonline.com/4c144ff2-e2e0-49b2-8dcf-00fb87794406
Jul 30, 2024 10:01:57 AM com.azure.security.keyvault.jca.implementation.utils.AccessTokenUtil getAccessToken
INFO: Getting access token using client ID / client secret
Jul 30, 2024 10:01:59 AM com.azure.security.keyvault.jca.implementation.KeyVaultClient getKey
INFO: Getting key for alias: pfxchain
Jul 30, 2024 10:02:01 AM com.azure.security.keyvault.jca.implementation.KeyVaultClient getCertificate
INFO: Getting certificate for alias: pfxchain
Jul 30, 2024 10:02:02 AM com.azure.security.keyvault.jca.implementation.KeyVaultClient getCertificateChain
INFO: Getting certificate chain for alias: pfxchain
Jul 30, 2024 10:02:04 AM com.azure.security.keyvault.jca.implementation.KeyVaultClient <init>
INFO: Using Azure Key Vault: https://rujchekeyvault.vault.azure.net/
Jul 30, 2024 10:02:04 AM com.azure.security.keyvault.jca.implementation.utils.AccessTokenUtil getLoginUri
INFO: Getting login URI using: https://rujchekeyvault.vault.azure.net/certificates?api-version=7.1
Jul 30, 2024 10:02:05 AM com.azure.security.keyvault.jca.implementation.utils.AccessTokenUtil getLoginUri
INFO: Obtained login URI: https://login.microsoftonline.com/4c144ff2-e2e0-49b2-8dcf-00fb87794406
Jul 30, 2024 10:02:05 AM com.azure.security.keyvault.jca.implementation.utils.AccessTokenUtil getAccessToken
INFO: Getting access token using client ID / client secret
Jul 30, 2024 10:02:06 AM com.azure.security.keyvault.jca.implementation.KeyVaultClient getKey
INFO: Getting key for alias: pfxchain
Jul 30, 2024 10:02:08 AM com.azure.security.keyvault.jca.implementation.KeyVaultClient getCertificate
INFO: Getting certificate for alias: pfxchain
Jul 30, 2024 10:02:09 AM com.azure.security.keyvault.jca.implementation.KeyVaultClient getCertificateChain
INFO: Getting certificate chain for alias: pfxchain
Jul 30, 2024 10:02:11 AM com.azure.security.keyvault.jca.implementation.KeyVaultClient <init>
INFO: Using Azure Key Vault: https://rujchekeyvault.vault.azure.net/
Jul 30, 2024 10:02:11 AM com.azure.security.keyvault.jca.implementation.utils.AccessTokenUtil getLoginUri
INFO: Getting login URI using: https://rujchekeyvault.vault.azure.net/certificates?api-version=7.1
Jul 30, 2024 10:02:12 AM com.azure.security.keyvault.jca.implementation.utils.AccessTokenUtil getLoginUri
INFO: Obtained login URI: https://login.microsoftonline.com/4c144ff2-e2e0-49b2-8dcf-00fb87794406
Jul 30, 2024 10:02:12 AM com.azure.security.keyvault.jca.implementation.utils.AccessTokenUtil getAccessToken
INFO: Getting access token using client ID / client secret
Jul 30, 2024 10:02:13 AM com.azure.security.keyvault.jca.implementation.KeyVaultClient getKey
INFO: Getting key for alias: pfxchain
Jul 30, 2024 10:02:16 AM com.azure.security.keyvault.jca.implementation.KeyVaultClient getCertificate
INFO: Getting certificate for alias: pfxchain
Jul 30, 2024 10:02:17 AM com.azure.security.keyvault.jca.implementation.KeyVaultClient getCertificateChain
INFO: Getting certificate chain for alias: pfxchain
updating: META-INF/MANIFEST.MF
adding: META-INF/PFXCHAIN.SF
adding: META-INF/PFXCHAIN.RSA
signing: META-INF/native-image/com.azure/azure-security-keyvault-keys/proxy-config.json
signing: META-INF/native-image/com.azure/azure-security-keyvault-keys/reflect-config.json
signing: META-INF/native-image/com.azure/azure-security-keyvault-keys/resource-config.json
signing: META-INF/maven/com.azure/azure-security-keyvault-keys/pom.xml
signing: META-INF/maven/com.azure/azure-security-keyvault-keys/pom.properties
adding: com/
adding: com/azure/
adding: com/azure/security/
adding: com/azure/security/keyvault/
adding: com/azure/security/keyvault/keys/
adding: com/azure/security/keyvault/keys/cryptography/
adding: com/azure/security/keyvault/keys/cryptography/implementation/
adding: com/azure/security/keyvault/keys/cryptography/models/
adding: com/azure/security/keyvault/keys/implementation/
adding: com/azure/security/keyvault/keys/implementation/models/
adding: com/azure/security/keyvault/keys/models/
signing: azure-key-vault-keys.properties
signing: com/azure/security/keyvault/keys/cryptography/CryptographyAsyncClient.class
...
signing: com/azure/security/keyvault/keys/models/ReleaseKeyResult.class
signing: module-info.class
>>> Signer
X.509, CN=signer, OU=IT Department, O=Example Corp, L=San Francisco, ST=California, C=US
Signature algorithm: SHA256withRSA, 4096-bit key
[trusted certificate]
X.509, CN=Intermediate CA, OU=IT Department, O=Example Corp, ST=California, C=US
Signature algorithm: SHA256withRSA, 4096-bit key
[certificate is valid from 24/07/2024, 9:03 pm to 22/07/2034, 9:03 pm]
X.509, CN=Root CA, OU=IT Department, O=Example Corp, L=Sam Francisco, ST=California, C=US
Signature algorithm: SHA256withRSA, 4096-bit key
[trusted certificate]
jar signed.
Warning:
No -tsa or -tsacert is provided and this jar is not timestamped. Without a timestamp, users may not be able to validate this jar after the signer certificate's expiration date (2034-07-22).
The signer certificate will expire on 2034-07-22.
$ jarsigner -verify -verbose -certs signedjar.jar
s 26366 Tue Jul 30 10:02:18 CST 2024 META-INF/MANIFEST.MF
>>> Signer
X.509, CN=signer, OU=IT Department, O=Example Corp, L=San Francisco, ST=California, C=US
Signature algorithm: SHA256withRSA, 4096-bit key
[certificate is valid from 25/07/2024, 10:21 am to 23/07/2034, 10:21 am]
X.509, CN=Intermediate CA, OU=IT Department, O=Example Corp, ST=California, C=US
Signature algorithm: SHA256withRSA, 4096-bit key
[certificate is valid from 24/07/2024, 9:03 pm to 22/07/2034, 9:03 pm]
X.509, CN=Root CA, OU=IT Department, O=Example Corp, L=Sam Francisco, ST=California, C=US
Signature algorithm: SHA256withRSA, 4096-bit key
[trusted certificate]
26349 Tue Jul 30 10:02:18 CST 2024 META-INF/PFXCHAIN.SF
5428 Tue Jul 30 10:02:18 CST 2024 META-INF/PFXCHAIN.RSA
0 Tue Jul 23 21:54:28 CST 2024 META-INF/
0 Tue Jul 23 21:54:04 CST 2024 META-INF/native-image/
0 Tue Jul 23 21:54:04 CST 2024 META-INF/native-image/com.azure/
0 Tue Jul 23 21:54:04 CST 2024 META-INF/native-image/com.azure/azure-security-keyvault-keys/
0 Tue Jul 23 21:54:28 CST 2024 META-INF/maven/
0 Tue Jul 23 21:54:28 CST 2024 META-INF/maven/com.azure/
0 Tue Jul 23 21:54:28 CST 2024 META-INF/maven/com.azure/azure-security-keyvault-keys/
0 Tue Jul 23 21:54:10 CST 2024 com/
0 Tue Jul 23 21:54:10 CST 2024 com/azure/
0 Tue Jul 23 21:54:10 CST 2024 com/azure/security/
0 Tue Jul 23 21:54:10 CST 2024 com/azure/security/keyvault/
0 Tue Jul 23 21:54:14 CST 2024 com/azure/security/keyvault/keys/
0 Tue Jul 23 21:54:14 CST 2024 com/azure/security/keyvault/keys/cryptography/
0 Tue Jul 23 21:54:14 CST 2024 com/azure/security/keyvault/keys/cryptography/implementation/
0 Tue Jul 23 21:54:12 CST 2024 com/azure/security/keyvault/keys/cryptography/models/
0 Tue Jul 23 21:54:14 CST 2024 com/azure/security/keyvault/keys/implementation/
0 Tue Jul 23 21:54:14 CST 2024 com/azure/security/keyvault/keys/implementation/models/
0 Tue Jul 23 21:54:14 CST 2024 com/azure/security/keyvault/keys/models/
sm 96 Tue Jun 11 15:21:16 CST 2024 META-INF/native-image/com.azure/azure-security-keyvault-keys/proxy-config.json
>>> Signer
X.509, CN=signer, OU=IT Department, O=Example Corp, L=San Francisco, ST=California, C=US
Signature algorithm: SHA256withRSA, 4096-bit key
[certificate is valid from 25/07/2024, 10:21 am to 23/07/2034, 10:21 am]
X.509, CN=Intermediate CA, OU=IT Department, O=Example Corp, ST=California, C=US
Signature algorithm: SHA256withRSA, 4096-bit key
[certificate is valid from 24/07/2024, 9:03 pm to 22/07/2034, 9:03 pm]
X.509, CN=Root CA, OU=IT Department, O=Example Corp, L=Sam Francisco, ST=California, C=US
Signature algorithm: SHA256withRSA, 4096-bit key
[trusted certificate]
...
sm 772 Tue Jul 23 21:54:28 CST 2024 module-info.class
>>> Signer
X.509, CN=signer, OU=IT Department, O=Example Corp, L=San Francisco, ST=California, C=US
Signature algorithm: SHA256withRSA, 4096-bit key
[certificate is valid from 25/07/2024, 10:21 am to 23/07/2034, 10:21 am]
X.509, CN=Intermediate CA, OU=IT Department, O=Example Corp, ST=California, C=US
Signature algorithm: SHA256withRSA, 4096-bit key
[certificate is valid from 24/07/2024, 9:03 pm to 22/07/2034, 9:03 pm]
X.509, CN=Root CA, OU=IT Department, O=Example Corp, L=Sam Francisco, ST=California, C=US
Signature algorithm: SHA256withRSA, 4096-bit key
[trusted certificate]
s = signature was verified
m = entry is listed in manifest
k = at least one certificate was found in keystore
- Signed by "CN=signer, OU=IT Department, O=Example Corp, L=San Francisco, ST=California, C=US"
Digest algorithm: SHA-256
Signature algorithm: SHA384withRSA, 4096-bit key
jar verified.
Warning:
This jar contains signatures that do not include a timestamp. Without a timestamp, users may not be able to validate this jar after any of the signer certificates expire (as early as 2034-07-22).
The signer certificate will expire on 2034-07-22.
$ keytool -delete -alias rootCA -keystore "C:\Program Files\Microsoft\jdk-17.0.11.9-hotspot\lib\security\cacerts"
Warning: use -cacerts option to access cacerts keystore
Enter keystore password: xxx
$ keytool -list -keystore "C:\Program Files\Microsoft\jdk-17.0.11.9-hotspot\lib\security\cacerts"
Warning: use -cacerts option to access cacerts keystore
Enter keystore password: xxx
|
…hed by java.util.ServiceLoader.
|
Hi, Xiaolu Dai (@saragluna) , please help to review this PR. |
|
Hi, Xiaolu Dai (@saragluna) , please help to review this PR. |
|
Any ETA on merging this? Thanks, |
|
I tried building this PR and looks like there's a problem still with signing. |
…t/.gitignore to sdk/keyvault/azure-security-keyvault-jca/.gitignore.
… module java.xml" by adding "requires java.xml" in module-info.java.
|
Hi, 3millionminds . Now the problem has been reproduced and fixed in f403bdf |
|
Rujun Chen (@rujche) - sorry to reopen this issue, but can you confirm that this PR was actually included in the 2.9.0 release? I don't see any reference to For reference, this is the commit: I think it'll be included in the 2.10.0 release? Any idea when we can expect this to show up in Maven? |
Hi, Ernie Costa (@eponerine) And of course, the bug fix will be included in 2.10.0. But now there is no plan about when to release 2.10.0. |
|
OK thank you very much. We'll keep our eyes open for the new release. Feel free to close this again. |
|
Hi, Ernie Costa (@eponerine) |


Description
Fix #39715, #39590
Reproduce the issue
root->intermediate->leaf). Refs: https://www.golinuxcloud.com/openssl-create-certificate-chain-linux/rootcert into${JAVA_HOME}/lib/security/cacerts.leaf-bundlebyleaf private key, leaf certificate, intermediate certificate, root certificate.download-from-keyvault.pemis just an example ofleaf-bundleleaf-bundleto Key Vault.leaf-bundle. Refs: 1. Integrate KeyVault JCA provider with Jarsigner, 2. jarsigner.This jar contains entries whose certificate chain is not validated..Confirm issue fixed
azure-security-keyvault-jca-2.9.0-beta.3.jarwith the changes in this PR.This jar contains entries whose certificate chain is not validated.) not exist anymore.About Key Vault endpoint
leaf-bundleto Key Vault, the certificate endpoint response (CertificateBundle#cer) only contains 1 certificate (theleafcertificate inleaf-bundle).leaf, intermediate, root).SecretBundle#valuehas 2 types:application/x-pem-fileandapplication/x-pkcs12. I added the response sample in this PR for test purpose:download-from-keyvault.pemanddownload-from-keyvault.pfx.txt.Why add dependency bcpkix-lts8on?
Please refer to 88dbeaf, without this commit, certificate chain in
SecretBundle.value/pkcs12-non-exportable-key.pfxcan not be loaded.Why add java.security.Provider
It's used to make KeyVaultJcaProvider can be searched by ServiceLoader. Refs: How to Implement a Provider
Why
exports com.azure.security.keyvault.jca.implementation.signature to java.base;?To fix #39590. Without this line, it will have error when create related instance. Here is the screenshot:
Confirmed that the issue will be fixed after
exports com.azure.security.keyvault.jca.implementation.signature to java.base.About test files
All test files in
src/test/resources/certificate-util/SecretBundle.valuefolder contain the (base64-encoded) text returned by (SecretBundle#value) endpoint.The 4 test files named by
pem/pkcs12andexportable/non-exportableare mapping to related configuration in Azure Portal. They are mainly used to test these kinds of certificates can be handled successfully.3-certificates-in-chain.pemand3-certificates-in-chain.pfx12are created manually, then upload to Azure Key Vault, then retrieved by (SecretBundle#value) endpoint. They have 3 certificates in certificate chain. They are mainly used to test all certificates in certificate chain can be loaded successfully.src/test/resources/certificate-util/downloaded-from-portalare downloaded from portalpem-exportable-key.pemandpem-non-exportable-key.pemunderdownloaded-from-portalfolder are identical the same-name files inSecretBundle.valuefolder.pkcs12-exportable-key.pfxandpkcs12-non-exportable-key.pfxunderdownloaded-from-portalare binary file. same-name files inSecretBundle.valuefolder are (base64-encoded) text files. So they are NOT identical.All SDK Contribution checklist:
General Guidelines and Best Practices
Testing Guidelines