azure-sdk-for-java: [BUG] jarsigner + jca unable to retrieve certificate chain for signing

Describe the bug When using a valid, DigiCert issued, non-exportable Azure Key Vault certificate to sign a .jar file with jarsigner + jca 2.10.0, the certificate chain retrieval appears to fail. Referencing : #41303

The trace below shows a repeat loop of “getCertificateChain”, but this might be in reference to each item in the chain: Signer > Intermediate > Root

Exception or Stack Trace

INFO: Using Azure Key Vault: https://xxx.vault.azure.net/
Feb 07, 2025 3:28:01 PM com.azure.security.keyvault.jca.implementation.utils.AccessTokenUtil getLoginUri
INFO: Getting login URI using: https://xxx.vault.azure.net/certificates?api-version=7.1
Feb 07, 2025 3:28:02 PM com.azure.security.keyvault.jca.implementation.utils.AccessTokenUtil getLoginUri
INFO: Obtained login URI: https://login.microsoftonline.com/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Feb 07, 2025 3:28:02 PM com.azure.security.keyvault.jca.implementation.utils.AccessTokenUtil getAccessToken
INFO: Getting access token using client ID / client secret
Feb 07, 2025 3:28:03 PM com.azure.security.keyvault.jca.implementation.KeyVaultClient getKey
INFO: Getting key for alias: Code-Signing
Feb 07, 2025 3:28:03 PM com.azure.security.keyvault.jca.implementation.KeyVaultClient getCertificate
INFO: Getting certificate for alias: Code-Signing
Feb 07, 2025 3:28:03 PM com.azure.security.keyvault.jca.implementation.KeyVaultClient getCertificateChain
INFO: Getting certificate chain for alias: Code-Signing
Feb 07, 2025 3:28:03 PM com.azure.security.keyvault.jca.implementation.KeyVaultClient <init>
INFO: Using Azure Key Vault: https://xxx.vault.azure.net/
Feb 07, 2025 3:28:03 PM com.azure.security.keyvault.jca.implementation.utils.AccessTokenUtil getLoginUri
INFO: Getting login URI using: https://xxx.vault.azure.net/certificates?api-version=7.1
Feb 07, 2025 3:28:03 PM com.azure.security.keyvault.jca.implementation.utils.AccessTokenUtil getLoginUri
INFO: Obtained login URI: https://login.microsoftonline.com/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Feb 07, 2025 3:28:03 PM com.azure.security.keyvault.jca.implementation.utils.AccessTokenUtil getAccessToken
INFO: Getting access token using client ID / client secret
Feb 07, 2025 3:28:04 PM com.azure.security.keyvault.jca.implementation.KeyVaultClient getKey
INFO: Getting key for alias: Code-Signing
Feb 07, 2025 3:28:04 PM com.azure.security.keyvault.jca.implementation.KeyVaultClient getCertificate
INFO: Getting certificate for alias: Code-Signing
Feb 07, 2025 3:28:04 PM com.azure.security.keyvault.jca.implementation.KeyVaultClient getCertificateChain
INFO: Getting certificate chain for alias: Code-Signing
Feb 07, 2025 3:28:04 PM com.azure.security.keyvault.jca.implementation.KeyVaultClient <init>
INFO: Using Azure Key Vault: https://xxx.vault.azure.net/
Feb 07, 2025 3:28:04 PM com.azure.security.keyvault.jca.implementation.utils.AccessTokenUtil getLoginUri
INFO: Getting login URI using: https://xxx.vault.azure.net/certificates?api-version=7.1
Feb 07, 2025 3:28:04 PM com.azure.security.keyvault.jca.implementation.utils.AccessTokenUtil getLoginUri
INFO: Obtained login URI: https://login.microsoftonline.com/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Feb 07, 2025 3:28:04 PM com.azure.security.keyvault.jca.implementation.utils.AccessTokenUtil getAccessToken
INFO: Getting access token using client ID / client secret
Feb 07, 2025 3:28:05 PM com.azure.security.keyvault.jca.implementation.KeyVaultClient getKey
INFO: Getting key for alias: Code-Signing
Feb 07, 2025 3:28:05 PM com.azure.security.keyvault.jca.implementation.KeyVaultClient getCertificate
INFO: Getting certificate for alias: Code-Signing
Feb 07, 2025 3:28:05 PM com.azure.security.keyvault.jca.implementation.KeyVaultClient getCertificateChain
INFO: Getting certificate chain for alias: Code-Signing
jarsigner error: java.lang.RuntimeException: unable to instantiate keystore class: AZUREKEYVAULT not found

