diff --git a/challenge/dns01/client_cname.go b/challenge/dns01/client_cname.go index b06041a33..79e625d61 100644 --- a/challenge/dns01/client_cname.go +++ b/challenge/dns01/client_cname.go @@ -2,6 +2,7 @@ package dns01 import ( "context" + "fmt" "log/slog" "github.com/go-acme/lego/v5/challenge/internal" @@ -9,6 +10,19 @@ import ( "github.com/miekg/dns" ) +func (c *Client) resolveCNAME(ctx context.Context, fqdn string) (string, error) { + r, err := c.sendQuery(ctx, fqdn, dns.TypeTXT, true) + if err != nil { + return "", fmt.Errorf("initial recursive nameserver: %w", err) + } + + if r.Rcode == dns.RcodeSuccess { + fqdn = updateDomainWithCName(r, fqdn) + } + + return fqdn, nil +} + func (c *Client) lookupCNAME(ctx context.Context, fqdn string) string { // recursion counter so it doesn't spin out of control for range 50 { diff --git a/challenge/dns01/dns_challenge_precheck.go b/challenge/dns01/dns_challenge_precheck.go index 17cb23651..4a354500d 100644 --- a/challenge/dns01/dns_challenge_precheck.go +++ b/challenge/dns01/dns_challenge_precheck.go @@ -3,8 +3,6 @@ package dns01 import ( "context" "fmt" - - "github.com/miekg/dns" ) // PreCheckFunc checks DNS propagation before notifying ACME that the DNS challenge is ready. @@ -53,15 +51,11 @@ func (p preCheck) checkDNSPropagation(ctx context.Context, fqdn, value string) ( client := DefaultClient() // Initial attempt to resolve at the recursive NS (require getting CNAME) - r, err := client.sendQuery(ctx, fqdn, dns.TypeTXT, true) + fqdn, err := client.resolveCNAME(ctx, fqdn) if err != nil { return false, fmt.Errorf("initial recursive nameserver: %w", err) } - if r.Rcode == dns.RcodeSuccess { - fqdn = updateDomainWithCName(r, fqdn) - } - if p.requireRecursiveNssPropagation { _, err = client.checkRecursiveNameserversPropagation(ctx, fqdn, value) if err != nil {