add TSIG axfr test, still needs work though
This commit is contained in:
parent
73cad7898b
commit
f53ca4bfc3
2
LICENSE
2
LICENSE
|
@ -1,4 +1,4 @@
|
||||||
Extensions from the original work are copyright (c) 2010 Miek Gieben
|
Extensions from the original work are copyright (c) 2010, 2011 Miek Gieben
|
||||||
|
|
||||||
As this is fork of the official Go code the same license applies:
|
As this is fork of the official Go code the same license applies:
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package dns
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestClientSync(t *testing.T) {
|
func TestClientSync(t *testing.T) {
|
||||||
|
@ -81,53 +82,23 @@ func TestResolverEdns(t *testing.T) {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
func TestClientTsigAXFR(t *testing.T) {
|
||||||
func TestResolverTsig(t *testing.T) {
|
|
||||||
res := new(Resolver)
|
|
||||||
res.Servers = []string{"127.0.0.1"}
|
|
||||||
res.Timeout = 2
|
|
||||||
res.Attempts = 1
|
|
||||||
|
|
||||||
m := new(Msg)
|
m := new(Msg)
|
||||||
m.MsgHdr.RecursionDesired = true //only set this bit
|
m.SetAxfr("miek.nl")
|
||||||
m.Question = make([]Question, 1)
|
|
||||||
|
|
||||||
// ask something
|
m.SetTsig("axfr", HmacMD5, 300, uint64(time.Seconds()))
|
||||||
m.Question[0] = Question{"powerdns.nl", TypeDNSKEY, ClassINET}
|
secrets := make(map[string]string)
|
||||||
m.Extra = make([]RR, 1)
|
secrets["axfr"] = "so6ZGir4GPAqINNh9U5c3A=="
|
||||||
m.Id = Id()
|
|
||||||
|
|
||||||
|
c := NewClient()
|
||||||
|
c.Net = "tcp"
|
||||||
|
c.TsigSecret = secrets
|
||||||
|
|
||||||
tsig := new(Tsig)
|
_, err := c.XfrReceive(m, "85.223.71.124:53")
|
||||||
tsig.Name = "miek.nl."
|
/*
|
||||||
tsig.Algorithm = HmacMD5
|
if err != nil {
|
||||||
tsig.Fudge = 300
|
t.Log("%s\n", err.String())
|
||||||
tsig.TimeSigned = uint64(time.Seconds())
|
t.Fail()
|
||||||
tsig.Secret = "ZGZqc2tmZAo="
|
}
|
||||||
|
*/
|
||||||
in, _ := res.QueryTsig(m,tsig)
|
|
||||||
if in != nil {
|
|
||||||
if in.Rcode != RcodeSuccess {
|
|
||||||
t.Logf("%v\n", in)
|
|
||||||
t.Log("Failed to get an valid answer")
|
|
||||||
// t.Fail()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAXFR(t *testing.T) {
|
|
||||||
res := new(Resolver)
|
|
||||||
res.Servers = []string{"127.0.0.1"}
|
|
||||||
m := new(Msg)
|
|
||||||
m.Question = make([]Question, 1)
|
|
||||||
m.Question[0] = Question{"miek.nl", TypeAXFR, ClassINET}
|
|
||||||
|
|
||||||
ch := make(chan Xfr)
|
|
||||||
go res.Xfr(m, ch)
|
|
||||||
for x := range ch {
|
|
||||||
var _ = x
|
|
||||||
// fmt.Printf("%v\n",dm.Dns)
|
|
||||||
}
|
|
||||||
// channel is closed by Axfr()
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
34
defaults.go
34
defaults.go
|
@ -16,8 +16,8 @@ func (dns *Msg) SetReply(request *Msg) {
|
||||||
|
|
||||||
// Create a question packet.
|
// Create a question packet.
|
||||||
func (dns *Msg) SetQuestion(z string, t uint16) {
|
func (dns *Msg) SetQuestion(z string, t uint16) {
|
||||||
dns.MsgHdr.Id = Id()
|
dns.MsgHdr.Id = Id()
|
||||||
dns.MsgHdr.RecursionDesired = true
|
dns.MsgHdr.RecursionDesired = true
|
||||||
dns.Question = make([]Question, 1)
|
dns.Question = make([]Question, 1)
|
||||||
dns.Question[0] = Question{z, t, ClassINET}
|
dns.Question[0] = Question{z, t, ClassINET}
|
||||||
}
|
}
|
||||||
|
@ -36,9 +36,9 @@ func (dns *Msg) IsUpdate() (ok bool) {
|
||||||
if len(dns.Question) == 0 {
|
if len(dns.Question) == 0 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
ok = dns.MsgHdr.Opcode == OpcodeUpdate
|
ok = dns.MsgHdr.Opcode == OpcodeUpdate
|
||||||
ok = ok && dns.Question[0].Qtype == TypeSOA
|
ok = ok && dns.Question[0].Qtype == TypeSOA
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is the message a valid notify packet?
|
// Is the message a valid notify packet?
|
||||||
|
@ -54,7 +54,7 @@ func (dns *Msg) IsNotify() (ok bool) {
|
||||||
|
|
||||||
// Create a dns msg suitable for requesting an ixfr.
|
// Create a dns msg suitable for requesting an ixfr.
|
||||||
func (dns *Msg) SetIxfr(z string, serial uint32) {
|
func (dns *Msg) SetIxfr(z string, serial uint32) {
|
||||||
dns.MsgHdr.Id = Id()
|
dns.MsgHdr.Id = Id()
|
||||||
dns.Question = make([]Question, 1)
|
dns.Question = make([]Question, 1)
|
||||||
dns.Ns = make([]RR, 1)
|
dns.Ns = make([]RR, 1)
|
||||||
s := new(RR_SOA)
|
s := new(RR_SOA)
|
||||||
|
@ -67,7 +67,7 @@ func (dns *Msg) SetIxfr(z string, serial uint32) {
|
||||||
|
|
||||||
// Create a dns msg suitable for requesting an axfr.
|
// Create a dns msg suitable for requesting an axfr.
|
||||||
func (dns *Msg) SetAxfr(z string) {
|
func (dns *Msg) SetAxfr(z string) {
|
||||||
dns.MsgHdr.Id = Id()
|
dns.MsgHdr.Id = Id()
|
||||||
dns.Question = make([]Question, 1)
|
dns.Question = make([]Question, 1)
|
||||||
dns.Question[0] = Question{z, TypeAXFR, ClassINET}
|
dns.Question[0] = Question{z, TypeAXFR, ClassINET}
|
||||||
}
|
}
|
||||||
|
@ -96,17 +96,17 @@ func (dns *Msg) IsIxfr() (ok bool) {
|
||||||
|
|
||||||
// Has a message a TSIG record as the last record?
|
// Has a message a TSIG record as the last record?
|
||||||
func (dns *Msg) IsTsig() (ok bool) {
|
func (dns *Msg) IsTsig() (ok bool) {
|
||||||
if len(dns.Extra) > 0 {
|
if len(dns.Extra) > 0 {
|
||||||
return dns.Extra[0].Header().Rrtype == TypeTSIG
|
return dns.Extra[0].Header().Rrtype == TypeTSIG
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dns *Msg) SetTsig(z, algo string, fudge uint16, timesigned uint64) {
|
func (dns *Msg) SetTsig(z, algo string, fudge uint16, timesigned uint64) {
|
||||||
t := new(RR_TSIG)
|
t := new(RR_TSIG)
|
||||||
t.Hdr = RR_Header{z, TypeTSIG, ClassANY, 0, 0}
|
t.Hdr = RR_Header{z, TypeTSIG, ClassANY, 0, 0}
|
||||||
t.Algorithm = algo
|
t.Algorithm = algo
|
||||||
t.Fudge = fudge
|
t.Fudge = fudge
|
||||||
t.TimeSigned = timesigned
|
t.TimeSigned = timesigned
|
||||||
dns.Extra = append(dns.Extra, t)
|
dns.Extra = append(dns.Extra, t)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue