Is there any python package for parsing pkcs7?

坚强是说给别人听的谎言 提交于 2020-05-30 07:08:21

问题


I'm extracting features from Android .APK files with androguard and right now I need to extract the serial number(*) from its signature file (usually CERT.RSA). I've found asn1crypto, but I don't quite understand, how to use it with pkcs7. So is there any python package suitable for this purpose?

(*):


回答1:


Comment: I have pkcs7 as a memory object, not a file

PyOpenSSL does not read from file!

OpenSSL.crypto.load_pkcs7_data(type, buffer)

Load pkcs7 data from the string buffer encoded with the type type.
The type type must either FILETYPE_PEM or FILETYPE_ASN1).

fromSO Answer 45111623import get_certificates

from OpenSSL import crypto
pkcs7 = crypto.load_pkcs7_data(crypto.FILETYPE_ASN1, 
                               open('certs/signature.der', 'rb').read())
certs = get_certificates(pkcs7)
for cert in certs:
    print('Subject:{}, Serial Nnumber:{}'.
        format(cert.get_subject(), cert.get_serial_number()))

>>>Subject:<X509Name object '/CN=key1'>, Serial Nnumber:13315126025841024674
>>>Subject:<X509Name object '/CN=key2'>, Serial Nnumber:14142490995367396705

Question: python package for parsing pkcs7?

You can convert PKCS#7 to PEM using openssl, PEM is readable using PyOpenSSL

openssl pkcs7 -print_certs -in sample.p7b -out sample.cer

Read that relevant SO Answer: pyOpenSSL's PKCS7



来源:https://stackoverflow.com/questions/45782506/is-there-any-python-package-for-parsing-pkcs7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!