android - Use m2crypto to print certificate in apk -
i show android apk certificate information openssl
command does. like
$ openssl pkcs7 -inform der -in cert.rsa -print_certs subject=... -----begin certificate----- miiebzccau+gawibagiekkpncjanbgkqhkig9w0baqsfadcbsjepma0ga1uebhmg ... 5be3oowpt+mhkewxsei9r+s7tuwkp+wopjevmbmga1uecgwm6yer5bgx572r57uc -----end certificate-----
at first used pycrypto
, found not include x509 format. after trying m2crypto
, output error like
in [7]: x509.load_cert('cert.rsa', x509.format_der) --------------------------------------------------------------------------- x509error traceback (most recent call last) <ipython-input-7-821a670a1ab6> in <module>() ----> 1 x509.load_cert('cert.rsa', x509.format_der) /usr/local/lib/python2.7/dist-packages/m2crypto/x509.pyc in load_cert(file, format) 613 cptr = m2.d2i_x509(bio._ptr()) 614 if cptr none: --> 615 raise x509error(err.get_error()) 616 return x509(cptr, _pyfree=1) 617 else: x509error: 140335753901888:error:0d0680a8:asn1 encoding routines:asn1_check_tlen:wrong tag:tasn_dec.c:1337: 140335753901888:error:0d07803a:asn1 encoding routines:asn1_item_ex_d2i:nested asn1 error:tasn_dec.c:388:type=x509_cinf 140335753901888:error:0d08303a:asn1 encoding routines:asn1_template_noexp_d2i:nested asn1 error:tasn_dec.c:769:field=cert_info, type=x509
what correct way show base64-encoded certificate?
inspired pkcs7dump.py use pyasn1
, pyasn1_modules
show base64-encoded certificate extracting file in pkcs#7(rfc2315) format.
following simple script
from pyasn1.codec.der import decoder, encoder pyasn1_modules import rfc2315 contentinfo, _ = decoder.decode(open('cert.rsa', 'rb').read(), asn1spec=rfc2315.contentinfo()) content = contentinfo.getcomponentbyname('content') signeddata, _ = decoder.decode(content, asn1spec=rfc2315.signeddata()) certs = signeddata.getcomponentbyname('certificates') cert = certs.getcomponentbyposition(0) print encoder.encode(cert).encode('base64')
Comments
Post a Comment