2

I'm trying to manually verify the signature in an S/MIME signed email with openssl as part of a homework. While I have the mail and can extract the chain of certificates, I'm failing to extract the actual signature of the email and verify that it matches the mail content and senders certificate.

I have the public key of the signer (the last certificate) and I have the plaintext, which I got with

openssl smime -verify -in <mail> -noverify -out mail_body.txt

I also get the pk7 structure from the mail with

openssl smime pk7out -in <mail> -text -out certs.p7s

and dump the chain of certs

openssl pkcs7 -in certs.p7s -print_certs -text -out certs.pem

From this I get the certificate of the signer and his public key (Just copied the base64 begin/end certificate and

openssl x509 -pubkey -in signer.crt -out signer.key

If I understand correctly now I need the encrypted signed hash, decrypt it with the signer public key and check that with the hash of mail_body.txt but I can't find the signature in the mail.

  • I'm not sure if I really understand your problem. The signature of the message should be contained in the mail. It will be automatically used - unless you explicitly give the -noverify option which you do for unknown reason. – Steffen Ullrich May 21 at 20:57
  • @SteffenUllrich I'm trying to verify it explicitly, getting the key, decrypting the signature and checking the hash, checking also the chain of certificates, etc. Of course If I use just run smime -verify I get that it is successful – Aram May 21 at 20:59
  • So you are asking us to show where in your specific mail the signature is or do you ask us to point you to the standard where you can see how the signature can be stored in general? There can be two ways how the signature can be stored: detached and embedded. It is unclear what is the case with your specific message. See RFC 8551 for more details. – Steffen Ullrich May 21 at 21:10
  • @SteffenUllrich I guess its embedded since its just one file, gonna read the RFC more thoroughly then.. I'll also edit my post because maybe its unclear what I'm doing. – Aram May 21 at 21:14
  • 2
    @SteffenUllrich: actually openssl smime -verify -noverify only suppresses validation (aka verification) of the signer's cert against its chain and the truststore; it still verifies the signature in SignerInfo against the message, and only -nosigs suppresses the latter. – dave_thompson_085 May 22 at 0:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.