From 94b98a5766c2aae2375f40044b08830503b06dc5 Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Mon, 7 Mar 2011 22:47:20 +0100 Subject: [PATCH] Add nsec3 hashing (non working atm) --- Makefile | 2 +- nsec3.go | 53 ++++++++++++++++++++++++++++++++++++++------------- nsec3_test.go | 11 +++++++++++ types.go | 10 +++++----- 4 files changed, 57 insertions(+), 19 deletions(-) create mode 100644 nsec3_test.go diff --git a/Makefile b/Makefile index ec7fd914..d33899c3 100644 --- a/Makefile +++ b/Makefile @@ -18,8 +18,8 @@ GOFILES=\ resolver.go\ config.go\ server.go \ + nsec3.go \ # y.go\ -# nsec3.go \ include $(GOROOT)/src/Make.pkg diff --git a/nsec3.go b/nsec3.go index e0b28631..d0b0d44a 100644 --- a/nsec3.go +++ b/nsec3.go @@ -1,22 +1,49 @@ package dns import ( - "crypto/sha1" + "io" + "hash" + "strings" + "crypto/sha1" ) -// NSEC3 related functions +type saltWireFmt struct { + Salt string "size-hex" +} // Hash a string/label according to RFC5155 -func Nsec3Hash(label string, hash int, i iterations, salt string) { - nsec3 := "" - switch hash { - case HashSHA1: - s := sha1.New() - // i times - // add salt, binary??? - io.WriteString(s, string(label)) - ds.Digest = hex.EncodeToString( - } +func Nsec3Hash(label string, ha int, iterations int, salt string) string { - return nsec3 + saltwire := new(saltWireFmt) + saltwire.Salt = salt + wire := make([]byte, DefaultMsgSize) + n, ok := packStruct(saltwire, wire, 0) + if !ok { + return "" + } + wire = wire[:n] + owner := make([]byte, 255) + off, ok1 := packDomainName(strings.ToLower(label), owner, 0) + if !ok1 { + return "" + } + owner = owner[:off] + + var s hash.Hash + switch ha { + case HashSHA1: + s = sha1.New() + } + + // k = 0 + h := append(owner, wire...) + io.WriteString(s, string(h)) + nsec3 := s.Sum() + + for k := 1; k < iterations; k++ { + h = append(nsec3, wire...) + io.WriteString(s, string(h)) + nsec3 = s.Sum() + } + return unpackBase32(nsec3) } diff --git a/nsec3_test.go b/nsec3_test.go new file mode 100644 index 00000000..8fb0fdf3 --- /dev/null +++ b/nsec3_test.go @@ -0,0 +1,11 @@ +package dns + +import ( + "testing" +) + +func TestPackNsec3(t *testing.T) { + nsec3 := Nsec3Hash("dnsex.nl", 1, 0, "DEAD") + t.Logf("%v\n", nsec3) + t.Fail() +} diff --git a/types.go b/types.go index e60f95f3..e56bcfbb 100644 --- a/types.go +++ b/types.go @@ -137,11 +137,11 @@ func (q *Question) String() string { // prefix with ; (as in dig) s := ";" + q.Name + "\t" s = s + Class_str[q.Qclass] + "\t" - if _, ok := Rr_str[q.Qtype]; ok { - s += " " + Rr_str[q.Qtype] - } else { - s += " " + "TYPE" + strconv.Itoa(int(q.Qtype)) - } + if _, ok := Rr_str[q.Qtype]; ok { + s += " " + Rr_str[q.Qtype] + } else { + s += " " + "TYPE" + strconv.Itoa(int(q.Qtype)) + } return s }