azure-sdk-for-java: [BUG] jarsigner + jca reports that entries in certificate chain are invalid

Describe the bug

When using a valid, DigiCert issued, non-exportable Azure Key Vault certificate to sign a .jar file with jarsigner + jca 2.8.2 OR jarsigner + jca 2.9.0-beta.3, the file is signed with apparently no issues.

>>> Signer
    X.509, CN=██████████ Limited, O=██████████ Limited, L=London, C=GB
    [trusted certificate]

jar signed.

However, upon verifying the file, a warning is produced:

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

This prevents the jar file to run on high-security systems, and we are unable to run the applications.

Exception or Stack Trace

jca282_signing.log jca282_verify.log jca282_environment.log

jca290_signing.log jca290_verify.log jca290_environment.log

To Reproduce

Steps to reproduce the behavior:

  1. Sign a JAR file with jarsigner and azure-security-keyvault-jca-2.8.2.jar (or 2.9.0-beta.3), with a valid certificate issued by DigiCert and stored in AzKV.

    $ jarsigner -keystore NONE -storetype AzureKeyVault \
            -signedjar SIGNED_SignMe.jar SignMe.jar "██████████CodeSigning" \
            -verbose -storepass "" \
            -tsa "http://timestamp.digicert.com/" \
            -providerName AzureKeyVault \
            -providerClass com.azure.security.keyvault.jca.KeyVaultJcaProvider \
            -J-Dazure.keyvault.uri="██████████" \
            -J-Dazure.keyvault.tenant-id="██████████" \
            -J-Dazure.keyvault.client-id="██████████" \
            -J-Dazure.keyvault.client-secret="██████████" 
    [lines omitted]
    >>> Signer
        X.509, CN=██████████ Limited, O=██████████ Limited, L=London, C=GB
        [trusted certificate]
    
    jar signed.
    
  2. Verify it’s signature

        $ jarsigner -verify SIGNED_SignMe.jar 
    
        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
    
    

Expected behavior There .jar should be signed, and there should be no warnings when verifying the signature.

Screenshots image

Setup (please complete the following information):

  • OS: (containerized) Red Hat Enterprise Linux release 8.10 (Ootpa)
  • IDE: N/A
  • Library/Libraries:
    • com.azure:azure-security-keyvault-jca:2.8.2
    • com.azure:azure-security-keyvault-jca:2.9.0-beta.3 (built from rev ac9ee6330b6)
  • Java version: openjdk-1.8.0_422
  • App Server/Environment: N/A
  • Frameworks: N/A

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: closed
  • Created 2 years ago
  • Comments: 38 (20 by maintainers)

Most upvoted comments

JCA 2.10.0 is available on Maven Central, please try it! Thanks!

@dacron Our plan updated. Here is the new plan:

  1. Release 2.10.0 around the end of this month.
  2. No patch release (2.9.1).

@dacron Sorry, my mistake. It should be this one: https://github.com/Azure/azure-sdk-for-java/pull/41303

Hi, @3millionminds

Good news: I reproduced this issue and fixed it.

1. Reproduce this issue.

1.1. Create a certificate in Azure Portal by configurations like this:

Image

1.2. Download csr from Azure Portal, then upload to by DigiCert: https://www.digicert.com/, sign it.

Image

1.3. Download the .crt (best for Apache / Linux) from DigiCert, then upload to Azure Portal.

Image

Image

1.4. Use it to sign and verify, problem reproduced.

2. Fix it

2.1. In step 1.3, download A single .pem file contains all certs instead of .crt (best for Apache / Linux)

Image

Image

2.2. Other steps same to step 1. Problem solved.

We have also hit this with a non-exportable HSM backed key. We have reissued the certificate multiple times and merged bundles in to new versions of KV certificates:

  1. leaf
  2. leaf -> intermediate
  3. leaf -> intermediate -> root.

With just the leaf we can sign but it is not trusted until we add the intermediate in to the cacerts store. With scenarios 2 and 3 jarsigner reports that everything is signed successfully, but verify says otherwise:

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).

With the debug enabled:

jar: beginEntry META-INF/MANIFEST.MF
jar: beginEntry META-INF/2024OVCS.SF
jar: processEntry: processing block
jar: beginEntry META-INF/2024OVCS.RSA
jar: processEntry: processing block
jar: Unsupported signer attribute: 1.2.840.113549.1.9.16.2.47
jar:
jar: Detected signature timestamp (#00:dc:50:89:c6:24:67:a6:ed:80:1e:ac:ca:90:98:99:45) generated on Fri Sep 27 16:14:05 BST 2024
jar:
jar: processEntry caught: java.security.SignatureException: Bad signature length: got 384 but was expecting 512
jar: done with meta!
jar: nothing to verify!
jar: Unsupported signer attribute: 1.2.840.113549.1.9.16.2.47

Our intermediate CA is DigiCert Trusted G4 Code Signing RSA4096 SHA384 2021 CA1 and the root is DigiCert Trusted Root G4

HI @3millionminds, thank you for filing this issue, I’ll pass it along to the team.

@saragluna, @rujche Could you take a look when you get a chance? Thanks!