Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,13 @@ INLINE static int IsMessageAllowedClient(WOLFSSH *ssh, byte msg)


/* 'state' argument is for if trying to send a message or receive one.
* Returns 1 if allowed 0 if not allowed. */
* Returns 1 if allowed 0 if not allowed.
*
* The side helpers implement the receive policy only; 'state' is unused,
* and both WS_MSG_SEND callers ask about channel messages that no role
* list names. IDs 30 to 49 are per KEX method, so those lists hold for
* the methods in cannedKexAlgoNames, not the ids; RFC 4432 and RFC 4462
* send some of those ids the other way. */
INLINE static int IsMessageAllowed(WOLFSSH *ssh, byte msg, byte state)
{
#ifndef NO_WOLFSSH_SERVER
Expand Down
27 changes: 27 additions & 0 deletions tests/regress.c
Original file line number Diff line number Diff line change
Expand Up @@ -2274,6 +2274,9 @@ static void TestClientOnlyKexMsgsBlocked(WOLFSSH* ssh)
ssh->isKeying = WOLFSSH_PEER_IS_KEYING;
ssh->handshake = AllocHandshake(ssh);
ssh->handshake->kexId = ID_DH_GEX_SHA256;
/* The client expects no particular message yet, so the expectMsgId
* check cannot catch these, the role check has to. */
AssertIntEQ(ssh->handshake->expectMsgId, MSGID_NONE);

allowed = wolfSSH_TestIsMessageAllowed(ssh, MSGID_KEXDH_INIT,
WS_MSG_RECV);
Expand All @@ -2300,11 +2303,35 @@ static void TestClientOnlyKexMsgsBlocked(WOLFSSH* ssh)
WS_MSG_RECV);
AssertTrue(allowed);
AssertIntEQ(ssh->handshake->expectMsgId, MSGID_NONE);
AssertIntEQ(ssh->error, WS_SUCCESS);

/* 33 sits between the two blocked ids and has to stay allowed. Assert
* it where the client actually expects it, once it has sent its GEX
* init. */
ssh->error = 0;
ssh->handshake->expectMsgId = MSGID_KEXDH_GEX_REPLY;
allowed = wolfSSH_TestIsMessageAllowed(ssh, MSGID_KEXDH_GEX_REPLY,
WS_MSG_RECV);
AssertTrue(allowed);
AssertIntEQ(ssh->handshake->expectMsgId, MSGID_NONE);
AssertIntEQ(ssh->error, WS_SUCCESS);

/* Same answer during a rekey on an established session. */
ssh->error = 0;
ssh->connectState = CONNECT_DONE;

allowed = wolfSSH_TestIsMessageAllowed(ssh, MSGID_KEXDH_INIT,
WS_MSG_RECV);
AssertFalse(allowed);
AssertIntEQ(ssh->error, WS_MSGID_NOT_ALLOWED_E);

ssh->error = 0;
allowed = wolfSSH_TestIsMessageAllowed(ssh, MSGID_KEXDH_GEX_INIT,
WS_MSG_RECV);
AssertFalse(allowed);
AssertIntEQ(ssh->error, WS_MSGID_NOT_ALLOWED_E);

ssh->error = 0;
allowed = wolfSSH_TestIsMessageAllowed(ssh, MSGID_KEXDH_GEX_REQUEST,
WS_MSG_RECV);
AssertFalse(allowed);
Expand Down
Loading