add a timeout for WKD and KOO requests
This commit is contained in:
parent
f503c62739
commit
18ad7ec742
|
|
@ -8,7 +8,17 @@ def request_from_koo(email: str) -> str:
|
|||
:return: the public key of the user, or "" if it isn't found
|
||||
"""
|
||||
koo_url = f"https://keys.openpgp.org/vks/v1/by-email/{email}"
|
||||
r = requests.get(koo_url)
|
||||
try:
|
||||
r = requests.get(koo_url, timeout=10)
|
||||
except requests.exceptions.SSLError:
|
||||
print(f"SSL Error when querying {koo_url}")
|
||||
return ""
|
||||
except requests.exceptions.ConnectionError:
|
||||
print(f"Connection Error when querying {koo_url}")
|
||||
return ""
|
||||
except requests.exceptions.Timeout:
|
||||
print(f"Timeout while connecting to {koo_url}")
|
||||
return ""
|
||||
if "No key found for email address" in r.content.decode():
|
||||
return ""
|
||||
keyparts = []
|
||||
|
|
|
|||
|
|
@ -14,13 +14,16 @@ def request_from_wkd(email: str, server: str) -> str:
|
|||
wkd_hash = wkdhash.userid_to_wkd_hash(email)
|
||||
wkd_url = f"https://{server}/.well-known/openpgpkey/{domain}/hu/{wkd_hash}?l={localpart}"
|
||||
try:
|
||||
r = requests.get(wkd_url)
|
||||
r = requests.get(wkd_url, timeout=10)
|
||||
except requests.exceptions.SSLError:
|
||||
print(f"SSL Error when querying {wkd_url}")
|
||||
return ""
|
||||
except requests.exceptions.ConnectionError:
|
||||
print(f"Connection Error when querying {wkd_url}")
|
||||
return ""
|
||||
except requests.exceptions.Timeout:
|
||||
print(f"Timeout while connecting to {wkd_url}")
|
||||
return ""
|
||||
if b"Too many recent failed key server lookups" in r.content:
|
||||
print(f"Too many failed lookups error when querying {wkd_url}")
|
||||
return ""
|
||||
|
|
|
|||
Loading…
Reference in a new issue