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

Delta Between Two Patch Sets: ssh/client.go

Issue 12837048: code review 12837048: crypto/ssh: ssh-agent forwarding support
Left Patch Set: diff -r 1e7a3e301825 https://code.google.com/p/go.crypto Created 10 years, 7 months ago
Right Patch Set: diff -r 1e7a3e301825 https://code.google.com/p/go.crypto Created 10 years, 7 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/session.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" 8 "crypto"
9 "crypto/rand" 9 "crypto/rand"
10 "encoding/binary" 10 "encoding/binary"
(...skipping 20 matching lines...) Expand all
31 dialAddress string 31 dialAddress string
32 32
33 serverVersion string 33 serverVersion string
34 } 34 }
35 35
36 type globalRequest struct { 36 type globalRequest struct {
37 sync.Mutex 37 sync.Mutex
38 response chan interface{} 38 response chan interface{}
39 } 39 }
40 40
41 // AgentDialer connects to the proper ssh-agent 41 // AgentDialer connects to the proper ssh-agent
jpsugar 2013/08/26 19:13:34 Un-wrap this comment now? Lines seem a little shor
42 // for key forwarding. 42 // for key forwarding.
43 type AgentDialer interface { 43 type AgentDialer interface {
44 Dial() (io.ReadWriteCloser, error) 44 Dial() (io.ReadWriteCloser, error)
45 } 45 }
46 46
47 // Client returns a new SSH client connection using c as the underlying transpor t. 47 // Client returns a new SSH client connection using c as the underlying transpor t.
48 func Client(c net.Conn, config *ClientConfig) (*ClientConn, error) { 48 func Client(c net.Conn, config *ClientConfig) (*ClientConn, error) {
49 return clientWithAddress(c, "", config) 49 return clientWithAddress(c, "", config)
50 } 50 }
51 51
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 MyId: ch.localId, 414 MyId: ch.localId,
415 MyWindow: 1 << 14, 415 MyWindow: 1 << 14,
416 416
417 // As per RFC 4253 6.1, 32k is also the minimum. 417 // As per RFC 4253 6.1, 32k is also the minimum.
418 MaxPacketSize: 1 << 15, 418 MaxPacketSize: 1 << 15,
419 } 419 }
420 420
421 c.writePacket(marshal(msgChannelOpenConfirm, m)) 421 c.writePacket(marshal(msgChannelOpenConfirm, m))
422 l <- forward{ch, raddr} 422 l <- forward{ch, raddr}
423 case "auth-agent@openssh.com": 423 case "auth-agent@openssh.com":
424 » » if c.config.ForwardingAgentDialer != nil { 424 » » if c.config.ForwardingAgentDialer == nil {
425 » » » agentConn, err := c.config.ForwardingAgentDialer.Dial()
426 » » » if err != nil {
427 » » » » c.sendConnectionFailed(msg.PeersId)
428 » » » } else {
429 » » » » ch := c.newChan(c.transport)
430 » » » » ch.remoteId = msg.PeersId
431 » » » » ch.remoteWin.add(msg.PeersWindow)
432 » » » » ch.maxPacket = msg.MaxPacketSize
433
434 » » » » m := channelOpenConfirmMsg{
435 » » » » » PeersId: ch.remoteId,
436 » » » » » MyId: ch.localId,
437 » » » » » MyWindow: 1 << 14,
438
439 » » » » » // As per RFC 4253 6.1, 32k is also the minimum.
440 » » » » » MaxPacketSize: 1 << 15,
441 » » » » }
442
443 » » » » c.writePacket(marshal(msgChannelOpenConfirm, m))
444
445 » » » » c.agentForward(agentConn, ch)
446 » » » }
447 » » } else {
448 // Client did not ask for key forwarding! 425 // Client did not ask for key forwarding!
449 c.sendUnknownChannel(msg.PeersId) 426 c.sendUnknownChannel(msg.PeersId)
450 » » } 427 » » » return
428 » » }
429 » » agentConn, err := c.config.ForwardingAgentDialer.Dial()
430 » » if err != nil {
431 » » » c.sendConnectionFailed(msg.PeersId)
432 » » » return
433 » » }
434 » » ch := c.newChan(c.transport)
435 » » ch.remoteId = msg.PeersId
436 » » ch.remoteWin.add(msg.PeersWindow)
437 » » ch.maxPacket = msg.MaxPacketSize
438
439 » » m := channelOpenConfirmMsg{
440 » » » PeersId: ch.remoteId,
441 » » » MyId: ch.localId,
442 » » » MyWindow: 1 << 14,
443
444 » » » // As per RFC 4253 6.1, 32k is also the minimum.
445 » » » MaxPacketSize: 1 << 15,
446 » » }
447
448 » » c.writePacket(marshal(msgChannelOpenConfirm, m))
449 » » c.agentForward(agentConn, ch)
451 default: 450 default:
452 // unknown channel type 451 // unknown channel type
453 c.sendUnknownChannel(msg.PeersId) 452 c.sendUnknownChannel(msg.PeersId)
454 } 453 }
455 } 454 }
456 455
457 // sendGlobalRequest sends a global request message as specified 456 // sendGlobalRequest sends a global request message as specified
458 // in RFC4254 section 4. To correctly synchronise messages, a lock 457 // in RFC4254 section 4. To correctly synchronise messages, a lock
459 // is held internally until a response is returned. 458 // is held internally until a response is returned.
460 func (c *ClientConn) sendGlobalRequest(m interface{}) (*globalRequestSuccessMsg, error) { 459 func (c *ClientConn) sendGlobalRequest(m interface{}) (*globalRequestSuccessMsg, error) {
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 defer c.Unlock() 605 defer c.Unlock()
607 606
608 for _, ch := range c.chans { 607 for _, ch := range c.chans {
609 if ch == nil { 608 if ch == nil {
610 continue 609 continue
611 } 610 }
612 ch.Close() 611 ch.Close()
613 close(ch.msg) 612 close(ch.msg)
614 } 613 }
615 } 614 }
LEFTRIGHT
« no previous file | ssh/session.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