summaryrefslogtreecommitdiff
path: root/reset-controller/fw/tools/crypto_test_runner.py
diff options
context:
space:
mode:
authorjaseg <git-bigdata-wsl-arch@jaseg.de>2021-04-09 18:38:02 +0200
committerjaseg <git-bigdata-wsl-arch@jaseg.de>2021-04-09 18:38:57 +0200
commit50998fcfb916ae251309bd4b464f2c122e8cb30d (patch)
tree4ecf7a7443b75ab51c4dc0c0fc9289342dc7d6a0 /reset-controller/fw/tools/crypto_test_runner.py
parent312fee491cfab436d52db4b6265107e20f3e1293 (diff)
downloadmaster-thesis-50998fcfb916ae251309bd4b464f2c122e8cb30d.tar.gz
master-thesis-50998fcfb916ae251309bd4b464f2c122e8cb30d.tar.bz2
master-thesis-50998fcfb916ae251309bd4b464f2c122e8cb30d.zip
Repo re-org
Diffstat (limited to 'reset-controller/fw/tools/crypto_test_runner.py')
-rw-r--r--reset-controller/fw/tools/crypto_test_runner.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/reset-controller/fw/tools/crypto_test_runner.py b/reset-controller/fw/tools/crypto_test_runner.py
new file mode 100644
index 0000000..34c8b59
--- /dev/null
+++ b/reset-controller/fw/tools/crypto_test_runner.py
@@ -0,0 +1,46 @@
+#!/usr/bin/env python3
+import subprocess
+from os import path
+import binascii
+import re
+
+import presig_gen
+
+def do_test(domain, value, height, root_key, binary, expect_fail=False):
+ auth = presig_gen.gen_at_height(domain, value, height, root_key)
+ auth = binascii.hexlify(auth).decode()
+
+ output = subprocess.check_output([binary, auth])
+ *lines, rc_line = output.decode().splitlines()
+ rc = int(re.match('^rc=(\d+)$', rc_line).group(1))
+ assert expect_fail == (rc == 0)
+
+def run_tests(root_key, max_height, binary):
+ for domain, value in {
+ 'all': 'all',
+ 'vendor': presig_gen.TEST_VENDOR,
+ 'series': presig_gen.TEST_SERIES,
+ 'country': presig_gen.TEST_COUNTRY,
+ 'region': presig_gen.TEST_REGION,
+ }.items():
+ for height in range(max_height):
+ do_test(domain, value, height, root_key, binary)
+ do_test(domain, 'fail', height, root_key, binary, expect_fail=True)
+ do_test('fail', 'fail', height, root_key, binary, expect_fail=True)
+ do_test('', '', height, root_key, binary, expect_fail=True)
+ do_test(domain, value, max_height, root_key, binary, expect_fail=True)
+ do_test(domain, value, max_height+1, root_key, binary, expect_fail=True)
+
+if __name__ == '__main__':
+ import argparse
+ parser = argparse.ArgumentParser()
+ parser.add_argument('keyfile', help='Root key file')
+ parser.add_argument('max_height', type=int, default=8, nargs='?', help='Height of generated prekeys')
+ default_binary = path.abspath(path.join(path.dirname(__file__), '../build/tools/crypto_test'))
+ parser.add_argument('binary', default=default_binary, nargs='?', help='crypto_test binary to use')
+ args = parser.parse_args()
+
+ with open(args.keyfile, 'r') as f:
+ root_key = binascii.unhexlify(f.read().strip())
+
+ run_tests(root_key, args.max_height, args.binary)