0

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..
IrAM
  • 1,720
  • 5
  • 18
  • As the error message indicates that Python 2.x you are using is “no longer supported” have you tried using Python 3.x? – DisappointedByUnaccountableMod Dec 09 '20 at 07:30
  • @barny if I comment last two lines I wont get any problem other than the warning. I currently don't have python 3.x but python 2.x should work with warning. All i need is a way to get the content of my signed file in asn1parse format. – IrAM Dec 09 '20 at 08:17
  • @barny, I realized that after the call `p7data = f.read()`, `p7data` is printing the data from my .p7s file , how can i convert that data to normal .txt format with asn1parse format. like the out i have shown – IrAM Dec 09 '20 at 09:24

0 Answers0