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

Delta Between Two Patch Sets: ssh/client.go

Issue 14641044: code review 14641044: go.crypto/ssh: put version exchange in function (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 bb19605bfacc 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | ssh/client_test.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 "crypto/rand" 8 "crypto/rand"
9 "encoding/binary" 9 "encoding/binary"
10 "errors" 10 "errors"
11 "fmt" 11 "fmt"
12 "io" 12 "io"
13 "net" 13 "net"
14 "sync" 14 "sync"
15 ) 15 )
16 16
17 // clientVersion is the default identification string that the client will use.
18 var clientVersion = []byte("SSH-2.0-Go")
19
20 // ClientConn represents the client side of an SSH connection. 17 // ClientConn represents the client side of an SSH connection.
21 type ClientConn struct { 18 type ClientConn struct {
22 *transport 19 *transport
23 config *ClientConfig 20 config *ClientConfig
24 chanList // channels associated with this connection 21 chanList // channels associated with this connection
25 forwardList // forwarded tcpip connections from the remote side 22 forwardList // forwarded tcpip connections from the remote side
26 globalRequest 23 globalRequest
27 24
28 // Address as passed to the Dial function. 25 // Address as passed to the Dial function.
29 dialAddress string 26 dialAddress string
(...skipping 22 matching lines...) Expand all
52 if err := conn.handshake(); err != nil { 49 if err := conn.handshake(); err != nil {
53 conn.Close() 50 conn.Close()
54 return nil, fmt.Errorf("handshake failed: %v", err) 51 return nil, fmt.Errorf("handshake failed: %v", err)
55 } 52 }
56 go conn.mainLoop() 53 go conn.mainLoop()
57 return conn, nil 54 return conn, nil
58 } 55 }
59 56
60 // handshake performs the client side key exchange. See RFC 4253 Section 7. 57 // handshake performs the client side key exchange. See RFC 4253 Section 7.
61 func (c *ClientConn) handshake() error { 58 func (c *ClientConn) handshake() error {
62 » clientVersion := packageVersion 59 » clientVersion := []byte(packageVersion)
63 if c.config.ClientVersion != "" { 60 if c.config.ClientVersion != "" {
64 » » clientVersion = c.config.ClientVersion 61 » » clientVersion = []byte(c.config.ClientVersion)
65 » } 62 » }
66 63
67 » myVersion, serverVersion, err := exchangeVersions(c.transport.Conn, clie ntVersion) 64 » serverVersion, err := exchangeVersions(c.transport.Conn, clientVersion)
68 if err != nil { 65 if err != nil {
69 return err 66 return err
70 } 67 }
71 c.serverVersion = string(serverVersion) 68 c.serverVersion = string(serverVersion)
72 69
73 clientKexInit := kexInitMsg{ 70 clientKexInit := kexInitMsg{
74 KexAlgos: c.config.Crypto.kexes(), 71 KexAlgos: c.config.Crypto.kexes(),
75 ServerHostKeyAlgos: supportedHostKeyAlgos, 72 ServerHostKeyAlgos: supportedHostKeyAlgos,
76 CiphersClientServer: c.config.Crypto.ciphers(), 73 CiphersClientServer: c.config.Crypto.ciphers(),
77 CiphersServerClient: c.config.Crypto.ciphers(), 74 CiphersServerClient: c.config.Crypto.ciphers(),
(...skipping 28 matching lines...) Expand all
106 return err 103 return err
107 } 104 }
108 } 105 }
109 106
110 kex, ok := kexAlgoMap[algs.kex] 107 kex, ok := kexAlgoMap[algs.kex]
111 if !ok { 108 if !ok {
112 return fmt.Errorf("ssh: unexpected key exchange algorithm %v", a lgs.kex) 109 return fmt.Errorf("ssh: unexpected key exchange algorithm %v", a lgs.kex)
113 } 110 }
114 111
115 magics := handshakeMagics{ 112 magics := handshakeMagics{
116 » » clientVersion: myVersion, 113 » » clientVersion: clientVersion,
117 serverVersion: serverVersion, 114 serverVersion: serverVersion,
118 clientKexInit: kexInitPacket, 115 clientKexInit: kexInitPacket,
119 serverKexInit: packet, 116 serverKexInit: packet,
120 } 117 }
121 result, err := kex.Client(c, c.config.rand(), &magics) 118 result, err := kex.Client(c, c.config.rand(), &magics)
122 if err != nil { 119 if err != nil {
123 return err 120 return err
124 } 121 }
125 122
126 err = verifyHostKeySignature(algs.hostKey, result.HostKey, result.H, res ult.Signature) 123 err = verifyHostKeySignature(algs.hostKey, result.HostKey, result.H, res ult.Signature)
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 defer c.Unlock() 508 defer c.Unlock()
512 509
513 for _, ch := range c.chans { 510 for _, ch := range c.chans {
514 if ch == nil { 511 if ch == nil {
515 continue 512 continue
516 } 513 }
517 ch.Close() 514 ch.Close()
518 close(ch.msg) 515 close(ch.msg)
519 } 516 }
520 } 517 }
LEFTRIGHT
« no previous file | ssh/client_test.go » ('j') | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

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