mirror of
https://github.com/espressif/openthread.git
synced 2026-08-15 23:27:47 +00:00
[pskc] set random PSKc when generating a new Active Dataset (#3769)
When generating a new Active Dataset, the current PSKc value is used. Because the PSKc is initialized to all zeros, new Active Datasets have a default PSKc value of all zeros. This commit checks if the PSKc has been set (i.e. not all zeros) and, if not set, generates a random PSKc when creating a new Active Dataset.
This commit is contained in:
committed by
Jonathan Hui
parent
f46fbb844d
commit
24307f1ba9
@@ -403,8 +403,22 @@ otError ActiveDataset::GenerateLocal(void)
|
||||
if (dataset.Get(Tlv::kPSKc) == NULL)
|
||||
{
|
||||
PSKcTlv tlv;
|
||||
|
||||
tlv.Init();
|
||||
tlv.SetPSKc(Get<KeyManager>().GetPSKc());
|
||||
|
||||
if (Get<KeyManager>().IsPSKcSet())
|
||||
{
|
||||
// use configured PSKc
|
||||
tlv.SetPSKc(Get<KeyManager>().GetPSKc());
|
||||
}
|
||||
else
|
||||
{
|
||||
// PSKc has not yet been configured, generate new PSKc at random
|
||||
otPSKc pskc;
|
||||
SuccessOrExit(error = otPlatRandomGetTrue(pskc.m8, sizeof(pskc)));
|
||||
tlv.SetPSKc(pskc);
|
||||
}
|
||||
|
||||
dataset.Set(tlv);
|
||||
}
|
||||
|
||||
|
||||
@@ -81,7 +81,9 @@ KeyManager::KeyManager(Instance &aInstance)
|
||||
, mKeyRotationTimer(aInstance, &KeyManager::HandleKeyRotationTimer, this)
|
||||
, mKekFrameCounter(0)
|
||||
, mSecurityPolicyFlags(0xff)
|
||||
, mIsPSKcSet(false)
|
||||
{
|
||||
memset(&mPSKc, 0, sizeof(mPSKc));
|
||||
ComputeKey(mKeySequence, mKey);
|
||||
}
|
||||
|
||||
@@ -104,7 +106,7 @@ void KeyManager::SetPSKc(const otPSKc &aPSKc)
|
||||
Get<Notifier>().Signal(OT_CHANGED_PSKC);
|
||||
|
||||
exit:
|
||||
return;
|
||||
mIsPSKcSet = true;
|
||||
}
|
||||
#endif // OPENTHREAD_MTD || OPENTHREAD_FTD
|
||||
|
||||
|
||||
@@ -103,6 +103,17 @@ public:
|
||||
otError SetMasterKey(const otMasterKey &aKey);
|
||||
|
||||
#if OPENTHREAD_FTD || OPENTHREAD_MTD
|
||||
/**
|
||||
* This method indicates whether the PSKc is configured.
|
||||
*
|
||||
* A value of all zeros indicates that the PSKc is not configured.
|
||||
*
|
||||
* @retval TRUE if the PSKc is configured.
|
||||
* @retval FALSE if the PSKc is not not configured.
|
||||
*
|
||||
*/
|
||||
bool IsPSKcSet(void) const { return mIsPSKcSet; }
|
||||
|
||||
/**
|
||||
* This method returns a pointer to the PSKc.
|
||||
*
|
||||
@@ -368,6 +379,7 @@ private:
|
||||
uint32_t mKekFrameCounter;
|
||||
|
||||
uint8_t mSecurityPolicyFlags;
|
||||
bool mIsPSKcSet : 1;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user