Skip to content

Commit

Permalink
sendKexInit: evaluate first key exchange only once
Browse files Browse the repository at this point in the history
we need it for both client and server

Signed-off-by: Nicola Murino <[email protected]>
  • Loading branch information
drakkan committed Mar 30, 2022
1 parent 4929d4a commit 76c9400
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions ssh/handshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ func (t *handshakeTransport) sendKexInit() error {
io.ReadFull(rand.Reader, msg.Cookie[:])

isServer := len(t.hostKeys) > 0
firstKeyExchange := t.sessionID == nil
if isServer {
for _, k := range t.hostKeys {
// If k is an AlgorithmSigner, presume it supports all signature algorithms
Expand All @@ -475,7 +476,7 @@ func (t *handshakeTransport) sendKexInit() error {
msg.ServerHostKeyAlgos = append(msg.ServerHostKeyAlgos, keyFormat)
}
}
if firstKeyExchange := t.sessionID == nil; firstKeyExchange {
if firstKeyExchange {
msg.KexAlgos = make([]string, 0, len(t.config.KeyExchanges)+1)
msg.KexAlgos = append(msg.KexAlgos, t.config.KeyExchanges...)
msg.KexAlgos = append(msg.KexAlgos, extInfoServer)
Expand All @@ -486,7 +487,7 @@ func (t *handshakeTransport) sendKexInit() error {
// As a client we opt in to receiving SSH_MSG_EXT_INFO so we know what
// algorithms the server supports for public key authentication. See RFC
// 8308, Section 2.1.
if firstKeyExchange := t.sessionID == nil; firstKeyExchange {
if firstKeyExchange {
msg.KexAlgos = make([]string, 0, len(t.config.KeyExchanges)+1)
msg.KexAlgos = append(msg.KexAlgos, t.config.KeyExchanges...)
msg.KexAlgos = append(msg.KexAlgos, extInfoClient)
Expand Down

0 comments on commit 76c9400

Please sign in to comment.