To Reproduce Create a non-exportable code signing certificate from Azure Key Vault (RSA-HSM, 4096) Sign the CSR through DigiCert Merge the signing request with Azure Key Vault Configure the app registration with secret, along with RBAC on Azure Key Vault for access Install Amazon Corretto 17.0.14.7.1 on Windows Open Powershell and run the Code Snippet below (With variables populated)

Code Snippet

jarsigner `
-keystore NONE `
-storetype AzureKeyVault `
-signedjar signed.jar D:\Cert-Sign\tosign.jar Code-Signing `
-verbose `
-storepass ' ' `
-tsa http://timestamp.digicert.com `
-providerName AzureKeyVault `
-providerClass com.azure.security.keyvault.jca.KeyVaultJcaProvider `
"-J--module-path=${PARAM_JCA_PROVIDER_JAR_PATH}" `
"-J--add-modules=com.azure.security.keyvault.jca" `
"-J-Dazure.keyvault.uri=${KEYVAULT_URL}" `
"-J-Dazure.keyvault.tenant-id=${TENANT}" `
"-J-Dazure.keyvault.client-id=${CLIENT_ID}" `
"-J-Dazure.keyvault.client-secret=${CLIENT_SECRET}"

Expected behavior The Jar file should be signed using the code signing certificate held in Azure.

Setup (please complete the following information):

  • OS: Windows
  • IDE: N/A
  • Library/Libraries: com.azure:azure-security-keyvault-jca:2.10.0
  • Java version: Amazon Corretto 17.0.14.7.1
  • App Server/Environment: N/A
  • Frameworks: N/A

Additional context I was able to sign a JAR with jca 2.8.2, but I experienced the exact same issue described in Issue: #41832, which should have been fixed in release 2.10.0 via #41303

Note that the validation tests use a “pkcs12-non-exportable-key.pfx” file, however pem/pfx cannot be exported from azure key vault when the certificate is generated with a non-exportable private key - Only the CER file can be exported from azure key vault.

Using jca 2.10.0, the call dies at “INFO: Getting certificate chain for alias: Code-Signing” with “unable to instantiate keystore class: AZUREKEYVAULT not found”

Information Checklist Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report

  • Bug Description Added
  • Repro Steps Added
  • Setup information Added

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 26 (10 by maintainers)

Most upvoted comments

Hi @moarychan,

  1. Only 1.3.6.1.5.5.7.3.3 was used to generate the CSR from Azure Key Vault- This was suggested by DigiCert support.
  2. The full .PEM downloaded from DigiCert only reflects “Code Signing”
X509v3 Extended Key Usage: 
                Code Signing

Hi @saragluna,

Unfortunately this is a Corporate vault and certificate - current security policies prohibit any kind of external sharing as this vault contains company data. If there are any tests you would like me to complete, please let me know. I am able to re-generate the CSR from Azure Key Vault and perform a re-issue of the existing certificate through DigiCert freely.

I have an update to this issue and have a workaround using:

  • Amazon Corretto 21.0.6.7
  • JCA azure-security-keyvault-jca: 2.10.0

Azure Key Vault least privileged roles for the Service Principal:

  • Key Vault Reader
  • Key Vault Certificate User
  • Key Vault Crypto User

TLDR I believe there is an issue with how the JCA 2.10 module retrieves the signed certificate from Azure Key Vault and how it parses the certificate chain based on what signed request is merged back into the vault during the certificate signing process. If a single CRT is merged back into the key vault, JCA will not read the certificate chain. If a PEM file containing the full chain is merged back into the key vault, JCA will read the chain in reverse and attempt to sign with the root certificate. (Merging a PEM with the certificates reversed has no impact on this problem).

To fix this, I merge the single CRT back into azure key vault, download the PEM file separately, and call the PEM file in the jarsigner command with the -certchain flag. END TLDR

When the CSR is generated in Azure Key Vault and signed by DigiCert, the signed request can be downloaded from the DigiCert portal in a number of various formats to be merged back into the Azure Key Vault. I have tested merging with two different formats:

  • Best format for FIPS 140-2 Level 2 or Common Criteria EAL4+ - This is the recommended download format suggested by a number of existing blogs. DigiCert will provide a .zip file containing each of the individual CRT files (Signer, Intermediate, Root).

    • When the “company_llc” CRT file is merged back into Azure Key Vault, JCA module is able to sign JAR files, however the certificate chain is not able to be retrieved.

    • The certificate will be signed, but only with the signer certificate:

>>> Signer
    X.509, CN=xxx, O=xxx, L=xxx, ST=xxx, C=US
    Signature algorithm: SHA256withRSA, 4096-bit key
    [trusted certificate]
>>> TSA
    X.509, CN=DigiCert Timestamp 2024, O=DigiCert, C=US
    Signature algorithm: SHA256withRSA, 4096-bit key
    [certificate is valid from 9/25/24, 8:00?PM to 11/25/35, 6:59?PM]
    X.509, CN=DigiCert Trusted G4 RSA4096 SHA256 TimeStamping CA, O="DigiCert, Inc.", C=US
    Signature algorithm: SHA256withRSA, 4096-bit key
    [certificate is valid from 3/22/22, 8:00?PM to 3/22/37, 7:59?PM]
    X.509, CN=DigiCert Trusted Root G4, OU=www.digicert.com, O=DigiCert Inc, C=US
    Signature algorithm: SHA384withRSA, 4096-bit key
    [certificate is valid from 7/31/22, 8:00?PM to 11/9/31, 6:59?PM]

jar signed.

The timestamp will expire on 2031-11-09.

- Signed by "CN=xxx, O=xxx, L=xxx, ST=xxx, C=US"
    Digest algorithm: SHA-384
    Signature algorithm: SHA512withRSA, 4096-bit key
  Timestamped by "CN=DigiCert Timestamp 2024, O=DigiCert, C=US" on Wed Feb 26 20:05:36 UTC 2025
    Timestamp digest algorithm: SHA-384
    Timestamp signature algorithm: SHA384withRSA, 4096-bit key

jar verified.

Warning: 
This jar contains entries whose certificate chain is invalid. Reason: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
  • A single .pem file containing all the certs - This download format can also be downloaded and merged back with the Azure Key Vault.

    • When this single .pem file is merged back into Azure Key Vault, JCA module is able to detect the certificate chain, however, reads the chain in reverse and attempts to utilize the Root CA to sign the JAR file.
- Signed by "CN=DigiCert Trusted Root G4, OU=www.digicert.com, O=DigiCert Inc, C=US"
    Digest algorithm: SHA-384
    Signature algorithm: SHA512withRSA, 4096-bit key
  Timestamped by "CN=DigiCert Timestamp 2024, O=DigiCert, C=US" on Wed Feb 19 16:55:26 UTC 2025
    Timestamp digest algorithm: SHA-384
    Timestamp signature algorithm: SHA384withRSA, 4096-bit key

WARNING: Signature is either not parsable or not verifiable, and the jar will be treated as unsigned. For more information, re-run jarsigner with debug enabled (-J-Djava.security.debug=jar).
  signing: oracle/apps/ad/worker/util/UtilInfo.class
  signing: oracle/apps/ad/worker/util/Utility.class

jar signed.

PS C:\Users\xxx> jarsigner -verify -verbose -certs D:\Cert-Sign\signerjar.jar
jarsigner: java.lang.SecurityException: cannot verify signature block file META-INF/xx-CODE

To resolve this issue, I have performed the following steps:

  1. Generate the CSR from Azure Key Vault
  2. Signed the CSR in DigiCert portal
  3. Download the signed certificate in format “Best format for FIPS 140-2 Level 2 or Common Criteria EAL4+”
  4. Extracted “company_llc.crt” from the .zip file and merged into Azure Key Vault
  5. Download the signed certificate in format “A single .pem file containing all the certs” and saved as “D:\Cert-Sign\chain.pem”
  6. Run the following - Note the use of: -certchain D:\Cert-Sign\chain.pem
jarsigner `
    -certchain D:\Cert-Sign\chain.pem `
    -keystore NONE `
    -storetype AzureKeyVault `
    -signedjar D:\Cert-Sign\signed.jar ${PARAM_YOUR_JAR_FILE_PATH} "${CERT_NAME}" `
    -verbose `
    -storepass '""' `
    -tsa http://timestamp.digicert.com `
    -providerName AzureKeyVault `
    -providerPath ${PARAM_JCA_PROVIDER_JAR_PATH} `
    -providerClass com.azure.security.keyvault.jca.KeyVaultJcaProvider `
    "-J-Dazure.keyvault.uri=${KEYVAULT_URL}" `
    "-J-Dazure.keyvault.tenant-id=${TENANT}" `
    "-J-Dazure.keyvault.client-id=${CLIENT_ID}" `
    "-J-Dazure.keyvault.client-secret=${CLIENT_SECRET}"

