Skip to content

Commit 5835f04

Browse files
committed
improve code comments
Signed-off-by: Nicola Murino <[email protected]>
1 parent 76c9400 commit 5835f04

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

ssh/common.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ const (
2424
serviceSSH = "ssh-connection"
2525
)
2626

27-
// These are string constants related to extensions and extension negotiation
27+
// These are string constants related to extensions and extension negotiation.
28+
// See RFC 8308
2829
const (
2930
extInfoServer = "ext-info-s"
3031
extInfoClient = "ext-info-c"
@@ -97,7 +98,7 @@ var supportedMACs = []string{
9798
var supportedCompressions = []string{compressionNone}
9899

99100
// supportedServerSigAlgs defines the algorithms supported for pubkey authentication
100-
// in no particular order.
101+
// in no particular order. See RFC 8308, Section 3.1.
101102
var supportedServerSigAlgs = []string{KeyAlgoRSASHA256,
102103
KeyAlgoRSASHA512, KeyAlgoRSA,
103104
KeyAlgoECDSA256, KeyAlgoECDSA384, KeyAlgoECDSA521,

ssh/handshake.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,9 @@ func (t *handshakeTransport) sendKexInit() error {
476476
msg.ServerHostKeyAlgos = append(msg.ServerHostKeyAlgos, keyFormat)
477477
}
478478
}
479+
// As a server we add ext-info-s to the KEX algorithms to indicate that we support
480+
// the Extension Negotiation Mechanism. The ext-info-s indicator must be added only
481+
// in the first key exchange. See RFC 8308, Section 2.1.
479482
if firstKeyExchange {
480483
msg.KexAlgos = make([]string, 0, len(t.config.KeyExchanges)+1)
481484
msg.KexAlgos = append(msg.KexAlgos, t.config.KeyExchanges...)
@@ -642,12 +645,10 @@ func (t *handshakeTransport) enterKeyExchange(otherInitPacket []byte) error {
642645

643646
if !isClient {
644647
// We're on the server side, if this is the first key exchange
645-
// see if the client sent the extension signal
648+
// and the client sent the ext-info-c indicator, we send an SSH_MSG_EXT_INFO
649+
// message with the server-sig-algs extension. See RFC 8308, Section 3.1.
646650
if firstKeyExchange && contains(clientInit.KexAlgos, extInfoClient) {
647-
// The other side supports ext info, and this is the first key exchange,
648-
// so send an SSH_MSG_EXT_INFO message.
649651
extensions := map[string][]byte{}
650-
// Prepare the server-sig-algos extension message to send.
651652
extensions[extServerSigAlgs] = []byte(strings.Join(supportedServerSigAlgs, ","))
652653

653654
extInfo := &extInfoMsg{

ssh/server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,13 @@ func (s *connection) serverHandshake(config *ServerConfig) (*Permissions, error)
256256
// We just did the key change, so the session ID is established.
257257
s.sessionID = s.transport.getSessionID()
258258

259-
// the client could send a SSH_MSG_EXT_INFO before SSH_MSG_SERVICE_REQUEST
259+
// the client could send a SSH_MSG_EXT_INFO after the first SSH_MSG_NEWKEYS
260+
// and so before SSH_MSG_SERVICE_REQUEST. See RFC 8308, Section 2.4.
260261
var packet []byte
261262
if packet, err = s.transport.readPacket(); err != nil {
262263
return nil, err
263264
}
264265

265-
// be permissive and don't add contains(s.transport.config.Extensions, ExtServerSigAlgs)
266266
if len(packet) > 0 && packet[0] == msgExtInfo {
267267
// read SSH_MSG_EXT_INFO
268268
var extInfo extInfoMsg

0 commit comments

Comments
 (0)