I have the following problem. I need to create a Python program where I can download any mail from host and decrypt it with given .pfx file and passcode. I am trying various solutions, but now I am stuck trying to force OpenSSL.crypto to simply decipher anything with given private key and certificate. The documentation and provided solutions on Google are also scarce. Any ideas?
Here is my code:
import pickle, email
file = open('cipher.pickle', 'rb')
msg_data = pickle.load(file)
file.close()
data = msg_data[0]
response = tuple(data)[1]
msg = email.message_from_bytes(response)
message = msg.get_payload()
# message = bytes(message, encoding='utf-8)
print(message)
#gives encrypted message: 'MIAGCSqGSIb3DQEHA6CAMIACA...14g/EwQIyhd0YOdnRR0AAAAAAAAAAAAA'
from OpenSSL import crypto
ssl_pass1 = "7F63CfcUauAf"
#generated certificate from https://extrassl.actalis.it/portal/uapub/freemail?lang=en for yahoo testmail
#together with password for this certificate
with open('testmail1_yahoo.pfx', 'rb') as f:
pfx_data = f.read()
pfx = crypto.load_pkcs12(pfx_data, bytes(ssl_pass1, encoding='utf-8'))
pem = crypto.dump_privatekey(crypto.FILETYPE_PEM, pfx.get_privatekey())
cert = crypto.dump_certificate(crypto.FILETYPE_PEM, pfx.get_certificate())
#private key and certificate extracted from pfx so far