Skip to content

Commit 833695f

Browse files
drakkanFiloSottile
authored andcommitted
ssh: add server side support for [email protected] protocol extension
Fixes golang/go#62390 Change-Id: Ie4dc577fb55b45a0c26a9e2dc5903af2bd382e00 Reviewed-on: https://go-review.googlesource.com/c/crypto/+/524775 TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Matthew Dempsky <[email protected]> Reviewed-by: Than McIntosh <[email protected]> Run-TryBot: Nicola Murino <[email protected]> Reviewed-by: Filippo Valsorda <[email protected]>
1 parent ec07f4e commit 833695f

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

ssh/doc.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ others.
1313
1414
References:
1515
16+
[PROTOCOL]: https://cvsweb.openbsd.org/cgi-bin/cvsweb/src/usr.bin/ssh/PROTOCOL?rev=HEAD
1617
[PROTOCOL.certkeys]: http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/usr.bin/ssh/PROTOCOL.certkeys?rev=HEAD
1718
[SSH-PARAMETERS]: http://www.iana.org/assignments/ssh-parameters/ssh-parameters.xml#ssh-parameters-1
1819

ssh/handshake.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -647,16 +647,20 @@ func (t *handshakeTransport) enterKeyExchange(otherInitPacket []byte) error {
647647

648648
// On the server side, after the first SSH_MSG_NEWKEYS, send a SSH_MSG_EXT_INFO
649649
// message with the server-sig-algs extension if the client supports it. See
650-
// RFC 8308, Sections 2.4 and 3.1.
650+
// RFC 8308, Sections 2.4 and 3.1, and [PROTOCOL], Section 1.9.
651651
if !isClient && firstKeyExchange && contains(clientInit.KexAlgos, "ext-info-c") {
652652
extInfo := &extInfoMsg{
653-
NumExtensions: 1,
654-
Payload: make([]byte, 0, 4+15+4+len(supportedPubKeyAuthAlgosList)),
653+
NumExtensions: 2,
654+
Payload: make([]byte, 0, 4+15+4+len(supportedPubKeyAuthAlgosList)+4+16+4+1),
655655
}
656656
extInfo.Payload = appendInt(extInfo.Payload, len("server-sig-algs"))
657657
extInfo.Payload = append(extInfo.Payload, "server-sig-algs"...)
658658
extInfo.Payload = appendInt(extInfo.Payload, len(supportedPubKeyAuthAlgosList))
659659
extInfo.Payload = append(extInfo.Payload, supportedPubKeyAuthAlgosList...)
660+
extInfo.Payload = appendInt(extInfo.Payload, len("[email protected]"))
661+
extInfo.Payload = append(extInfo.Payload, "[email protected]"...)
662+
extInfo.Payload = appendInt(extInfo.Payload, 1)
663+
extInfo.Payload = append(extInfo.Payload, "0"...)
660664
if err := t.conn.writePacket(Marshal(extInfo)); err != nil {
661665
return err
662666
}

ssh/messages.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,20 @@ type userAuthGSSAPIError struct {
349349
LanguageTag string
350350
}
351351

352+
// Transport layer OpenSSH extension. See [PROTOCOL], section 1.9
353+
const msgPing = 192
354+
355+
type pingMsg struct {
356+
Data string `sshtype:"192"`
357+
}
358+
359+
// Transport layer OpenSSH extension. See [PROTOCOL], section 1.9
360+
const msgPong = 193
361+
362+
type pongMsg struct {
363+
Data string `sshtype:"193"`
364+
}
365+
352366
// typeTags returns the possible type bytes for the given reflect.Type, which
353367
// should be a struct. The possible values are separated by a '|' character.
354368
func typeTags(structType reflect.Type) (tags []byte) {

ssh/mux.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,12 @@ func (m *mux) onePacket() error {
231231
return m.handleChannelOpen(packet)
232232
case msgGlobalRequest, msgRequestSuccess, msgRequestFailure:
233233
return m.handleGlobalPacket(packet)
234+
case msgPing:
235+
var msg pingMsg
236+
if err := Unmarshal(packet, &msg); err != nil {
237+
return fmt.Errorf("failed to unmarshal [email protected] message: %w", err)
238+
}
239+
return m.sendMessage(pongMsg(msg))
234240
}
235241

236242
// assume a channel packet.

0 commit comments

Comments
 (0)