Skip to content

Commit

Permalink
[secure-transport] set app keys on config before SSL context setup (o…
Browse files Browse the repository at this point in the history
…penthread#11044)

This commit updates `Setup()`, which initializes and sets up
`mbedtls_ssl_config` and `mbedtls_ssl_context`. The call
`mExtension->SetApplicationSecureKeys()` (which updates the
`mbedtls_ssl_config`) is now called before `mbedtls_ssl_setup()`
associates the config with the `mbedtls_ssl_context`. This
follows the recommendation that the config structure is not
modified after `ssl_setup()` and while a session is active.
  • Loading branch information
abtink authored Dec 16, 2024
1 parent e583b42 commit 3560870
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/core/meshcop/secure_transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,14 @@ Error SecureTransport::Setup(void)
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Setup the `Extension` components.

#if OPENTHREAD_CONFIG_TLS_API_ENABLE && defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED)
#if OPENTHREAD_CONFIG_TLS_API_ENABLE
if (mExtension != nullptr)
{
#if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED)
mExtension->mEcdheEcdsaInfo.Init();
#endif
rval = mExtension->SetApplicationSecureKeys();
VerifyOrExit(rval == 0);
}
#endif

Expand Down Expand Up @@ -404,14 +408,8 @@ Error SecureTransport::Setup(void)
if (mCipherSuite == kEcjpakeWithAes128Ccm8)
{
rval = mbedtls_ssl_set_hs_ecjpake_password(&mSsl, mPsk, mPskLength);
VerifyOrExit(rval == 0);
}
#if OPENTHREAD_CONFIG_TLS_API_ENABLE
else if (mExtension != nullptr)
{
rval = mExtension->SetApplicationSecureKeys();
}
#endif
VerifyOrExit(rval == 0);

mReceiveMessage = nullptr;
mMessageSubType = Message::kSubTypeNone;
Expand Down Expand Up @@ -937,6 +935,10 @@ int SecureTransport::Extension::SetApplicationSecureKeys(void)

switch (mSecureTransport.mCipherSuite)
{
case kEcjpakeWithAes128Ccm8:
// PSK will be set on `mbedtls_ssl_context` when set up.
break;

#ifdef MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
case kEcdheEcdsaWithAes128Ccm8:
case kEcdheEcdsaWithAes128GcmSha256:
Expand Down

0 comments on commit 3560870

Please sign in to comment.