Decoding an incoming email in Python, I have an attachment "smime.p7s". If I write this to a file, then it can be extracted and viewed using
openssl pkcs7 -inform der -print_certs <smime.p7s
I'd like to do that in Python. There's an example here of the inverse process, i.e. how to sign a mail.
Looking at the OpenSSL API documentation there is an entry point PKCS7_get0_signers
which seems to do this.
Here's the code snippet I'm trying, based on a naive reworking of the signing code.
with open(fname, 'wb') as p7sfile:
p7sfile.write(sig)
pkcs7 = crypto._lib.PKCS7_get0_signers(sig, None, 0)
It doesn't work - giving
pkcs7 = crypto._lib.PKCS7_get0_signers(sig, None, 0)
TypeError: initializer for ctype 'PKCS7 *' must be a cdata pointer, not bytes
The function seems to require three parameters, although maybe flags is optional?
This line of code (from the older M2Crypto library) also suggests that entry point needs three parameters.
I don't understand why it would need a "certs.stack" as an input param when we are trying to extract the certs, and I don't understand what to put in "flags".
I'm pretty sure I need some specially typed buffer declarations to set up the call, and also retrieve the results (like the bio_in = crypto._new_mem_buf(data)
preamble in 1). Can someone please suggest how to do it?
Also - the M2Crypto
library is not compatible with Python 3.x, hence looking for an alternative.