Handle broken output format

This commit is contained in:
Alexandre Dulaunoy 2015-04-22 17:04:25 +02:00
parent bd59ac25ab
commit cfe59cc00c

View file

@ -50,14 +50,25 @@ for l in fileinput.input(args.r):
if ((cert is None) and (len(certstring) > 0)): if ((cert is None) and (len(certstring) > 0)):
y = re.sub(" ", "", certstring).split('=') y = re.sub(" ", "", certstring).split('=')
a = y[1].split('certificate')[0] a = y[2].split('certificate')[0]
dercert = binascii.unhexlify(a) try:
dercert = binascii.unhexlify(a)
except TypeError:
continue
x509 = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_ASN1, dercert) x509 = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_ASN1, dercert)
c['fp'] = x509.digest('sha1').replace(':','').lower() c['fp'] = x509.digest('sha1').replace(':','').lower()
if args.v: if args.v:
print "("+c['session']+") "+c['srcip']+"<->"+c['dstip']+":"+c['dstport'] print "("+c['session']+") "+c['srcip']+"<->"+c['dstip']+":"+c['dstport']
print "Issuer: "+x509.get_issuer().CN Issuer = x509.get_issuer().CN
print "CN: " + x509.get_subject().CN if Issuer is not None:
print "Issuer: "+ Issuer
else:
print "Issuer: None"
CN = x509.get_subject().CN
if CN is not None:
print "CN: "+ CN
else:
print "Issuer: None"
c['pem'] = OpenSSL.crypto.dump_certificate(OpenSSL.crypto.FILETYPE_PEM, x509) c['pem'] = OpenSSL.crypto.dump_certificate(OpenSSL.crypto.FILETYPE_PEM, x509)
if args.j: if args.j:
print (json.dumps(c)) print (json.dumps(c))