...
1
2
3
4
5
6
7
8
9 package ssh
10
11 import (
12 "crypto/rand"
13 "fmt"
14
15 "golang.org/x/crypto/ssh/testdata"
16 )
17
18 var (
19 testPrivateKeys map[string]interface{}
20 testSigners map[string]Signer
21 testPublicKeys map[string]PublicKey
22 )
23
24 func init() {
25 var err error
26
27 n := len(testdata.PEMBytes)
28 testPrivateKeys = make(map[string]interface{}, n)
29 testSigners = make(map[string]Signer, n)
30 testPublicKeys = make(map[string]PublicKey, n)
31 for t, k := range testdata.PEMBytes {
32 testPrivateKeys[t], err = ParseRawPrivateKey(k)
33 if err != nil {
34 panic(fmt.Sprintf("Unable to parse test key %s: %v", t, err))
35 }
36 testSigners[t], err = NewSignerFromKey(testPrivateKeys[t])
37 if err != nil {
38 panic(fmt.Sprintf("Unable to create signer for test key %s: %v", t, err))
39 }
40 testPublicKeys[t] = testSigners[t].PublicKey()
41 }
42
43
44 testCert := &Certificate{
45 Nonce: []byte{},
46 ValidPrincipals: []string{"gopher1", "gopher2"},
47 ValidAfter: 0,
48 ValidBefore: CertTimeInfinity,
49 Reserved: []byte{},
50 Key: testPublicKeys["ecdsa"],
51 SignatureKey: testPublicKeys["rsa"],
52 Permissions: Permissions{
53 CriticalOptions: map[string]string{},
54 Extensions: map[string]string{},
55 },
56 }
57 testCert.SignCert(rand.Reader, testSigners["rsa"])
58 testPrivateKeys["cert"] = testPrivateKeys["ecdsa"]
59 testSigners["cert"], err = NewCertSigner(testCert, testSigners["ecdsa"])
60 if err != nil {
61 panic(fmt.Sprintf("Unable to create certificate signer: %v", err))
62 }
63 }
64
View as plain text