The output of the command:

  signing: oracle/apps/ame/transactionhistory/server/server.xml
  signing: oracle/apps/ame/transactionhistory/webui/TransactionHistoryCO.class

>>> Signer
    X.509, CN=xxx, O=xxx, L=xxx, ST=xxx, C=US
    Signature algorithm: SHA256withRSA, 4096-bit key
    [trusted certificate]
    X.509, CN=DigiCert Trusted G4 Code Signing RSA4096 SHA384 2021 CA1, O="DigiCert, Inc.", C=US
    Signature algorithm: SHA384withRSA, 4096-bit key
    [certificate is valid from 4/28/21, 8:00?PM to 4/28/36, 7:59?PM]
    X.509, CN=DigiCert Trusted Root G4, OU=www.digicert.com, O=DigiCert Inc, C=US
    Signature algorithm: SHA384withRSA, 4096-bit key
    [trusted certificate]
>>> TSA
    X.509, CN=DigiCert Timestamp 2024, O=DigiCert, C=US
    Signature algorithm: SHA256withRSA, 4096-bit key
    [certificate is valid from 9/25/24, 8:00?PM to 11/25/35, 6:59?PM]
    X.509, CN=DigiCert Trusted G4 RSA4096 SHA256 TimeStamping CA, O="DigiCert, Inc.", C=US
    Signature algorithm: SHA256withRSA, 4096-bit key
    [certificate is valid from 3/22/22, 8:00?PM to 3/22/37, 7:59?PM]
    X.509, CN=DigiCert Trusted Root G4, OU=www.digicert.com, O=DigiCert Inc, C=US
    Signature algorithm: SHA384withRSA, 4096-bit key
    [certificate is valid from 7/31/22, 8:00?PM to 11/9/31, 6:59?PM]

