I have a very strange problem and i would like to get some guidance on this. Problem description: My application is sending S/MIME signed Email messages to clients. It worked perfectly no problems were reported and also in my mail client and with openssl i could verify the S/MIME Signature. Now something odd happened: When sending a large number of mails (200k) some users reported the email signature seems to be invalid. One of the users sent me the mail as an .eml and i tried to verify the signature with openssl.
openssl smime -verify -in invalidSignature.eml -noverify
Output:
408160FD01000000:error:10800065:PKCS7 routines:PKCS7_signatureVerify:digest failure:crypto/pkcs7/pk7_doit.c:1089:
408160FD01000000:error:10800069:PKCS7 routines:PKCS7_verify:signature failure:crypto/pkcs7/pk7_smime.c:363:
The .eml also appears with an invalid signature in my email clients. So the problems seems to be the message digest. Users are also reporting, if they are clicking on the certificate itself the certificate appears to be valid.
So i compared the invalidSignature.eml to a successfullMail.eml and the mails are exactly the same. The only difference is the signature and the boundary numbers. I cannot explain to myself how this happened the problem is i cannot replicate this issue.
I know this is a very broad question but can somebody of you provide some guidance on how to debug this? The problem is im 100% sure this is about my application or the mail system and not some malicious activity. Maybe somebody has experience with troubleshooting such issues and can provide guidance. Thank you
Edit: I made some wrong assumptions. I think my solution may still provide value to some people: The problem was in the S/MIME implementation i signed the subject header as well. The odd thing is it seems like in 90% of cases this actually works and most mail clients will indeed verify the signature. However some very special subject headers break the signature. I still cannot figure out what's exactly causing this, but in general i read up about the topic and the subject header shouldn't be signed. Thanks for your help!
cms -cmsout -print
is indeed a good way to see the messageDigest attribute (in signedAttrs in signerInfos), and if it is different then the data in those messages IS DIFFERENT even if they LOOK the same or compare 'equal' – dave_thompson_085 Nov 15 '23 at 22:39