Mismatch in keytool and openssl certificate fingerprint

时光毁灭记忆、已成空白 提交于 2019-12-01 09:07:30

The different SHA1 fingerprints are caused by different encodings of the code signing certificate.

The first fingerprint (by keytool) is calculated over the certificate bytes exactly as they are contained in the PKCS#7 file META-INF/CERT.RSA. The length of the signature (of the certificate, not the signature of the code) is encoded here in two bytes, where actually one byte would be enough. To see this we have to take a look at the ASN.1 dump of CERT.RSA. There are several programs that can do this, but I recommend Peter Gutmann's dumpasn1/GUIdumpASN. The relevant part is this:

    <06 09>
532   9:             OBJECT IDENTIFIER
       :               sha1WithRSAEncryption (1 2 840 113549 1 1 5)
    <05 00>
543   0:             NULL
       :             }
    <03 82 00 81>
545 129:           BIT STRING    
       :             65 26 30 0C 41 32 63 75    e&0.A2cu
       :             2F B7 DF 9A 96 37 72 1B    /....7r.

The bytes 82 00 81 are the length bytes of the BITSTRING (which is the signature of the certificate) encoded in the long form.

According to the Distinguished Encoding Rules DER the "shortest possible length encoding must be used", which would have been 81 81. This means that the code signing certificate is not completely DER encoded.

When you exported the certificate with openssl, it re-encoded the certificate to valid DER:

    <03 81 81>
489 129:   BIT STRING    
        :     65 26 30 0C 41 32 63 75    e&0.A2cu
        :     2F B7 DF 9A 96 37 72 1B    /....7r. 

Therefore the hash value (fingerprint) of the certificate is different, it has changed.

Neither keytool nor openssl did something wrong. The point of DER encoding is that it generates always exactly the same byte representation of ASN.1 structures.

The software that caused this issue is the tool the faulty code signing certificate was created with.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!