[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.
This commit is contained in:
hemanth-silabs
2024-01-31 12:17:26 -08:00
committed by GitHub
parent 176be05644
commit 75abc7c871
+2 -2
View File
@@ -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;