Added TSIG
By defining a new struct I can re-use all the nice stuff in msg.go
This commit is contained in:
parent
c6655f6e6d
commit
b2e9fc8d84
2
Makefile
2
Makefile
|
@ -11,6 +11,8 @@ GOFILES=\
|
||||||
msg.go\
|
msg.go\
|
||||||
types.go\
|
types.go\
|
||||||
edns.go\
|
edns.go\
|
||||||
|
tsig.go\
|
||||||
|
|
||||||
|
|
||||||
include $(GOROOT)/src/Make.pkg
|
include $(GOROOT)/src/Make.pkg
|
||||||
|
|
||||||
|
|
1
TODO
1
TODO
|
@ -22,6 +22,5 @@ Issues:
|
||||||
- DnsMsg when doing resolver querying
|
- DnsMsg when doing resolver querying
|
||||||
|
|
||||||
Port over from LDNS:
|
Port over from LDNS:
|
||||||
* ldns-notify
|
|
||||||
* ldns-rrsig
|
* ldns-rrsig
|
||||||
* ldns-keygen - generate a key - more server side
|
* ldns-keygen - generate a key - more server side
|
||||||
|
|
4
msg.go
4
msg.go
|
@ -540,10 +540,6 @@ func packRR(rr RR, msg []byte, off int) (off2 int, ok bool) {
|
||||||
return len(msg), false
|
return len(msg), false
|
||||||
}
|
}
|
||||||
|
|
||||||
// DEBUG TODO(mg)
|
|
||||||
// println("Header", off1)
|
|
||||||
// println("Rest", off2)
|
|
||||||
|
|
||||||
// TODO make this quicker?
|
// TODO make this quicker?
|
||||||
// pack a third time; redo header with correct data length
|
// pack a third time; redo header with correct data length
|
||||||
rr.Header().Rdlength = uint16(off2 - off1)
|
rr.Header().Rdlength = uint16(off2 - off1)
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
|
@ -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()
|
||||||
|
}
|
||||||
|
}
|
13
types.go
13
types.go
|
@ -504,7 +504,7 @@ func (rr *RR_NSEC3PARAM) String() string {
|
||||||
|
|
||||||
type RR_TKEY struct {
|
type RR_TKEY struct {
|
||||||
Hdr RR_Header
|
Hdr RR_Header
|
||||||
Algoritim string "domain-name"
|
Algorithm string "domain-name"
|
||||||
Inception uint32
|
Inception uint32
|
||||||
Expiration uint32
|
Expiration uint32
|
||||||
Mode uint16
|
Mode uint16
|
||||||
|
@ -520,15 +520,17 @@ func (rr *RR_TKEY) Header() *RR_Header {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rr *RR_TKEY) String() string {
|
func (rr *RR_TKEY) String() string {
|
||||||
return rr.Hdr.String() + "BLAHBLAH"
|
// It has no presentation format
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
type RR_TSIG struct {
|
type RR_TSIG struct {
|
||||||
Hdr RR_Header
|
Hdr RR_Header
|
||||||
Algoritim string "domain-name"
|
Algorithm string "domain-name"
|
||||||
TimeSigned [3]uint16 // uint48 *sigh*
|
TimeSigned [3]uint16
|
||||||
Fudge uint16
|
Fudge uint16
|
||||||
MACSize uint16
|
MACSize uint16
|
||||||
|
OrigId uint16 // msg id
|
||||||
MAC string
|
MAC string
|
||||||
Error uint16
|
Error uint16
|
||||||
OtherLen uint16
|
OtherLen uint16
|
||||||
|
@ -540,7 +542,8 @@ func (rr *RR_TSIG) Header() *RR_Header {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rr *RR_TSIG) String() string {
|
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.
|
// Translate the RRSIG's incep. and expir. time to the correct date.
|
||||||
|
|
Loading…
Reference in New Issue