Skip to content

Commit

Permalink
remove extInfoSent field
Browse files Browse the repository at this point in the history
we already know if this is the first key exchange

Signed-off-by: Nicola Murino <[email protected]>
  • Loading branch information
drakkan committed Mar 30, 2022
1 parent 2b41359 commit 4929d4a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 23 deletions.
39 changes: 17 additions & 22 deletions ssh/handshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,6 @@ type handshakeTransport struct {

// The session ID or nil if first kex did not complete yet.
sessionID []byte

// True if the first ext info message has been sent immediately following
// SSH_MSG_NEWKEYS, false otherwise.
extInfoSent bool
}

type pendingKex struct {
Expand Down Expand Up @@ -625,7 +621,8 @@ func (t *handshakeTransport) enterKeyExchange(otherInitPacket []byte) error {
return err
}

if t.sessionID == nil {
firstKeyExchange := t.sessionID == nil
if firstKeyExchange {
t.sessionID = result.H
}
result.SessionID = t.sessionID
Expand All @@ -643,29 +640,27 @@ func (t *handshakeTransport) enterKeyExchange(otherInitPacket []byte) error {
}

if !isClient {
// We're on the server side, see if the client sent the extension signal
if !t.extInfoSent && contains(clientInit.KexAlgos, extInfoClient) {
// The other side supports ext info, an ext info message hasn't been sent this session,
// and we have at least one extension enabled, so send an SSH_MSG_EXT_INFO message.
// We're on the server side, if this is the first key exchange
// see if the client sent the extension signal
if firstKeyExchange && contains(clientInit.KexAlgos, extInfoClient) {
// The other side supports ext info, and this is the first key exchange,
// so send an SSH_MSG_EXT_INFO message.
extensions := map[string][]byte{}
// We're the server, the client supports SSH_MSG_EXT_INFO and server-sig-algs
// is enabled. Prepare the server-sig-algos extension message to send.
// Prepare the server-sig-algos extension message to send.
extensions[extServerSigAlgs] = []byte(strings.Join(supportedServerSigAlgs, ","))
var payload []byte
for k, v := range extensions {
payload = appendInt(payload, len(k))
payload = append(payload, k...)
payload = appendInt(payload, len(v))
payload = append(payload, v...)
}
extInfo := extInfoMsg{

extInfo := &extInfoMsg{
NumExtensions: uint32(len(extensions)),
Payload: payload,
}
if err := t.conn.writePacket(Marshal(&extInfo)); err != nil {
for k, v := range extensions {
extInfo.Payload = appendInt(extInfo.Payload, len(k))
extInfo.Payload = append(extInfo.Payload, k...)
extInfo.Payload = appendInt(extInfo.Payload, len(v))
extInfo.Payload = append(extInfo.Payload, v...)
}
if err := t.conn.writePacket(Marshal(extInfo)); err != nil {
return err
}
t.extInfoSent = true
}
}

Expand Down
1 change: 0 additions & 1 deletion ssh/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ func (s *connection) serverHandshake(config *ServerConfig) (*Permissions, error)
}

// read the next packet
packet = nil
if packet, err = s.transport.readPacket(); err != nil {
return nil, err
}
Expand Down

0 comments on commit 4929d4a

Please sign in to comment.