aboutsummaryrefslogtreecommitdiff
path: root/siglog-witness.py
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordberg.se>2021-06-03 06:46:56 +0200
committerLinus Nordberg <linus@nordberg.se>2021-06-03 06:46:56 +0200
commite55094358cd825a12ea3f4fd542c6cfe874966b2 (patch)
treef9867fc511d5ceddfd6231244a92802cfa089aaf /siglog-witness.py
parent4c61f7e4c4c471ae2fdf6aee13c2d147eed7282d (diff)
exit with error if uploading the signature fails
Also, make the code that is doing hex encoding in ASCII more readable by splitting up hashing and signing on the one side and hex encoding and converting bytes to ASCII on the other.
Diffstat (limited to 'siglog-witness.py')
-rwxr-xr-xsiglog-witness.py28
1 files changed, 15 insertions, 13 deletions
diff --git a/siglog-witness.py b/siglog-witness.py
index ece3957..fe15c4e 100755
--- a/siglog-witness.py
+++ b/siglog-witness.py
@@ -232,21 +232,22 @@ def consistency_proof_valid(first, second, proof):
return sn == 0 and fr == first.root_hash() and sr == second.root_hash()
-def send_to_log(keyhash_hex, signature_hex):
- post_data = 'signature={}\n'.format(signature_hex)
- post_data += 'key_hash={}\n'.format(keyhash_hex)
+def sign_and_send_sig(signing_key, sth):
+ hash = sha256(signing_key.verify_key.encode())
+ signature = signing_key.sign(sth.serialise()).signature
+
+ post_data = 'signature={}\n'.format(hexlify(signature).decode('ascii'))
+ post_data += 'key_hash={}\n'.format(hash.hexdigest())
+
req = requests.post(g_args.base_url + 'st/v0/add-cosignature', post_data)
if req.status_code != 200:
- return req
+ print("ERROR: Unable to post signature to log: {} => {}: {}".
+ format(req.url,
+ req.err_code,
+ req.text))
+ return None
+ return True
-def sign_and_send_sig(signing_key, sth):
- keyhash = sha256(signing_key.verify_key.encode()).hexdigest()
- status = send_to_log(keyhash,
- hexlify(signing_key.sign(sth.serialise()).signature).decode('ascii'))
- if status:
- print("ERROR: Unable to post signature to log: {} => {}: {}".format(status.url,
- status.status_code,
- status.text))
def main(args):
global g_args
g_args = Parser()
@@ -333,7 +334,8 @@ def main(args):
store_tree_head(new)
if consistency_verified or ignore_consistency:
- sign_and_send_sig(signing_key, new)
+ if not sign_and_send_sig(signing_key, new):
+ return 13
return 0