Skip to content

Commit 4929d4a

Browse files
committed
remove extInfoSent field
we already know if this is the first key exchange Signed-off-by: Nicola Murino <[email protected]>
1 parent 2b41359 commit 4929d4a

File tree

2 files changed

+17
-23
lines changed

2 files changed

+17
-23
lines changed

ssh/handshake.go

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,6 @@ type handshakeTransport struct {
9595

9696
// The session ID or nil if first kex did not complete yet.
9797
sessionID []byte
98-
99-
// True if the first ext info message has been sent immediately following
100-
// SSH_MSG_NEWKEYS, false otherwise.
101-
extInfoSent bool
10298
}
10399

104100
type pendingKex struct {
@@ -625,7 +621,8 @@ func (t *handshakeTransport) enterKeyExchange(otherInitPacket []byte) error {
625621
return err
626622
}
627623

628-
if t.sessionID == nil {
624+
firstKeyExchange := t.sessionID == nil
625+
if firstKeyExchange {
629626
t.sessionID = result.H
630627
}
631628
result.SessionID = t.sessionID
@@ -643,29 +640,27 @@ func (t *handshakeTransport) enterKeyExchange(otherInitPacket []byte) error {
643640
}
644641

645642
if !isClient {
646-
// We're on the server side, see if the client sent the extension signal
647-
if !t.extInfoSent && contains(clientInit.KexAlgos, extInfoClient) {
648-
// The other side supports ext info, an ext info message hasn't been sent this session,
649-
// and we have at least one extension enabled, so send an SSH_MSG_EXT_INFO message.
643+
// We're on the server side, if this is the first key exchange
644+
// see if the client sent the extension signal
645+
if firstKeyExchange && contains(clientInit.KexAlgos, extInfoClient) {
646+
// The other side supports ext info, and this is the first key exchange,
647+
// so send an SSH_MSG_EXT_INFO message.
650648
extensions := map[string][]byte{}
651-
// We're the server, the client supports SSH_MSG_EXT_INFO and server-sig-algs
652-
// is enabled. Prepare the server-sig-algos extension message to send.
649+
// Prepare the server-sig-algos extension message to send.
653650
extensions[extServerSigAlgs] = []byte(strings.Join(supportedServerSigAlgs, ","))
654-
var payload []byte
655-
for k, v := range extensions {
656-
payload = appendInt(payload, len(k))
657-
payload = append(payload, k...)
658-
payload = appendInt(payload, len(v))
659-
payload = append(payload, v...)
660-
}
661-
extInfo := extInfoMsg{
651+
652+
extInfo := &extInfoMsg{
662653
NumExtensions: uint32(len(extensions)),
663-
Payload: payload,
664654
}
665-
if err := t.conn.writePacket(Marshal(&extInfo)); err != nil {
655+
for k, v := range extensions {
656+
extInfo.Payload = appendInt(extInfo.Payload, len(k))
657+
extInfo.Payload = append(extInfo.Payload, k...)
658+
extInfo.Payload = appendInt(extInfo.Payload, len(v))
659+
extInfo.Payload = append(extInfo.Payload, v...)
660+
}
661+
if err := t.conn.writePacket(Marshal(extInfo)); err != nil {
666662
return err
667663
}
668-
t.extInfoSent = true
669664
}
670665
}
671666

ssh/server.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,6 @@ func (s *connection) serverHandshake(config *ServerConfig) (*Permissions, error)
285285
}
286286

287287
// read the next packet
288-
packet = nil
289288
if packet, err = s.transport.readPacket(); err != nil {
290289
return nil, err
291290
}

0 commit comments

Comments
 (0)