示例#1
0
        public override async Task PrepareChallenge()
        {
            // Check for substitute domains
            if (_settings.Validation.AllowDnsSubstitution)
            {
                try
                {
                    // Resolve CNAME in DNS
                    var result = await _dnsClient.GetAuthority(Challenge.DnsRecordName);

                    // Substitute
                    if (result.Domain != Challenge.DnsRecordName)
                    {
                        _log.Information("Detected that {DnsRecordName} is a CNAME that leads to {cname}", Challenge.DnsRecordName, result.Domain);
                        _recordName = result.Domain;
                    }
                }
                catch (Exception ex)
                {
                    _log.Debug("Error checking for substitute domains: {ex}", ex.Message);
                }
            }

            // Create record
            await CreateRecord(_recordName ?? Challenge.DnsRecordName, Challenge.DnsRecordValue);

            _log.Information("Answer should now be available at {answerUri}", _recordName ?? Challenge.DnsRecordName);

            // Verify that the record was created succesfully and wait for possible
            // propagation/caching/TTL issues to resolve themselves naturally
            var retry        = 0;
            var maxRetries   = _settings.Validation.PreValidateDnsRetryCount;
            var retrySeconds = _settings.Validation.PreValidateDnsRetryInterval;

            while (_settings.Validation.PreValidateDns)
            {
                if (await PreValidate(retry))
                {
                    break;
                }
                else
                {
                    retry += 1;
                    if (retry > maxRetries)
                    {
                        _log.Information("It looks like validation is going to fail, but we will try now anyway...");
                        break;
                    }
                    else
                    {
                        _log.Information("Will retry in {s} seconds (retry {i}/{j})...", retrySeconds, retry, maxRetries);
                        Thread.Sleep(retrySeconds * 1000);
                    }
                }
            }
        }
        //[DataRow("_acme-challenge.www2.candell.org", "IpualE-HBtD8bxr60LoyuLw8FxMPOIUgg2XQTR6mSvw")]
        //[DataRow("_acme-challenge.www2.candell.org", "I2F57jex1qSMXprwPy0crWFSUe2n5AowLitxU0q_WKM")]
        //[DataRow("_acme-challenge.wouter.tinus.online", "DHrsG3LudqI9S0jvitp25tDofK1Jf58J08s3c5rIY3k")]
        //[DataRow("_acme-challenge.www7.candell.org", "xxx")]
        public void Should_recursively_follow_cnames(string challengeUri, string expectedToken)
        {
            //var client = _dnsClient.DefaultClient();
            var auth = _dnsClient.GetAuthority(challengeUri).Result;

            Assert.AreEqual(auth.Domain, "_acme-challenge.logs.hourstrackercloud.com");
            var tokens = auth.Nameservers.First().GetTxtRecords(challengeUri).Result;

            Assert.IsTrue(tokens.Contains(expectedToken));
        }
示例#3
0
        public override async Task PrepareChallenge()
        {
            // Check for substitute domains
            _authority = await _dnsClient.GetAuthority(
                Challenge.DnsRecordName,
                followCnames : _settings.Validation.AllowDnsSubstitution);

            var success = false;

            while (!success)
            {
                success = await CreateRecord(_authority.Domain, Challenge.DnsRecordValue);

                if (!success)
                {
                    if (_authority.From == null)
                    {
                        throw new Exception("Unable to prepare for challenge answer");
                    }
                    else
                    {
                        _authority = _authority.From;
                    }
                }
            }

            // Verify that the record was created succesfully and wait for possible
            // propagation/caching/TTL issues to resolve themselves naturally
            var retry        = 0;
            var maxRetries   = _settings.Validation.PreValidateDnsRetryCount;
            var retrySeconds = _settings.Validation.PreValidateDnsRetryInterval;

            while (_settings.Validation.PreValidateDns)
            {
                if (await PreValidate())
                {
                    break;
                }
                else
                {
                    retry += 1;
                    if (retry > maxRetries)
                    {
                        _log.Information("It looks like validation is going to fail, but we will try now anyway...");
                        break;
                    }
                    else
                    {
                        _log.Information("Will retry in {s} seconds (retry {i}/{j})...", retrySeconds, retry, maxRetries);
                        Thread.Sleep(retrySeconds * 1000);
                    }
                }
            }
        }