mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-02-05 09:40:32 +00:00
cert_audit: Improve the method to find tests folder
Signed-off-by: Pengyu Lv <pengyu.lv@arm.com>
This commit is contained in:
parent
a228cbcecc
commit
2d487217cd
@ -42,15 +42,20 @@ from cryptography import x509 #pylint: disable=import-error
|
|||||||
from generate_test_code import parse_test_data as parse_suite_data
|
from generate_test_code import parse_test_data as parse_suite_data
|
||||||
from generate_test_code import FileWrapper
|
from generate_test_code import FileWrapper
|
||||||
|
|
||||||
|
import scripts_path # pylint: disable=unused-import
|
||||||
|
from mbedtls_dev import build_tree
|
||||||
|
|
||||||
class DataType(Enum):
|
class DataType(Enum):
|
||||||
CRT = 1 # Certificate
|
CRT = 1 # Certificate
|
||||||
CRL = 2 # Certificate Revocation List
|
CRL = 2 # Certificate Revocation List
|
||||||
CSR = 3 # Certificate Signing Request
|
CSR = 3 # Certificate Signing Request
|
||||||
|
|
||||||
|
|
||||||
class DataFormat(Enum):
|
class DataFormat(Enum):
|
||||||
PEM = 1 # Privacy-Enhanced Mail
|
PEM = 1 # Privacy-Enhanced Mail
|
||||||
DER = 2 # Distinguished Encoding Rules
|
DER = 2 # Distinguished Encoding Rules
|
||||||
|
|
||||||
|
|
||||||
class AuditData:
|
class AuditData:
|
||||||
"""Store data location, type and validity period of X.509 objects."""
|
"""Store data location, type and validity period of X.509 objects."""
|
||||||
#pylint: disable=too-few-public-methods
|
#pylint: disable=too-few-public-methods
|
||||||
@ -78,6 +83,7 @@ class AuditData:
|
|||||||
else:
|
else:
|
||||||
raise ValueError("Unsupported file_type: {}".format(self.data_type))
|
raise ValueError("Unsupported file_type: {}".format(self.data_type))
|
||||||
|
|
||||||
|
|
||||||
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}\n(?P<data>.*?)-{5}END (?P=type)-{5}\n'
|
||||||
@ -167,6 +173,7 @@ class X509Parser:
|
|||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
class Auditor:
|
class Auditor:
|
||||||
"""A base class for audit."""
|
"""A base class for audit."""
|
||||||
def __init__(self, logger):
|
def __init__(self, logger):
|
||||||
@ -231,15 +238,8 @@ class Auditor:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def find_test_dir():
|
def find_test_dir():
|
||||||
"""Get the relative path for the MbedTLS test directory."""
|
"""Get the relative path for the MbedTLS test directory."""
|
||||||
if os.path.isdir('tests'):
|
return os.path.relpath(build_tree.guess_mbedtls_root() + '/tests')
|
||||||
tests_dir = 'tests'
|
|
||||||
elif os.path.isdir('suites'):
|
|
||||||
tests_dir = '.'
|
|
||||||
elif os.path.isdir('../suites'):
|
|
||||||
tests_dir = '..'
|
|
||||||
else:
|
|
||||||
raise Exception("Mbed TLS source tree not found")
|
|
||||||
return tests_dir
|
|
||||||
|
|
||||||
class TestDataAuditor(Auditor):
|
class TestDataAuditor(Auditor):
|
||||||
"""Class for auditing files in tests/data_files/"""
|
"""Class for auditing files in tests/data_files/"""
|
||||||
@ -255,6 +255,7 @@ class TestDataAuditor(Auditor):
|
|||||||
if os.path.isfile(f)]
|
if os.path.isfile(f)]
|
||||||
return data_files
|
return data_files
|
||||||
|
|
||||||
|
|
||||||
class SuiteDataAuditor(Auditor):
|
class SuiteDataAuditor(Auditor):
|
||||||
"""Class for auditing files in tests/suites/*.data"""
|
"""Class for auditing files in tests/suites/*.data"""
|
||||||
def __init__(self, options):
|
def __init__(self, options):
|
||||||
@ -294,6 +295,7 @@ class SuiteDataAuditor(Auditor):
|
|||||||
|
|
||||||
return audit_data_list
|
return audit_data_list
|
||||||
|
|
||||||
|
|
||||||
def list_all(audit_data: AuditData):
|
def list_all(audit_data: AuditData):
|
||||||
print("{}\t{}\t{}\t{}".format(
|
print("{}\t{}\t{}\t{}".format(
|
||||||
audit_data.not_valid_before.isoformat(timespec='seconds'),
|
audit_data.not_valid_before.isoformat(timespec='seconds'),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user