cert_audit: Support parsing file with multiple PEMs
Previously, if a file had multiple PEM objects, only the first one would be parsed. This commit add the support so that we could parse all the PEM objects in the file. Signed-off-by: Pengyu Lv <pengyu.lv@arm.com>
This commit is contained in:
parent
eb2c39ed2b
commit
e245c0c734
1 changed files with 10 additions and 7 deletions
|
@ -90,7 +90,7 @@ class AuditData:
|
||||||
|
|
||||||
class X509Parser:
|
class X509Parser:
|
||||||
"""A parser class to parse crt/crl/csr file or data in PEM/DER format."""
|
"""A parser class to parse crt/crl/csr file or data in PEM/DER format."""
|
||||||
PEM_REGEX = br'-{5}BEGIN (?P<type>.*?)-{5}\n(?P<data>.*?)-{5}END (?P=type)-{5}\n'
|
PEM_REGEX = br'-{5}BEGIN (?P<type>.*?)-{5}(?P<data>.*?)-{5}END (?P=type)-{5}'
|
||||||
PEM_TAG_REGEX = br'-{5}BEGIN (?P<type>.*?)-{5}\n'
|
PEM_TAG_REGEX = br'-{5}BEGIN (?P<type>.*?)-{5}\n'
|
||||||
PEM_TAGS = {
|
PEM_TAGS = {
|
||||||
DataType.CRT: 'CERTIFICATE',
|
DataType.CRT: 'CERTIFICATE',
|
||||||
|
@ -277,12 +277,15 @@ class TestDataAuditor(Auditor):
|
||||||
"""
|
"""
|
||||||
with open(filename, 'rb') as f:
|
with open(filename, 'rb') as f:
|
||||||
data = f.read()
|
data = f.read()
|
||||||
result = self.parse_bytes(data)
|
|
||||||
|
results = []
|
||||||
|
for idx, m in enumerate(re.finditer(X509Parser.PEM_REGEX, data, flags=re.S), 1):
|
||||||
|
result = self.parse_bytes(data[m.start():m.end()])
|
||||||
if result is not None:
|
if result is not None:
|
||||||
result.location = filename
|
result.location = "{}#{}".format(filename, idx)
|
||||||
return [result]
|
results.append(result)
|
||||||
else:
|
|
||||||
return []
|
return results
|
||||||
|
|
||||||
|
|
||||||
def parse_suite_data(data_f):
|
def parse_suite_data(data_f):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue