Require Thread Master Key to be 16 bytes. (#1724)

- Update code to use `otMasterKey` type.
This commit is contained in:
Jonathan Hui
2017-05-05 09:21:43 -07:00
committed by GitHub
parent 08f46b3038
commit da7ba8ba19
18 changed files with 89 additions and 140 deletions
+12 -20
View File
@@ -296,39 +296,31 @@ public:
String^ get()
{
constexpr char hexmap[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
uint8_t keyLen;
auto key = otThreadGetMasterKey(DeviceInstance, &keyLen);
auto key = otThreadGetMasterKey(DeviceInstance);
WCHAR szKey[OT_MASTER_KEY_SIZE * 2 + 1] = { 0 };
for (uint8_t i = 0; i < keyLen; i++)
for (uint8_t i = 0; i < OT_MASTER_KEY_SIZE; i++)
{
szKey[2 * i] = hexmap[(key[i] & 0xF0) >> 4];
szKey[2 * i + 1] = hexmap[key[i] & 0x0F];
szKey[2 * i] = hexmap[(key->m8[i] & 0xF0) >> 4];
szKey[2 * i + 1] = hexmap[key->m8[i] & 0x0F];
}
otFreeMemory(key);
return ref new String(szKey);
}
void set(String^ value)
{
uint8_t key[OT_MASTER_KEY_SIZE];
otMasterKey key;
uint8_t keyLen = 0;
if (value->Length() % 2 == 0)
for (uint32_t i = 0; i < value->Length() - 1; i+=2)
{
for (uint32_t i = 0; i < value->Length(); i+=2)
{
key[keyLen++] = (uint8_t)((charToValue(value->Data()[i]) << 4) |
charToValue(value->Data()[i + 1]));
}
key.m8[keyLen++] = (uint8_t)((charToValue(value->Data()[i]) << 4) |
charToValue(value->Data()[i + 1]));
}
else
if (keyLen * 2 == value->Length() - 1)
{
key[keyLen++] = (uint8_t)(charToValue(value->Data()[0]));
for (uint32_t i = 1; i < value->Length(); i += 2)
{
key[keyLen++] = (uint8_t)((charToValue(value->Data()[i]) << 4) |
charToValue(value->Data()[i + 1]));
}
key.m8[keyLen++] = (uint8_t)(charToValue(value->Data()[value->Length()-1])) << 4;
}
ThrowOnFailure(otThreadSetMasterKey(DeviceInstance, key, keyLen));
memset(key.m8 + keyLen, 0, sizeof(key) - keyLen);
ThrowOnFailure(otThreadSetMasterKey(DeviceInstance, &key));
}
}
+7 -25
View File
@@ -1598,34 +1598,22 @@ otThreadSetLinkMode(
}
OTAPI
const uint8_t *
const otMasterKey *
OTCALL
otThreadGetMasterKey(
_In_ otInstance *aInstance,
_Out_ uint8_t *aKeyLength
_In_ otInstance *aInstance
)
{
if (aInstance == nullptr || aKeyLength == nullptr) return nullptr;
if (aInstance == nullptr) return nullptr;
*aKeyLength = 0;
struct otMasterKeyAndLength
{
otMasterKey Key;
uint8_t Length;
};
otMasterKeyAndLength *Result = (otMasterKeyAndLength*)malloc(sizeof(otMasterKeyAndLength));
otMasterKey *Result = (otMasterKey*)malloc(sizeof(otMasterKey));
if (Result == nullptr) return nullptr;
if (QueryIOCTL(aInstance, IOCTL_OTLWF_OT_MASTER_KEY, Result) != ERROR_SUCCESS)
{
free(Result);
return nullptr;
}
else
{
*aKeyLength = Result->Length;
}
return (uint8_t*)Result;
return Result;
}
OTAPI
@@ -1633,18 +1621,12 @@ ThreadError
OTCALL
otThreadSetMasterKey(
_In_ otInstance *aInstance,
const uint8_t *aKey,
uint8_t aKeyLength
const otMasterKey *aKey
)
{
if (aInstance == nullptr) return kThreadError_InvalidArgs;
BYTE Buffer[sizeof(GUID) + sizeof(otMasterKey) + sizeof(uint8_t)];
memcpy_s(Buffer, sizeof(Buffer), &aInstance->InterfaceGuid, sizeof(GUID));
memcpy_s(Buffer + sizeof(GUID), sizeof(Buffer) - sizeof(GUID), aKey, aKeyLength);
memcpy_s(Buffer + sizeof(GUID) + sizeof(otMasterKey), sizeof(Buffer) - sizeof(GUID) - sizeof(otMasterKey), &aKeyLength, sizeof(aKeyLength));
return DwordToThreadError(SendIOCTL(aInstance->ApiHandle, IOCTL_OTLWF_OT_MASTER_KEY, Buffer, sizeof(Buffer), nullptr, 0));
return DwordToThreadError(SetIOCTL(aInstance, IOCTL_OTLWF_OT_MASTER_KEY, aKey));
}
OTAPI
+12 -18
View File
@@ -1632,19 +1632,16 @@ otLwfIoCtl_otMasterKey(
{
NTSTATUS status = STATUS_INVALID_PARAMETER;
if (InBufferLength >= sizeof(otMasterKey) + sizeof(uint8_t))
if (InBufferLength >= sizeof(otMasterKey))
{
uint8_t aKeyLength = *(uint8_t*)(InBuffer + sizeof(otMasterKey));
status = ThreadErrorToNtstatus(otThreadSetMasterKey(pFilter->otCtx, InBuffer, aKeyLength));
status = ThreadErrorToNtstatus(otThreadSetMasterKey(pFilter->otCtx, (otMasterKey*)InBuffer));
*OutBufferLength = 0;
}
else if (*OutBufferLength >= sizeof(otMasterKey) + sizeof(uint8_t))
else if (*OutBufferLength >= sizeof(otMasterKey))
{
uint8_t aKeyLength = 0;
const uint8_t* aMasterKey = otThreadGetMasterKey(pFilter->otCtx, &aKeyLength);
memcpy(OutBuffer, aMasterKey, aKeyLength);
memcpy((PUCHAR)OutBuffer + sizeof(otMasterKey), &aKeyLength, sizeof(uint8_t));
*OutBufferLength = sizeof(otMasterKey) + sizeof(uint8_t);
const otMasterKey* aMasterKey = otThreadGetMasterKey(pFilter->otCtx);
memcpy(OutBuffer, aMasterKey, sizeof(otMasterKey));
*OutBufferLength = sizeof(otMasterKey);
status = STATUS_SUCCESS;
}
else
@@ -1668,10 +1665,8 @@ otLwfTunIoCtl_otMasterKey(
{
NTSTATUS status = STATUS_INVALID_PARAMETER;
if (InBufferLength >= sizeof(otMasterKey) + sizeof(uint8_t))
if (InBufferLength >= sizeof(otMasterKey))
{
spinel_size_t aKeyLength = *(uint8_t*)(InBuffer + sizeof(otMasterKey));
status =
otLwfTunSendCommandForIrp(
pFilter,
@@ -1682,9 +1677,9 @@ otLwfTunIoCtl_otMasterKey(
sizeof(otMasterKey) + sizeof(uint16_t),
SPINEL_DATATYPE_DATA_S,
(otMasterKey*)InBuffer,
aKeyLength);
sizeof(otMasterKey));
}
else if (OutBufferLength >= sizeof(otMasterKey) + sizeof(uint8_t))
else if (OutBufferLength >= sizeof(otMasterKey))
{
status =
otLwfTunSendCommandForIrp(
@@ -1717,11 +1712,10 @@ otLwfTunIoCtl_otMasterKey_Handler(
uint8_t *data = NULL;
spinel_size_t aKeyLength;
if (try_spinel_datatype_unpack(Data, DataLength, SPINEL_DATATYPE_DATA_S, &data, &aKeyLength) && data != NULL &&
aKeyLength <= sizeof(otMasterKey))
aKeyLength == sizeof(otMasterKey))
{
memcpy(OutBuffer, data, aKeyLength);
*(uint8_t*)((PUCHAR)OutBuffer + sizeof(otMasterKey)) = (uint8_t)aKeyLength;
*OutBufferLength = sizeof(otMasterKey) + sizeof(uint8_t);
memcpy(OutBuffer, data, sizeof(otMasterKey));
*OutBufferLength = sizeof(otMasterKey);
status = STATUS_SUCCESS;
}
}
@@ -1200,14 +1200,14 @@ OTNODEAPI int32_t OTCALL otNodeSetMasterkey(otNode* aNode, const char *aMasterke
printf("%d: masterkey %s\r\n", aNode->mId, aMasterkey);
int keyLength;
uint8_t key[OT_MASTER_KEY_SIZE];
if ((keyLength = Hex2Bin(aMasterkey, key, sizeof(key))) != OT_MASTER_KEY_SIZE)
otMasterKey key;
if ((keyLength = Hex2Bin(aMasterkey, key.m8, sizeof(key.m8))) != OT_MASTER_KEY_SIZE)
{
printf("invalid length key %d\r\n", keyLength);
return kThreadError_Parse;
}
auto error = otThreadSetMasterKey(aNode->mInstance, key, (uint8_t)keyLength);
auto error = otThreadSetMasterKey(aNode->mInstance, &key);
otLogFuncExit();
return error;
}
@@ -1215,15 +1215,14 @@ OTNODEAPI int32_t OTCALL otNodeSetMasterkey(otNode* aNode, const char *aMasterke
OTNODEAPI const char* OTCALL otNodeGetMasterkey(otNode* aNode)
{
otLogFuncEntryMsg("[%d]", aNode->mId);
uint8_t aKeyLength = 0;
auto aMasterKey = otThreadGetMasterKey(aNode->mInstance, &aKeyLength);
uint8_t strLength = 2*aKeyLength + 1;
auto aMasterKey = otThreadGetMasterKey(aNode->mInstance);
uint8_t strLength = 2*sizeof(otMasterKey) + 1;
char* str = (char*)malloc(strLength);
if (str != nullptr)
{
aNode->mMemoryToFree.push_back(str);
for (int i = 0; i < aKeyLength; i++)
sprintf_s(str + i * 2, strLength - (2 * i), "%02x", aMasterKey[i]);
for (int i = 0; i < sizeof(otMasterKey); i++)
sprintf_s(str + i * 2, strLength - (2 * i), "%02x", aMasterKey->m8[i]);
printf("%d: masterkey\r\n%s\r\n", aNode->mId, str);
}
otFreeMemory(aMasterKey);
+2 -5
View File
@@ -232,14 +232,12 @@ OTAPI ThreadError OTCALL otThreadSetLinkMode(otInstance *aInstance, otLinkModeCo
* Get the thrMasterKey.
*
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[out] aKeyLength A pointer to an unsigned 8-bit value that the function will set to the number of bytes that
* represent the thrMasterKey. Caller may set to NULL.
*
* @returns A pointer to a buffer containing the thrMasterKey.
*
* @sa otThreadSetMasterKey
*/
OTAPI const uint8_t *OTCALL otThreadGetMasterKey(otInstance *aInstance, uint8_t *aKeyLength);
OTAPI const otMasterKey *OTCALL otThreadGetMasterKey(otInstance *aInstance);
/**
* Set the thrMasterKey.
@@ -250,7 +248,6 @@ OTAPI const uint8_t *OTCALL otThreadGetMasterKey(otInstance *aInstance, uint8_t
*
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[in] aKey A pointer to a buffer containing the thrMasterKey.
* @param[in] aKeyLength Number of bytes representing the thrMasterKey stored at aKey. Valid range is [0, 16].
*
* @retval kThreadErrorNone Successfully set the thrMasterKey.
* @retval kThreadErrorInvalidArgs If aKeyLength is larger than 16.
@@ -258,7 +255,7 @@ OTAPI const uint8_t *OTCALL otThreadGetMasterKey(otInstance *aInstance, uint8_t
*
* @sa otThreadGetMasterKey
*/
OTAPI ThreadError OTCALL otThreadSetMasterKey(otInstance *aInstance, const uint8_t *aKey, uint8_t aKeyLength);
OTAPI ThreadError OTCALL otThreadSetMasterKey(otInstance *aInstance, const otMasterKey *aKey);
/**
* Get the thrPSKc.
+5 -2
View File
@@ -213,10 +213,13 @@ typedef enum ThreadError
* This structure represents a Thread Master Key.
*
*/
typedef struct otMasterKey
OT_TOOL_PACKED_BEGIN
struct otMasterKey
{
uint8_t m8[OT_MASTER_KEY_SIZE];
} otMasterKey;
} OT_TOOL_PACKED_END;
typedef struct otMasterKey otMasterKey;
#define OT_NETWORK_NAME_MAX_SIZE 16 ///< Maximum size of the Thread Network Name field (bytes)
+5 -7
View File
@@ -1354,10 +1354,9 @@ void Interpreter::ProcessMasterKey(int argc, char *argv[])
if (argc == 0)
{
uint8_t keyLength;
otBufferPtr key(otThreadGetMasterKey(mInstance, &keyLength));
otBufferPtr key(reinterpret_cast<const uint8_t *>(otThreadGetMasterKey(mInstance)));
for (int i = 0; i < keyLength; i++)
for (int i = 0; i < OT_MASTER_KEY_SIZE; i++)
{
sServer->OutputFormat("%02x", key[i]);
}
@@ -1366,11 +1365,10 @@ void Interpreter::ProcessMasterKey(int argc, char *argv[])
}
else
{
int keyLength;
uint8_t key[OT_MASTER_KEY_SIZE];
otMasterKey key;
VerifyOrExit((keyLength = Hex2Bin(argv[0], key, sizeof(key))) == OT_MASTER_KEY_SIZE, error = kThreadError_Parse);
SuccessOrExit(error = otThreadSetMasterKey(mInstance, key, static_cast<uint8_t>(keyLength)));
VerifyOrExit(Hex2Bin(argv[0], key.m8, sizeof(key.m8)) == OT_MASTER_KEY_SIZE, error = kThreadError_Parse);
SuccessOrExit(error = otThreadSetMasterKey(mInstance, &key));
}
exit:
+5 -4
View File
@@ -170,19 +170,20 @@ exit:
}
#endif
const uint8_t *otThreadGetMasterKey(otInstance *aInstance, uint8_t *aKeyLength)
const otMasterKey *otThreadGetMasterKey(otInstance *aInstance)
{
return aInstance->mThreadNetif.GetKeyManager().GetMasterKey(aKeyLength);
return &aInstance->mThreadNetif.GetKeyManager().GetMasterKey();
}
ThreadError otThreadSetMasterKey(otInstance *aInstance, const uint8_t *aKey, uint8_t aKeyLength)
ThreadError otThreadSetMasterKey(otInstance *aInstance, const otMasterKey *aKey)
{
ThreadError error = kThreadError_None;
VerifyOrExit(aKey != NULL, error = kThreadError_InvalidArgs);
VerifyOrExit(aInstance->mThreadNetif.GetMle().GetDeviceState() == Mle::kDeviceStateDisabled,
error = kThreadError_InvalidState);
error = aInstance->mThreadNetif.GetKeyManager().SetMasterKey(aKey, aKeyLength);
error = aInstance->mThreadNetif.GetKeyManager().SetMasterKey(*aKey);
aInstance->mThreadNetif.GetActiveDataset().Clear(false);
aInstance->mThreadNetif.GetPendingDataset().Clear(false);
+2 -2
View File
@@ -188,7 +188,7 @@ void Dataset::Get(otOperationalDataset &aDataset) const
case Tlv::kNetworkMasterKey:
{
const NetworkMasterKeyTlv *tlv = static_cast<const NetworkMasterKeyTlv *>(cur);
memcpy(aDataset.mMasterKey.m8, tlv->GetNetworkMasterKey(), sizeof(aDataset.mMasterKey));
aDataset.mMasterKey = tlv->GetNetworkMasterKey();
aDataset.mIsMasterKeySet = true;
break;
}
@@ -328,7 +328,7 @@ ThreadError Dataset::Set(const otOperationalDataset &aDataset)
{
MeshCoP::NetworkMasterKeyTlv tlv;
tlv.Init();
tlv.SetNetworkMasterKey(aDataset.mMasterKey.m8);
tlv.SetNetworkMasterKey(aDataset.mMasterKey);
Set(tlv);
}
+4 -6
View File
@@ -131,7 +131,7 @@ ThreadError DatasetManager::ApplyConfiguration(void)
case Tlv::kNetworkMasterKey:
{
const NetworkMasterKeyTlv *key = static_cast<const NetworkMasterKeyTlv *>(cur);
mNetif.GetKeyManager().SetMasterKey(key->GetNetworkMasterKey(), key->GetLength());
mNetif.GetKeyManager().SetMasterKey(key->GetNetworkMasterKey());
break;
}
@@ -461,8 +461,7 @@ ThreadError DatasetManager::Set(Coap::Header &aHeader, Message &aMessage, const
// check network master key
if (Tlv::GetTlv(aMessage, Tlv::kNetworkMasterKey, sizeof(masterKey), masterKey) == kThreadError_None &&
memcmp(masterKey.GetNetworkMasterKey(), mNetif.GetKeyManager().GetMasterKey(NULL),
masterKey.GetLength()))
memcmp(&masterKey.GetNetworkMasterKey(), &mNetif.GetKeyManager().GetMasterKey(), OT_MASTER_KEY_SIZE))
{
doesAffectConnectivity = true;
doesAffectMasterKey = true;
@@ -471,8 +470,7 @@ ThreadError DatasetManager::Set(Coap::Header &aHeader, Message &aMessage, const
// check active timestamp rollback
if (type == Tlv::kPendingTimestamp &&
(masterKey.GetLength() == 0 ||
memcmp(masterKey.GetNetworkMasterKey(), mNetif.GetKeyManager().GetMasterKey(NULL),
masterKey.GetLength()) == 0))
memcmp(&masterKey.GetNetworkMasterKey(), &mNetif.GetKeyManager().GetMasterKey(), OT_MASTER_KEY_SIZE) == 0))
{
// no change to master key, active timestamp must be ahead
const Timestamp *localActiveTimestamp = mNetif.GetActiveDataset().GetNetwork().GetTimestamp();
@@ -666,7 +664,7 @@ ThreadError DatasetManager::SendSetRequest(const otOperationalDataset &aDataset,
{
NetworkMasterKeyTlv masterkey;
masterkey.Init();
masterkey.SetNetworkMasterKey(aDataset.mMasterKey.m8);
masterkey.SetNetworkMasterKey(aDataset.mMasterKey);
SuccessOrExit(error = message->Append(&masterkey, sizeof(masterkey)));
}
+1 -1
View File
@@ -137,7 +137,7 @@ ThreadError ActiveDataset::GenerateLocal(void)
{
NetworkMasterKeyTlv tlv;
tlv.Init();
tlv.SetNetworkMasterKey(mNetif.GetKeyManager().GetMasterKey(NULL));
tlv.SetNetworkMasterKey(mNetif.GetKeyManager().GetMasterKey());
mLocal.Set(tlv);
}
+1 -1
View File
@@ -429,7 +429,7 @@ void Joiner::HandleJoinerEntrust(Coap::Header &aHeader, Message &aMessage, const
SuccessOrExit(error = Tlv::GetTlv(aMessage, Tlv::kNetworkKeySequence, sizeof(networkKeySeq), networkKeySeq));
VerifyOrExit(networkKeySeq.IsValid(), error = kThreadError_Parse);
mNetif.GetKeyManager().SetMasterKey(masterKey.GetNetworkMasterKey(), masterKey.GetLength());
mNetif.GetKeyManager().SetMasterKey(masterKey.GetNetworkMasterKey());
mNetif.GetKeyManager().SetCurrentKeySequence(networkKeySeq.GetNetworkKeySequence());
mNetif.GetMle().SetMeshLocalPrefix(meshLocalPrefix.GetMeshLocalPrefix());
mNetif.GetMac().SetExtendedPanId(extendedPanId.GetExtendedPanId());
+1 -1
View File
@@ -346,7 +346,7 @@ ThreadError JoinerRouter::DelaySendingJoinerEntrust(const Ip6::MessageInfo &aMes
message->SetSubType(Message::kSubTypeJoinerEntrust);
masterKey.Init();
masterKey.SetNetworkMasterKey(mNetif.GetKeyManager().GetMasterKey(NULL));
masterKey.SetNetworkMasterKey(mNetif.GetKeyManager().GetMasterKey());
SuccessOrExit(error = message->Append(&masterKey, sizeof(masterKey)));
meshLocalPrefix.Init();
+4 -4
View File
@@ -437,7 +437,7 @@ public:
* @returns The Network Master Key value.
*
*/
const uint8_t *GetNetworkMasterKey(void) const { return mNetworkMasterKey; }
const otMasterKey &GetNetworkMasterKey(void) const { return mNetworkMasterKey; }
/**
* This method sets the Network Master Key value.
@@ -445,12 +445,12 @@ public:
* @param[in] aNetworkMasterKey A pointer to the Network Master Key value.
*
*/
void SetNetworkMasterKey(const uint8_t *aNetworkMasterKey) {
memcpy(mNetworkMasterKey, aNetworkMasterKey, sizeof(mNetworkMasterKey));
void SetNetworkMasterKey(const otMasterKey &aNetworkMasterKey) {
mNetworkMasterKey = aNetworkMasterKey;
}
private:
uint8_t mNetworkMasterKey[16];
otMasterKey mNetworkMasterKey;
} OT_TOOL_PACKED_END;
/**
+5 -13
View File
@@ -54,7 +54,6 @@ static const uint8_t kThreadString[] =
KeyManager::KeyManager(ThreadNetif &aThreadNetif):
mNetif(aThreadNetif),
mMasterKeyLength(0),
mKeySequence(0),
mMacFrameCounter(0),
mMleFrameCounter(0),
@@ -92,28 +91,21 @@ void KeyManager::SetPSKc(const uint8_t *aPSKc)
}
#endif
const uint8_t *KeyManager::GetMasterKey(uint8_t *aKeyLength) const
const otMasterKey &KeyManager::GetMasterKey(void) const
{
if (aKeyLength)
{
*aKeyLength = mMasterKeyLength;
}
return mMasterKey;
}
ThreadError KeyManager::SetMasterKey(const void *aKey, uint8_t aKeyLength)
ThreadError KeyManager::SetMasterKey(const otMasterKey &aKey)
{
ThreadError error = kThreadError_None;
Router *routers;
Child *children;
uint8_t num;
VerifyOrExit(aKeyLength <= sizeof(mMasterKey), error = kThreadError_InvalidArgs);
VerifyOrExit((mMasterKeyLength != aKeyLength) || (memcmp(mMasterKey, aKey, aKeyLength) != 0));
VerifyOrExit(memcmp(&mMasterKey, &aKey, sizeof(mMasterKey)) != 0);
memcpy(mMasterKey, aKey, aKeyLength);
mMasterKeyLength = aKeyLength;
mMasterKey = aKey;
mKeySequence = 0;
ComputeKey(mKeySequence, mKey);
@@ -154,7 +146,7 @@ ThreadError KeyManager::ComputeKey(uint32_t aKeySequence, uint8_t *aKey)
Crypto::HmacSha256 hmac;
uint8_t keySequenceBytes[4];
hmac.Start(mMasterKey, mMasterKeyLength);
hmac.Start(mMasterKey.m8, sizeof(mMasterKey.m8));
keySequenceBytes[0] = (aKeySequence >> 24) & 0xff;
keySequenceBytes[1] = (aKeySequence >> 16) & 0xff;
+6 -10
View File
@@ -83,26 +83,23 @@ public:
void Stop(void);
/**
* This method returns a pointer to the Thread Master Key
* This method returns a reference to the Thread Master Key
*
* @param[out] aKeyLength A pointer where the key length value will be placed.
*
* @returns A pointer to the Thread Master Key.
* @returns A reference to the Thread Master Key.
*
*/
const uint8_t *GetMasterKey(uint8_t *aKeyLength) const;
const otMasterKey &GetMasterKey(void) const;
/**
* This method sets the Thread Master Key.
*
* @param[in] aKey A pointer to the Thread Master Key.
* @param[in] aKeyLength The length of @p aKey.
* @param[in] aKey A reference to the Thread Master Key.
*
* @retval kThreadError_None Successfully set the Thread Master Key.
* @retval kThreadError_InvalidArgs The @p aKeyLength value was invalid.
*
*/
ThreadError SetMasterKey(const void *aKey, uint8_t aKeyLength);
ThreadError SetMasterKey(const otMasterKey &aKey);
/**
* This method returns a pointer to the PSKc.
@@ -344,8 +341,7 @@ private:
ThreadNetif &mNetif;
uint8_t mMasterKey[kMaxKeyLength];
uint8_t mMasterKeyLength;
otMasterKey mMasterKey;
uint32_t mKeySequence;
uint8_t mKey[Crypto::HmacSha256::kHashSize];
+6 -4
View File
@@ -54,10 +54,12 @@ using ot::Encoding::BigEndian::HostSwap16;
namespace ot {
static const uint8_t kThreadMasterKey[] =
static const otMasterKey kThreadMasterKey =
{
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff,
{
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff,
}
};
ThreadNetif::ThreadNetif(Ip6::Ip6 &aIp6):
@@ -114,7 +116,7 @@ ThreadNetif::ThreadNetif(Ip6::Ip6 &aIp6):
mEnergyScan(*this)
{
mKeyManager.SetMasterKey(kThreadMasterKey, sizeof(kThreadMasterKey));
mKeyManager.SetMasterKey(kThreadMasterKey);
mCoapServer.SetInterceptor(&ThreadNetif::TmfFilter);
}
+4 -9
View File
@@ -2269,18 +2269,13 @@ ThreadError NcpBase::GetPropertyHandler_NET_XPANID(uint8_t header, spinel_prop_k
ThreadError NcpBase::GetPropertyHandler_NET_MASTER_KEY(uint8_t header, spinel_prop_key_t key)
{
const uint8_t *ptr(NULL);
uint8_t len(0);
ptr = otThreadGetMasterKey(mInstance, &len);
return SendPropertyUpdate(
header,
SPINEL_CMD_PROP_VALUE_IS,
key,
SPINEL_DATATYPE_DATA_S,
ptr,
len
otThreadGetMasterKey(mInstance)->m8,
OT_MASTER_KEY_SIZE
);
}
@@ -4435,9 +4430,9 @@ ThreadError NcpBase::SetPropertyHandler_NET_MASTER_KEY(uint8_t header, spinel_pr
&len
);
if ((parsedLength > 0) && (len < 100))
if ((parsedLength > 0) && (len == OT_MASTER_KEY_SIZE))
{
errorCode = otThreadSetMasterKey(mInstance, ptr, static_cast<uint8_t>(len));
errorCode = otThreadSetMasterKey(mInstance, reinterpret_cast<const otMasterKey *>(ptr));
if (errorCode == kThreadError_None)
{