ssh: permit empty but non-nil HostKeyAlgorithms, KeyExchanges, Ciphers, MACs
The documentation of ClientConfig.HostKeyAlgorithms says: If empty, a reasonable default is used. However, if HostKeyAlgorithms is empty but non-nil, the reasonable default won't be applied, and the SSH handshake will fail. Fix this by changing the nil check to a length check. While here, do the same for KeyExchanges, Ciphers, MACs in Config. Change-Id: I1b3d2d2159f3c7d57a9a690ad04f1f6818b39a5c Reviewed-on: https://go-review.googlesource.com/c/crypto/+/800080 Reviewed-by: Nicola Murino <nicola.murino@gmail.com> LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Filippo Valsorda <filippo@golang.org> Reviewed-by: Carlos Amedee <carlos@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> Auto-Submit: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
committed by
Gopher Robot
parent
626e40fc98
commit
b53964a1ca
+3
-3
@@ -544,7 +544,7 @@ func (c *Config) SetDefaults() {
|
||||
if c.Rand == nil {
|
||||
c.Rand = rand.Reader
|
||||
}
|
||||
if c.Ciphers == nil {
|
||||
if len(c.Ciphers) == 0 {
|
||||
c.Ciphers = defaultCiphers
|
||||
}
|
||||
var ciphers []string
|
||||
@@ -556,7 +556,7 @@ func (c *Config) SetDefaults() {
|
||||
}
|
||||
c.Ciphers = ciphers
|
||||
|
||||
if c.KeyExchanges == nil {
|
||||
if len(c.KeyExchanges) == 0 {
|
||||
c.KeyExchanges = defaultKexAlgos
|
||||
}
|
||||
var kexs []string
|
||||
@@ -571,7 +571,7 @@ func (c *Config) SetDefaults() {
|
||||
}
|
||||
c.KeyExchanges = kexs
|
||||
|
||||
if c.MACs == nil {
|
||||
if len(c.MACs) == 0 {
|
||||
c.MACs = defaultMACs
|
||||
}
|
||||
var macs []string
|
||||
|
||||
+1
-1
@@ -162,7 +162,7 @@ func newClientTransport(conn keyingTransport, clientVersion, serverVersion []byt
|
||||
t.remoteAddr = addr
|
||||
t.hostKeyCallback = config.HostKeyCallback
|
||||
t.bannerCallback = config.BannerCallback
|
||||
if config.HostKeyAlgorithms != nil {
|
||||
if len(config.HostKeyAlgorithms) > 0 {
|
||||
t.hostKeyAlgorithms = config.HostKeyAlgorithms
|
||||
} else {
|
||||
t.hostKeyAlgorithms = defaultHostKeyAlgos
|
||||
|
||||
Reference in New Issue
Block a user