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\
|
resolver.go\
|
||||||
config.go\
|
config.go\
|
||||||
server.go \
|
server.go \
|
||||||
|
nsec3.go \
|
||||||
# y.go\
|
# y.go\
|
||||||
# nsec3.go \
|
|
||||||
|
|
||||||
include $(GOROOT)/src/Make.pkg
|
include $(GOROOT)/src/Make.pkg
|
||||||
|
|
||||||
|
|
47
nsec3.go
47
nsec3.go
|
@ -1,22 +1,49 @@
|
||||||
package dns
|
package dns
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io"
|
||||||
|
"hash"
|
||||||
|
"strings"
|
||||||
"crypto/sha1"
|
"crypto/sha1"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NSEC3 related functions
|
type saltWireFmt struct {
|
||||||
|
Salt string "size-hex"
|
||||||
|
}
|
||||||
|
|
||||||
// Hash a string/label according to RFC5155
|
// Hash a string/label according to RFC5155
|
||||||
func Nsec3Hash(label string, hash int, i iterations, salt string) {
|
func Nsec3Hash(label string, ha int, iterations int, salt string) string {
|
||||||
nsec3 := ""
|
|
||||||
switch hash {
|
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:
|
case HashSHA1:
|
||||||
s := sha1.New()
|
s = sha1.New()
|
||||||
// i times
|
|
||||||
// add salt, binary???
|
|
||||||
io.WriteString(s, string(label))
|
|
||||||
ds.Digest = hex.EncodeToString(
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nsec3
|
// 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()
|
||||||
|
}
|
Loading…
Reference in New Issue