mirror of
https://github.com/certbot/certbot.git
synced 2026-07-28 00:35:50 +02:00
refactor client.namedtuples to le_util
Conflicts: letsencrypt/client/client.py letsencrypt/client/le_util.py letsencrypt/client/tests/apache/dvsni_test.py letsencrypt/client/tests/challenge_util_test.py
This commit is contained in:
@@ -18,7 +18,7 @@ class ApacheDvsni(object):
|
||||
:ivar dvsni_chall: Data required for challenges.
|
||||
where DvsniChall tuples have the following fields
|
||||
`domain` (`str`), `r_b64` (base64 `str`), `nonce` (hex `str`)
|
||||
`key` (:class:`letsencrypt.client.client.Client.Key`)
|
||||
`key` (:class:`letsencrypt.client.le_util.Key`)
|
||||
:type dvsni_chall: `list` of
|
||||
:class:`letsencrypt.client.challenge_util.DvsniChall`
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ class AuthHandler(object): # pylint: disable=too-many-instance-attributes
|
||||
|
||||
:ivar list domains: list of str domains to get authorization
|
||||
:ivar dict authkey: Authorized Keys for each domain.
|
||||
values are of type :class:`letsencrypt.client.client.Client.Key`
|
||||
values are of type :class:`letsencrypt.client.le_util.Key`
|
||||
:ivar dict responses: keys: domain, values: list of dict responses
|
||||
:ivar dict msgs: ACME Challenge messages with domain as a key
|
||||
:ivar dict paths: optimal path for authorization. eg. paths[domain]
|
||||
@@ -56,7 +56,7 @@ class AuthHandler(object): # pylint: disable=too-many-instance-attributes
|
||||
:param dict msg: ACME challenge message
|
||||
|
||||
:param authkey: authorized key for the challenge
|
||||
:type authkey: :class:`letsencrypt.client.client.Client.Key`
|
||||
:type authkey: :class:`letsencrypt.client.le_util.Key`
|
||||
|
||||
"""
|
||||
if domain in self.domains:
|
||||
|
||||
@@ -35,7 +35,7 @@ def dvsni_gen_cert(name, r_b64, nonce, key):
|
||||
:param str nonce: hex value of nonce
|
||||
|
||||
:param key: Key to perform challenge
|
||||
:type key: :class:`letsencrypt.client.client.Client.Key`
|
||||
:type key: :class:`letsencrypt.client.le_util.Key`
|
||||
|
||||
:returns: tuple of (cert_pem, s) where
|
||||
cert_pem is the certificate in pem form
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
"""ACME protocol client class and helper functions."""
|
||||
import collections
|
||||
import csv
|
||||
import logging
|
||||
import os
|
||||
@@ -30,7 +29,7 @@ class Client(object):
|
||||
:type network: :class:`letsencrypt.client.network.Network`
|
||||
|
||||
:ivar authkey: Authorization Key
|
||||
:type authkey: :class:`letsencrypt.client.client.Client.Key`
|
||||
:type authkey: :class:`letsencrypt.client.le_util.Key`
|
||||
|
||||
:ivar auth_handler: Object that supports the IAuthenticator interface.
|
||||
auth_handler contains both a dv_authenticator and a client_authenticator
|
||||
@@ -45,9 +44,6 @@ class Client(object):
|
||||
"""
|
||||
zope.interface.implements(interfaces.IAuthenticator)
|
||||
|
||||
# Note: form is the type of data, "pem" or "der"
|
||||
CSR = collections.namedtuple("CSR", "file data form")
|
||||
|
||||
def __init__(self, config, authkey, dv_auth, installer):
|
||||
"""Initialize a client.
|
||||
|
||||
@@ -174,7 +170,7 @@ class Client(object):
|
||||
:param list domains: list of domains to install the certificate
|
||||
|
||||
:param privkey: private key for certificate
|
||||
:type privkey: :class:`Key`
|
||||
:type privkey: :class:`letsencrypt.client.le_util.Key`
|
||||
|
||||
:param str cert_file: certificate file path
|
||||
:param str chain_file: chain file path
|
||||
@@ -301,10 +297,10 @@ def validate_key_csr(privkey, csr=None):
|
||||
If csr is left as None, only the key will be validated.
|
||||
|
||||
:param privkey: Key associated with CSR
|
||||
:type privkey: :class:`letsencrypt.client.client.Client.Key`
|
||||
:type privkey: :class:`letsencrypt.client.le_util.Key`
|
||||
|
||||
:param csr: CSR
|
||||
:type csr: :class:`letsencrypt.client.client.Client.CSR`
|
||||
:type csr: :class:`letsencrypt.client.le_util.CSR`
|
||||
|
||||
:raises LetsEncryptClientError: if validation fails
|
||||
|
||||
@@ -321,7 +317,7 @@ def validate_key_csr(privkey, csr=None):
|
||||
if csr:
|
||||
if csr.form == "der":
|
||||
csr_obj = M2Crypto.X509.load_request_der_string(csr.data)
|
||||
csr = Client.CSR(csr.file, csr_obj.as_pem(), "der")
|
||||
csr = le_util.CSR(csr.file, csr_obj.as_pem(), "der")
|
||||
|
||||
# If CSR is provided, it must be readable and valid.
|
||||
if csr.data and not crypto_util.valid_csr(csr.data):
|
||||
@@ -383,14 +379,14 @@ def init_csr(privkey, names, cert_dir):
|
||||
|
||||
logging.info("Creating CSR: %s", csr_filename)
|
||||
|
||||
return Client.CSR(csr_filename, csr_der, "der")
|
||||
return le_util.CSR(csr_filename, csr_der, "der")
|
||||
|
||||
|
||||
def csr_pem_to_der(csr):
|
||||
"""Convert pem CSR to der."""
|
||||
|
||||
csr_obj = M2Crypto.X509.load_request_string(csr.data)
|
||||
return Client.CSR(csr.file, csr_obj.as_der(), "der")
|
||||
return le_util.CSR(csr.file, csr_obj.as_der(), "der")
|
||||
|
||||
|
||||
# This should be controlled by commandline parameters
|
||||
|
||||
@@ -9,7 +9,8 @@ from letsencrypt.client import errors
|
||||
|
||||
|
||||
Key = collections.namedtuple("Key", "file pem")
|
||||
|
||||
# Note: form is the type of data, "pem" or "der"
|
||||
CSR = collections.namedtuple("CSR", "file data form")
|
||||
|
||||
def make_or_verify_dir(directory, mode=0o755, uid=0):
|
||||
"""Make sure directory exists with proper permissions.
|
||||
@@ -32,8 +33,8 @@ def make_or_verify_dir(directory, mode=0o755, uid=0):
|
||||
if exception.errno == errno.EEXIST:
|
||||
if not check_permissions(directory, mode, uid):
|
||||
raise errors.LetsEncryptClientError(
|
||||
'%s exists, but does not have the proper '
|
||||
'permissions or owner' % directory)
|
||||
"%s exists, but does not have the proper "
|
||||
"permissions or owner" % directory)
|
||||
else:
|
||||
raise
|
||||
|
||||
@@ -68,7 +69,7 @@ def unique_file(path, mode=0o777):
|
||||
fname = os.path.join(path, "%04d_%s" % (count, tail))
|
||||
try:
|
||||
file_d = os.open(fname, os.O_CREAT | os.O_EXCL | os.O_RDWR, mode)
|
||||
return os.fdopen(file_d, 'w'), fname
|
||||
return os.fdopen(file_d, "w"), fname
|
||||
except OSError:
|
||||
pass
|
||||
count += 1
|
||||
@@ -96,8 +97,8 @@ def jose_b64encode(data):
|
||||
|
||||
"""
|
||||
if not isinstance(data, str):
|
||||
raise TypeError('argument should be str or bytearray')
|
||||
return base64.urlsafe_b64encode(data).rstrip('=')
|
||||
raise TypeError("argument should be str or bytearray")
|
||||
return base64.urlsafe_b64encode(data).rstrip("=")
|
||||
|
||||
|
||||
def jose_b64decode(data):
|
||||
@@ -115,11 +116,11 @@ def jose_b64decode(data):
|
||||
"""
|
||||
if isinstance(data, unicode):
|
||||
try:
|
||||
data = data.encode('ascii')
|
||||
data = data.encode("ascii")
|
||||
except UnicodeEncodeError:
|
||||
raise ValueError(
|
||||
'unicode argument should contain only ASCII characters')
|
||||
"unicode argument should contain only ASCII characters")
|
||||
elif not isinstance(data, str):
|
||||
raise TypeError('argument should be a str or unicode')
|
||||
raise TypeError("argument should be a str or unicode")
|
||||
|
||||
return base64.urlsafe_b64decode(data + '=' * (4 - (len(data) % 4)))
|
||||
return base64.urlsafe_b64decode(data + "=" * (4 - (len(data) % 4)))
|
||||
|
||||
Reference in New Issue
Block a user