Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(947)

Delta Between Two Patch Sets: ssh/client_auth_test.go

Issue 13338044: code review 13338044: go.crypto/ssh: introduce PrivateKey method. (Closed)
Left Patch Set: diff -r c923f02daf74 https://code.google.com/p/go.crypto Created 10 years, 6 months ago
Right Patch Set: diff -r c923f02daf74 https://code.google.com/p/go.crypto Created 10 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « ssh/certs.go ('k') | ssh/common.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 // Copyright 2011 The Go Authors. All rights reserved. 1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 package ssh 5 package ssh
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "crypto/dsa" 9 "crypto/dsa"
10 "io" 10 "io"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 r/ZwVaFzjWzxaf6zQIJbfaSEAhqD5yo72+sCAwEAAQJBAK8PEVU23Wj8mV0QjwcJ 50 r/ZwVaFzjWzxaf6zQIJbfaSEAhqD5yo72+sCAwEAAQJBAK8PEVU23Wj8mV0QjwcJ
51 tZ4GcTUYQL7cF4+ezTCE9a1NrGnCP2RuQkHEKxuTVrxXt+6OF15/1/fuXnxKjmJC 51 tZ4GcTUYQL7cF4+ezTCE9a1NrGnCP2RuQkHEKxuTVrxXt+6OF15/1/fuXnxKjmJC
52 nxkCIQDaXvPPBi0c7vAxGwNY9726x01/dNbHCE0CBtcotobxpwIhANbbQbh3JHVW 52 nxkCIQDaXvPPBi0c7vAxGwNY9726x01/dNbHCE0CBtcotobxpwIhANbbQbh3JHVW
53 2haQh4fAG5mhesZKAGcxTyv4mQ7uMSQdAiAj+4dzMpJWdSzQ+qGHlHMIBvVHLkqB 53 2haQh4fAG5mhesZKAGcxTyv4mQ7uMSQdAiAj+4dzMpJWdSzQ+qGHlHMIBvVHLkqB
54 y2VdEyF7DPCZewIhAI7GOI/6LDIFOvtPo6Bj2nNmyQ1HU6k/LRtNIXi4c9NJAiAr 54 y2VdEyF7DPCZewIhAI7GOI/6LDIFOvtPo6Bj2nNmyQ1HU6k/LRtNIXi4c9NJAiAr
55 rrxx26itVhJmcvoUhOjwuzSlP2bE5VHAvkGB352YBg== 55 rrxx26itVhJmcvoUhOjwuzSlP2bE5VHAvkGB352YBg==
56 -----END RSA PRIVATE KEY-----` 56 -----END RSA PRIVATE KEY-----`
57 57
58 // keychain implements the ClientKeyring interface 58 // keychain implements the ClientKeyring interface
59 type keychain struct { 59 type keychain struct {
60 » keys []PrivateKey 60 » keys []Signer
61 } 61 }
62 62
63 func (k *keychain) Key(i int) (PublicKey, error) { 63 func (k *keychain) Key(i int) (PublicKey, error) {
64 if i < 0 || i >= len(k.keys) { 64 if i < 0 || i >= len(k.keys) {
65 return nil, nil 65 return nil, nil
66 } 66 }
67 67
68 return k.keys[i].PublicKey(), nil 68 return k.keys[i].PublicKey(), nil
69 } 69 }
70 70
71 func (k *keychain) Sign(i int, rand io.Reader, data []byte) (sig []byte, err err or) { 71 func (k *keychain) Sign(i int, rand io.Reader, data []byte) (sig []byte, err err or) {
72 return k.keys[i].Sign(rand, data) 72 return k.keys[i].Sign(rand, data)
73 } 73 }
74 74
75 func (k *keychain) add(key PrivateKey) { 75 func (k *keychain) add(key Signer) {
76 k.keys = append(k.keys, key) 76 k.keys = append(k.keys, key)
77 } 77 }
78 78
79 func (k *keychain) loadPEM(file string) error { 79 func (k *keychain) loadPEM(file string) error {
80 buf, err := ioutil.ReadFile(file) 80 buf, err := ioutil.ReadFile(file)
81 if err != nil { 81 if err != nil {
82 return err 82 return err
83 } 83 }
84 key, err := ParsePrivateKey(buf) 84 key, err := ParsePrivateKey(buf)
85 if err != nil { 85 if err != nil {
(...skipping 15 matching lines...) Expand all
101 func (cr *keyboardInteractive) Challenge(user string, instruction string, questi ons []string, echos []bool) ([]string, error) { 101 func (cr *keyboardInteractive) Challenge(user string, instruction string, questi ons []string, echos []bool) ([]string, error) {
102 var answers []string 102 var answers []string
103 for _, q := range questions { 103 for _, q := range questions {
104 answers = append(answers, (*cr)[q]) 104 answers = append(answers, (*cr)[q])
105 } 105 }
106 return answers, nil 106 return answers, nil
107 } 107 }
108 108
109 // reused internally by tests 109 // reused internally by tests
110 var ( 110 var (
111 » rsaKey PrivateKey 111 » rsaKey Signer
112 » dsaKey PrivateKey 112 » dsaKey Signer
113 clientKeychain = new(keychain) 113 clientKeychain = new(keychain)
114 clientPassword = password("tiger") 114 clientPassword = password("tiger")
115 serverConfig = &ServerConfig{ 115 serverConfig = &ServerConfig{
116 PasswordCallback: func(conn *ServerConn, user, pass string) bool { 116 PasswordCallback: func(conn *ServerConn, user, pass string) bool {
117 return user == "testuser" && pass == string(clientPasswo rd) 117 return user == "testuser" && pass == string(clientPasswo rd)
118 }, 118 },
119 PublicKeyCallback: func(conn *ServerConn, user, algo string, pub key []byte) bool { 119 PublicKeyCallback: func(conn *ServerConn, user, algo string, pub key []byte) bool {
120 key, _ := clientKeychain.Key(0) 120 key, _ := clientKeychain.Key(0)
121 expected := MarshalPublicKey(key) 121 expected := MarshalPublicKey(key)
122 algoname := key.PublicKeyAlgo() 122 algoname := key.PublicKeyAlgo()
(...skipping 22 matching lines...) Expand all
145 } 145 }
146 rawDSAKey := new(dsa.PrivateKey) 146 rawDSAKey := new(dsa.PrivateKey)
147 147
148 // taken from crypto/dsa/dsa_test.go 148 // taken from crypto/dsa/dsa_test.go
149 rawDSAKey.P, _ = new(big.Int).SetString("A9B5B793FB4785793D246BAE77E8FF6 3CA52F442DA763C440259919FE1BC1D6065A9350637A04F75A2F039401D49F08E066C4D275A5A65D A5684BC563C14289D7AB8A67163BFBF79D85972619AD2CFF55AB0EE77A9002B0EF96293BDD0F4268 5EBB2C66C327079F6C98000FBCB79AACDE1BC6F9D5C7B1A97E3D9D54ED7951FEF", 16) 149 rawDSAKey.P, _ = new(big.Int).SetString("A9B5B793FB4785793D246BAE77E8FF6 3CA52F442DA763C440259919FE1BC1D6065A9350637A04F75A2F039401D49F08E066C4D275A5A65D A5684BC563C14289D7AB8A67163BFBF79D85972619AD2CFF55AB0EE77A9002B0EF96293BDD0F4268 5EBB2C66C327079F6C98000FBCB79AACDE1BC6F9D5C7B1A97E3D9D54ED7951FEF", 16)
150 rawDSAKey.Q, _ = new(big.Int).SetString("E1D3391245933D68A0714ED34BBCB7A 1F422B9C1", 16) 150 rawDSAKey.Q, _ = new(big.Int).SetString("E1D3391245933D68A0714ED34BBCB7A 1F422B9C1", 16)
151 rawDSAKey.G, _ = new(big.Int).SetString("634364FC25248933D01D1993ECABD06 57CC0CB2CEED7ED2E3E8AECDFCDC4A25C3B15E9E3B163ACA2984B5539181F3EFF1A5E8903D71D5B9 5DA4F27202B77D2C44B430BB53741A8D59A8F86887525C9F2A6A5980A195EAA7F2FF910064301DEF 89D3AA213E1FAC7768D89365318E370AF54A112EFBA9246D9158386BA1B4EEFDA", 16) 151 rawDSAKey.G, _ = new(big.Int).SetString("634364FC25248933D01D1993ECABD06 57CC0CB2CEED7ED2E3E8AECDFCDC4A25C3B15E9E3B163ACA2984B5539181F3EFF1A5E8903D71D5B9 5DA4F27202B77D2C44B430BB53741A8D59A8F86887525C9F2A6A5980A195EAA7F2FF910064301DEF 89D3AA213E1FAC7768D89365318E370AF54A112EFBA9246D9158386BA1B4EEFDA", 16)
152 rawDSAKey.Y, _ = new(big.Int).SetString("32969E5780CFE1C849A1C276D7AEB4F 38A23B591739AA2FE197349AEEBD31366AEE5EB7E6C6DDB7C57D02432B30DB5AA66D9884299FAA72 568944E4EEDC92EA3FBC6F39F53412FBCC563208F7C15B737AC8910DBC2D9C9B8C001E72FDC40EB6 94AB1F06A5A2DBD18D9E36C66F31F566742F11EC0A52E9F7B89355C02FB5D32D2", 16) 152 rawDSAKey.Y, _ = new(big.Int).SetString("32969E5780CFE1C849A1C276D7AEB4F 38A23B591739AA2FE197349AEEBD31366AEE5EB7E6C6DDB7C57D02432B30DB5AA66D9884299FAA72 568944E4EEDC92EA3FBC6F39F53412FBCC563208F7C15B737AC8910DBC2D9C9B8C001E72FDC40EB6 94AB1F06A5A2DBD18D9E36C66F31F566742F11EC0A52E9F7B89355C02FB5D32D2", 16)
153 rawDSAKey.X, _ = new(big.Int).SetString("5078D4D29795CBE76D3AACFE48C9AF0 BCDBEE91A", 16) 153 rawDSAKey.X, _ = new(big.Int).SetString("5078D4D29795CBE76D3AACFE48C9AF0 BCDBEE91A", 16)
154 154
155 » dsaKey, err = NewPrivateKey(rawDSAKey) 155 » dsaKey, err = NewSignerFromKey(rawDSAKey)
156 » if err != nil { 156 » if err != nil {
157 » » panic("NewPrivateKey: " + err.Error()) 157 » » panic("NewSignerFromKey: " + err.Error())
158 } 158 }
159 clientKeychain.add(rsaKey) 159 clientKeychain.add(rsaKey)
160 serverConfig.AddHostKey(rsaKey) 160 serverConfig.AddHostKey(rsaKey)
161 } 161 }
162 162
163 // newMockAuthServer creates a new Server bound to 163 // newMockAuthServer creates a new Server bound to
164 // the loopback interface. The server exits after 164 // the loopback interface. The server exits after
165 // processing one handshake. 165 // processing one handshake.
166 func newMockAuthServer(t *testing.T) string { 166 func newMockAuthServer(t *testing.T) string {
167 l, err := Listen("tcp", "127.0.0.1:0", serverConfig) 167 l, err := Listen("tcp", "127.0.0.1:0", serverConfig)
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 Crypto: CryptoConfig{ 357 Crypto: CryptoConfig{
358 KeyExchanges: []string{"diffie-hellman-group-exchange-sh a256"}, // not currently supported 358 KeyExchanges: []string{"diffie-hellman-group-exchange-sh a256"}, // not currently supported
359 }, 359 },
360 } 360 }
361 c, err := Dial("tcp", newMockAuthServer(t), config) 361 c, err := Dial("tcp", newMockAuthServer(t), config)
362 if err == nil || !strings.Contains(err.Error(), "no common algorithms") { 362 if err == nil || !strings.Contains(err.Error(), "no common algorithms") {
363 t.Errorf("got %v, expected 'no common algorithms'", err) 363 t.Errorf("got %v, expected 'no common algorithms'", err)
364 c.Close() 364 c.Close()
365 } 365 }
366 } 366 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b