Exemplo n.º 1
0
    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 JWK account_public_key: Public key for the key pair
            being authorized.

        :returns: ``True`` iff validation with the TXT records resolved from a
            DNS server is successful.
        :rtype: bool

        """
        if not self.verify(chall, account_public_key):
            logger.debug(
                "Verification of key authorization in response failed")
            return False

        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)

        try:
            from acme import dns_resolver
        except ImportError:  # pragma: no cover
            raise errors.DependencyError("Local validation for 'dns-01' "
                                         "challenges requires 'dnspython'")
        txt_records = dns_resolver.txt_records_for_name(validation_domain_name)
        exists = validation in txt_records
        if not exists:
            logger.debug(
                "Key authorization from response (%r) doesn't match "
                "any DNS response in %r", self.key_authorization, txt_records)
        return exists
Exemplo n.º 2
0
    def test_perform_missing_dependency(self, mock_raw_input, mock_verify,
                                        mock_interaction):
        mock_interaction().yesno.return_value = True
        mock_verify.side_effect = acme_errors.DependencyError()

        with mock.patch("certbot.plugins.manual.logger") as mock_logger:
            self.auth.perform([self.dns01])
            self.assertEqual(1, mock_logger.warning.call_count)

        mock_raw_input.assert_called_once_with("Press ENTER to continue")
Exemplo n.º 3
0
def activate(requirement):
    """Make requirement importable.

    :param str requirement: the distribution and version to activate

    :raises acme.errors.DependencyError: if cannot activate requirement

    """
    try:
        for distro in pkg_resources.require(requirement):  # pylint: disable=not-callable
            distro.activate()
    except (pkg_resources.DistributionNotFound, pkg_resources.VersionConflict):
        raise errors.DependencyError('{0} is unavailable'.format(requirement))
Exemplo n.º 4
0
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, if empty the name could not be resolved
    :rtype: list of unicode

    """
    if not DNS_AVAILABLE:
        raise errors.DependencyError(
            '{0} is required to use this function'.format(DNS_REQUIREMENT))
    try:
        dns_response = dns.resolver.query(name, 'TXT')
    except dns.resolver.NXDOMAIN as error:
        return []
    except dns.exception.DNSException as error:
        logger.error("Error resolving %s: %s", name, str(error))
        return []

    return [txt_rec.decode("utf-8") for rdata in dns_response
            for txt_rec in rdata.strings]