Add nsec3 hashing (non working atm)
This commit is contained in:
parent
77562dcfed
commit
94b98a5766
2
Makefile
2
Makefile
|
@ -18,8 +18,8 @@ GOFILES=\
|
|||
resolver.go\
|
||||
config.go\
|
||||
server.go \
|
||||
nsec3.go \
|
||||
# y.go\
|
||||
# nsec3.go \
|
||||
|
||||
include $(GOROOT)/src/Make.pkg
|
||||
|
||||
|
|
53
nsec3.go
53
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)
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
10
types.go
10
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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue