Skip to content

Commit 76c9400

Browse files
committed
sendKexInit: evaluate first key exchange only once
we need it for both client and server Signed-off-by: Nicola Murino <[email protected]>
1 parent 4929d4a commit 76c9400

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

ssh/handshake.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ func (t *handshakeTransport) sendKexInit() error {
457457
io.ReadFull(rand.Reader, msg.Cookie[:])
458458

459459
isServer := len(t.hostKeys) > 0
460+
firstKeyExchange := t.sessionID == nil
460461
if isServer {
461462
for _, k := range t.hostKeys {
462463
// If k is an AlgorithmSigner, presume it supports all signature algorithms
@@ -475,7 +476,7 @@ func (t *handshakeTransport) sendKexInit() error {
475476
msg.ServerHostKeyAlgos = append(msg.ServerHostKeyAlgos, keyFormat)
476477
}
477478
}
478-
if firstKeyExchange := t.sessionID == nil; firstKeyExchange {
479+
if firstKeyExchange {
479480
msg.KexAlgos = make([]string, 0, len(t.config.KeyExchanges)+1)
480481
msg.KexAlgos = append(msg.KexAlgos, t.config.KeyExchanges...)
481482
msg.KexAlgos = append(msg.KexAlgos, extInfoServer)
@@ -486,7 +487,7 @@ func (t *handshakeTransport) sendKexInit() error {
486487
// As a client we opt in to receiving SSH_MSG_EXT_INFO so we know what
487488
// algorithms the server supports for public key authentication. See RFC
488489
// 8308, Section 2.1.
489-
if firstKeyExchange := t.sessionID == nil; firstKeyExchange {
490+
if firstKeyExchange {
490491
msg.KexAlgos = make([]string, 0, len(t.config.KeyExchanges)+1)
491492
msg.KexAlgos = append(msg.KexAlgos, t.config.KeyExchanges...)
492493
msg.KexAlgos = append(msg.KexAlgos, extInfoClient)

0 commit comments

Comments
 (0)