Merge pull request #8787 from julek-wolfssl/refactor-GetHandshakeHeader

Refactor GetHandshakeHeader/GetHandShakeHeader into one
pull/8543/merge
David Garske 2025-05-27 15:26:24 -07:00 committed by GitHub
commit 6de7bb74ed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 33 additions and 50 deletions

View File

@ -11578,6 +11578,33 @@ static int MsgCheckBoundary(const WOLFSSL* ssl, byte type,
#endif /* WOLFSSL_DISABLE_EARLY_SANITY_CHECKS */
/* Extract the handshake header information.
*
* ssl The SSL/TLS object.
* input The buffer holding the message data.
* inOutIdx On entry, the index into the buffer of the handshake data.
* On exit, the start of the handshake data.
* type Type of handshake message.
* size The length of the handshake message data.
* totalSz The total size of data in the buffer.
* returns BUFFER_E if there is not enough input data and 0 on success.
*/
int GetHandshakeHeader(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
byte* type, word32* size, word32 totalSz)
{
const byte* ptr = input + *inOutIdx;
(void)ssl;
*inOutIdx += HANDSHAKE_HEADER_SZ;
if (*inOutIdx > totalSz)
return BUFFER_E;
*type = ptr[0];
c24to32(&ptr[1], size);
return 0;
}
/**
* This check is performed as soon as the handshake message type becomes known.
* These checks can not be delayed and need to be performed when the msg is
@ -12043,24 +12070,6 @@ static int GetRecordHeader(WOLFSSL* ssl, word32* inOutIdx,
return 0;
}
#ifndef WOLFSSL_NO_TLS12
static int GetHandShakeHeader(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
byte *type, word32 *size, word32 totalSz)
{
const byte *ptr = input + *inOutIdx;
(void)ssl;
*inOutIdx += HANDSHAKE_HEADER_SZ;
if (*inOutIdx > totalSz)
return BUFFER_E;
*type = ptr[0];
c24to32(&ptr[1], size);
return 0;
}
#endif
#ifdef WOLFSSL_DTLS
int GetDtlsHandShakeHeader(WOLFSSL* ssl, const byte* input,
word32* inOutIdx, byte *type, word32 *size,
@ -18122,7 +18131,7 @@ static int DoHandShakeMsg(WOLFSSL* ssl, byte* input, word32* inOutIdx,
byte type;
word32 size;
if (GetHandShakeHeader(ssl,input,inOutIdx,&type, &size, totalSz) != 0) {
if (GetHandshakeHeader(ssl,input,inOutIdx,&type, &size, totalSz) != 0) {
WOLFSSL_ERROR_VERBOSE(PARSE_ERROR);
return PARSE_ERROR;
}
@ -18150,7 +18159,7 @@ static int DoHandShakeMsg(WOLFSSL* ssl, byte* input, word32* inOutIdx,
byte type;
word32 size;
if (GetHandShakeHeader(ssl, input, inOutIdx, &type, &size,
if (GetHandshakeHeader(ssl, input, inOutIdx, &type, &size,
totalSz) != 0) {
WOLFSSL_ERROR_VERBOSE(PARSE_ERROR);
return PARSE_ERROR;

View File

@ -2236,34 +2236,6 @@ end:
#endif /* WOLFSSL_32BIT_MILLI_TIME */
#endif /* HAVE_SESSION_TICKET || !NO_PSK */
/* Extract the handshake header information.
*
* ssl The SSL/TLS object.
* input The buffer holding the message data.
* inOutIdx On entry, the index into the buffer of the handshake data.
* On exit, the start of the handshake data.
* type Type of handshake message.
* size The length of the handshake message data.
* totalSz The total size of data in the buffer.
* returns BUFFER_E if there is not enough input data and 0 on success.
*/
static int GetHandshakeHeader(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
byte* type, word32* size, word32 totalSz)
{
const byte* ptr = input + *inOutIdx;
(void)ssl;
*inOutIdx += HANDSHAKE_HEADER_SZ;
if (*inOutIdx > totalSz)
return BUFFER_E;
*type = ptr[0];
c24to32(&ptr[1], size);
return 0;
}
/* Add record layer header to message.
*
* output The buffer to write the record layer header into.

View File

@ -19,8 +19,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/
#ifndef TESTS_API_TEST_TLS_EMS_H
#define TESTS_API_TEST_TLS_EMS_H
#ifndef TESTS_API_TEST_TLS_EXT_H
#define TESTS_API_TEST_TLS_EXT_H
int test_tls_ems_downgrade(void);
int test_wolfSSL_DisableExtendedMasterSecret(void);

View File

@ -6709,6 +6709,8 @@ WOLFSSL_LOCAL int GrowInputBuffer(WOLFSSL* ssl, int size, int usedLength);
WOLFSSL_LOCAL int MsgCheckEncryption(WOLFSSL* ssl, byte type, byte encrypted);
WOLFSSL_LOCAL int EarlySanityCheckMsgReceived(WOLFSSL* ssl, byte type,
word32 msgSz);
WOLFSSL_LOCAL int GetHandshakeHeader(WOLFSSL* ssl, const byte* input,
word32* inOutIdx, byte* type, word32* size, word32 totalSz);
#if !defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH)
WOLFSSL_LOCAL void DoCertFatalAlert(WOLFSSL* ssl, int ret);
#endif