mtrojnar / osslsigncode

OpenSSL based Authenticode signing for PE/MSI/Java CAB files
Other
770 stars 128 forks source link

Failed Timestamp validation in verify #243

Closed marcosdiazr closed 1 year ago

marcosdiazr commented 1 year ago

when running osslsigncode verify -in wpbbin.exe -CAfile verisign.cer -TSA-CAfile thawte.cer files.zip

(attached the binary and the root certificates that should validate it)

Expected: to get successful validation Actual:

CMS_verify error
00E4660D7A7F0000:error:1700006B:CMS routines:cms_get_enveloped_type:content type not enveloped data:../crypto/cms/cms_env.c:41:
00E4660D7A7F0000:error:02000068:rsa routines:ossl_rsa_verify:bad signature:../crypto/rsa/rsa_sign.c:430:
00E4660D7A7F0000:error:1C880004:Provider routines:rsa_verify:RSA lib:../providers/implementations/signature/rsa_sig.c:774:
00E4660D7A7F0000:error:1700009E:CMS routines:CMS_SignerInfo_verify:verification failure:../crypto/cms/cms_sd.c:899:
Timestamp Server Signature verification: failed

PKCS7_verify error
00E4660D7A7F0000:error:10800075:PKCS7 routines:PKCS7_verify:certificate verify error:../crypto/pkcs7/pk7_smime.c:293:Verify error: certificate has expired
Signature verification: failed

Number of verified signatures: 1
Failed

fullerror.txt

I expect it to pass because If I validate the attached binary with signtool: signtool.exe verify /pa /v .\wpbbin.exe I get successful validation. The root certs I exported from windows itself.

Notes: This is an scenario where both the signing certificates and the timestamp server root certs are expired, signtool validates that, but I tested other binaries and using the -time parameter and it works ok.

This might probably be an issue with this file's signatures plus how openssl validates it but maybe there is something in osslsign code too.

I checked these are the correct certificates because if i change them I get different errors.

This error: 00E4660D7A7F0000:error:1700006B:CMS routines:cms_get_enveloped_type:content type not enveloped data:../crypto/cms/cms_env.c:41: looks like is always generated so probably is something that doesn't gets cleaned in openssl

I original thought that it might be that osslsigncode doesn't pass all the intermediate certs for the timestamp server. But the error is different if it doesn't find the correct cert.

Maybe if you can help me to extract the signature to check with openssl

mtrojnar commented 1 year ago

The Microsoft's digital signature verification accepts signatures created with invalid padding. Microsoft has acknowledged the bug, but they are not going to fix it.

I'm not going to introduce the bug either. Consequently, a small fraction of signatures accepted by Microsoft will be rejected by osslsigncode.

marcosdiazr commented 1 year ago

Thanks! do you have more info on Microsoft's issue that can lead me to investigate?