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

Delta Between Two Patch Sets: ssh/test/test_unix_test.go

Issue 14494058: code review 14494058: go.crypto/ssh: support rekeying in both directions. (Closed)
Left Patch Set: diff -r bb19605bfacc https://code.google.com/p/go.crypto Created 10 years, 5 months ago
Right Patch Set: diff -r cd1eea1eb828 https://code.google.com/p/go.crypto Created 10 years, 5 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:
Right: Side by side diff | Download
LEFTRIGHT
(no file at all)
1 // Copyright 2012 The Go Authors. All rights reserved. 1 // Copyright 2012 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 // +build darwin freebsd linux netbsd openbsd 5 // +build darwin freebsd linux netbsd openbsd
6 6
7 package test 7 package test
8 8
9 // functional test harness for unix. 9 // functional test harness for unix.
10 10
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 } 100 }
101 if username == "" { 101 if username == "" {
102 panic("Unable to get username") 102 panic("Unable to get username")
103 } 103 }
104 return username 104 return username
105 } 105 }
106 106
107 type storedHostKey struct { 107 type storedHostKey struct {
108 // keys map from an algorithm string to binary key data. 108 // keys map from an algorithm string to binary key data.
109 keys map[string][]byte 109 keys map[string][]byte
110
111 // checkCount counts the Check calls. Used for testing
112 // rekeying.
113 checkCount int
110 } 114 }
111 115
112 func (k *storedHostKey) Add(key ssh.PublicKey) { 116 func (k *storedHostKey) Add(key ssh.PublicKey) {
113 if k.keys == nil { 117 if k.keys == nil {
114 k.keys = map[string][]byte{} 118 k.keys = map[string][]byte{}
115 } 119 }
116 k.keys[key.PublicKeyAlgo()] = ssh.MarshalPublicKey(key) 120 k.keys[key.PublicKeyAlgo()] = ssh.MarshalPublicKey(key)
117 } 121 }
118 122
119 func (k *storedHostKey) Check(addr string, remote net.Addr, algo string, key []b yte) error { 123 func (k *storedHostKey) Check(addr string, remote net.Addr, algo string, key []b yte) error {
124 k.checkCount++
120 if k.keys == nil || bytes.Compare(key, k.keys[algo]) != 0 { 125 if k.keys == nil || bytes.Compare(key, k.keys[algo]) != 0 {
121 return fmt.Errorf("host key mismatch. Got %q, want %q", key, k.k eys[algo]) 126 return fmt.Errorf("host key mismatch. Got %q, want %q", key, k.k eys[algo])
122 } 127 }
123 return nil 128 return nil
124 } 129 }
125 130
126 func clientConfig() *ssh.ClientConfig { 131 func clientConfig() *ssh.ClientConfig {
127 keyChecker := storedHostKey{} 132 keyChecker := storedHostKey{}
128 keyChecker.Add(hostKeyECDSA.PublicKey()) 133 keyChecker.Add(hostKeyECDSA.PublicKey())
129 keyChecker.Add(hostKeyRSA.PublicKey()) 134 keyChecker.Add(hostKeyRSA.PublicKey())
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 if err != nil { 292 if err != nil {
288 return err 293 return err
289 } 294 }
290 key, err := ssh.ParsePrivateKey(buf) 295 key, err := ssh.ParsePrivateKey(buf)
291 if err != nil { 296 if err != nil {
292 return err 297 return err
293 } 298 }
294 k.keys = append(k.keys, key) 299 k.keys = append(k.keys, key)
295 return nil 300 return nil
296 } 301 }
LEFTRIGHT

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