Commit 3ae41967 authored by Adrien Dorsaz's avatar Adrien Dorsaz

adt: send-request can perform POST-as-GET request (since draft 15)

parent 0bf25874
...@@ -34,7 +34,10 @@ def get_crt(config, log=LOGGER): ...@@ -34,7 +34,10 @@ def get_crt(config, log=LOGGER):
def _send_signed_request(url, payload): def _send_signed_request(url, payload):
"""Sends signed requests to ACME server.""" """Sends signed requests to ACME server."""
nonlocal jws_nonce nonlocal jws_nonce
payload64 = _b64(json.dumps(payload).encode("utf8")) if payload == "": # on POST-as-GET, final payload has to be just empty string
payload64 = ""
else:
payload64 = _b64(json.dumps(payload).encode("utf8"))
protected = copy.deepcopy(jws_header) protected = copy.deepcopy(jws_header)
protected["nonce"] = jws_nonce or requests.get(acme_config["newNonce"]).headers['Replay-Nonce'] protected["nonce"] = jws_nonce or requests.get(acme_config["newNonce"]).headers['Replay-Nonce']
protected["url"] = url protected["url"] = url
...@@ -49,15 +52,15 @@ def get_crt(config, log=LOGGER): ...@@ -49,15 +52,15 @@ def get_crt(config, log=LOGGER):
"protected": protected64, "payload": payload64,"signature": _b64(signature) "protected": protected64, "payload": payload64,"signature": _b64(signature)
} }
try: try:
resp = requests.post(url, json=jose, headers=joseheaders) response = requests.post(url, json=jose, headers=joseheaders)
except requests.exceptions.RequestException as error: except requests.exceptions.RequestException as error:
resp = error.response response = error.response
finally: finally:
jws_nonce = resp.headers['Replay-Nonce'] jws_nonce = response.headers['Replay-Nonce']
if resp.text != '': try:
return resp.status_code, resp.json(), resp.headers return response, response.json()
else: except ValueError as error:
return resp.status_code, json.dumps({}), resp.headers return response, json.dumps({})
# main code # main code
adtheaders = {'User-Agent': 'acme-dns-tiny/2.1', adtheaders = {'User-Agent': 'acme-dns-tiny/2.1',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment