From b2e9fc8d8407a934aaef3c7db1bb52a8e4ca86a5 Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Sat, 8 Jan 2011 21:51:20 +0100 Subject: [PATCH] Added TSIG By defining a new struct I can re-use all the nice stuff in msg.go --- Makefile | 2 ++ TODO | 1 - msg.go | 4 ---- tsig.go | 37 +++++++++++++++++++++++++++++++++++++ tsig_test.go | 19 +++++++++++++++++++ types.go | 13 ++++++++----- 6 files changed, 66 insertions(+), 10 deletions(-) create mode 100644 tsig.go create mode 100644 tsig_test.go diff --git a/Makefile b/Makefile index ee3feafb..d5710aef 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,8 @@ GOFILES=\ msg.go\ types.go\ edns.go\ + tsig.go\ + include $(GOROOT)/src/Make.pkg diff --git a/TODO b/TODO index 84684744..c07f1bae 100644 --- a/TODO +++ b/TODO @@ -22,6 +22,5 @@ Issues: - DnsMsg when doing resolver querying Port over from LDNS: -* ldns-notify * ldns-rrsig * ldns-keygen - generate a key - more server side diff --git a/msg.go b/msg.go index 222d3185..91b7b493 100644 --- a/msg.go +++ b/msg.go @@ -540,10 +540,6 @@ func packRR(rr RR, msg []byte, off int) (off2 int, ok bool) { return len(msg), false } - // DEBUG TODO(mg) - // println("Header", off1) - // println("Rest", off2) - // TODO make this quicker? // pack a third time; redo header with correct data length rr.Header().Rdlength = uint16(off2 - off1) diff --git a/tsig.go b/tsig.go new file mode 100644 index 00000000..5a0b10b5 --- /dev/null +++ b/tsig.go @@ -0,0 +1,37 @@ +package dns + +// The following values must be put in wireformat, so that +// the MAC can be calculated +// RFC 2845, section 3.4.2. TSIG Variables +type tsig_generation_fmt struct { + // From RR_HEADER + Name string "domain-name" + Class uint16 + Ttl uint32 + // Rdata of the TSIG + Algorithm string "domain-name" + TimeSigned [3]uint16 + Fudge uint16 + // MACSize, MAC and OrigId excluded + Error uint16 + OtherLen uint16 + OtherData string +} + +func (rr *RR_TSIG) GenerateMAC() bool { + buf := make([]byte, 2048) // TODO(mg) bufsize! + tsigbuf := new(tsig_generation_fmt) + + // Fill the struct and generate the wiredata + tsigbuf.Name = rr.Header().Name + tsigbuf.Class = rr.Header().Class + tsigbuf.Ttl = rr.Header().Ttl + tsigbuf.Algorithm = rr.Algorithm + tsigbuf.TimeSigned = rr.TimeSigned + tsigbuf.Fudge = rr.Fudge + tsigbuf.Error = rr.Error + tsigbuf.OtherLen = rr.OtherLen + tsigbuf.OtherData = rr.OtherData + packStruct(tsigbuf, buf, 0) + return true +} diff --git a/tsig_test.go b/tsig_test.go new file mode 100644 index 00000000..ba62df72 --- /dev/null +++ b/tsig_test.go @@ -0,0 +1,19 @@ +package dns + +import ( + "testing" +) + +func TestTsig(t *testing.T) { + tsig := new(RR_TSIG) + tsig.Hdr.Name = "miek.nl" + tsig.Hdr.Rrtype = TypeTSIG + tsig.Hdr.Class = ClassANY + tsig.Hdr.Ttl = 0 + + ok := tsig.GenerateMAC() + if !ok { + t.Log("Failed") + t.Fail() + } +} diff --git a/types.go b/types.go index 927a776a..3aeea2f6 100644 --- a/types.go +++ b/types.go @@ -504,7 +504,7 @@ func (rr *RR_NSEC3PARAM) String() string { type RR_TKEY struct { Hdr RR_Header - Algoritim string "domain-name" + Algorithm string "domain-name" Inception uint32 Expiration uint32 Mode uint16 @@ -520,15 +520,17 @@ func (rr *RR_TKEY) Header() *RR_Header { } func (rr *RR_TKEY) String() string { - return rr.Hdr.String() + "BLAHBLAH" + // It has no presentation format + return "" } type RR_TSIG struct { Hdr RR_Header - Algoritim string "domain-name" - TimeSigned [3]uint16 // uint48 *sigh* + Algorithm string "domain-name" + TimeSigned [3]uint16 Fudge uint16 MACSize uint16 + OrigId uint16 // msg id MAC string Error uint16 OtherLen uint16 @@ -540,7 +542,8 @@ func (rr *RR_TSIG) Header() *RR_Header { } func (rr *RR_TSIG) String() string { - return rr.Hdr.String() + "TODO" + // It has no presentation format + return "" } // Translate the RRSIG's incep. and expir. time to the correct date.