mirror of
https://github.com/certbot/certbot.git
synced 2026-08-04 20:32:33 +02:00
Account.id: use key md5 hexdigest.
This commit is contained in:
+17
-16
@@ -1,9 +1,11 @@
|
|||||||
"""Creates ACME accounts for server."""
|
"""Creates ACME accounts for server."""
|
||||||
import datetime
|
import datetime
|
||||||
|
import hashlib
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import socket
|
import socket
|
||||||
|
|
||||||
|
from cryptography.hazmat.primitives import serialization
|
||||||
import pyrfc3339
|
import pyrfc3339
|
||||||
import pytz
|
import pytz
|
||||||
import zope.component
|
import zope.component
|
||||||
@@ -20,15 +22,13 @@ from letsencrypt import le_util
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class Account(object):
|
class Account(object): # pylint: disable=too-few-public-methods
|
||||||
"""ACME protocol registration.
|
"""ACME protocol registration.
|
||||||
|
|
||||||
:ivar .RegistrationResource regr: Registration Resource
|
:ivar .RegistrationResource regr: Registration Resource
|
||||||
:ivar .JWK key: Authorized Account Key
|
:ivar .JWK key: Authorized Account Key
|
||||||
:ivar .Meta: Account metadata
|
:ivar .Meta: Account metadata
|
||||||
|
:ivar str id: Globally unique account identifier.
|
||||||
.. note:: ``creation_dt`` and ``creation_host`` are useful in
|
|
||||||
cross-machine migration scenarios.
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@@ -38,6 +38,9 @@ class Account(object):
|
|||||||
:ivar datetime.datetime creation_dt: Creation date and time (UTC).
|
:ivar datetime.datetime creation_dt: Creation date and time (UTC).
|
||||||
:ivar str creation_host: FQDN of host, where account has been created.
|
:ivar str creation_host: FQDN of host, where account has been created.
|
||||||
|
|
||||||
|
.. note:: ``creation_dt`` and ``creation_host`` are useful in
|
||||||
|
cross-machine migration scenarios.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
creation_dt = acme_fields.RFC3339Field("creation_dt")
|
creation_dt = acme_fields.RFC3339Field("creation_dt")
|
||||||
creation_host = jose.Field("creation_host")
|
creation_host = jose.Field("creation_host")
|
||||||
@@ -51,18 +54,16 @@ class Account(object):
|
|||||||
tz=pytz.UTC).replace(microsecond=0),
|
tz=pytz.UTC).replace(microsecond=0),
|
||||||
creation_host=socket.getfqdn()) if meta is None else meta
|
creation_host=socket.getfqdn()) if meta is None else meta
|
||||||
|
|
||||||
@property
|
self.id = hashlib.md5( # pylint: disable=invalid-name
|
||||||
def id(self): # pylint: disable=invalid-name
|
self.key.key.public_key().public_bytes(
|
||||||
"""Globally unique account identifier.
|
encoding=serialization.Encoding.DER,
|
||||||
|
format=serialization.PublicFormat.SubjectPublicKeyInfo)
|
||||||
Implementation note: Email? Multiple accounts can have the same
|
).hexdigest()
|
||||||
email address. Registration URI? Assigned by the server, not
|
# Implementation note: Email? Multiple accounts can have the
|
||||||
guaranteed to be stable over time, nor cannonical URI can be
|
# same email address. Registration URI? Assigned by the
|
||||||
generated. One could use the account key (fingerprint), as ACME
|
# server, not guaranteed to be stable over time, nor
|
||||||
protocol doesn't allow it to be updated...
|
# cannonical URI can be generated. ACME protocol doesn't allow
|
||||||
|
# account key (and thus its fingerprint) to be updated...
|
||||||
"""
|
|
||||||
return self.slug
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def slug(self):
|
def slug(self):
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ class AccountTest(unittest.TestCase):
|
|||||||
|
|
||||||
def test_id(self):
|
def test_id(self):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.acc.id, "test.letsencrypt.org@2015-07-04T14:04:10Z")
|
self.acc.id, "2ba35a3bdf380ed76a5ac9e740568395")
|
||||||
|
|
||||||
def test_slug(self):
|
def test_slug(self):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
@@ -54,7 +54,7 @@ class AccountTest(unittest.TestCase):
|
|||||||
def test_repr(self):
|
def test_repr(self):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
repr(self.acc),
|
repr(self.acc),
|
||||||
"<Account(test.letsencrypt.org@2015-07-04T14:04:10Z)>")
|
"<Account(2ba35a3bdf380ed76a5ac9e740568395)>")
|
||||||
|
|
||||||
|
|
||||||
class ReportNewAccountTest(unittest.TestCase):
|
class ReportNewAccountTest(unittest.TestCase):
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
"""Test letsencrypt.display.ops."""
|
"""Test letsencrypt.display.ops."""
|
||||||
import os
|
import os
|
||||||
|
import pkg_resources
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
import unittest
|
import unittest
|
||||||
@@ -7,6 +8,7 @@ import unittest
|
|||||||
import mock
|
import mock
|
||||||
import zope.component
|
import zope.component
|
||||||
|
|
||||||
|
from acme import jose
|
||||||
from acme import messages
|
from acme import messages
|
||||||
|
|
||||||
from letsencrypt import account
|
from letsencrypt import account
|
||||||
@@ -15,6 +17,10 @@ from letsencrypt import interfaces
|
|||||||
from letsencrypt.display import util as display_util
|
from letsencrypt.display import util as display_util
|
||||||
|
|
||||||
|
|
||||||
|
KEY = jose.JWKRSA.load(pkg_resources.resource_string(
|
||||||
|
"letsencrypt.tests", os.path.join("testdata", "rsa512_key.pem")))
|
||||||
|
|
||||||
|
|
||||||
class ChoosePluginTest(unittest.TestCase):
|
class ChoosePluginTest(unittest.TestCase):
|
||||||
"""Tests for letsencrypt.display.ops.choose_plugin."""
|
"""Tests for letsencrypt.display.ops.choose_plugin."""
|
||||||
|
|
||||||
@@ -186,7 +192,7 @@ class ChooseAccountTest(unittest.TestCase):
|
|||||||
accounts_dir=self.accounts_dir,
|
accounts_dir=self.accounts_dir,
|
||||||
account_keys_dir=self.account_keys_dir,
|
account_keys_dir=self.account_keys_dir,
|
||||||
server="letsencrypt-demo.org")
|
server="letsencrypt-demo.org")
|
||||||
self.key = mock.MagicMock()
|
self.key = KEY
|
||||||
|
|
||||||
self.acc1 = account.Account(messages.RegistrationResource(
|
self.acc1 = account.Account(messages.RegistrationResource(
|
||||||
uri=None, new_authzr_uri=None, body=messages.Registration.from_data(
|
uri=None, new_authzr_uri=None, body=messages.Registration.from_data(
|
||||||
|
|||||||
Reference in New Issue
Block a user