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