Verbose option added (-v) to show issuer CN and subject CN

This commit is contained in:
Alexandre Dulaunoy 2015-02-01 14:03:16 +01:00
parent b1bdae9f89
commit b1643dab64

View file

@ -14,6 +14,7 @@ import OpenSSL
import argparse
argParser = argparse.ArgumentParser(description='Extract certificate to PEM format from an ssldump output')
argParser.add_argument('-v', default=False, action='store_true', help='Verbose output')
argParser.add_argument('-r', default='-', help='Read from a file, default is stdin')
args = argParser.parse_args()
@ -39,6 +40,9 @@ for l in fileinput.input(args.r):
dercert = binascii.unhexlify(a)
x509 = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_ASN1, dercert)
fp = x509.digest('sha1').replace(':','').lower()
if args.v:
print "Issuer: " + x509.get_issuer().CN
print "CN: " + x509.get_subject().CN
print OpenSSL.crypto.dump_certificate(OpenSSL.crypto.FILETYPE_PEM, x509)
certstring = ""
y = ""