forked from ztp-at/RKSV
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_test.py
More file actions
executable file
·94 lines (76 loc) · 3.17 KB
/
Copy pathrun_test.py
File metadata and controls
executable file
·94 lines (76 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env python2.7
###########################################################################
# Copyright 2017 ZT Prentner IT GmbH (www.ztp.at)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
###########################################################################
from builtins import int
import json
import os
import sys
import gettext
gettext.install('rktool', './lang', True)
from librksv.run_test import runTest
def usage():
print("Usage: ./run_test.py open <JSON test case spec> <cert 1 priv> <cert 1> [<cert 2 priv> <cert 2>]... [<turnover counter size>]")
print(" ./run_test.py closed <JSON test case spec> <key 1 priv> <pub key 1> [<key 2 priv> <pub key 2>]... [<turnover counter size>]")
sys.exit(0)
if __name__ == "__main__":
import gettext
gettext.install('rktool', './lang', True)
if len(sys.argv) < 5:
usage()
closed = False
if sys.argv[1] == 'closed':
closed = True
elif sys.argv[1] != 'open':
usage()
tcJson = None
with open(sys.argv[2]) as f:
tcJson = json.loads(f.read())
if len(sys.argv) != (tcJson['numberOfSignatureDevices'] * 2 + 3
) and len(sys.argv) != (tcJson['numberOfSignatureDevices']
* 2 + 3 + 1):
print(_("I need keys and certificates for %d signature devices.") %
tcJson['numberOfSignatureDevices'])
sys.exit(0)
baseDir = tcJson['simulationRunLabel']
if not os.path.exists(baseDir):
os.mkdir(baseDir)
turnoverCounterSize = None
if len(sys.argv) % 2 != 1:
turnoverCounterSize = int(sys.argv[-1])
if turnoverCounterSize < 5 or turnoverCounterSize > 16:
print(_("Turnover counter size needs to be between 5 and 16."))
sys.exit(0)
keymat = list()
for i in range(tcJson['numberOfSignatureDevices']):
pub = None
priv = None
with open(sys.argv[i * 2 + 1 + 3]) as f:
pub = f.read()
with open(sys.argv[i * 2 + 3]) as f:
priv = f.read()
keymat.append((pub, priv))
deps, ks = runTest(tcJson, keymat, closed, turnoverCounterSize)
os.chdir(baseDir)
with open('cryptographicMaterialContainer.json', 'w') as f:
f.write(json.dumps(ks, sort_keys=False, indent=2))
if len(deps) == 1:
with open('dep-export.json', 'w') as f:
f.write(json.dumps(deps[0], sort_keys=False, indent=2))
else:
for i in range(len(deps)):
with open('dep-export{}.json'.format(i), 'w') as f:
f.write(json.dumps(deps[i], sort_keys=False, indent=2))