Merge pull request #9541 from certbot/remove-legacy-new-authz-support

account: stop storing legacy new_authzr_uri
This commit is contained in:
Will Greenberg
2023-01-26 17:52:33 -08:00
committed by GitHub
4 changed files with 11 additions and 45 deletions
+1
View File
@@ -17,6 +17,7 @@ Certbot adheres to [Semantic Versioning](https://semver.org/).
### Fixed
* Fixed a crash when registering an account with BuyPass' ACME server.
* Fixed a bug where Certbot would crash with `AttributeError: can't set attribute` on ACME server errors in Python 3.11. See [GH #9539](https://github.com/certbot/certbot/issues/9539).
More details about these changes can be found on our GitHub repo.
+7 -31
View File
@@ -126,18 +126,6 @@ class AccountMemoryStorage(interfaces.AccountStorage):
raise errors.AccountNotFound(account_id)
class RegistrationResourceWithNewAuthzrURI(messages.RegistrationResource):
"""A backwards-compatible RegistrationResource with a new-authz URI.
Hack: Certbot versions pre-0.11.1 expect to load
new_authzr_uri as part of the account. Because people
sometimes switch between old and new versions, we will
continue to write out this field for some time so older
clients don't crash in that scenario.
"""
new_authzr_uri: str = jose.field('new_authzr_uri')
class AccountFileStorage(interfaces.AccountStorage):
"""Accounts file storage.
@@ -254,20 +242,19 @@ class AccountFileStorage(interfaces.AccountStorage):
dir_path = self._prepare(account)
self._create(account, dir_path)
self._update_meta(account, dir_path)
self._update_regr(account, client, dir_path)
self._update_regr(account, dir_path)
except IOError as error:
raise errors.AccountStorageError(error)
def update_regr(self, account: Account, client: ClientV2) -> None:
def update_regr(self, account: Account) -> None:
"""Update the registration resource.
:param Account account: account to update
:param ClientV2 client: ACME client associated to the account
"""
try:
dir_path = self._prepare(account)
self._update_regr(account, client, dir_path)
self._update_regr(account, dir_path)
except IOError as error:
raise errors.AccountStorageError(error)
@@ -358,22 +345,11 @@ class AccountFileStorage(interfaces.AccountStorage):
with util.safe_open(self._key_path(dir_path), "w", chmod=0o400) as key_file:
key_file.write(account.key.json_dumps())
def _update_regr(self, account: Account, acme: ClientV2, dir_path: str) -> None:
def _update_regr(self, account: Account, dir_path: str) -> None:
with open(self._regr_path(dir_path), "w") as regr_file:
regr = account.regr
# If we have a value for new-authz, save it for forwards
# compatibility with older versions of Certbot. If we don't
# have a value for new-authz, this is an ACMEv2 directory where
# an older version of Certbot won't work anyway.
if hasattr(acme.directory, "new-authz"):
regr = RegistrationResourceWithNewAuthzrURI(
new_authzr_uri=acme.directory.new_authz,
body={},
uri=regr.uri)
else:
regr = messages.RegistrationResource(
body={},
uri=regr.uri)
regr = messages.RegistrationResource(
body={},
uri=account.regr.uri)
regr_file.write(regr.json_dumps())
def _update_meta(self, account: Account, dir_path: str) -> None:
+1 -1
View File
@@ -948,7 +948,7 @@ def update_account(config: configuration.NamespaceConfig,
# the v2 uri. Since it's the same object on disk, put it back to the v1 uri
# so that we can also continue to use the account object with acmev1.
acc.regr = acc.regr.update(uri=prev_regr_uri)
account_storage.update_regr(acc, cb_client.acme)
account_storage.update_regr(acc)
if not config.email:
display_util.notify("Any contact information associated "
+2 -13
View File
@@ -109,19 +109,16 @@ class AccountFileStorageTest(test_util.ConfigTestCase):
self.storage = AccountFileStorage(self.config)
from certbot._internal.account import Account
new_authzr_uri = "hi"
meta = Account.Meta(
creation_host="test.example.org",
creation_dt=datetime.datetime(
2021, 1, 5, 14, 4, 10, tzinfo=pytz.UTC))
self.acc = Account(
regr=messages.RegistrationResource(
uri=None, body=messages.Registration(),
new_authzr_uri=new_authzr_uri),
uri=None, body=messages.Registration()),
key=KEY,
meta=meta)
self.mock_client = mock.MagicMock()
self.mock_client.directory.new_authz = new_authzr_uri
def test_init_creates_dir(self):
self.assertTrue(os.path.isdir(
@@ -141,16 +138,8 @@ class AccountFileStorageTest(test_util.ConfigTestCase):
loaded = self.storage.load(self.acc.id)
self.assertEqual(self.acc, loaded)
def test_save_and_restore_old_version(self):
"""Saved regr should include a new_authzr_uri for older Certbots"""
self.storage.save(self.acc, self.mock_client)
path = os.path.join(self.config.accounts_dir, self.acc.id, "regr.json")
with open(path, "r") as f:
regr = json.load(f)
self.assertIn("new_authzr_uri", regr)
def test_update_regr(self):
self.storage.update_regr(self.acc, self.mock_client)
self.storage.update_regr(self.acc)
account_path = os.path.join(self.config.accounts_dir, self.acc.id)
self.assertTrue(os.path.exists(account_path))
self.assertTrue(os.path.exists(os.path.join(account_path, "regr.json")))