mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-04-09 21:44:28 +00:00
cert_audit: Make FILE as positional argument
Make FILE as positional argument so that we can pass multiple files to the script. This commit also contains some help message improvements. Signed-off-by: Pengyu Lv <pengyu.lv@arm.com>
This commit is contained in:
parent
3179232211
commit
57240958ed
@ -15,11 +15,12 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
"""Audit validity date of X509 crt/crl/csr
|
"""Audit validity date of X509 crt/crl/csr.
|
||||||
|
|
||||||
This script is used to audit the validity date of crt/crl/csr used for testing.
|
This script is used to audit the validity date of crt/crl/csr used for testing.
|
||||||
The files are in tests/data_files/ while some data are in test suites data in
|
It prints the information of X509 data whose validity duration does not cover
|
||||||
tests/suites/*.data files.
|
the provided validity duration. The data are collected from tests/data_files/
|
||||||
|
and tests/suites/*.data files by default.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
@ -362,24 +363,23 @@ def main():
|
|||||||
"""
|
"""
|
||||||
Perform argument parsing.
|
Perform argument parsing.
|
||||||
"""
|
"""
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(description=__doc__)
|
||||||
description='Audit script for X509 crt/crl/csr files.'
|
|
||||||
)
|
|
||||||
|
|
||||||
parser.add_argument('-a', '--all',
|
parser.add_argument('-a', '--all',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
help='list the information of all files')
|
help='list the information of all the files')
|
||||||
parser.add_argument('-v', '--verbose',
|
parser.add_argument('-v', '--verbose',
|
||||||
action='store_true', dest='verbose',
|
action='store_true', dest='verbose',
|
||||||
help='Show warnings')
|
help='show warnings')
|
||||||
parser.add_argument('--not-before', dest='not_before',
|
parser.add_argument('--not-before', dest='not_before',
|
||||||
help='not valid before this date(UTC), YYYY-MM-DD',
|
help=('not valid before this date (UTC, YYYY-MM-DD). '
|
||||||
|
'Default: today'),
|
||||||
metavar='DATE')
|
metavar='DATE')
|
||||||
parser.add_argument('--not-after', dest='not_after',
|
parser.add_argument('--not-after', dest='not_after',
|
||||||
help='not valid after this date(UTC), YYYY-MM-DD',
|
help=('not valid after this date (UTC, YYYY-MM-DD). '
|
||||||
|
'Default: not-before'),
|
||||||
metavar='DATE')
|
metavar='DATE')
|
||||||
parser.add_argument('-f', '--file', dest='file',
|
parser.add_argument('files', nargs='*', help='files to audit',
|
||||||
help='file to audit (Debug only)',
|
|
||||||
metavar='FILE')
|
metavar='FILE')
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
@ -388,9 +388,9 @@ def main():
|
|||||||
td_auditor = TestDataAuditor(args.verbose)
|
td_auditor = TestDataAuditor(args.verbose)
|
||||||
sd_auditor = SuiteDataAuditor(args.verbose)
|
sd_auditor = SuiteDataAuditor(args.verbose)
|
||||||
|
|
||||||
if args.file:
|
if args.files:
|
||||||
data_files = [args.file]
|
data_files = args.files
|
||||||
suite_data_files = [args.file]
|
suite_data_files = args.files
|
||||||
else:
|
else:
|
||||||
data_files = td_auditor.default_files
|
data_files = td_auditor.default_files
|
||||||
suite_data_files = sd_auditor.default_files
|
suite_data_files = sd_auditor.default_files
|
||||||
@ -408,7 +408,7 @@ def main():
|
|||||||
sd_auditor.walk_all(suite_data_files)
|
sd_auditor.walk_all(suite_data_files)
|
||||||
audit_results = td_auditor.audit_data + sd_auditor.audit_data
|
audit_results = td_auditor.audit_data + sd_auditor.audit_data
|
||||||
|
|
||||||
# we filter out the files whose validity duration covers the provide
|
# we filter out the files whose validity duration covers the provided
|
||||||
# duration.
|
# duration.
|
||||||
filter_func = lambda d: (not_before_date < d.not_valid_before) or \
|
filter_func = lambda d: (not_before_date < d.not_valid_before) or \
|
||||||
(d.not_valid_after < not_after_date)
|
(d.not_valid_after < not_after_date)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user