completely fix private key reading

This commit is contained in:
Miek Gieben 2011-01-17 20:18:51 +01:00
parent 1f6a221bd8
commit 48cbf55a23
5 changed files with 29 additions and 31 deletions

View File

@ -2,7 +2,6 @@ package dns
import ( import (
"testing" "testing"
"fmt"
"time" "time"
) )
@ -77,12 +76,9 @@ func TestTsig(t *testing.T) {
t.Log("Failed") t.Log("Failed")
t.Fail() t.Fail()
} }
fmt.Printf("%v\n", tsig)
// Having the TSIG record, it must now be added to the msg // Having the TSIG record, it must now be added to the msg
// in the extra section // in the extra section
out.Extra = make([]RR, 1) out.Extra = make([]RR, 1)
out.Extra[0] = tsig out.Extra[0] = tsig
fmt.Printf("%v\n", out)
} }

View File

@ -451,6 +451,7 @@ func (k *RR_DNSKEY) setPubKeyRSA(_E int, _N *big.Int) {
} }
// 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
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))

View File

@ -119,7 +119,6 @@ func TestSignVerify(t *testing.T) {
t.Log("Failure to sign the SOA record") t.Log("Failure to sign the SOA record")
t.Fail() t.Fail()
} }
fmt.Fprintf(os.Stderr, "%v\n%v\n%v\n", soa, key, sig)
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()

View File

@ -105,9 +105,8 @@ func (k *RR_DNSKEY) PrivateKeySetString(s string) (PrivateKey, os.Error) {
p := new(rsa.PrivateKey) p := new(rsa.PrivateKey)
r := bufio.NewReader(strings.NewReader(s)) r := bufio.NewReader(strings.NewReader(s))
var left, right string var left, right string
// I think I'm doing too much work here TODO(mg)
line, _ := r.ReadBytes('\n') line, _ := r.ReadBytes('\n')
// Do we care about the order of things? // Do we care about the order of things? TODO(mg)
for len(line) > 0 { for len(line) > 0 {
n, _ := fmt.Sscanf(string(line), "%s %s+\n", &left, &right) n, _ := fmt.Sscanf(string(line), "%s %s+\n", &left, &right)
if n > 0 { if n > 0 {
@ -154,7 +153,6 @@ func (k *RR_DNSKEY) PrivateKeySetString(s string) (PrivateKey, os.Error) {
case "Created:", "Publish:", "Activate:": case "Created:", "Publish:", "Activate:":
/* not used in Go (yet) */ /* not used in Go (yet) */
default: default:
println("ERR:", left, "end")
return nil, &Error{Error: "Private key file not recognized"} return nil, &Error{Error: "Private key file not recognized"}
} }
} }

View File

@ -1,6 +1,6 @@
package dns package dns
import ( "testing"; "fmt") import ( "testing"; "fmt"; "crypto/rsa")
func TestConversion(t *testing.T) { func TestConversion(t *testing.T) {
/* /*
@ -75,12 +75,16 @@ Activate: 20110109154937`
k.Protocol = 3 k.Protocol = 3
k.Flags = 256 k.Flags = 256
p, _ := k.PrivateKeySetString(a) p, _ := k.PrivateKeySetString(a)
p = p switch priv := p.(type) {
fmt.Printf("New key %v\n", k) case *rsa.PrivateKey:
fmt.Printf("Keytag %d", k.KeyTag()) if 65537 != priv.PublicKey.E {
t.Log("Exponenet should be 65537")
t.Fail()
}
}
if k.KeyTag() != 41946 { if k.KeyTag() != 41946 {
t.Log("Keytag should be 41946") t.Log("Keytag should be 41946")
t.Fail() t.Fail()
} }
fmt.Printf("%v\n", k)
} }