diff options
Diffstat (limited to 'misc/python/nisttest.py')
-rwxr-xr-x | misc/python/nisttest.py | 62 |
1 files changed, 39 insertions, 23 deletions
diff --git a/misc/python/nisttest.py b/misc/python/nisttest.py index c070f76a9..c1131d2b0 100755 --- a/misc/python/nisttest.py +++ b/misc/python/nisttest.py @@ -3,43 +3,59 @@ import sys, os, botan from os.path import join; -class TestResult(Exception): - def __init__(self, r): - self.result = r - def __str__(self): - return repr(self.result).replace('botan._botan.verify_result.', '') - -def raise_unless_ok(r): - if r != botan.verify_result.verified: - raise TestResult(r) - def validate(ca_certs, certs, crls, ee_certs): store = botan.X509_Store() - for cert in certs: if cert not in ee_certs: store.add_cert(botan.X509_Certificate(cert), cert in ca_certs) for crl in crls: - raise_unless_ok(store.add_crl(botan.X509_CRL(crl))) + r = store.add_crl(botan.X509_CRL(crl)) + if r != botan.verify_result.verified: + return r for ee in ee_certs: - raise_unless_ok(store.validate(botan.X509_Certificate(ee))) + r = store.validate(botan.X509_Certificate(ee)) + if r != botan.verify_result.verified: + return r + + return botan.verify_result.verified - raise TestResult(botan.verify_result.verified) +def run_test(files, rootdir, testname, expected): + crls = [join(rootdir,x) for x in files if x.endswith(".crl")] + certs = [join(rootdir,x) for x in files if x.endswith(".crt")] + end_entity = [x for x in certs if x.find("End Cert") != -1] + ca_certs = [x for x in certs if x.find("Trust Anchor") != -1] + + print "Running", testname, "...", + + result = validate(ca_certs, certs, crls, end_entity) + result = repr(result).replace('botan._botan.verify_result.', '') + + if result != expected: + print "FAILED: got", result, "expected", expected + else: + print "passed" def main(): + def load_results(file): + results = {} + for line in open(file, 'r'): + line = line[0:line.find('#')].strip() + if line: + test,result = line.split(' ') + results[test] = result + return results + + results = load_results('results.txt') + for root, dirs, files in os.walk('../nist_tests/tests'): if files: - crls = [join(root,x) for x in files if x.endswith(".crl")] - certs = [join(root,x) for x in files if x.endswith(".crt")] - end_entity = [x for x in certs if x.find("End Cert") != -1] - ca_certs = [x for x in certs if x.find("Trust Anchor") != -1] - - try: - validate(ca_certs, certs, crls, end_entity) - except TestResult, result: - print result + thistest = root[root.rfind('/')+1:] + if thistest in results: + run_test(files, root, thistest, results[thistest]) + else: + print "Skipping", thistest, "- no expected result set" if __name__ == "__main__": sys.exit(main()) |