mirror of
https://github.com/go-acme/lego
synced 2026-03-14 14:35:48 +01:00
refactor: extract resolveCNAME
This commit is contained in:
parent
d50362c5d0
commit
d8f2938799
2 changed files with 15 additions and 7 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue