1 // Copyright 2014 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // IMPLEMENTATION NOTE: To avoid a package loop, this file is in three places:
6 // ssh/, ssh/agent, and ssh/test/. It should be kept in sync across all three
15 "golang.org/x/crypto/ssh/testdata"
19 testPrivateKeys map[string]interface{}
20 testSigners map[string]Signer
21 testPublicKeys map[string]PublicKey
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)
34 panic(fmt.Sprintf("Unable to parse test key %s: %v", t, err))
36 testSigners[t], err = NewSignerFromKey(testPrivateKeys[t])
38 panic(fmt.Sprintf("Unable to create signer for test key %s: %v", t, err))
40 testPublicKeys[t] = testSigners[t].PublicKey()
43 // Create a cert and sign it for use in tests.
44 testCert := &Certificate{
45 Nonce: []byte{}, // To pass reflect.DeepEqual after marshal & parse, this must be non-nil
46 ValidPrincipals: []string{"gopher1", "gopher2"}, // increases test coverage
47 ValidAfter: 0, // unix epoch
48 ValidBefore: CertTimeInfinity, // The end of currently representable time.
49 Reserved: []byte{}, // To pass reflect.DeepEqual after marshal & parse, this must be non-nil
50 Key: testPublicKeys["ecdsa"],
51 SignatureKey: testPublicKeys["rsa"],
52 Permissions: Permissions{
53 CriticalOptions: map[string]string{},
54 Extensions: map[string]string{},
57 testCert.SignCert(rand.Reader, testSigners["rsa"])
58 testPrivateKeys["cert"] = testPrivateKeys["ecdsa"]
59 testSigners["cert"], err = NewCertSigner(testCert, testSigners["ecdsa"])
61 panic(fmt.Sprintf("Unable to create certificate signer: %v", err))