fixing small bug

This commit is contained in:
brent s 2018-05-08 05:27:12 -04:00
parent 36c20eae91
commit 4f775159c8

View File

@ -196,97 +196,104 @@ class CertParse(object):
exts[keyname] = value_str exts[keyname] = value_str
# These are split FURTHER into dicts but require unique... massaging. # These are split FURTHER into dicts but require unique... massaging.
# authorityInfoAccess # authorityInfoAccess
_tmp = copy.deepcopy(exts['authorityInfoAccess']) if 'authorityInfoAccess' in exts.keys():
exts['authorityInfoAccess'] = {} _tmp = copy.deepcopy(exts['authorityInfoAccess'])
for i in _tmp: exts['authorityInfoAccess'] = {}
x = [n.strip() for n in i.split('-', 1)] for i in _tmp:
y = [n.strip() for n in x[1].split(':', 1)] x = [n.strip() for n in i.split('-', 1)]
exts['authorityInfoAccess'][x[0]] = {y[0]: y[1]} y = [n.strip() for n in x[1].split(':', 1)]
exts['authorityInfoAccess'][x[0]] = {y[0]: y[1]}
# authorityKeyIdentifier # authorityKeyIdentifier
_tmp = copy.deepcopy(exts['authorityKeyIdentifier']) if 'authorityKeyIdentifier' in exts.keys():
exts['authorityKeyIdentifier'] = {_tmp.split(':', 1)[0]: _tmp = copy.deepcopy(exts['authorityKeyIdentifier'])
exts['authorityKeyIdentifier'] = {_tmp.split(':', 1)[0]:
_tmp.split(':', 1)[1]} _tmp.split(':', 1)[1]}
# basicConstraints # basicConstraints
_tmp = copy.deepcopy(exts['basicConstraints']) if 'basicConstraints' in exts.keys():
exts['basicConstraints'] = {} _tmp = copy.deepcopy(exts['basicConstraints'])
for i in _tmp: exts['basicConstraints'] = {}
x = [n.strip() for n in i.split(':', 1)] for i in _tmp:
if len(x) >= 1: x = [n.strip() for n in i.split(':', 1)]
if x[1].lower() in ('true', 'false'): if len(x) >= 1:
x[1] = (x[1].lower() == 'true') if x[1].lower() in ('true', 'false'):
exts['basicConstraints'][x[0]] = x[1] x[1] = (x[1].lower() == 'true')
else: exts['basicConstraints'][x[0]] = x[1]
exts['basicConstraints'][x[0]] = True else:
exts['basicConstraints'][x[0]] = True
# certificatePolicies # certificatePolicies
# What a mess. # What a mess.
_tmp = copy.deepcopy(exts['certificatePolicies']) if 'certificatePolicies' in exts.keys():
exts['certificatePolicies'] = {} _tmp = copy.deepcopy(exts['certificatePolicies'])
last_key = None exts['certificatePolicies'] = {}
for i in [n.strip() for n in _tmp]: last_key = None
l = [y for y in i.split(':', 1) if y not in ('', None)] for i in [n.strip() for n in _tmp]:
if len(l) > 1: l = [y for y in i.split(':', 1) if y not in ('', None)]
# It MAY be a key:value. if len(l) > 1:
if re.search('^\s+', l[1]) and last_key != 'User Notice': # It MAY be a key:value.
# It's a value. if re.search('^\s+', l[1]) and last_key != 'User Notice':
# It's a value.
last_key = l[0].strip()
exts['certificatePolicies'][last_key] = l[1].strip()
elif re.search('^\s+', l[1]):
k = l[0].strip()
exts['certificatePolicies'][last_key][k] = l[1].strip()
else:
# Standalone key line
last_key = l[0].strip() last_key = l[0].strip()
exts['certificatePolicies'][last_key] = l[1].strip() exts['certificatePolicies'][last_key] = {}
elif re.search('^\s+', l[1]):
k = l[0].strip()
exts['certificatePolicies'][last_key][k] = l[1].strip()
else:
# Standalone key line
last_key = l[0].strip()
exts['certificatePolicies'][last_key] = {}
# ct_precert_scts # ct_precert_scts
# another mess. # another mess. a much. much, bigger mess.
_tmp = copy.deepcopy(exts['ct_precert_scts']) if 'ct_precert_scts' in exts.keys():
exts['ct_precert_scts'] = {} _tmp = copy.deepcopy(exts['ct_precert_scts'])
last_key = None exts['ct_precert_scts'] = {}
last_sub_key = None last_key = None
cnt = 0 last_sub_key = None
for i in [n.strip() for n in _tmp]: cnt = 0
l = [y for y in i.split(':', 1) if y not in ('', None)] for i in [n.strip() for n in _tmp]:
if len(l) > 1: l = [y for y in i.split(':', 1) if y not in ('', None)]
print(l) if len(l) > 1:
# Is it a line continuation (of a hex value)? print(l)
if ((re.search('^[0-9A-Z]{2}$', l[0])) and # Is it a line continuation (of a hex value)?
if ((re.search('^[0-9A-Z]{2}$', l[0])) and
(re.search('^[0-9A-Z:]*:?$', ':'.join(l)))): (re.search('^[0-9A-Z:]*:?$', ':'.join(l)))):
exts['ct_precert_scts'][last_key][cnt][last_sub_key] += \ exts['ct_precert_scts'][last_key][cnt]\
':'.join(l) [last_sub_key] += ':'.join(l)
continue continue
# It MAY be a key:value. # It MAY be a key:value.
if re.search('^\s+', l[1]) and ( if re.search('^\s+', l[1]) and (
last_key != last_key !=
'Signed Certificate Timestamp'): 'Signed Certificate Timestamp'):
# It's a value. # It's a value.
last_key = l[0].strip()
val = l[1].strip()
if val.lower() == 'none':
val = None
exts['ct_precert_scts'][last_key] = val
elif re.search('^\s+', l[1]):
last_sub_key = l[0].strip()
val = l[1].strip()
if val.lower() == 'none':
val = None
if last_sub_key == 'Signature':
val += ' '
exts['ct_precert_scts'][last_key][cnt]\
[last_sub_key] = val
else:
# Standalone key line
last_key = l[0].strip() last_key = l[0].strip()
val = l[1].strip() if last_key == 'Signed Certificate Timestamp':
if val.lower() == 'none': if last_key not in exts['ct_precert_scts'].keys():
val = None exts['ct_precert_scts'][last_key] = [{}]
exts['ct_precert_scts'][last_key] = val else:
elif re.search('^\s+', l[1]): exts['ct_precert_scts'][last_key].append({})
last_sub_key = l[0].strip() cnt += 1
val = l[1].strip() # some laaaast bit of cleanup...
if val.lower() == 'none': if 'Signed Certificate Timestamp' in exts['ct_precert_scts']:
val = None for i in exts['ct_precert_scts']\
if last_sub_key == 'Signature': ['Signed Certificate Timestamp']:
val += ' ' if 'Signature' in i.keys():
exts['ct_precert_scts'][last_key][cnt][last_sub_key] = val d = i['Signature'].split()
else: i['Signature'] = {d[0]: d[1]}
# Standalone key line
last_key = l[0].strip()
if last_key == 'Signed Certificate Timestamp':
if last_key not in exts['ct_precert_scts'].keys():
exts['ct_precert_scts'][last_key] = [{}]
else:
exts['ct_precert_scts'][last_key].append({})
cnt += 1
# some laaaast bit of cleanup...
if 'Signed Certificate Timestamp' in exts['ct_precert_scts'].keys():
for i in exts['ct_precert_scts']['Signed Certificate Timestamp']:
if 'Signature' in i.keys():
d = i['Signature'].split()
i['Signature'] = {d[0]: d[1]}
return(exts) return(exts)


def get_domain_from_url(self, url): def get_domain_from_url(self, url):