go.crypto/ssh: fix and test port forwarding.

Set maxPacket in forwarded connection, and use the requested port
number as key in forwardList.

R=golang-dev, agl, dave
CC=golang-dev
https://golang.org/cl/9753044
This commit is contained in:
Han-Wen Nienhuys
2013-06-11 22:10:15 -04:00
committed by Dave Cheney
parent c2ba5865a8
commit 0d8dc3cd6a
3 changed files with 131 additions and 19 deletions
+15 -5
View File
@@ -335,6 +335,10 @@ func (c *ClientConn) mainLoop() {
// Handle channel open messages from the remote side.
func (c *ClientConn) handleChanOpen(msg *channelOpenMsg) {
if msg.MaxPacketSize < minPacketLength || msg.MaxPacketSize > 1<<31 {
c.sendConnectionFailed(msg.PeersId)
}
switch msg.ChanType {
case "forwarded-tcpip":
laddr, rest, ok := parseTCPAddr(msg.TypeSpecificData)
@@ -343,8 +347,10 @@ func (c *ClientConn) handleChanOpen(msg *channelOpenMsg) {
c.sendConnectionFailed(msg.PeersId)
return
}
l, ok := c.forwardList.lookup(laddr)
l, ok := c.forwardList.lookup(*laddr)
if !ok {
// TODO: print on a more structured log.
fmt.Println("could not find forward list entry for", laddr)
// Section 7.2, implementations MUST reject suprious incoming
// connections.
@@ -360,13 +366,17 @@ func (c *ClientConn) handleChanOpen(msg *channelOpenMsg) {
ch := c.newChan(c.transport)
ch.remoteId = msg.PeersId
ch.remoteWin.add(msg.PeersWindow)
ch.maxPacket = msg.MaxPacketSize
m := channelOpenConfirmMsg{
PeersId: ch.remoteId,
MyId: ch.localId,
MyWindow: 1 << 14,
MaxPacketSize: 1 << 15, // RFC 4253 6.1
PeersId: ch.remoteId,
MyId: ch.localId,
MyWindow: 1 << 14,
// As per RFC 4253 6.1, 32k is also the minimum.
MaxPacketSize: 1 << 15,
}
c.writePacket(marshal(msgChannelOpenConfirm, m))
l <- forward{ch, raddr}
default: