I am trying to extract content(asn1parse) from p7s file and using below code, but looks like i miss something.
I am new with pyOpenSSL, OpenSSL and python itself.
Can you anyone please point me what i am missing.
import sys
from OpenSSL import crypto
p7s_file = sys.argv[1]
with open(p7s_file, 'rb') as f:
p7data = f.read()
p7 = crypto.load_pkcs7_data(crypto.FILETYPE_ASN1, p7data)
print p7
buffer = crypto.dump_certificate(crypto.FILETYPE_ASN1, p7)
print buffer
Actual Output
C:\Python27\lib\site-packages\OpenSSL\crypto.py:14: CryptographyDeprecationWarning: Python 2 is no longer supported by the Python core team. Support for it is now deprecated in cryptography, and will be removed in a future release.
from cryptography import utils, x509
<OpenSSL.crypto.PKCS7 object at 0x0000000003314F60>
Traceback (most recent call last):
File "extract_ans1parse.py", line 10, in <module>
buffer = crypto.dump_certificate(crypto.FILETYPE_ASN1, p7)
File "C:\Python27\lib\site-packages\OpenSSL\crypto.py", line 1971, in dump_certificate
result_code = _lib.i2d_X509_bio(bio, cert._x509)
AttributeError: 'PKCS7' object has no attribute '_x509'
Expected Ouput
0:d=0 hl=2 l=inf cons: SEQUENCE
2:d=1 hl=2 l= 9 prim: OBJECT :pkcs7-signedData
13:d=1 hl=2 l=inf cons: cont [ 0 ]
15:d=2 hl=2 l=inf cons: SEQUENCE
17:d=3 hl=2 l= 1 prim: INTEGER :01
20:d=3 hl=2 l= 15 cons: SET
etc.. etc..