From 75abc7c871e18b5c41c22f998b9e5cdbb7868d84 Mon Sep 17 00:00:00 2001 From: hemanth-silabs <50145824+hemanth-silabs@users.noreply.github.com> Date: Wed, 31 Jan 2024 15:17:26 -0500 Subject: [PATCH] [key-manager] check if the key is present before exporting the key (#9814) While trying to read the Pskc or networkkey, we check if the keyref is valid. We instead need to check if the key is present. There is a possibility that the persistent data was erased before trying to read the key, which might result in asserts. --- src/core/thread/key_manager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/thread/key_manager.cpp b/src/core/thread/key_manager.cpp index 4d734442a..3d9337d93 100644 --- a/src/core/thread/key_manager.cpp +++ b/src/core/thread/key_manager.cpp @@ -516,7 +516,7 @@ void KeyManager::HandleKeyRotationTimer(void) void KeyManager::GetNetworkKey(NetworkKey &aNetworkKey) const { #if OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLE - if (Crypto::Storage::IsKeyRefValid(mNetworkKeyRef)) + if (Crypto::Storage::HasKey(mNetworkKeyRef)) { size_t keyLen; @@ -535,7 +535,7 @@ void KeyManager::GetNetworkKey(NetworkKey &aNetworkKey) const void KeyManager::GetPskc(Pskc &aPskc) const { #if OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLE - if (Crypto::Storage::IsKeyRefValid(mPskcRef)) + if (Crypto::Storage::HasKey(mPskcRef)) { size_t keyLen;