aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrégoire Détrez <gregoire@mullvad.net>2022-06-28 17:12:42 +0200
committerGrégoire Détrez <gregoire@mullvad.net>2022-06-28 17:29:42 +0200
commitd27fab1ee267947610d7fdf882ad49850ebeba74 (patch)
tree16cd6dfa7e9365b507bffc37e1cf6283bc0eb537
parent5e6b83d17629fb8e8ae81638b2056a37364ec703 (diff)
Catch requests' ConnectionError
This is a tentative fix for #44: catch exceptions raised by requests if it cannot connect to the log so that the witness can return the expected exit codes.
-rwxr-xr-xsigsum-witness.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/sigsum-witness.py b/sigsum-witness.py
index ef63c4c..5cd9f7a 100755
--- a/sigsum-witness.py
+++ b/sigsum-witness.py
@@ -279,7 +279,10 @@ def store_tree_head(tree_head):
f.write(tree_head.text())
def fetch_tree_head_and_verify(log_verification_key):
- req = requests.get(g_args.base_url + 'sigsum/v0/get-tree-head-to-cosign')
+ try:
+ req = requests.get(g_args.base_url + 'sigsum/v0/get-tree-head-to-cosign')
+ except requests.ConnectionError as err:
+ return None, (ERR_TREEHEAD_FETCH, f"ERROR: unable to fetch new tree head: {err}")
if req.status_code != 200:
return None, (ERR_TREEHEAD_FETCH,
"ERROR: unable to fetch new tree head: {}".format(req.status_code))
@@ -293,7 +296,10 @@ def fetch_tree_head_and_verify(log_verification_key):
def fetch_consistency_proof(first, second):
url = g_args.base_url + 'sigsum/v0/get-consistency-proof/{}/{}'.format(first, second)
- req = requests.get(url)
+ try:
+ req = requests.get(url)
+ except requests.ConnectionError as err:
+ return None, (ERR_TREEHEAD_FETCH, f"ERROR: unable to fetch consistency proof: {err}")
if req.status_code != 200:
return None, (ERR_CONSISTENCYPROOF_FETCH,
"ERROR: unable to fetch consistency proof: {}".format(req.status_code))
@@ -354,7 +360,10 @@ def sign_send_store_tree_head(signing_key, log_key, tree_head):
post_data = 'cosignature={}\n'.format(hexlify(signature).decode('ascii'))
post_data += 'key_hash={}\n'.format(hash.hexdigest())
- req = requests.post(g_args.base_url + 'sigsum/v0/add-cosignature', post_data)
+ try:
+ req = requests.post(g_args.base_url + 'sigsum/v0/add-cosignature', post_data)
+ except requests.ConnectionError as err:
+ return (ERR_COSIG_POST, f"ERROR: Unable to post signature to log: {err}")
if req.status_code != 200:
return (ERR_COSIG_POST,
"ERROR: Unable to post signature to log: {} => {}: {}". format(req.url,