Skip to content

Commit be4aa44

Browse files
ejohnstownpadelsbach
authored andcommitted
DoNewKeys: reject NEWKEYS with non-empty payload
- Reject SSH_MSG_NEWKEYS when len != 0 per RFC 4253 7.3. - Update wolfSSH_TestDoNewKeys to take buf/len/idx instead of assuming NULL/0, and add a non-zero len test case. Issue: F-2079
1 parent 63a63cf commit be4aa44

3 files changed

Lines changed: 14 additions & 10 deletions

File tree

src/internal.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6309,10 +6309,10 @@ static int DoNewKeys(WOLFSSH* ssh, byte* buf, word32 len, word32* idx)
63096309
int ret = WS_SUCCESS;
63106310

63116311
WOLFSSH_UNUSED(buf);
6312-
WOLFSSH_UNUSED(len);
63136312
WOLFSSH_UNUSED(idx);
63146313

6315-
if (ssh == NULL || ssh->handshake == NULL)
6314+
/* RFC 4253 7.3: SSH_MSG_NEWKEYS has no payload. */
6315+
if (ssh == NULL || ssh->handshake == NULL || len != 0)
63166316
ret = WS_BAD_ARGUMENT;
63176317

63186318
if (ret == WS_SUCCESS) {
@@ -18135,10 +18135,9 @@ int wolfSSH_TestDoKexInit(WOLFSSH* ssh, byte* buf, word32 len, word32* idx)
1813518135
return DoKexInit(ssh, buf, len, idx);
1813618136
}
1813718137

18138-
int wolfSSH_TestDoNewKeys(WOLFSSH* ssh)
18138+
int wolfSSH_TestDoNewKeys(WOLFSSH* ssh, byte* buf, word32 len, word32* idx)
1813918139
{
18140-
/* DoNewKeys ignores buf/len/idx (marked WOLFSSH_UNUSED internally). */
18141-
return DoNewKeys(ssh, NULL, 0, NULL);
18140+
return DoNewKeys(ssh, buf, len, idx);
1814218141
}
1814318142

1814418143
void wolfSSH_TestFreeHandshake(WOLFSSH* ssh)

tests/regress.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3000,7 +3000,7 @@ static void TestDoNewKeys(void)
30003000

30013001
/* Peer has sent NewKeys; self has already sent its own (not keying). */
30023002
ssh->isKeying = WOLFSSH_PEER_IS_KEYING;
3003-
AssertIntEQ(wolfSSH_TestDoNewKeys(ssh), WS_SUCCESS);
3003+
AssertIntEQ(wolfSSH_TestDoNewKeys(ssh, NULL, 0, NULL), WS_SUCCESS);
30043004

30053005
/* handshake freed by DoNewKeys. */
30063006
AssertTrue(ssh->handshake == NULL);
@@ -3055,7 +3055,7 @@ static void TestDoNewKeys(void)
30553055
WMEMCPY(&savedPeerKeys, &ssh->handshake->peerKeys, sizeof(Keys));
30563056

30573057
ssh->isKeying = WOLFSSH_PEER_IS_KEYING;
3058-
AssertIntEQ(wolfSSH_TestDoNewKeys(ssh), WS_SUCCESS);
3058+
AssertIntEQ(wolfSSH_TestDoNewKeys(ssh, NULL, 0, NULL), WS_SUCCESS);
30593059

30603060
AssertTrue(ssh->handshake == NULL);
30613061

@@ -3109,7 +3109,7 @@ static void TestDoNewKeys(void)
31093109
WMEMCPY(&savedPeerKeys, &ssh->handshake->peerKeys, sizeof(Keys));
31103110

31113111
ssh->isKeying = WOLFSSH_PEER_IS_KEYING;
3112-
AssertIntEQ(wolfSSH_TestDoNewKeys(ssh), WS_SUCCESS);
3112+
AssertIntEQ(wolfSSH_TestDoNewKeys(ssh, NULL, 0, NULL), WS_SUCCESS);
31133113

31143114
AssertTrue(ssh->handshake == NULL);
31153115

@@ -3163,7 +3163,11 @@ static void TestDoNewKeys(void)
31633163
WMEMCPY(&savedPeerKeys, &ssh->handshake->peerKeys, sizeof(Keys));
31643164

31653165
ssh->isKeying = WOLFSSH_PEER_IS_KEYING;
3166-
AssertIntEQ(wolfSSH_TestDoNewKeys(ssh), WS_SUCCESS);
3166+
/* Exercise the len != 0 rejection while handshake is still allocated,
3167+
* so the guard is reached and not short-circuited by handshake == NULL. */
3168+
AssertIntEQ(wolfSSH_TestDoNewKeys(ssh, NULL, 1, NULL), WS_BAD_ARGUMENT);
3169+
AssertNotNull(ssh->handshake);
3170+
AssertIntEQ(wolfSSH_TestDoNewKeys(ssh, NULL, 0, NULL), WS_SUCCESS);
31673171

31683172
AssertTrue(ssh->handshake == NULL);
31693173

wolfssh/internal.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1366,8 +1366,9 @@ enum WS_MessageIdLimits {
13661366
word32 len, word32* idx);
13671367
WOLFSSH_API int wolfSSH_TestDoKexInit(WOLFSSH* ssh, byte* buf,
13681368
word32 len, word32* idx);
1369+
WOLFSSH_API int wolfSSH_TestDoNewKeys(WOLFSSH* ssh, byte* buf,
1370+
word32 len, word32* idx);
13691371
WOLFSSH_API int wolfSSH_TestGenerateKeys(WOLFSSH* ssh, byte hashId);
1370-
WOLFSSH_API int wolfSSH_TestDoNewKeys(WOLFSSH* ssh);
13711372
WOLFSSH_API void wolfSSH_TestFreeHandshake(WOLFSSH* ssh);
13721373
WOLFSSH_API int wolfSSH_TestDoKexDhInit(WOLFSSH* ssh, byte* buf,
13731374
word32 len, word32* idx);

0 commit comments

Comments
 (0)