Left: | ||
Right: |
OLD | NEW |
---|---|
1 package ssh | 1 package ssh |
2 | 2 |
3 import ( | 3 import ( |
4 "crypto/dsa" | 4 "crypto/dsa" |
5 "crypto/ecdsa" | 5 "crypto/ecdsa" |
6 "crypto/elliptic" | 6 "crypto/elliptic" |
7 "crypto/rand" | 7 "crypto/rand" |
8 "crypto/rsa" | 8 "crypto/rsa" |
9 "reflect" | 9 "reflect" |
10 "strings" | 10 "strings" |
11 "testing" | 11 "testing" |
12 "time" | |
13 ) | 12 ) |
14 | 13 |
15 var ( | 14 var ( |
16 ecdsaKey Signer | 15 ecdsaKey Signer |
17 ecdsa384Key Signer | 16 ecdsa384Key Signer |
18 ecdsa521Key Signer | 17 ecdsa521Key Signer |
19 testCertKey Signer | 18 testCertKey Signer |
20 ) | 19 ) |
21 | 20 |
22 type testSigner struct { | 21 type testSigner struct { |
(...skipping 16 matching lines...) Expand all Loading... | |
39 ecdsa384Key, _ = NewSignerFromKey(raw384) | 38 ecdsa384Key, _ = NewSignerFromKey(raw384) |
40 | 39 |
41 raw521, _ := ecdsa.GenerateKey(elliptic.P521(), rand.Reader) | 40 raw521, _ := ecdsa.GenerateKey(elliptic.P521(), rand.Reader) |
42 ecdsa521Key, _ = NewSignerFromKey(raw521) | 41 ecdsa521Key, _ = NewSignerFromKey(raw521) |
43 | 42 |
44 // Create a cert and sign it for use in tests. | 43 // Create a cert and sign it for use in tests. |
45 testCert := &OpenSSHCertV01{ | 44 testCert := &OpenSSHCertV01{ |
46 Nonce: []byte{}, // To pass reflect.DeepEqual after ma rshal & parse, this must be non-nil | 45 Nonce: []byte{}, // To pass reflect.DeepEqual after ma rshal & parse, this must be non-nil |
47 Key: ecdsaKey.PublicKey(), | 46 Key: ecdsaKey.PublicKey(), |
48 ValidPrincipals: []string{"gopher1", "gopher2"}, // increases te st coverage | 47 ValidPrincipals: []string{"gopher1", "gopher2"}, // increases te st coverage |
49 » » ValidAfter: time.Now().Truncate(time.Second), | 48 » » ValidAfter: 0, // unix epoch |
50 » » ValidBefore: time.Now().Truncate(time.Second).Add(time.Hour) , | 49 » » ValidBefore: 0xFFFFFFFFFFFFFFFF, // The end of c urrently representable time. |
jpsugar
2013/10/22 21:45:35
Use a constant here?
jmpittman
2013/10/23 00:19:02
Done.
| |
51 » » Reserved: []byte{}, // To pass reflect.DeepEqual after ma rshal & parse, this must be non-nil | 50 » » Reserved: []byte{}, // To pass refl ect.DeepEqual after marshal & parse, this must be non-nil |
52 SignatureKey: rsaKey.PublicKey(), | 51 SignatureKey: rsaKey.PublicKey(), |
53 } | 52 } |
54 sigBytes, _ := rsaKey.Sign(rand.Reader, testCert.BytesForSigning()) | 53 sigBytes, _ := rsaKey.Sign(rand.Reader, testCert.BytesForSigning()) |
55 testCert.Signature = &signature{ | 54 testCert.Signature = &signature{ |
56 Format: testCert.SignatureKey.PublicKeyAlgo(), | 55 Format: testCert.SignatureKey.PublicKeyAlgo(), |
57 Blob: sigBytes, | 56 Blob: sigBytes, |
58 } | 57 } |
59 testCertKey = &testSigner{ | 58 testCertKey = &testSigner{ |
60 Signer: ecdsaKey, | 59 Signer: ecdsaKey, |
61 pub: testCert, | 60 pub: testCert, |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
206 data := []byte("sign me") | 205 data := []byte("sign me") |
207 sig, err := s.Sign(rand.Reader, data) | 206 sig, err := s.Sign(rand.Reader, data) |
208 if err != nil { | 207 if err != nil { |
209 t.Fatalf("dsa.Sign: %v", err) | 208 t.Fatalf("dsa.Sign: %v", err) |
210 } | 209 } |
211 | 210 |
212 if !s.PublicKey().Verify(data, sig) { | 211 if !s.PublicKey().Verify(data, sig) { |
213 t.Error("Verify failed.") | 212 t.Error("Verify failed.") |
214 } | 213 } |
215 } | 214 } |
OLD | NEW |