Certificate generated through CSR signing with BouncyCastle considered untrusted

后端 未结 1 1322
甜味超标
甜味超标 2021-01-03 13:25

I am struggling with the following issue:

I have a CSR which I am signing with this code:

@Override
public X509Certificate signCSR( Reader pemcsr, in         


        
相关标签:
1条回答
  • 2021-01-03 13:42

    If you look at the Issuer DN in your two certificates, they don't match (output from openssl x509 -text):

    Issuer: C=AT, ST=Wien, L=Wien, O=Test CA, OU=Test CA, CN=Test CA/emailAddress=testca@testca.com
    

    and

    Issuer: emailAddress=testca@testca.com, CN=Test CA, OU=Test CA, O=Test CA, L=Wien, ST=Wien, C=AT
    

    As a result, it's not going to be able to match the wrong issuer to the CA's Subject DN.

    Unfortunately, X500Name issuer = new X500Name(cacert.getSubjectX500Principal().getName()) doesn't do what you'd expect. The order of the RDNs is reversed. Generally, re-building the DN from a string representation can fail, since there are different ways of serialising the ASN.1 representation into a string. Java's X500Principal has multiple formats available for getName(...) and it even provides a way to provide your own OID to string maps (for more obscure OIDs). The way emailAddress is separated can also cause problems (notice the way it's separated with a comma or with a slash).

    Instead, build the X500Name from the encoded form, this should always work:

    X500Name x500Name = X500Name.getInstance(cert
                            .getSubjectX500Principal().getEncoded());
    
    0 讨论(0)
提交回复
热议问题