Skip to content
Open
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
17 changes: 17 additions & 0 deletions src/internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -12813,10 +12813,12 @@ int DoReceive(WOLFSSH* ssh)
int ret = WS_SUCCESS;
int verifyResult;
word32 readSz;
word32 alignSz;
byte peerBlockSz = ssh->peerBlockSz;
byte peerMacSz = ssh->peerMacSz;
byte aeadMode = ssh->peerAeadMode;
byte bufferConsumed = 0;
byte alignBlockSz;

switch (ssh->processReplyState) {
case PROCESS_INIT:
Expand Down Expand Up @@ -12855,6 +12857,21 @@ int DoReceive(WOLFSSH* ssh)
ssh->error = WS_OVERFLOW_E;
return WS_FATAL_ERROR;
}

/* RFC 4253 section 6 aligns packet_length through the padding
* on the block size, or 8, whichever is larger. Under AES-GCM
* the length is AAD, so RFC 5647 section 7.2 aligns the body. */
alignBlockSz = peerBlockSz < MIN_BLOCK_SZ ?
MIN_BLOCK_SZ : peerBlockSz;
alignSz = aeadMode ? ssh->curSz : UINT32_SZ + ssh->curSz;
if (alignSz % alignBlockSz != 0) {
WLOG(WS_LOG_DEBUG,
"Packet not block aligned: aligned size = %u, "
"block = %u, aead = %u",
alignSz, (word32)alignBlockSz, (word32)aeadMode);
ssh->error = WS_BUFFER_E;
return WS_FATAL_ERROR;
}
ssh->processReplyState = PROCESS_PACKET_FINISH;
FALL_THROUGH;

Expand Down
5 changes: 2 additions & 3 deletions tests/regress.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,10 @@ static HandshakeInfo* AllocHandshake(WOLFSSH* ssh)
}

/* Build a minimal SSH binary packet carrying only a message ID.
* Layout: uint32 packetLen, byte padLen, payload[msgId], pad[padLen].
* Choose padLen so total is 8-byte aligned for the clear transport case. */
* Layout: uint32 packetLen, byte padLen, payload[msgId], pad[padLen]. */
static word32 BuildPacket(byte msgId, byte* out, word32 outSz)
{
byte padLen = 6; /* 1 (msgId) +1 (padLen) +6 = 8 */
byte padLen = 10; /* 4 (len) +1 (padLen) +1 (msgId) +10 = 16 */
word32 packetLen = 1 + 1 + padLen; /* payload + padLen field + pad */
word32 need = 4 + packetLen;

Expand Down
Loading
Loading