add hex encoding for DS record
* some more edns finishing touches
This commit is contained in:
parent
b634118257
commit
830b2eae29
|
@ -43,7 +43,7 @@ func KeyToDS(k *RR_DNSKEY, hash int) *RR_DS {
|
||||||
// signature validate period is NOT checked. Used
|
// signature validate period is NOT checked. Used
|
||||||
// ValidSignaturePeriod for that
|
// ValidSignaturePeriod for that
|
||||||
func Valid(rrset []RR, signature *RR_RRSIG, key *RR_DNSKEY) bool {
|
func Valid(rrset []RR, signature *RR_RRSIG, key *RR_DNSKEY) bool {
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate the keytag of the DNSKEY
|
// Calculate the keytag of the DNSKEY
|
||||||
|
|
|
@ -38,7 +38,6 @@ func main() {
|
||||||
res := new(dns.Resolver)
|
res := new(dns.Resolver)
|
||||||
ch := dns.NewQuerier(res)
|
ch := dns.NewQuerier(res)
|
||||||
|
|
||||||
|
|
||||||
// configure the resolver
|
// configure the resolver
|
||||||
res.Servers = []string{"192.168.1.2"}
|
res.Servers = []string{"192.168.1.2"}
|
||||||
res.Timeout = 2
|
res.Timeout = 2
|
||||||
|
@ -50,7 +49,7 @@ func main() {
|
||||||
m.MsgHdr.Recursion_desired = true //only set this bit
|
m.MsgHdr.Recursion_desired = true //only set this bit
|
||||||
m.Question = make([]dns.Question, 1)
|
m.Question = make([]dns.Question, 1)
|
||||||
|
|
||||||
m.Question[0] = dns.Question{"nlnetlabs.nl", dns.TypeDNSKEY, dns.ClassINET}
|
m.Question[0] = dns.Question{"miek.nl", dns.TypeDS, dns.ClassINET}
|
||||||
ch <- dns.DnsMsg{m, nil}
|
ch <- dns.DnsMsg{m, nil}
|
||||||
in := <-ch
|
in := <-ch
|
||||||
fmt.Printf("%v\n", in.Dns)
|
fmt.Printf("%v\n", in.Dns)
|
||||||
|
|
31
edns.go
31
edns.go
|
@ -1,3 +1,5 @@
|
||||||
|
// EDNS0 OTP RR implementation. Define the OPT RR and some
|
||||||
|
// convience functions to operate on it.
|
||||||
package dns
|
package dns
|
||||||
|
|
||||||
// EDNS0 option codes
|
// EDNS0 option codes
|
||||||
|
@ -15,9 +17,7 @@ type Option struct {
|
||||||
Data string "hex"
|
Data string "hex"
|
||||||
}
|
}
|
||||||
|
|
||||||
// EDNS extended RR.
|
/* EDNS extended RR.
|
||||||
// Not used yet
|
|
||||||
/*
|
|
||||||
This is the EDNS0 Header
|
This is the EDNS0 Header
|
||||||
Name string "domain-name"
|
Name string "domain-name"
|
||||||
Opt uint16 // was type, but is always TypeOPT
|
Opt uint16 // was type, but is always TypeOPT
|
||||||
|
@ -29,16 +29,21 @@ This is the EDNS0 Header
|
||||||
*/
|
*/
|
||||||
|
|
||||||
type RR_OPT struct {
|
type RR_OPT struct {
|
||||||
Hdr RR_Header // this must become a EDNS0_Header
|
Hdr RR_Header
|
||||||
Option []Option "OPT" // Tag is used in pack and unpack
|
Option []Option "OPT" // Tag is used in pack and unpack
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A ENDS packet must show differently. TODO
|
||||||
|
func (h *RR_Header) ednsString() string {
|
||||||
|
return h.String()
|
||||||
|
}
|
||||||
|
|
||||||
func (rr *RR_OPT) Header() *RR_Header {
|
func (rr *RR_OPT) Header() *RR_Header {
|
||||||
return &rr.Hdr
|
return &rr.Hdr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rr *RR_OPT) String() string {
|
func (rr *RR_OPT) String() string {
|
||||||
s := rr.Hdr.String() // Hier misschien andere representatie
|
s := rr.Hdr.ednsString() // Hier misschien andere representatie
|
||||||
for _, o := range rr.Option {
|
for _, o := range rr.Option {
|
||||||
switch o.Code {
|
switch o.Code {
|
||||||
case OptionCodeNSID:
|
case OptionCodeNSID:
|
||||||
|
@ -50,15 +55,27 @@ func (rr *RR_OPT) String() string {
|
||||||
|
|
||||||
// when set is true, set the size otherwise get it
|
// when set is true, set the size otherwise get it
|
||||||
func (rr *RR_OPT) UDPSize(size int, set bool) int {
|
func (rr *RR_OPT) UDPSize(size int, set bool) int {
|
||||||
return 0
|
// fiddle in rr.Hdr.Class should be set
|
||||||
|
if set {
|
||||||
|
rr.Hdr.Class = uint16(size)
|
||||||
|
}
|
||||||
|
return int(rr.Hdr.Class)
|
||||||
}
|
}
|
||||||
|
|
||||||
// when set is true, set the Do bit, otherwise get it
|
// when set is true, set the Do bit, otherwise get it
|
||||||
func (rr *RR_OPT) DoBit(do, set bool) bool {
|
func (rr *RR_OPT) DoBit(do, set bool) bool {
|
||||||
return true
|
// rr.TTL last 2 bytes, left most bit
|
||||||
|
if set {
|
||||||
|
rr.Hdr.Ttl = 1
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return true // dead code, bug in Go
|
||||||
}
|
}
|
||||||
|
|
||||||
// when set is true, set the nsid, otherwise get it
|
// when set is true, set the nsid, otherwise get it
|
||||||
func (rr *RR_OPT) Nsid(nsid string, set bool) string {
|
func (rr *RR_OPT) Nsid(nsid string, set bool) string {
|
||||||
|
// RR.Option[0] to be set
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
12
msg.go
12
msg.go
|
@ -21,6 +21,7 @@ import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"net"
|
"net"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
)
|
)
|
||||||
|
@ -265,8 +266,12 @@ func packStructValue(val *reflect.StructValue, msg []byte, off int) (off1 int, o
|
||||||
return len(msg), false
|
return len(msg), false
|
||||||
}
|
}
|
||||||
case "hex":
|
case "hex":
|
||||||
// TODO need this for DS
|
// There is no length encoded here, for DS at least
|
||||||
println("hex packing not implemented")
|
h, e := hex.DecodeString(s)
|
||||||
|
if e != nil {
|
||||||
|
return len(msg), false
|
||||||
|
}
|
||||||
|
copy(msg[off:off+hex.DecodedLen(len(s))], h)
|
||||||
case "":
|
case "":
|
||||||
// Counted string: 1 byte length.
|
// Counted string: 1 byte length.
|
||||||
if len(s) > 255 || off+1+len(s) > len(msg) {
|
if len(s) > 255 || off+1+len(s) > len(msg) {
|
||||||
|
@ -373,7 +378,7 @@ func unpackStructValue(val *reflect.StructValue, msg []byte, off int) (off1 int,
|
||||||
fmt.Fprintf(os.Stderr, "net: dns: unknown string tag %v", f.Tag)
|
fmt.Fprintf(os.Stderr, "net: dns: unknown string tag %v", f.Tag)
|
||||||
return len(msg), false
|
return len(msg), false
|
||||||
case "hex":
|
case "hex":
|
||||||
// Rest of the RR is hex encoded
|
// Rest of the RR is hex encoded, network order an issue here?
|
||||||
rdlength := int(val.FieldByName("Hdr").(*reflect.StructValue).FieldByName("Rdlength").(*reflect.UintValue).Get())
|
rdlength := int(val.FieldByName("Hdr").(*reflect.StructValue).FieldByName("Rdlength").(*reflect.UintValue).Get())
|
||||||
var consumed int
|
var consumed int
|
||||||
switch val.Type().Name() {
|
switch val.Type().Name() {
|
||||||
|
@ -383,6 +388,7 @@ func unpackStructValue(val *reflect.StructValue, msg []byte, off int) (off1 int,
|
||||||
consumed = 0 // TODO
|
consumed = 0 // TODO
|
||||||
}
|
}
|
||||||
s = hex.EncodeToString(msg[off : off+rdlength-consumed])
|
s = hex.EncodeToString(msg[off : off+rdlength-consumed])
|
||||||
|
s = strings.ToUpper(s)
|
||||||
off += rdlength - consumed
|
off += rdlength - consumed
|
||||||
case "base64":
|
case "base64":
|
||||||
// Rest of the RR is base64 encoded value
|
// Rest of the RR is base64 encoded value
|
||||||
|
|
|
@ -2,6 +2,7 @@ package dns
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestResolverEdns(t *testing.T) {
|
func TestResolverEdns(t *testing.T) {
|
||||||
|
@ -23,28 +24,28 @@ func TestResolverEdns(t *testing.T) {
|
||||||
edns.Hdr.Rrtype = TypeOPT
|
edns.Hdr.Rrtype = TypeOPT
|
||||||
// You can handle an OTP RR as any other, but there
|
// You can handle an OTP RR as any other, but there
|
||||||
// are some convience functions
|
// are some convience functions
|
||||||
// edns.UDPSize(4096, true)
|
edns.UDPSize(4096, true)
|
||||||
// edns.DoBit(true, true)
|
edns.DoBit(true, true)
|
||||||
// edns.Nsid("mieks-server", true)
|
// edns.Nsid("mieks-server", true)
|
||||||
edns.Hdr.Class = ClassINET
|
// edns.Hdr.Class = ClassINET
|
||||||
edns.Hdr.Ttl = 3600
|
// edns.Hdr.Ttl = 3600
|
||||||
// no options for now
|
// no options for now
|
||||||
// edns.Option = make([]Option, 1)
|
// edns.Option = make([]Option, 1)
|
||||||
// edns.Option[0].Code = OptionCodeNSID
|
// edns.Option[0].Code = OptionCodeNSID
|
||||||
// edns.Option[0].Data = "lalalala"
|
// edns.Option[0].Data = "lalalala"
|
||||||
|
|
||||||
// ask something
|
// ask something
|
||||||
m.Question[0] = Question{"miek.nl", TypeSOA, ClassINET}
|
m.Question[0] = Question{"nlnetlabs.nl", TypeSOA, ClassINET}
|
||||||
m.Extra[0] = edns
|
m.Extra[0] = edns
|
||||||
|
|
||||||
ch <- DnsMsg{m, nil}
|
ch <- DnsMsg{m, nil}
|
||||||
in := <-ch
|
in := <-ch
|
||||||
|
|
||||||
if in.Dns.Rcode != RcodeSuccess {
|
if in.Dns.Rcode != RcodeSuccess {
|
||||||
t.Logf("Recv: %v\n", in.Dns)
|
|
||||||
t.Log("Failed to get an valid answer")
|
t.Log("Failed to get an valid answer")
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
|
fmt.Printf("recv: %v\n", in.Dns) // TODO remove print (MG)
|
||||||
ch <- DnsMsg{nil, nil}
|
ch <- DnsMsg{nil, nil}
|
||||||
<-ch // wait for ch to close channel
|
<-ch // wait for ch to close channel
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ func TestSignature(t *testing.T) {
|
||||||
sig.Sig = "AwEAAaHIwpx3w4VHKi6i1LHnTaWeHCL154Jug0Rtc9ji5qwPXpBo6A5sRv7cSsPQKPIwxLpyCrbJ4mr2L0EPOdvP6z6YfljK2ZmTbogU9aSU2fiq/4wjxbdkLyoDVgtO+JsxNN4bjr4WcWhsmk1Hg93FV9ZpkWb0Tbad8DFqNDzr//kZ"
|
sig.Sig = "AwEAAaHIwpx3w4VHKi6i1LHnTaWeHCL154Jug0Rtc9ji5qwPXpBo6A5sRv7cSsPQKPIwxLpyCrbJ4mr2L0EPOdvP6z6YfljK2ZmTbogU9aSU2fiq/4wjxbdkLyoDVgtO+JsxNN4bjr4WcWhsmk1Hg93FV9ZpkWb0Tbad8DFqNDzr//kZ"
|
||||||
|
|
||||||
// Should not be valid
|
// Should not be valid
|
||||||
if validSignaturePeriod(sig.Inception, sig.Expiration) {
|
if ValidSignaturePeriod(sig.Inception, sig.Expiration) {
|
||||||
t.Log("Should not be valid")
|
t.Log("Should not be valid")
|
||||||
t.Fail()
|
t.Fail()
|
||||||
} else {
|
} else {
|
||||||
|
|
4
types.go
4
types.go
|
@ -438,7 +438,7 @@ func (rr *RR_DS) Header() *RR_Header {
|
||||||
func (rr *RR_DS) String() string {
|
func (rr *RR_DS) String() string {
|
||||||
return rr.Hdr.String() +
|
return rr.Hdr.String() +
|
||||||
" " + strconv.Itoa(int(rr.KeyTag)) +
|
" " + strconv.Itoa(int(rr.KeyTag)) +
|
||||||
" " + alg_str[rr.Algorithm] +
|
" " + strconv.Itoa(int(rr.Algorithm)) +
|
||||||
" " + strconv.Itoa(int(rr.DigestType)) +
|
" " + strconv.Itoa(int(rr.DigestType)) +
|
||||||
" " + rr.Digest
|
" " + rr.Digest
|
||||||
}
|
}
|
||||||
|
@ -550,7 +550,7 @@ var rr_str = map[uint16]string{
|
||||||
TypeNSEC3PARAM: "NSEC3PARAM",
|
TypeNSEC3PARAM: "NSEC3PARAM",
|
||||||
}
|
}
|
||||||
|
|
||||||
// Map for algorithm names.
|
// Map for algorithm names.
|
||||||
var alg_str = map[uint8]string{
|
var alg_str = map[uint8]string{
|
||||||
AlgRSAMD5: "RSAMD5",
|
AlgRSAMD5: "RSAMD5",
|
||||||
AlgDH: "DH",
|
AlgDH: "DH",
|
||||||
|
|
Loading…
Reference in New Issue