-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
84 lines (75 loc) · 3.35 KB
/
main.py
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
import argparse
from util import extract_public_key, verify_artifact_signature
from merkle_proof import DefaultHasher, verify_consistency, verify_inclusion, compute_leaf_hash
def get_log_entry(log_index, debug=False):
# verify that log index value is sane
pass
def get_verification_proof(log_index, debug=False):
# verify that log index value is sane
pass
def inclusion(log_index, artifact_filepath, debug=False):
# verify that log index and artifact filepath values are sane
# extract_public_key(certificate)
# verify_artifact_signature(signature, public_key, artifact_filepath)
# get_verification_proof(log_index)
# verify_inclusion(DefaultHasher, index, tree_size, leaf_hash, hashes, root_hash)
pass
def get_latest_checkpoint(debug=False):
pass
def consistency(prev_checkpoint, debug=False):
# verify that prev checkpoint is not empty
# get_latest_checkpoint()
pass
def main():
debug = False
parser = argparse.ArgumentParser(description="Rekor Verifier")
parser.add_argument('-d', '--debug', help='Debug mode',
required=False, action='store_true') # Default false
parser.add_argument('-c', '--checkpoint', help='Obtain latest checkpoint\
from Rekor Server public instance',
required=False, action='store_true')
parser.add_argument('--inclusion', help='Verify inclusion of an\
entry in the Rekor Transparency Log using log index\
and artifact filename.\
Usage: --inclusion 126574567',
required=False, type=int)
parser.add_argument('--artifact', help='Artifact filepath for verifying\
signature',
required=False)
parser.add_argument('--consistency', help='Verify consistency of a given\
checkpoint with the latest checkpoint.',
action='store_true')
parser.add_argument('--tree-id', help='Tree ID for consistency proof',
required=False)
parser.add_argument('--tree-size', help='Tree size for consistency proof',
required=False, type=int)
parser.add_argument('--root-hash', help='Root hash for consistency proof',
required=False)
args = parser.parse_args()
if args.debug:
debug = True
print("enabled debug mode")
if args.checkpoint:
# get and print latest checkpoint from server
# if debug is enabled, store it in a file checkpoint.json
checkpoint = get_latest_checkpoint(debug)
print(json.dumps(checkpoint, indent=4))
if args.inclusion:
inclusion(args.inclusion, args.artifact, debug)
if args.consistency:
if not args.tree_id:
print("please specify tree id for prev checkpoint")
return
if not args.tree_size:
print("please specify tree size for prev checkpoint")
return
if not args.root_hash:
print("please specify root hash for prev checkpoint")
return
prev_checkpoint = {}
prev_checkpoint["treeID"] = args.tree_id
prev_checkpoint["treeSize"] = args.tree_size
prev_checkpoint["rootHash"] = args.root_hash
consistency(prev_checkpoint, debug)
if __name__ == "__main__":
main()