Fix DNSKEY and RRSIG records

This commit is contained in:
Miek Gieben 2010-12-20 22:19:34 +01:00
parent 35bd71b0fa
commit 02c4a4b165
2 changed files with 124 additions and 0 deletions

63
dnssectest.go Normal file
View File

@ -0,0 +1,63 @@
package main
import (
"dns"
"time"
"fmt"
)
const (
NLOOP = 5
)
func main() {
res := new(dns.Resolver)
ch := dns.NewQuerier(res)
// configure the resolver
res.Servers = []string{"192.168.1.2"}
res.Timeout = 2
res.Attempts = 1
// Setup done, now for some real work
// Create a new message
m := new(dns.Msg)
m.MsgHdr.Recursion_desired = true //only set this bit
m.Question = make([]dns.Question, 1)
for i:=0; i< NLOOP; i++ {
// ask something
m.Question[0] = dns.Question{"miek.nl", dns.TypeSOA, dns.ClassINET}
ch <- dns.DnsMsg{m, nil}
// wait for an reply
in := <-ch
fmt.Printf("%v\n", in.Dns)
m.Question[0] = dns.Question{"a.miek.nl", dns.TypeTXT, dns.ClassINET}
ch <- dns.DnsMsg{m, nil}
in = <-ch
fmt.Printf("%v\n", in.Dns)
m.Question[0] = dns.Question{"miek.nl", dns.TypeTXT, dns.ClassINET}
ch <- dns.DnsMsg{m, nil}
in = <-ch
fmt.Printf("%v\n", in.Dns)
m.Question[0] = dns.Question{"nl", dns.TypeDNSKEY, dns.ClassINET}
ch <- dns.DnsMsg{m, nil}
in = <-ch
fmt.Printf("%v\n", in.Dns)
m.Question[0] = dns.Question{"pa1ton.nl", dns.TypeDS, dns.ClassINET}
ch <- dns.DnsMsg{m, nil}
in = <-ch
fmt.Printf("%v\n", in.Dns)
}
ch <- dns.DnsMsg{nil, nil}
time.Sleep(2.0e9) // wait for Go routine to do something
}

61
pack_test.go Normal file
View File

@ -0,0 +1,61 @@
package dns
import (
"testing"
"net"
)
func main() {
out := new(dns.Msg)
r := new(dns.RR_AAAA)
r.AAAA = net.ParseIP("2001:7b8:206:1:200:39ff:fe59:b187").To16()
r.Hdr.Name = "a.miek.nl"
r.Hdr.Rrtype = dns.TypeAAAA
r.Hdr.Class = dns.ClassINET
r.Hdr.Ttl = 3600
out.Answer = make([]dns.RR, 1)
out.Answer[0] = r
msg, err := out.Pack()
if err != nil {
t.Log("Failed to pack msg with AAAA")
t.Fail()
}
in := new(dns.Msg)
if in.Unpack(msg) != true {
t.Log("Failed to unpack msg with AAAA")
t.Fail()
}
fmt.Printf("%v\n", in)
sig := new(dns.RR_RRSIG)
sig.Hdr.Name = "miek.nl."
sig.Hdr.Rrtype = dns.TypeRRSIG
sig.Hdr.Class = dns.ClassINET
sig.Hdr.Ttl = 3600
sig.TypeCovered = dns.TypeDNSKEY
sig.Algorithm = dns.AlgRSASHA1
sig.OrigTtl = 4000
sig.Expiration = 1000
sig.Inception = 800
sig.KeyTag = 34641
sig.SignerName = "miek.nl."
sig.Sig = "AwEAAaHIwpx3w4VHKi6i1LHnTaWeHCL154Jug0Rtc9ji5qwPXpBo6A5sRv7cSsPQKPIwxLpyCrbJ4mr2L0EPOdvP6z6YfljK2ZmTbogU9aSU2fiq/4wjxbdkLyoDVgtO+JsxNN4bjr4WcWhsmk1Hg93FV9ZpkWb0Tbad8DFq NDzr//kZ"
out.Answer[0] = sig
msg, err = out.Pack()
if err != nil {
t.Log("Failed to pack msg with RRSIG")
t.Fail()
}
if in.Unpack(msg) != true {
t.Log("Failed to unpack msg with RRSIG")
t.Fail()
}
fmt.Printf("%v\n", in)
}