From 280be005b3a662119e76768fe9d91171c1142511 Mon Sep 17 00:00:00 2001 From: Kristopher Watts Date: Thu, 18 Dec 2014 21:06:17 -0700 Subject: [PATCH] ssh: add ServerConfig.ServerVersion option The SSH server does not allow for setting a version string in the same manner as the client. This update adds a ServerVersion member to the ServerConfig structure which when set, causes the server to use that member instead of the default version string. This allows building an golang based SSH server which can present any version string the user wishes. It also adds an else statement to the client assignment of the ClientVersion to avoid an allocation when using a user defined ClientVersion. Change-Id: I43d97cfd5a174f2c68f53c5b4e267539ef21937b Reviewed-on: https://go-review.googlesource.com/1860 Reviewed-by: Brad Fitzpatrick --- ssh/client.go | 4 ++-- ssh/server.go | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/ssh/client.go b/ssh/client.go index 03c4e77..e607610 100644 --- a/ssh/client.go +++ b/ssh/client.go @@ -82,11 +82,11 @@ func NewClientConn(c net.Conn, addr string, config *ClientConfig) (Conn, <-chan // clientHandshake performs the client side key exchange. See RFC 4253 Section // 7. func (c *connection) clientHandshake(dialAddress string, config *ClientConfig) error { - c.clientVersion = []byte(packageVersion) if config.ClientVersion != "" { c.clientVersion = []byte(config.ClientVersion) + } else { + c.clientVersion = []byte(packageVersion) } - var err error c.serverVersion, err = exchangeVersions(c.sshConn.conn, c.clientVersion) if err != nil { diff --git a/ssh/server.go b/ssh/server.go index 8c4f142..ee2eeab 100644 --- a/ssh/server.go +++ b/ssh/server.go @@ -65,6 +65,11 @@ type ServerConfig struct { // AuthLogCallback, if non-nil, is called to log all authentication // attempts. AuthLogCallback func(conn ConnMetadata, method string, err error) + + // ServerVersion is the version identification string to + // announce in the public handshake. + // If empty, a reasonable default is used. + ServerVersion string } // AddHostKey adds a private key as a host key. If an existing host @@ -163,8 +168,12 @@ func (s *connection) serverHandshake(config *ServerConfig) (*Permissions, error) return nil, errors.New("ssh: server has no host keys") } + if config.ServerVersion != "" { + s.serverVersion = []byte(config.ServerVersion) + } else { + s.serverVersion = []byte(packageVersion) + } var err error - s.serverVersion = []byte(packageVersion) s.clientVersion, err = exchangeVersions(s.sshConn.conn, s.serverVersion) if err != nil { return nil, err