Skip to content

Commit 329123f

Browse files
committed
ssh: send ext-info-c only once
In accordance to RFC8308, send ext-info-c only during the first key exchange. Some server implementations such as OpenSSH 7 will send an extInfoMsg message each time when ext-info-c is received. This results in a closed connection, as our client does not expect this message while handling the mux. See https://bugzilla.mindrot.org/show_bug.cgi?id=2929 regarding the behaviour of OpenSSH if it sees ext-info-c in later key exchanges. Fixes #51808 Signed-off-by: Peter Verraedt <[email protected]>
1 parent 3147a52 commit 329123f

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

ssh/handshake.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -479,10 +479,12 @@ func (t *handshakeTransport) sendKexInit() error {
479479

480480
// As a client we opt in to receiving SSH_MSG_EXT_INFO so we know what
481481
// algorithms the server supports for public key authentication. See RFC
482-
// 8303, Section 2.1.
483-
msg.KexAlgos = make([]string, 0, len(t.config.KeyExchanges)+1)
484-
msg.KexAlgos = append(msg.KexAlgos, t.config.KeyExchanges...)
485-
msg.KexAlgos = append(msg.KexAlgos, "ext-info-c")
482+
// 8308, Section 2.1.
483+
if firstKeyExchange := t.sessionID == nil; firstKeyExchange {
484+
msg.KexAlgos = make([]string, 0, len(t.config.KeyExchanges)+1)
485+
msg.KexAlgos = append(msg.KexAlgos, t.config.KeyExchanges...)
486+
msg.KexAlgos = append(msg.KexAlgos, "ext-info-c")
487+
}
486488
}
487489

488490
packet := Marshal(msg)

ssh/mux.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,10 @@ func (m *mux) onePacket() error {
227227
}
228228

229229
switch packet[0] {
230+
case msgExtInfo:
231+
// OpenSSH 7.4p1 sends msgExtInfo at the wrong time, breaking RFC8308. We simply ignore the packet.
232+
log.Print("Received msgExtInfo at wrong time")
233+
return nil
230234
case msgChannelOpen:
231235
return m.handleChannelOpen(packet)
232236
case msgGlobalRequest, msgRequestSuccess, msgRequestFailure:

0 commit comments

Comments
 (0)