Add nsec3 hashing (non working atm)

This commit is contained in:
Miek Gieben 2011-03-07 22:47:20 +01:00
parent 77562dcfed
commit 94b98a5766
4 changed files with 57 additions and 19 deletions

View File

@ -18,8 +18,8 @@ GOFILES=\
resolver.go\
config.go\
server.go \
nsec3.go \
# y.go\
# nsec3.go \
include $(GOROOT)/src/Make.pkg

View File

@ -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)
}

11
nsec3_test.go Normal file
View File

@ -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()
}

View File

@ -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
}