Skip to content

Commit b13704a

Browse files
ejohnstownphilljj
authored andcommitted
Cover and document the client KEX role check
TestClientOnlyKexMsgsBlocked now asserts that 31 and 33, the ids a client does receive, stay allowed where the handshake expects them, so widening the role check into a 30-34 range fails the suite. The IsMessageAllowed() comment records the receive-only policy and the per-KEX-method id namespace. - assert id 33 is allowed once expectMsgId is MSGID_KEXDH_GEX_REPLY - assert expectMsgId starts at MSGID_NONE, so the role check is what rejects the blocked ids - recheck all three blocked ids during a rekey on an established session
1 parent 557f3df commit b13704a

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

src/internal.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,13 @@ INLINE static int IsMessageAllowedClient(WOLFSSH *ssh, byte msg)
950950

951951

952952
/* 'state' argument is for if trying to send a message or receive one.
953-
* Returns 1 if allowed 0 if not allowed. */
953+
* Returns 1 if allowed 0 if not allowed.
954+
*
955+
* The side helpers implement the receive policy only; 'state' is unused,
956+
* and both WS_MSG_SEND callers ask about channel messages that no role
957+
* list names. IDs 30 to 49 are per KEX method, so those lists hold for
958+
* the methods in cannedKexAlgoNames, not the ids; RFC 4432 and RFC 4462
959+
* send some of those ids the other way. */
954960
INLINE static int IsMessageAllowed(WOLFSSH *ssh, byte msg, byte state)
955961
{
956962
#ifndef NO_WOLFSSH_SERVER

tests/regress.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2274,6 +2274,9 @@ static void TestClientOnlyKexMsgsBlocked(WOLFSSH* ssh)
22742274
ssh->isKeying = WOLFSSH_PEER_IS_KEYING;
22752275
ssh->handshake = AllocHandshake(ssh);
22762276
ssh->handshake->kexId = ID_DH_GEX_SHA256;
2277+
/* The client expects no particular message yet, so the expectMsgId
2278+
* check cannot catch these, the role check has to. */
2279+
AssertIntEQ(ssh->handshake->expectMsgId, MSGID_NONE);
22772280

22782281
allowed = wolfSSH_TestIsMessageAllowed(ssh, MSGID_KEXDH_INIT,
22792282
WS_MSG_RECV);
@@ -2300,11 +2303,35 @@ static void TestClientOnlyKexMsgsBlocked(WOLFSSH* ssh)
23002303
WS_MSG_RECV);
23012304
AssertTrue(allowed);
23022305
AssertIntEQ(ssh->handshake->expectMsgId, MSGID_NONE);
2306+
AssertIntEQ(ssh->error, WS_SUCCESS);
2307+
2308+
/* 33 sits between the two blocked ids and has to stay allowed. Assert
2309+
* it where the client actually expects it, once it has sent its GEX
2310+
* init. */
2311+
ssh->error = 0;
2312+
ssh->handshake->expectMsgId = MSGID_KEXDH_GEX_REPLY;
2313+
allowed = wolfSSH_TestIsMessageAllowed(ssh, MSGID_KEXDH_GEX_REPLY,
2314+
WS_MSG_RECV);
2315+
AssertTrue(allowed);
2316+
AssertIntEQ(ssh->handshake->expectMsgId, MSGID_NONE);
2317+
AssertIntEQ(ssh->error, WS_SUCCESS);
23032318

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

2323+
allowed = wolfSSH_TestIsMessageAllowed(ssh, MSGID_KEXDH_INIT,
2324+
WS_MSG_RECV);
2325+
AssertFalse(allowed);
2326+
AssertIntEQ(ssh->error, WS_MSGID_NOT_ALLOWED_E);
2327+
2328+
ssh->error = 0;
2329+
allowed = wolfSSH_TestIsMessageAllowed(ssh, MSGID_KEXDH_GEX_INIT,
2330+
WS_MSG_RECV);
2331+
AssertFalse(allowed);
2332+
AssertIntEQ(ssh->error, WS_MSGID_NOT_ALLOWED_E);
2333+
2334+
ssh->error = 0;
23082335
allowed = wolfSSH_TestIsMessageAllowed(ssh, MSGID_KEXDH_GEX_REQUEST,
23092336
WS_MSG_RECV);
23102337
AssertFalse(allowed);

0 commit comments

Comments
 (0)