[secure-transport] use mbedtls_ssl_is_handshake_over() (#10973)

This commit updates how the handshake completion is checked on MBedTLS
version 3.0 or later. Instead of accessing the private `state`
variable, the `mbedtls_ssl_is_handshake_over()` function is used.
This follows the recommendation of the MbedTLS documentation to avoid
using the deprecated `mSsl->MBEDTLS_PRIVATE(state)` access on newer
versions.
This commit is contained in:
Abtin Keshavarzian
2024-11-27 07:31:14 -08:00
committed by GitHub
parent 65dd8bff66
commit 88ab0174ec
2 changed files with 15 additions and 3 deletions
+13 -3
View File
@@ -771,6 +771,16 @@ exit:
return error;
}
bool SecureTransport::IsMbedtlsHandshakeOver(mbedtls_ssl_context *aSslContext)
{
return
#if (MBEDTLS_VERSION_NUMBER >= 0x03000000)
mbedtls_ssl_is_handshake_over(aSslContext);
#else
(aSslContext->MBEDTLS_PRIVATE(state) == MBEDTLS_SSL_HANDSHAKE_OVER);
#endif
}
int SecureTransport::HandleMbedtlsTransmit(void *aContext, const unsigned char *aBuf, size_t aLength)
{
return static_cast<SecureTransport *>(aContext)->HandleMbedtlsTransmit(aBuf, aLength);
@@ -1016,7 +1026,7 @@ void SecureTransport::Process(void)
{
rval = mbedtls_ssl_handshake(&mSsl);
if (mSsl.MBEDTLS_PRIVATE(state) == MBEDTLS_SSL_HANDSHAKE_OVER)
if (IsMbedtlsHandshakeOver(&mSsl))
{
SetState(kStateConnected);
mConnectEvent = kConnected;
@@ -1060,7 +1070,7 @@ void SecureTransport::Process(void)
break;
case MBEDTLS_ERR_SSL_INVALID_MAC:
if (mSsl.MBEDTLS_PRIVATE(state) != MBEDTLS_SSL_HANDSHAKE_OVER)
if (!IsMbedtlsHandshakeOver(&mSsl))
{
mbedtls_ssl_send_alert_message(&mSsl, MBEDTLS_SSL_ALERT_LEVEL_FATAL,
MBEDTLS_SSL_ALERT_MSG_BAD_RECORD_MAC);
@@ -1069,7 +1079,7 @@ void SecureTransport::Process(void)
break;
default:
if (mSsl.MBEDTLS_PRIVATE(state) != MBEDTLS_SSL_HANDSHAKE_OVER)
if (!IsMbedtlsHandshakeOver(&mSsl))
{
mbedtls_ssl_send_alert_message(&mSsl, MBEDTLS_SSL_ALERT_LEVEL_FATAL,
MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE);
+2
View File
@@ -527,6 +527,8 @@ private:
size_t *aAttributeLength);
#endif
static bool IsMbedtlsHandshakeOver(mbedtls_ssl_context *aSslContext);
static void HandleMbedtlsDebug(void *aContext, int aLevel, const char *aFile, int aLine, const char *aStr);
void HandleMbedtlsDebug(int aLevel, const char *aFile, int aLine, const char *aStr);