jar signed.

The signer certificate will expire on 2036-04-28.
The timestamp will expire on 2031-11-09.

Verification output:

sm       774 Tue Jan 01 04:01:00 EST 2002 oracle/apps/ame/transactionhistory/server/server.xml
sm      2297 Thu Jan 13 04:37:34 EST 2011 oracle/apps/ame/transactionhistory/webui/TransactionHistoryCO.class

  s = signature was verified 
  m = entry is listed in manifest
  k = at least one certificate was found in keystore

- Signed by "CN=xxx, O=xxx, L=xxx, ST=xxx, C=US"
    Digest algorithm: SHA-384
    Signature algorithm: SHA512withRSA, 4096-bit key
  Timestamped by "CN=DigiCert Timestamp 2024, O=DigiCert, C=US" on Wed Feb 26 20:40:37 UTC 2025
    Timestamp digest algorithm: SHA-384
    Timestamp signature algorithm: SHA384withRSA, 4096-bit key

jar verified.

The signer certificate will expire on 2026-02-05.
The timestamp will expire on 2031-11-09.

It would be nice if a single PEM file could be merged back into Azure Key Vault and used with jarsigner instead of the single CRT with -certchain specified in a separate .pem file.

Edit @Netyyyy I did not mean to click the “close this issue”. This is still an issue, however I have a workaround for now