Skip to content

First packet follows check needs pubkey guess#927

Open
ejohnstown wants to merge 2 commits intowolfSSL:masterfrom
ejohnstown:first-kex-follows
Open

First packet follows check needs pubkey guess#927
ejohnstown wants to merge 2 commits intowolfSSL:masterfrom
ejohnstown:first-kex-follows

Conversation

@ejohnstown
Copy link
Copy Markdown
Contributor

@ejohnstown ejohnstown commented Apr 16, 2026

When processing the KEX Init message, stash guesses for the peer's KEX and public key algorithms. When reading first_packet_follows, if set check the guesses and set the handshake info flag ignoreNextKexMsg. When processing the KexDhInit message, check that flag.

Affected functions: DoKexInit, DoKexDhInit.
Issue: F-1686

Copilot AI review requested due to automatic review settings April 16, 2026 21:15
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates KEX negotiation handling to correctly evaluate the SSH first_packet_follows optimization by tracking and validating both the peer’s guessed KEX algorithm and guessed server host key algorithm (Issue F-1686).

Changes:

  • Add pubKeyIdGuess to HandshakeInfo to store the peer’s first “server host key algorithms” preference from KEXINIT.
  • In DoKexInit(), stash the peer’s host-key-algorithm guess (list[0]) alongside the existing KEX guess.
  • In DoKexDhInit(), skip the first packet that follows KEXINIT when either the KEX guess or host-key guess differs from the negotiated algorithms.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
wolfssh/internal.h Extends handshake state to track the peer’s host-key algorithm guess for first_packet_follows validation.
src/internal.c Records host-key guess during KEXINIT parsing and uses it in the first_packet_follows skip decision during KEXDH/ECDH init handling.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/internal.c Outdated
Copilot AI review requested due to automatic review settings April 16, 2026 23:33
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/internal.c
Comment thread src/internal.c Outdated
Comment thread tests/regress.c
When processing the KEX Init message, stash guesses for the peer's
KEX and public key algorithms. When reading first_packet_follows, if set
check the guesses and set the handshake info flag ignoreNextKexMsg. When
processing the KexDhInit message, check that flag.

Affected functions: DoKexInit, DoKexDhInit.
Issue: F-1686
Add a regression for checking the `first_kex_packet_follows` flag versus
the guesses for KEX algorithm and public key algorithm.
Copilot AI review requested due to automatic review settings April 17, 2026 00:57
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/internal.c
Comment on lines +4845 to 4851
if (ssh->handshake->ignoreNextKexMsg) {
/* skip this message. */
WLOG(WS_LOG_DEBUG, "Skipping the client's KEX init function.");
ssh->handshake->kexPacketFollows = 0;
WLOG(WS_LOG_DEBUG, "Skipping client's KEXDH_INIT message due to "
"first_packet_follows guess mismatch.");
ssh->handshake->ignoreNextKexMsg = 0;
*idx += len;
return WS_SUCCESS;
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ignoreNextKexMsg is only consumed/cleared in DoKexDhInit, but the first packet after KEXINIT can also be SSH_MSG_KEXDH_GEX_REQUEST (34) when DH-GEX is in play. If a peer sets first_packet_follows=1 and guesses GEX incorrectly, the guessed 34 message should be ignored per RFC 4253, but DoKexDhGexRequest() currently won’t check this flag and will process it instead. Consider applying the same “consume + clear flag + no state advance” behavior in DoKexDhGexRequest() (and any other possible first-KEX message handlers) so first_packet_follows mismatches are handled uniformly across KEX methods.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants