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.
diff --git a/ssh/common.go b/ssh/common.go
index 2e44e9c..613b7db 100644
--- a/ssh/common.go
+++ b/ssh/common.go
@@ -544,7 +544,7 @@
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 @@
}
c.Ciphers = ciphers
- if c.KeyExchanges == nil {
+ if len(c.KeyExchanges) == 0 {
c.KeyExchanges = defaultKexAlgos
}
var kexs []string
@@ -571,7 +571,7 @@
}
c.KeyExchanges = kexs
- if c.MACs == nil {
+ if len(c.MACs) == 0 {
c.MACs = defaultMACs
}
var macs []string
diff --git a/ssh/handshake.go b/ssh/handshake.go
index 4be3cbb..711a7f7 100644
--- a/ssh/handshake.go
+++ b/ssh/handshake.go
@@ -162,7 +162,7 @@
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
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Code-Review | +2 |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Code-Review | +2 |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Code-Review | +1 |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Code-Review | +1 |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |