go.crypto/ssh: ensure {Server,Client}Conn do not expose io.ReadWriter
Transport should not be a ReadWriter. It can only write packets, i.e. no partial reads or writes. Furthermore, you can currently do ClientConn.Write() while the connection is live, which sends raw bytes over the connection. Doing so will confuse the transports because the data is not encrypted.
As a consequence, ClientConn and ServerConn stop being a net.Conn
Finally, ensure that {Server,Client}Conn implement LocalAddr and RemoteAddr methods that previously were exposed by an embedded net.Conn field.
R=hanwen
CC=golang-dev
https://golang.org/cl/16610043
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
package ssh
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -24,3 +26,32 @@ func TestSafeString(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure Read/Write are not exposed.
|
||||
func TestConnHideRWMethods(t *testing.T) {
|
||||
for _, c := range []interface{}{new(ServerConn), new(ClientConn)} {
|
||||
if _, ok := c.(io.Reader); ok {
|
||||
t.Errorf("%T implements io.Reader", c)
|
||||
}
|
||||
if _, ok := c.(io.Writer); ok {
|
||||
t.Errorf("%T implements io.Writer", c)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestConnSupportsLocalRemoteMethods(t *testing.T) {
|
||||
type LocalAddr interface {
|
||||
LocalAddr() net.Addr
|
||||
}
|
||||
type RemoteAddr interface {
|
||||
RemoteAddr() net.Addr
|
||||
}
|
||||
for _, c := range []interface{}{new(ServerConn), new(ClientConn)} {
|
||||
if _, ok := c.(LocalAddr); !ok {
|
||||
t.Errorf("%T does not implement LocalAddr", c)
|
||||
}
|
||||
if _, ok := c.(RemoteAddr); !ok {
|
||||
t.Errorf("%T does not implement RemoteAddr", c)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user