From e88a23ad76b6dc092645a870b3b5f99bd4fbd095 Mon Sep 17 00:00:00 2001 From: osirisinferi Date: Tue, 31 May 2022 20:10:25 +0200 Subject: [PATCH] Improve `_get_v2_account()` Required for proper working of `certbot.main.update_registration()`. This function updates the `regr.body` locally instead of passing the fields which need to be updated to `acme.client.update_registration()` as a separate argument in the `update` parameter. --- acme/acme/client.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/acme/acme/client.py b/acme/acme/client.py index f4bc7bf4a..044099a05 100644 --- a/acme/acme/client.py +++ b/acme/acme/client.py @@ -8,6 +8,7 @@ import datetime from email.utils import parsedate_tz import heapq import http.client as http_client +import json import logging import re import sys @@ -672,7 +673,19 @@ class ClientV2(ClientBase): only_existing_reg = regr.body.update(only_return_existing=True) response = self._post(self.directory['newAccount'], only_existing_reg) updated_uri = response.headers['Location'] - new_regr = regr.update(body=messages.Registration.from_json(response.json()), + + # Check for an empty `regr.body` by using the `json_dumps()` method to remove all the + # `None` fields from the `regr.body` (subclass of `jose.JSONObjectWithFields`) object + # which only leaves a `contact` field if everything else is `None`. The `contact` field + # contains an empty list if the `regr.body` is empty. + regr_body = json.loads(regr.body.json_dumps()) + regr_body_empty = bool(len(regr_body) == 1 and not regr_body['contact']) + + # If the original `regr.body` was empty, populate it with info received from the + # ACME server. If it isn't empty, pass through the original body, as it might be + # an updated body in `certbot.main.update_account()`. + new_regr = regr.update(body=messages.Registration.from_json(response.json()) + if regr_body_empty else regr.body, uri=updated_uri) self.net.account = new_regr return new_regr