mirror of
https://github.com/certbot/certbot.git
synced 2026-06-04 06:15:36 -04:00
Style changes.
This commit is contained in:
parent
7747dc8488
commit
b5bb90628c
2 changed files with 14 additions and 20 deletions
|
|
@ -1,13 +1,13 @@
|
|||
"""ACME Identifier Validation Challenges."""
|
||||
import abc
|
||||
import dns.resolver
|
||||
import dns.exception
|
||||
import functools
|
||||
import hashlib
|
||||
import logging
|
||||
import socket
|
||||
|
||||
from cryptography.hazmat.primitives import hashes
|
||||
import dns.resolver
|
||||
import dns.exception
|
||||
import OpenSSL
|
||||
import requests
|
||||
|
||||
|
|
@ -217,17 +217,16 @@ class KeyAuthorizationChallenge(_TokenDVChallenge):
|
|||
self.validation(account_key, *args, **kwargs))
|
||||
|
||||
|
||||
@ChallengeResponse.register
|
||||
class DNS01Response(KeyAuthorizationChallengeResponse):
|
||||
"""ACME "dns-01" challenge response."""
|
||||
typ = "dns-01"
|
||||
|
||||
def txt_records_for_name(self, name):
|
||||
def txt_records_for_name(name):
|
||||
"""Resolve the name and return the TXT records.
|
||||
|
||||
:param unicode name: Domain name being verified.
|
||||
|
||||
:returns: A list of txt records, or None if the name could not be resolved
|
||||
:returns: A list of txt records, if empty the name could not be resolved
|
||||
:rtype: list of unicode
|
||||
|
||||
"""
|
||||
|
|
@ -235,17 +234,17 @@ class DNS01Response(KeyAuthorizationChallengeResponse):
|
|||
dns_response = dns.resolver.query(name, 'TXT')
|
||||
except dns.exception.DNSException as error:
|
||||
logger.error("Unable to resolve %s: %s", name, error)
|
||||
return None
|
||||
return sum([rdata.strings for rdata in dns_response], [])
|
||||
return []
|
||||
return [txt_rec in dns_response for txt_rec in rdata.strings]
|
||||
|
||||
@ChallengeResponse.register
|
||||
def simple_verify(self, chall, domain, account_public_key):
|
||||
"""Simple verify.
|
||||
|
||||
:param challenges.DNS01 chall: Corresponding challenge.
|
||||
:param unicode domain: Domain name being verified.
|
||||
:param account_public_key: Public key for the key pair
|
||||
being authorized. If ``None`` key verification is not
|
||||
performed!
|
||||
being authorized.
|
||||
:param JWK account_public_key:
|
||||
|
||||
:returns: ``True`` iff validation with the TXT records resolved from a
|
||||
|
|
@ -260,14 +259,9 @@ class DNS01Response(KeyAuthorizationChallengeResponse):
|
|||
validation_domain_name = chall.validation_domain_name(domain)
|
||||
validation = chall.validation(account_public_key)
|
||||
logger.debug("Verifying %s at %s...", chall.typ, validation_domain_name)
|
||||
txt_records = self.txt_records_for_name(validation_domain_name)
|
||||
if txt_records == None:
|
||||
return False
|
||||
|
||||
for txt_record in txt_records:
|
||||
if txt_record == validation:
|
||||
return True
|
||||
|
||||
if validation in txt_records_for_name(validation_domain_name):
|
||||
return True
|
||||
logger.debug("Key authorization from response (%r) doesn't match any "
|
||||
"DNS response in %r", self.key_authorization, txt_records)
|
||||
return False
|
||||
|
|
@ -289,8 +283,8 @@ class DNS01(KeyAuthorizationChallenge):
|
|||
:rtype: unicode
|
||||
|
||||
"""
|
||||
key_authorization = self.key_authorization(account_key)
|
||||
return jose.b64encode(hashlib.sha256(key_authorization).digest())
|
||||
return jose.b64encode(hashlib.sha256(
|
||||
self.key_authorization(account_key)).digest())
|
||||
|
||||
def validation_domain_name(self, name):
|
||||
"""Domain name for TXT validation record.
|
||||
|
|
|
|||
|
|
@ -77,6 +77,7 @@ class KeyAuthorizationChallengeResponseTest(unittest.TestCase):
|
|||
key_authorization='.foo.oKGqedy-b-acd5eoybm2f-NVFxvyOoET5CNy3xnv8WY')
|
||||
self.assertFalse(response.verify(self.chall, KEY.public_key()))
|
||||
|
||||
|
||||
class DNS01ResponseTest(unittest.TestCase):
|
||||
# pylint: disable=too-many-instance-attributes
|
||||
|
||||
|
|
@ -108,8 +109,7 @@ class DNS01ResponseTest(unittest.TestCase):
|
|||
|
||||
def test_from_json(self):
|
||||
from acme.challenges import DNS01Response
|
||||
self.assertEqual(
|
||||
self.msg, DNS01Response.from_json(self.jmsg))
|
||||
self.assertEqual(self.msg, DNS01Response.from_json(self.jmsg))
|
||||
|
||||
def test_from_json_hashable(self):
|
||||
from acme.challenges import DNS01Response
|
||||
|
|
|
|||
Loading…
Reference in a new issue