mirror of
https://github.com/certbot/certbot.git
synced 2026-08-04 08:03:44 +02:00
add and use request_authorizations
This commit is contained in:
@@ -671,6 +671,7 @@ class BackwardsCompatibleClientV2(object):
|
|||||||
self.client = Client(directory, key=key, net=net)
|
self.client = Client(directory, key=key, net=net)
|
||||||
else:
|
else:
|
||||||
self.client = ClientV2(directory, net=net)
|
self.client = ClientV2(directory, net=net)
|
||||||
|
self.orderr = None
|
||||||
|
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
if name in vars(self.client):
|
if name in vars(self.client):
|
||||||
@@ -705,6 +706,19 @@ class BackwardsCompatibleClientV2(object):
|
|||||||
regr = regr.update(terms_of_service_agreed=True)
|
regr = regr.update(terms_of_service_agreed=True)
|
||||||
return self.client.new_account(regr)
|
return self.client.new_account(regr)
|
||||||
|
|
||||||
|
def request_authorizations(self, csr_pem):
|
||||||
|
if self.acme_version == 1:
|
||||||
|
csr = OpenSSL.crypto.load_certificate_request(OpenSSL.crypto.FILETYPE_PEM, csr_pem)
|
||||||
|
# pylint: disable=protected-access
|
||||||
|
dnsNames = crypto_util._pyopenssl_cert_or_req_all_names(csr)
|
||||||
|
authorizations = []
|
||||||
|
for domain in dnsNames:
|
||||||
|
authorizations.append(self.client.request_domain_challenges(domain))
|
||||||
|
return authorizations
|
||||||
|
else:
|
||||||
|
self.orderr = self.client.new_order(csr_pem)
|
||||||
|
return self.orderr.authorizations
|
||||||
|
|
||||||
def _acme_version_from_directory(self, directory):
|
def _acme_version_from_directory(self, directory):
|
||||||
if hasattr(directory, 'newNonce'):
|
if hasattr(directory, 'newNonce'):
|
||||||
return 2
|
return 2
|
||||||
|
|||||||
@@ -48,10 +48,10 @@ class AuthHandler(object):
|
|||||||
# List must be used to keep responses straight.
|
# List must be used to keep responses straight.
|
||||||
self.achalls = []
|
self.achalls = []
|
||||||
|
|
||||||
def get_authorizations(self, domains, best_effort=False):
|
def get_authorizations(self, csr_pem, best_effort=False):
|
||||||
"""Retrieve all authorizations for challenges.
|
"""Retrieve all authorizations for challenges.
|
||||||
|
|
||||||
:param list domains: Domains for authorization
|
:param list csr_pem: CSR containing domains for authorization
|
||||||
:param bool best_effort: Whether or not all authorizations are
|
:param bool best_effort: Whether or not all authorizations are
|
||||||
required (this is useful in renewal)
|
required (this is useful in renewal)
|
||||||
|
|
||||||
@@ -62,8 +62,10 @@ class AuthHandler(object):
|
|||||||
authorizations
|
authorizations
|
||||||
|
|
||||||
"""
|
"""
|
||||||
for domain in domains:
|
authzrs = self.acme.request_authorizations(csr_pem)
|
||||||
self.authzr[domain] = self.acme.request_domain_challenges(domain)
|
for authzr in authzrs:
|
||||||
|
self.authzr[authzr.body.identifier.value] = authzr
|
||||||
|
domains = self.authzr.keys()
|
||||||
|
|
||||||
self._choose_challenges(domains)
|
self._choose_challenges(domains)
|
||||||
config = zope.component.getUtility(interfaces.IConfig)
|
config = zope.component.getUtility(interfaces.IConfig)
|
||||||
|
|||||||
+8
-15
@@ -235,13 +235,9 @@ class Client(object):
|
|||||||
else:
|
else:
|
||||||
self.auth_handler = None
|
self.auth_handler = None
|
||||||
|
|
||||||
def obtain_certificate_from_csr(self, domains, csr, authzr=None):
|
def obtain_certificate_from_csr(self, csr, authzr=None):
|
||||||
"""Obtain certificate.
|
"""Obtain certificate.
|
||||||
|
|
||||||
Internal function with precondition that `domains` are
|
|
||||||
consistent with identifiers present in the `csr`.
|
|
||||||
|
|
||||||
:param list domains: Domain names.
|
|
||||||
:param .util.CSR csr: PEM-encoded Certificate Signing
|
:param .util.CSR csr: PEM-encoded Certificate Signing
|
||||||
Request. The key used to generate this CSR can be different
|
Request. The key used to generate this CSR can be different
|
||||||
than `authkey`.
|
than `authkey`.
|
||||||
@@ -261,10 +257,10 @@ class Client(object):
|
|||||||
if self.account.regr is None:
|
if self.account.regr is None:
|
||||||
raise errors.Error("Please register with the ACME server first.")
|
raise errors.Error("Please register with the ACME server first.")
|
||||||
|
|
||||||
logger.debug("CSR: %s, domains: %s", csr, domains)
|
logger.debug("CSR: %s", csr)
|
||||||
|
|
||||||
if authzr is None:
|
if authzr is None:
|
||||||
authzr = self.auth_handler.get_authorizations(domains)
|
authzr = self.auth_handler.get_authorizations(csr)
|
||||||
|
|
||||||
certr = self.acme.request_issuance(
|
certr = self.acme.request_issuance(
|
||||||
jose.ComparableX509(
|
jose.ComparableX509(
|
||||||
@@ -307,13 +303,6 @@ class Client(object):
|
|||||||
:rtype: tuple
|
:rtype: tuple
|
||||||
|
|
||||||
"""
|
"""
|
||||||
authzr = self.auth_handler.get_authorizations(
|
|
||||||
domains,
|
|
||||||
self.config.allow_subset_of_names)
|
|
||||||
|
|
||||||
auth_domains = set(a.body.identifier.value for a in authzr)
|
|
||||||
domains = [d for d in domains if d in auth_domains]
|
|
||||||
|
|
||||||
# Create CSR from names
|
# Create CSR from names
|
||||||
if self.config.dry_run:
|
if self.config.dry_run:
|
||||||
key = util.Key(file=None,
|
key = util.Key(file=None,
|
||||||
@@ -326,8 +315,12 @@ class Client(object):
|
|||||||
self.config.rsa_key_size, self.config.key_dir)
|
self.config.rsa_key_size, self.config.key_dir)
|
||||||
csr = crypto_util.init_save_csr(key, domains, self.config.csr_dir)
|
csr = crypto_util.init_save_csr(key, domains, self.config.csr_dir)
|
||||||
|
|
||||||
|
authzr = self.auth_handler.get_authorizations(
|
||||||
|
csr,
|
||||||
|
self.config.allow_subset_of_names)
|
||||||
|
|
||||||
certr, chain = self.obtain_certificate_from_csr(
|
certr, chain = self.obtain_certificate_from_csr(
|
||||||
domains, csr, authzr=authzr)
|
csr, authzr=authzr)
|
||||||
|
|
||||||
return certr, chain, key, csr
|
return certr, chain, key, csr
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1064,7 +1064,7 @@ def _csr_get_and_save_cert(config, le_client):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
csr, _ = config.actual_csr
|
csr, _ = config.actual_csr
|
||||||
certr, chain = le_client.obtain_certificate_from_csr(config.domains, csr)
|
certr, chain = le_client.obtain_certificate_from_csr(csr)
|
||||||
if config.dry_run:
|
if config.dry_run:
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"Dry run: skipping saving certificate to %s", config.cert_path)
|
"Dry run: skipping saving certificate to %s", config.cert_path)
|
||||||
|
|||||||
Reference in New Issue
Block a user