Less verbose tests
This commit is contained in:
parent
48cbf55a23
commit
96a55dee9b
34
dnssec.go
34
dnssec.go
|
@ -444,28 +444,28 @@ func (k *RR_DNSKEY) pubKeyRSA() *rsa.PublicKey {
|
||||||
|
|
||||||
// Set the public key (the value E and N)
|
// Set the public key (the value E and N)
|
||||||
func (k *RR_DNSKEY) setPubKeyRSA(_E int, _N *big.Int) {
|
func (k *RR_DNSKEY) setPubKeyRSA(_E int, _N *big.Int) {
|
||||||
buf := exponentToBuf(_E)
|
buf := exponentToBuf(_E)
|
||||||
buf = append(buf, _N.Bytes()...)
|
buf = append(buf, _N.Bytes()...)
|
||||||
k.PubKey = unpackBase64(buf)
|
k.PubKey = unpackBase64(buf)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the public key (the value E and N)
|
// Set the public key (the value E and N)
|
||||||
// RFC 3110: Section 2. RSA Public KEY Resource Records
|
// RFC 3110: Section 2. RSA Public KEY Resource Records
|
||||||
func exponentToBuf(_E int) []byte {
|
func exponentToBuf(_E int) []byte {
|
||||||
var buf []byte
|
var buf []byte
|
||||||
i := big.NewInt(int64(_E))
|
i := big.NewInt(int64(_E))
|
||||||
if len(i.Bytes()) < 256 {
|
if len(i.Bytes()) < 256 {
|
||||||
buf = make([]byte, 1)
|
buf = make([]byte, 1)
|
||||||
buf[0] = uint8(len(i.Bytes()))
|
buf[0] = uint8(len(i.Bytes()))
|
||||||
} else {
|
} else {
|
||||||
buf = make([]byte, 3)
|
buf = make([]byte, 3)
|
||||||
buf[0] = 0
|
buf[0] = 0
|
||||||
buf[1] = uint8(len(i.Bytes()) >> 8)
|
buf[1] = uint8(len(i.Bytes()) >> 8)
|
||||||
buf[2] = uint8(len(i.Bytes()))
|
buf[2] = uint8(len(i.Bytes()))
|
||||||
}
|
}
|
||||||
buf = append(buf, i.Bytes()...)
|
buf = append(buf, i.Bytes()...)
|
||||||
return buf
|
return buf
|
||||||
}
|
}
|
||||||
|
|
||||||
// Map for algorithm names.
|
// Map for algorithm names.
|
||||||
|
|
|
@ -3,8 +3,6 @@ package dns
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
"strings"
|
"strings"
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSecure(t *testing.T) {
|
func TestSecure(t *testing.T) {
|
||||||
|
@ -39,13 +37,10 @@ func TestSecure(t *testing.T) {
|
||||||
key.Algorithm = AlgRSASHA256
|
key.Algorithm = AlgRSASHA256
|
||||||
key.PubKey = "AwEAAcNEU67LJI5GEgF9QLNqLO1SMq1EdoQ6E9f85ha0k0ewQGCblyW2836GiVsm6k8Kr5ECIoMJ6fZWf3CQSQ9ycWfTyOHfmI3eQ/1Covhb2y4bAmL/07PhrL7ozWBW3wBfM335Ft9xjtXHPy7ztCbV9qZ4TVDTW/Iyg0PiwgoXVesz"
|
key.PubKey = "AwEAAcNEU67LJI5GEgF9QLNqLO1SMq1EdoQ6E9f85ha0k0ewQGCblyW2836GiVsm6k8Kr5ECIoMJ6fZWf3CQSQ9ycWfTyOHfmI3eQ/1Covhb2y4bAmL/07PhrL7ozWBW3wBfM335Ft9xjtXHPy7ztCbV9qZ4TVDTW/Iyg0PiwgoXVesz"
|
||||||
|
|
||||||
fmt.Fprintf(os.Stderr, "%v\n%v\n", sig, soa)
|
|
||||||
// It should validate. Period is checked seperately, so this will keep on working
|
// It should validate. Period is checked seperately, so this will keep on working
|
||||||
if ! sig.Verify(key, []RR{soa}) {
|
if ! sig.Verify(key, []RR{soa}) {
|
||||||
t.Log("Failure to validate")
|
t.Log("Failure to validate")
|
||||||
t.Fail()
|
t.Fail()
|
||||||
} else {
|
|
||||||
println("It validates!!")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,7 +95,6 @@ func TestSignVerify(t *testing.T) {
|
||||||
key.Protocol = 3
|
key.Protocol = 3
|
||||||
key.Algorithm = AlgRSASHA256
|
key.Algorithm = AlgRSASHA256
|
||||||
privkey, _ := key.Generate(512)
|
privkey, _ := key.Generate(512)
|
||||||
fmt.Fprintf(os.Stderr, "Key tag: %d\n", key.KeyTag())
|
|
||||||
|
|
||||||
// Fill in the values of the Sig, before signing
|
// Fill in the values of the Sig, before signing
|
||||||
sig := new(RR_RRSIG)
|
sig := new(RR_RRSIG)
|
||||||
|
@ -122,9 +116,7 @@ func TestSignVerify(t *testing.T) {
|
||||||
if !sig.Verify(key, []RR{soa}) {
|
if !sig.Verify(key, []RR{soa}) {
|
||||||
t.Log("Failure to validate")
|
t.Log("Failure to validate")
|
||||||
t.Fail()
|
t.Fail()
|
||||||
} else {
|
}
|
||||||
println("It validates!!")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestKeyGen(t *testing.T) {
|
func TestKeyGen(t *testing.T) {
|
||||||
|
@ -156,7 +148,6 @@ func TestDnskey(t *testing.T) {
|
||||||
key.Protocol = 3
|
key.Protocol = 3
|
||||||
key.Algorithm = AlgRSASHA256
|
key.Algorithm = AlgRSASHA256
|
||||||
key.PubKey = "AwEAAcELcuxHosJX3LjbR6EFzsqI3mKivwvO6Y5Kzt/OXYmLQUI8tnOrX9ilT/0qGraxoONayVX3A6bl1pG3h/xOxVEGcJGqbrZnhr2+4S9tW2GWQwevV+NhinE7v6MCCCheVCnAPh0KFb/u14ng3DQizP1spBU/NoAN31l678snBpZX"
|
key.PubKey = "AwEAAcELcuxHosJX3LjbR6EFzsqI3mKivwvO6Y5Kzt/OXYmLQUI8tnOrX9ilT/0qGraxoONayVX3A6bl1pG3h/xOxVEGcJGqbrZnhr2+4S9tW2GWQwevV+NhinE7v6MCCCheVCnAPh0KFb/u14ng3DQizP1spBU/NoAN31l678snBpZX"
|
||||||
fmt.Printf("%v\n", key)
|
|
||||||
|
|
||||||
soa := new(RR_SOA)
|
soa := new(RR_SOA)
|
||||||
soa.Hdr = RR_Header{"Miek.nl.", TypeSOA, ClassINET, 875, 0}
|
soa.Hdr = RR_Header{"Miek.nl.", TypeSOA, ClassINET, 875, 0}
|
||||||
|
@ -244,11 +235,7 @@ func TestKeyGenRSA(t *testing.T) {
|
||||||
sig.SignerName = "miek.nl."
|
sig.SignerName = "miek.nl."
|
||||||
|
|
||||||
sig.Sign(priv, []RR{soa})
|
sig.Sign(priv, []RR{soa})
|
||||||
|
//s := key.PrivateKeyString(priv)
|
||||||
s := key.PrivateKeyString(priv)
|
|
||||||
fmt.Printf("%s\n", s)
|
|
||||||
|
|
||||||
fmt.Printf("%v\n", sig)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestKeyToDS(t *testing.T) {
|
func TestKeyToDS(t *testing.T) {
|
||||||
|
|
38
keygen.go
38
keygen.go
|
@ -44,7 +44,7 @@ func (r *RR_DNSKEY) Generate(bits int) (PrivateKey, os.Error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
keybuf := exponentToBuf(priv.PublicKey.E)
|
keybuf := exponentToBuf(priv.PublicKey.E)
|
||||||
keybuf = append(keybuf, priv.PublicKey.N.Bytes()...)
|
keybuf = append(keybuf, priv.PublicKey.N.Bytes()...)
|
||||||
r.PubKey = unpackBase64(keybuf)
|
r.PubKey = unpackBase64(keybuf)
|
||||||
return priv, nil
|
return priv, nil
|
||||||
|
@ -62,11 +62,11 @@ func (r *RR_DNSKEY) PrivateKeyString(p PrivateKey) (s string) {
|
||||||
case *rsa.PrivateKey:
|
case *rsa.PrivateKey:
|
||||||
algorithm := strconv.Itoa(int(r.Algorithm)) + " (" + alg_str[r.Algorithm] + ")"
|
algorithm := strconv.Itoa(int(r.Algorithm)) + " (" + alg_str[r.Algorithm] + ")"
|
||||||
modulus := unpackBase64(t.PublicKey.N.Bytes())
|
modulus := unpackBase64(t.PublicKey.N.Bytes())
|
||||||
e := big.NewInt(int64(t.PublicKey.E))
|
e := big.NewInt(int64(t.PublicKey.E))
|
||||||
/*
|
/*
|
||||||
pub := make([]byte, 1)
|
pub := make([]byte, 1)
|
||||||
pub[0] = uint8(t.PublicKey.E) // Todo does not fit with binds 65537 exp!
|
pub[0] = uint8(t.PublicKey.E) // Todo does not fit with binds 65537 exp!
|
||||||
*/
|
*/
|
||||||
publicExponent := unpackBase64(e.Bytes())
|
publicExponent := unpackBase64(e.Bytes())
|
||||||
privateExponent := unpackBase64(t.D.Bytes())
|
privateExponent := unpackBase64(t.D.Bytes())
|
||||||
prime1 := unpackBase64(t.P.Bytes())
|
prime1 := unpackBase64(t.P.Bytes())
|
||||||
|
@ -116,10 +116,10 @@ func (k *RR_DNSKEY) PrivateKeySetString(s string) (PrivateKey, os.Error) {
|
||||||
return nil, &Error{Error: "v1.3 supported"}
|
return nil, &Error{Error: "v1.3 supported"}
|
||||||
}
|
}
|
||||||
case "Algorithm:":
|
case "Algorithm:":
|
||||||
a, _ := strconv.Atoi(right)
|
a, _ := strconv.Atoi(right)
|
||||||
if a == 0 {
|
if a == 0 {
|
||||||
return nil, &Error{Error: "incorrect algorithm"}
|
return nil, &Error{Error: "incorrect algorithm"}
|
||||||
}
|
}
|
||||||
k.Algorithm = uint8(a)
|
k.Algorithm = uint8(a)
|
||||||
case "Modulus:", "PublicExponent:", "PrivateExponent:", "Prime1:", "Prime2:":
|
case "Modulus:", "PublicExponent:", "PrivateExponent:", "Prime1:", "Prime2:":
|
||||||
v, err := packBase64([]byte(right))
|
v, err := packBase64([]byte(right))
|
||||||
|
@ -127,25 +127,25 @@ func (k *RR_DNSKEY) PrivateKeySetString(s string) (PrivateKey, os.Error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if left == "Modulus:" {
|
if left == "Modulus:" {
|
||||||
p.PublicKey.N = big.NewInt(0)
|
p.PublicKey.N = big.NewInt(0)
|
||||||
p.PublicKey.N.SetBytes(v)
|
p.PublicKey.N.SetBytes(v)
|
||||||
}
|
}
|
||||||
if left == "PublicExponent:" {
|
if left == "PublicExponent:" {
|
||||||
i := big.NewInt(0)
|
i := big.NewInt(0)
|
||||||
i.SetBytes(v)
|
i.SetBytes(v)
|
||||||
// Int64 should be large enough
|
// Int64 should be large enough
|
||||||
p.PublicKey.E = int(i.Int64())
|
p.PublicKey.E = int(i.Int64())
|
||||||
}
|
}
|
||||||
if left == "PrivateExponent:" {
|
if left == "PrivateExponent:" {
|
||||||
p.D = big.NewInt(0)
|
p.D = big.NewInt(0)
|
||||||
p.D.SetBytes(v)
|
p.D.SetBytes(v)
|
||||||
}
|
}
|
||||||
if left == "Prime1:" {
|
if left == "Prime1:" {
|
||||||
p.P = big.NewInt(0)
|
p.P = big.NewInt(0)
|
||||||
p.P.SetBytes(v)
|
p.P.SetBytes(v)
|
||||||
}
|
}
|
||||||
if left == "Prime2:" {
|
if left == "Prime2:" {
|
||||||
p.Q = big.NewInt(0)
|
p.Q = big.NewInt(0)
|
||||||
p.Q.SetBytes(v)
|
p.Q.SetBytes(v)
|
||||||
}
|
}
|
||||||
case "Exponent1:", "Exponent2:", "Coefficient:":
|
case "Exponent1:", "Exponent2:", "Coefficient:":
|
||||||
|
@ -158,6 +158,6 @@ func (k *RR_DNSKEY) PrivateKeySetString(s string) (PrivateKey, os.Error) {
|
||||||
}
|
}
|
||||||
line, _ = r.ReadBytes('\n')
|
line, _ = r.ReadBytes('\n')
|
||||||
}
|
}
|
||||||
k.setPubKeyRSA(p.PublicKey.E, p.PublicKey.N)
|
k.setPubKeyRSA(p.PublicKey.E, p.PublicKey.N)
|
||||||
return p, nil
|
return p, nil
|
||||||
}
|
}
|
||||||
|
|
105
parse_test.go
105
parse_test.go
|
@ -1,31 +1,34 @@
|
||||||
package dns
|
package dns
|
||||||
|
|
||||||
import ( "testing"; "fmt"; "crypto/rsa")
|
import (
|
||||||
|
"testing"
|
||||||
|
"crypto/rsa"
|
||||||
|
)
|
||||||
|
|
||||||
func TestConversion(t *testing.T) {
|
func TestConversion(t *testing.T) {
|
||||||
/*
|
/*
|
||||||
println(StringToSeconds("6w8d50"))
|
println(StringToSeconds("6w8d50"))
|
||||||
println(StringToSeconds("50"))
|
println(StringToSeconds("50"))
|
||||||
println(StringToSeconds("1m1m"))
|
println(StringToSeconds("1m1m"))
|
||||||
println(StringToSeconds("1w"))
|
println(StringToSeconds("1w"))
|
||||||
println(StringToSeconds("1d"))
|
println(StringToSeconds("1d"))
|
||||||
println(StringToSeconds("2d"))
|
println(StringToSeconds("2d"))
|
||||||
println(StringToSeconds("1d1d"))
|
println(StringToSeconds("1d1d"))
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
println(SecondsToString(604800)) // 1w
|
println(SecondsToString(604800)) // 1w
|
||||||
println(SecondsToString(604799)) // 1w-1
|
println(SecondsToString(604799)) // 1w-1
|
||||||
println(SecondsToString(86400)) // 1d
|
println(SecondsToString(86400)) // 1d
|
||||||
println(SecondsToString(86401)) // 1d+1
|
println(SecondsToString(86401)) // 1d+1
|
||||||
println(SecondsToString(86399)) // 1d-1
|
println(SecondsToString(86399)) // 1d-1
|
||||||
println(SecondsToString(86)) // 1m26
|
println(SecondsToString(86)) // 1m26
|
||||||
println(SecondsToString(60)) // 1m
|
println(SecondsToString(60)) // 1m
|
||||||
println(SecondsToString(59)) // 59
|
println(SecondsToString(59)) // 59
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrivateKeyRead1(t *testing.T) {
|
func TestPrivateKeyRead1(t *testing.T) {
|
||||||
a:=`Private-key-format: v1.3
|
a := `Private-key-format: v1.3
|
||||||
Algorithm: 5 (RSASHA1)
|
Algorithm: 5 (RSASHA1)
|
||||||
Modulus: vyVjCzz87g3rg9vDj1NJ1tlFP7lEY2pEQLkWGXAFuZM6Fw/bNmEH/z3ybDfsJqx4QQ6YZXN8V2kbzY7oX+tExf6AMiMIcKYzEGwg5xBYFh33du4G+6kE/VzG906ubpaIEnrZOMTdGqE7OwptAqrqXe4uGXY99ZqNdqutOKQyIzs=
|
Modulus: vyVjCzz87g3rg9vDj1NJ1tlFP7lEY2pEQLkWGXAFuZM6Fw/bNmEH/z3ybDfsJqx4QQ6YZXN8V2kbzY7oX+tExf6AMiMIcKYzEGwg5xBYFh33du4G+6kE/VzG906ubpaIEnrZOMTdGqE7OwptAqrqXe4uGXY99ZqNdqutOKQyIzs=
|
||||||
PublicExponent: AQAB
|
PublicExponent: AQAB
|
||||||
|
@ -39,22 +42,20 @@ Created: 20101221142359
|
||||||
Publish: 20101221142359
|
Publish: 20101221142359
|
||||||
Activate: 20101221142359`
|
Activate: 20101221142359`
|
||||||
|
|
||||||
k := new(RR_DNSKEY)
|
k := new(RR_DNSKEY)
|
||||||
p,_ := k.PrivateKeySetString(a)
|
p, _ := k.PrivateKeySetString(a)
|
||||||
p = p
|
p = p
|
||||||
fmt.Printf("%v\n", k)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrivateKeyRead2(t *testing.T) {
|
func TestPrivateKeyRead2(t *testing.T) {
|
||||||
b:=`; This is a zone-signing key, keyid 41946, for miek.nl.
|
/* b:=`; This is a zone-signing key, keyid 41946, for miek.nl.
|
||||||
; Created: 20110109154937 (Sun Jan 9 16:49:37 2011)
|
; Created: 20110109154937 (Sun Jan 9 16:49:37 2011)
|
||||||
; Publish: 20110109154937 (Sun Jan 9 16:49:37 2011)
|
; Publish: 20110109154937 (Sun Jan 9 16:49:37 2011)
|
||||||
; Activate: 20110109154937 (Sun Jan 9 16:49:37 2011)
|
; Activate: 20110109154937 (Sun Jan 9 16:49:37 2011)
|
||||||
miek.nl. IN DNSKEY 256 3 5 AwEAAeETsGZdYlTsHK8wc1yo9Zcj4dMEpPWRTYuTmGD3e4Qsk4/uyKf5jhsNZhp8no7GKHTEe7+K1prC4iXo3X5oQyDDmx76hDo5u6fblu/XaQw16wqMDQDPiURUKkzobJlmY6fYNKRz7A01J73V6qDMCvlk+8p+fb0a+LiJ2NJDACln`
|
miek.nl. IN DNSKEY 256 3 5 AwEAAeETsGZdYlTsHK8wc1yo9Zcj4dMEpPWRTYuTmGD3e4Qsk4/uyKf5jhsNZhp8no7GKHTEe7+K1prC4iXo3X5oQyDDmx76hDo5u6fblu/XaQw16wqMDQDPiURUKkzobJlmY6fYNKRz7A01J73V6qDMCvlk+8p+fb0a+LiJ2NJDACln`
|
||||||
|
*/
|
||||||
|
|
||||||
b = b
|
a := `Private-key-format: v1.3
|
||||||
|
|
||||||
a:=`Private-key-format: v1.3
|
|
||||||
Algorithm: 5 (RSASHA1)
|
Algorithm: 5 (RSASHA1)
|
||||||
Modulus: 4ROwZl1iVOwcrzBzXKj1lyPh0wSk9ZFNi5OYYPd7hCyTj+7Ip/mOGw1mGnyejsYodMR7v4rWmsLiJejdfmhDIMObHvqEOjm7p9uW79dpDDXrCowNAM+JRFQqTOhsmWZjp9g0pHPsDTUnvdXqoMwK+WT7yn59vRr4uInY0kMAKWc=
|
Modulus: 4ROwZl1iVOwcrzBzXKj1lyPh0wSk9ZFNi5OYYPd7hCyTj+7Ip/mOGw1mGnyejsYodMR7v4rWmsLiJejdfmhDIMObHvqEOjm7p9uW79dpDDXrCowNAM+JRFQqTOhsmWZjp9g0pHPsDTUnvdXqoMwK+WT7yn59vRr4uInY0kMAKWc=
|
||||||
PublicExponent: AQAB
|
PublicExponent: AQAB
|
||||||
|
@ -68,23 +69,23 @@ Created: 20110109154937
|
||||||
Publish: 20110109154937
|
Publish: 20110109154937
|
||||||
Activate: 20110109154937`
|
Activate: 20110109154937`
|
||||||
|
|
||||||
k := new(RR_DNSKEY)
|
k := new(RR_DNSKEY)
|
||||||
k.Hdr.Rrtype = TypeDNSKEY
|
k.Hdr.Rrtype = TypeDNSKEY
|
||||||
k.Hdr.Class = ClassINET
|
k.Hdr.Class = ClassINET
|
||||||
k.Hdr.Name = "miek.nl."
|
k.Hdr.Name = "miek.nl."
|
||||||
k.Protocol = 3
|
k.Protocol = 3
|
||||||
k.Flags = 256
|
k.Flags = 256
|
||||||
p, _ := k.PrivateKeySetString(a)
|
p, _ := k.PrivateKeySetString(a)
|
||||||
switch priv := p.(type) {
|
switch priv := p.(type) {
|
||||||
case *rsa.PrivateKey:
|
case *rsa.PrivateKey:
|
||||||
if 65537 != priv.PublicKey.E {
|
if 65537 != priv.PublicKey.E {
|
||||||
t.Log("Exponenet should be 65537")
|
t.Log("Exponenet should be 65537")
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if k.KeyTag() != 41946 {
|
if k.KeyTag() != 41946 {
|
||||||
t.Log("Keytag should be 41946")
|
t.Logf("%v\n", k)
|
||||||
t.Fail()
|
t.Log("Keytag should be 41946")
|
||||||
}
|
t.Fail()
|
||||||
fmt.Printf("%v\n", k)
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,7 @@ package resolver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
"fmt"
|
"dns"
|
||||||
"dns"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestResolver(t *testing.T) {
|
func TestResolver(t *testing.T) {
|
||||||
|
@ -24,7 +23,7 @@ func TestResolver(t *testing.T) {
|
||||||
if in.Dns != nil && in.Dns.Rcode != dns.RcodeSuccess {
|
if in.Dns != nil && in.Dns.Rcode != dns.RcodeSuccess {
|
||||||
t.Log("Failed to get an valid answer")
|
t.Log("Failed to get an valid answer")
|
||||||
t.Fail()
|
t.Fail()
|
||||||
t.Logf("%v\n", in)
|
t.Logf("%v\n", in)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ask something
|
// ask something
|
||||||
|
@ -35,13 +34,11 @@ func TestResolver(t *testing.T) {
|
||||||
if in.Dns != nil && in.Dns.Rcode != dns.RcodeSuccess {
|
if in.Dns != nil && in.Dns.Rcode != dns.RcodeSuccess {
|
||||||
t.Log("Failed to get an valid answer")
|
t.Log("Failed to get an valid answer")
|
||||||
t.Fail()
|
t.Fail()
|
||||||
t.Logf("%v\n", in)
|
t.Logf("%v\n", in)
|
||||||
} else {
|
}
|
||||||
fmt.Printf("%v\n", in.Dns)
|
|
||||||
}
|
|
||||||
|
|
||||||
ch <- Msg{nil, nil}
|
ch <- Msg{nil, nil}
|
||||||
<-ch
|
<-ch
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestResolverEdns(t *testing.T) {
|
func TestResolverEdns(t *testing.T) {
|
||||||
|
@ -76,12 +73,10 @@ func TestResolverEdns(t *testing.T) {
|
||||||
in := <-ch
|
in := <-ch
|
||||||
if in.Dns != nil {
|
if in.Dns != nil {
|
||||||
if in.Dns.Rcode != dns.RcodeSuccess {
|
if in.Dns.Rcode != dns.RcodeSuccess {
|
||||||
|
t.Logf("%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("%v\n", in.Dns)
|
|
||||||
} else {
|
|
||||||
fmt.Printf("Failed to get a good anwer")
|
|
||||||
}
|
}
|
||||||
ch <- Msg{nil, nil}
|
ch <- Msg{nil, nil}
|
||||||
<-ch // wait for ch to close channel
|
<-ch // wait for ch to close channel
|
||||||
|
@ -102,27 +97,25 @@ func TestResolverTsig(t *testing.T) {
|
||||||
// ask something
|
// ask something
|
||||||
m.Question[0] = dns.Question{"powerdns.nl", dns.TypeDNSKEY, dns.ClassINET}
|
m.Question[0] = dns.Question{"powerdns.nl", dns.TypeDNSKEY, dns.ClassINET}
|
||||||
m.Extra = make([]dns.RR, 1)
|
m.Extra = make([]dns.RR, 1)
|
||||||
m.SetId()
|
m.SetId()
|
||||||
|
|
||||||
tsig := new(dns.RR_TSIG)
|
tsig := new(dns.RR_TSIG)
|
||||||
tsig.Hdr.Name = "miek.nl" // for tsig this is the key's name
|
tsig.Hdr.Name = "miek.nl" // for tsig this is the key's name
|
||||||
tsig.Hdr.Rrtype = dns.TypeTSIG
|
tsig.Hdr.Rrtype = dns.TypeTSIG
|
||||||
tsig.Hdr.Class = dns.ClassANY
|
tsig.Hdr.Class = dns.ClassANY
|
||||||
tsig.Hdr.Ttl = 0
|
tsig.Hdr.Ttl = 0
|
||||||
tsig.Generate(m, "geheim")
|
tsig.Generate(m, "geheim")
|
||||||
// Add it to the msg
|
// Add it to the msg
|
||||||
m.Extra[0] = tsig
|
m.Extra[0] = tsig
|
||||||
|
|
||||||
ch <- Msg{m, nil}
|
ch <- Msg{m, nil}
|
||||||
in := <-ch
|
in := <-ch
|
||||||
if in.Dns != nil {
|
if in.Dns != nil {
|
||||||
if in.Dns.Rcode != dns.RcodeSuccess {
|
if in.Dns.Rcode != dns.RcodeSuccess {
|
||||||
|
t.Logf("%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("%v\n", in.Dns)
|
|
||||||
} else {
|
|
||||||
fmt.Printf("Failed to get a good anwer")
|
|
||||||
}
|
}
|
||||||
ch <- Msg{nil, nil}
|
ch <- Msg{nil, nil}
|
||||||
<-ch // wait for ch to close channel
|
<-ch // wait for ch to close channel
|
||||||
|
@ -135,20 +128,20 @@ func TestAXFR(t *testing.T) {
|
||||||
res.Servers = []string{"127.0.0.1"}
|
res.Servers = []string{"127.0.0.1"}
|
||||||
m := new(dns.Msg)
|
m := new(dns.Msg)
|
||||||
m.Question = make([]dns.Question, 1)
|
m.Question = make([]dns.Question, 1)
|
||||||
m.Question[0] = dns.Question{"miek.nl", dns.TypeAXFR, dns.ClassINET}
|
m.Question[0] = dns.Question{"miek.nl", dns.TypeAXFR, dns.ClassINET}
|
||||||
//m.Question[0] = dns.Question{"atoom.net", dns.TypeAXFR, dns.ClassINET}
|
//m.Question[0] = dns.Question{"atoom.net", dns.TypeAXFR, dns.ClassINET}
|
||||||
|
|
||||||
ch <- Msg{m, nil}
|
ch <- Msg{m, nil}
|
||||||
for dm := range ch {
|
for dm := range ch {
|
||||||
var _ = dm
|
var _ = dm
|
||||||
/* fmt.Printf("%v\n",dm.Dns) */
|
/* fmt.Printf("%v\n",dm.Dns) */
|
||||||
}
|
}
|
||||||
/* channel is closed by NewXfer() */
|
/* channel is closed by NewXfer() */
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFromFile(t *testing.T) {
|
func TestFromFile(t *testing.T) {
|
||||||
res := new(Resolver)
|
res := new(Resolver)
|
||||||
res.FromFile("/etc/resolv.conf")
|
res.FromFile("/etc/resolv.conf")
|
||||||
ch := res.NewQuerier()
|
ch := res.NewQuerier()
|
||||||
m := new(dns.Msg)
|
m := new(dns.Msg)
|
||||||
m.Question = make([]dns.Question, 1)
|
m.Question = make([]dns.Question, 1)
|
||||||
|
@ -161,6 +154,5 @@ func TestFromFile(t *testing.T) {
|
||||||
t.Log("Failed to get an valid answer")
|
t.Log("Failed to get an valid answer")
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
fmt.Printf("%v\n", in.Dns)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
60
string.go
60
string.go
|
@ -2,7 +2,7 @@ package dns
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"unicode"
|
"unicode"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -30,44 +30,44 @@ func StringToSeconds(ttl string) (sec uint32, ok bool) {
|
||||||
sec += uint32(i) * d
|
sec += uint32(i) * d
|
||||||
case 'w':
|
case 'w':
|
||||||
sec += uint32(i) * w
|
sec += uint32(i) * w
|
||||||
default:
|
default:
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
num = ""
|
num = ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
i, _ := strconv.Atoi(num)
|
i, _ := strconv.Atoi(num)
|
||||||
sec += uint32(i)
|
sec += uint32(i)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func SecondsToString(val uint32) (str string) {
|
func SecondsToString(val uint32) (str string) {
|
||||||
mod := val / w
|
mod := val / w
|
||||||
if mod > 0 {
|
if mod > 0 {
|
||||||
str += strconv.Itoa(int(mod)) + "w"
|
str += strconv.Itoa(int(mod)) + "w"
|
||||||
}
|
}
|
||||||
val -= mod * w
|
val -= mod * w
|
||||||
|
|
||||||
mod = val / d
|
mod = val / d
|
||||||
if mod > 0 {
|
if mod > 0 {
|
||||||
str += strconv.Itoa(int(mod)) + "d"
|
str += strconv.Itoa(int(mod)) + "d"
|
||||||
}
|
}
|
||||||
val -= mod * d
|
val -= mod * d
|
||||||
|
|
||||||
mod = val / h
|
mod = val / h
|
||||||
if mod > 0 {
|
if mod > 0 {
|
||||||
str += strconv.Itoa(int(mod)) + "h"
|
str += strconv.Itoa(int(mod)) + "h"
|
||||||
}
|
}
|
||||||
val -= mod * h
|
val -= mod * h
|
||||||
|
|
||||||
mod = val / m
|
mod = val / m
|
||||||
if mod > 0 {
|
if mod > 0 {
|
||||||
str += strconv.Itoa(int(mod)) + "m"
|
str += strconv.Itoa(int(mod)) + "m"
|
||||||
}
|
}
|
||||||
val -= mod * m
|
val -= mod * m
|
||||||
|
|
||||||
if val > 0 {
|
if val > 0 {
|
||||||
str += strconv.Itoa(int(val))
|
str += strconv.Itoa(int(val))
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue