Skip to content

Commit 129afad

Browse files
authored
[key-manager] add ClearKek() to remove KEK when no longer needed (openthread#13072)
This commit introduces the `KeyManager::ClearKek()` method, which clears the `Kek` and resets the `mIsKekSet` flag. The KEK is a temporary key used during the commissioning and entrust phases. To improve security and key hygiene, this commit updates the `Joiner` and `JoinerRouter` to explicitly clear the KEK once these operations have concluded. Specifically: - `Joiner::Finish()` clears the KEK when finishing in `kStateEntrust` or `kStateJoined`. - `JoinerRouter::HandleJoinerEntrustResponse()` clears the KEK immediately upon handling the entrust response, before scheduling any delayed entrusts (which set their own KEK from metadata).
1 parent 763af19 commit 129afad

4 files changed

Lines changed: 14 additions & 0 deletions

File tree

src/core/meshcop/joiner.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ void Joiner::Finish(Error aError)
184184
case kStateJoined:
185185
Get<Tmf::SecureAgent>().Disconnect();
186186
mTimer.Stop();
187+
Get<KeyManager>().ClearKek();
187188

188189
OT_FALL_THROUGH;
189190

src/core/meshcop/joiner_router.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,8 @@ Coap::Message *JoinerRouter::PrepareJoinerEntrustMessage(void)
302302

303303
void JoinerRouter::HandleJoinerEntrustResponse(Coap::Msg *aMsg, Error aResult)
304304
{
305+
Get<KeyManager>().ClearKek();
306+
305307
SendDelayedJoinerEntrust();
306308

307309
VerifyOrExit(aResult == kErrorNone && aMsg != nullptr);

src/core/thread/key_manager.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,12 @@ void KeyManager::SetKek(const Kek &aKek)
516516
mIsKekSet = true;
517517
}
518518

519+
void KeyManager::ClearKek(void)
520+
{
521+
mKek.Clear();
522+
mIsKekSet = false;
523+
}
524+
519525
void KeyManager::SetSecurityPolicy(const SecurityPolicy &aSecurityPolicy)
520526
{
521527
SecurityPolicy newPolicy = aSecurityPolicy;

src/core/thread/key_manager.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,11 @@ class KeyManager : public InstanceLocator, private NonCopyable
485485
*/
486486
void SetKek(const uint8_t *aKekBytes) { SetKek(*reinterpret_cast<const Kek *>(aKekBytes)); }
487487

488+
/**
489+
* Clears the KEK.
490+
*/
491+
void ClearKek(void);
492+
488493
/**
489494
* Returns the current KEK Frame Counter value.
490495
*

0 commit comments

Comments
 (0)