forked from TrueCloudLab/lego
fix: ensure case-insensitive comparison of CNAME records (#1956)
Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
This commit is contained in:
parent
d4f31eb8b0
commit
3cd3024561
2 changed files with 41 additions and 2 deletions
|
@ -1,12 +1,16 @@
|
||||||
package dns01
|
package dns01
|
||||||
|
|
||||||
import "github.com/miekg/dns"
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/miekg/dns"
|
||||||
|
)
|
||||||
|
|
||||||
// Update FQDN with CNAME if any.
|
// Update FQDN with CNAME if any.
|
||||||
func updateDomainWithCName(r *dns.Msg, fqdn string) string {
|
func updateDomainWithCName(r *dns.Msg, fqdn string) string {
|
||||||
for _, rr := range r.Answer {
|
for _, rr := range r.Answer {
|
||||||
if cn, ok := rr.(*dns.CNAME); ok {
|
if cn, ok := rr.(*dns.CNAME); ok {
|
||||||
if cn.Hdr.Name == fqdn {
|
if strings.EqualFold(cn.Hdr.Name, fqdn) {
|
||||||
return cn.Target
|
return cn.Target
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
35
challenge/dns01/cname_test.go
Normal file
35
challenge/dns01/cname_test.go
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
package dns01
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/miekg/dns"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_updateDomainWithCName_caseInsensitive(t *testing.T) {
|
||||||
|
qname := "_acme-challenge.uppercase-test.example.com."
|
||||||
|
cnameTarget := "_acme-challenge.uppercase-test.cname-target.example.com."
|
||||||
|
|
||||||
|
msg := &dns.Msg{
|
||||||
|
MsgHdr: dns.MsgHdr{
|
||||||
|
Authoritative: true,
|
||||||
|
},
|
||||||
|
Answer: []dns.RR{
|
||||||
|
&dns.CNAME{
|
||||||
|
Hdr: dns.RR_Header{
|
||||||
|
Name: strings.ToUpper(qname), // CNAME names are case-insensitive
|
||||||
|
Rrtype: dns.TypeCNAME,
|
||||||
|
Class: dns.ClassINET,
|
||||||
|
Ttl: 3600,
|
||||||
|
},
|
||||||
|
Target: cnameTarget,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
fqdn := updateDomainWithCName(msg, qname)
|
||||||
|
|
||||||
|
assert.Equal(t, cnameTarget, fqdn)
|
||||||
|
}
|
Loading…
Reference in a new issue