From c6042c4ce88877c561288ee82272012d7f07463b Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Thu, 23 Feb 2012 12:46:39 +0100 Subject: [PATCH] Work on copy of the header when validating --- dns.go | 12 ++++++++++++ dnssec.go | 30 +++++++++++------------------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/dns.go b/dns.go index 10b515fc..953894f6 100644 --- a/dns.go +++ b/dns.go @@ -171,6 +171,18 @@ func (h *RR_Header) Len() int { return l } +// Create a copy of the header + +func (h *RR_Header) Copy() *RR_Header { + h1 := new(RR_Header) + h1.Name = h.Name + h1.Rrtype = h.Rrtype + h1.Class = h.Class + h1.Ttl = h.Ttl + h1.Rdlength = h.Rdlength + return h1 +} + func zoneMatch(pattern, zone string) (ok bool) { if len(pattern) == 0 { return diff --git a/dnssec.go b/dnssec.go index 9a7d9cc2..005fcd59 100644 --- a/dnssec.go +++ b/dnssec.go @@ -493,33 +493,28 @@ func (p wireSlice) Less(i, j int) bool { } func (p wireSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] } -// Return the raw signature data. The data in []RR is modified in -// this function. +// Return the raw signature data. +// TODO: the rr rdata is lowercased for some records func rawSignatureData(rrset []RR, s *RR_RRSIG) (buf []byte) { wires := make(wireSlice, len(rrset)) for i, r := range rrset { - h := r.Header() - name := h.Name - labels := SplitLabels(h.Name) + r1 := r + h1 := r1.Header() + labels := SplitLabels(h1.Name) // 6.2. Canonical RR Form. (4) - wildcards if len(labels) > int(s.Labels) { // Wildcard - h.Name = "*." + strings.Join(labels[len(labels)-int(s.Labels):], ".") + "." + h1.Name = "*." + strings.Join(labels[len(labels)-int(s.Labels):], ".") + "." } // RFC 4034: 6.2. Canonical RR Form. (2) - domain name to lowercase - h.Name = strings.ToLower(h.Name) + h1.Name = strings.ToLower(h1.Name) // 6.2. Canonical RR Form. (3) - domain rdata to lowercase. // NS, MD, MF, CNAME, SOA, MB, MG, MR, PTR, // HINFO, MINFO, MX, RP, AFSDB, RT, SIG, PX, NXT, NAPTR, KX, // SRV, DNAME, A6 - switch x := r.(type) { - default: - case *RR_RRSIG, *RR_NSEC: - break + switch x := r1.(type) { case *RR_NS: x.Ns = strings.ToLower(x.Ns) - //case *RR_MD: - //case *RR_MF: case *RR_CNAME: x.Cname = strings.ToLower(x.Cname) case *RR_SOA: @@ -548,16 +543,13 @@ func rawSignatureData(rrset []RR, s *RR_RRSIG) (buf []byte) { x.Target = strings.ToLower(x.Target) } // 6.2. Canonical RR Form. (5) - origTTL - ttl := h.Ttl - wire := make([]byte, r.Len()*2) - h.Ttl = s.OrigTtl - off, ok1 := packRR(r, wire, 0, nil, false) + wire := make([]byte, r1.Len()*2) + h1.Ttl = s.OrigTtl + off, ok1 := packRR(r1, wire, 0, nil, false) if !ok1 { return nil } - h.Ttl = ttl // restore the order in the universe wire = wire[:off] - h.Name = name wires[i] = wire } sort.Sort(wires)