"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "sig0_test.go" between
dns-1.1.46.tar.gz and dns-1.1.47.tar.gz

About: GO DNS implements a DNS library in Go.

sig0_test.go  (dns-1.1.46):sig0_test.go  (dns-1.1.47)
skipping to change at line 15 skipping to change at line 15
"testing" "testing"
"time" "time"
) )
func TestSIG0(t *testing.T) { func TestSIG0(t *testing.T) {
if testing.Short() { if testing.Short() {
t.Skip("skipping test in short mode.") t.Skip("skipping test in short mode.")
} }
m := new(Msg) m := new(Msg)
m.SetQuestion("example.org.", TypeSOA) m.SetQuestion("example.org.", TypeSOA)
for _, alg := range []uint8{ECDSAP256SHA256, ECDSAP384SHA384, RSASHA1, RS ASHA256, RSASHA512} { for _, alg := range []uint8{ECDSAP256SHA256, ECDSAP384SHA384, RSASHA1, RS ASHA256, RSASHA512, ED25519} {
algstr := AlgorithmToString[alg] algstr := AlgorithmToString[alg]
keyrr := new(KEY) keyrr := new(KEY)
keyrr.Hdr.Name = algstr + "." keyrr.Hdr.Name = algstr + "."
keyrr.Hdr.Rrtype = TypeKEY keyrr.Hdr.Rrtype = TypeKEY
keyrr.Hdr.Class = ClassINET keyrr.Hdr.Class = ClassINET
keyrr.Algorithm = alg keyrr.Algorithm = alg
keysize := 512 keysize := 512
switch alg { switch alg {
case ECDSAP256SHA256: case ECDSAP256SHA256, ED25519:
keysize = 256 keysize = 256
case ECDSAP384SHA384: case ECDSAP384SHA384:
keysize = 384 keysize = 384
case RSASHA512: case RSASHA512:
keysize = 1024 keysize = 1024
} }
pk, err := keyrr.Generate(keysize) pk, err := keyrr.Generate(keysize)
if err != nil { if err != nil {
t.Errorf("failed to generate key for “%s”: %v", algstr, e rr) t.Errorf("failed to generate key for %q: %v", algstr, err )
continue continue
} }
now := uint32(time.Now().Unix()) now := uint32(time.Now().Unix())
sigrr := new(SIG) sigrr := new(SIG)
sigrr.Hdr.Name = "." sigrr.Hdr.Name = "."
sigrr.Hdr.Rrtype = TypeSIG sigrr.Hdr.Rrtype = TypeSIG
sigrr.Hdr.Class = ClassANY sigrr.Hdr.Class = ClassANY
sigrr.Algorithm = alg sigrr.Algorithm = alg
sigrr.Expiration = now + 300 sigrr.Expiration = now + 300
sigrr.Inception = now - 300 sigrr.Inception = now - 300
sigrr.KeyTag = keyrr.KeyTag() sigrr.KeyTag = keyrr.KeyTag()
sigrr.SignerName = keyrr.Hdr.Name sigrr.SignerName = keyrr.Hdr.Name
mb, err := sigrr.Sign(pk.(crypto.Signer), m) mb, err := sigrr.Sign(pk.(crypto.Signer), m)
if err != nil { if err != nil {
t.Errorf("failed to sign message using “%s”: %v", algstr, err) t.Errorf("failed to sign message using %q: %v", algstr, e rr)
continue continue
} }
m := new(Msg) m := new(Msg)
if err := m.Unpack(mb); err != nil { if err := m.Unpack(mb); err != nil {
t.Errorf("failed to unpack message signed using “%s”: %v" , algstr, err) t.Errorf("failed to unpack message signed using %q: %v", algstr, err)
continue continue
} }
if len(m.Extra) != 1 { if len(m.Extra) != 1 {
t.Errorf("missing SIG for message signed using “%s”", alg str) t.Errorf("missing SIG for message signed using %q", algst r)
continue continue
} }
var sigrrwire *SIG var sigrrwire *SIG
switch rr := m.Extra[0].(type) { switch rr := m.Extra[0].(type) {
case *SIG: case *SIG:
sigrrwire = rr sigrrwire = rr
default: default:
t.Errorf("expected SIG RR, instead: %v", rr) t.Errorf("expected SIG RR, instead: %v", rr)
continue continue
} }
for _, rr := range []*SIG{sigrr, sigrrwire} { for _, rr := range []*SIG{sigrr, sigrrwire} {
id := "sigrr" id := "sigrr"
if rr == sigrrwire { if rr == sigrrwire {
id = "sigrrwire" id = "sigrrwire"
} }
if err := rr.Verify(keyrr, mb); err != nil { if err := rr.Verify(keyrr, mb); err != nil {
t.Errorf("failed to verify “%s” signed SIG(%s): % v", algstr, id, err) t.Errorf("failed to verify %q signed SIG(%s): %v" , algstr, id, err)
continue continue
} }
} }
mb[13]++ mb[13]++
if err := sigrr.Verify(keyrr, mb); err == nil { if err := sigrr.Verify(keyrr, mb); err == nil {
t.Errorf("verify succeeded on an altered message using “% s”", algstr) t.Errorf("verify succeeded on an altered message using %q ", algstr)
continue continue
} }
sigrr.Expiration = 2 sigrr.Expiration = 2
sigrr.Inception = 1 sigrr.Inception = 1
mb, _ = sigrr.Sign(pk.(crypto.Signer), m) mb, _ = sigrr.Sign(pk.(crypto.Signer), m)
if err := sigrr.Verify(keyrr, mb); err == nil { if err := sigrr.Verify(keyrr, mb); err == nil {
t.Errorf("verify succeeded on an expired message using “% s”", algstr) t.Errorf("verify succeeded on an expired message using %q ", algstr)
continue continue
} }
} }
} }
 End of changes. 9 change blocks. 
9 lines changed or deleted 9 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)