Skip to content
This repository was archived by the owner on Dec 20, 2023. It is now read-only.

Commit 83bec2e

Browse files
author
Jay Logue
authored
Merge pull request #450 from openweave/feature/emargolis/device-layer-credential-storage
Added Operational Device Credentials Support for the Weave Device Layer.
2 parents f65c034 + 60375d4 commit 83bec2e

File tree

16 files changed

+527
-90
lines changed

16 files changed

+527
-90
lines changed

src/adaptations/device-layer/DeviceControlServer.cpp

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
*
3+
* Copyright (c) 2019-2020 Google LLC.
34
* Copyright (c) 2018 Nest Labs, Inc.
45
* All rights reserved.
56
*
@@ -69,9 +70,15 @@ WEAVE_ERROR DeviceControlServer::OnResetConfig(uint16_t resetFlags)
6970

7071
else
7172
{
72-
// If a service config request has been requested, clear the persisted
73+
// If a service config reset has been requested, clear the persisted
7374
// service provisioning data, if present.
74-
if ((resetFlags & kResetConfigFlag_ServiceConfig) != 0)
75+
if (((resetFlags & kResetConfigFlag_ServiceConfig) != 0)
76+
#if WEAVE_DEVICE_CONFIG_ENABLE_JUST_IN_TIME_PROVISIONING
77+
// Always reset service provisioning data, when requested to reset operational
78+
// device credentials.
79+
|| ((resetFlags & kResetConfigFlag_OperationalCredentials) != 0)
80+
#endif // WEAVE_DEVICE_CONFIG_ENABLE_JUST_IN_TIME_PROVISIONING
81+
)
7582
{
7683
WeaveLogProgress(DeviceLayer, "Reset service config");
7784
tmpErr = ConfigurationMgr().ClearServiceProvisioningData();
@@ -109,6 +116,21 @@ WEAVE_ERROR DeviceControlServer::OnResetConfig(uint16_t resetFlags)
109116
ThreadStackMgr().ClearThreadProvision();
110117
#endif // WEAVE_DEVICE_CONFIG_ENABLE_THREAD
111118
}
119+
120+
#if WEAVE_DEVICE_CONFIG_ENABLE_JUST_IN_TIME_PROVISIONING
121+
// If the device operational credentials reset has been requested, clear
122+
// the device operational credentials, if present.
123+
if ((resetFlags & kResetConfigFlag_OperationalCredentials) != 0)
124+
{
125+
WeaveLogProgress(DeviceLayer, "Reset operational credentials");
126+
tmpErr = ConfigurationMgr().ClearOperationalDeviceCredentials();
127+
if (tmpErr != WEAVE_NO_ERROR)
128+
{
129+
WeaveLogProgress(DeviceLayer, "ConfigurationMgr().ClearOperationalDeviceCredentials() failed: %s", ErrorStr(tmpErr));
130+
err = (err == WEAVE_NO_ERROR) ? tmpErr : err;
131+
}
132+
}
133+
#endif // WEAVE_DEVICE_CONFIG_ENABLE_JUST_IN_TIME_PROVISIONING
112134
}
113135

114136
return err;
@@ -171,7 +193,8 @@ bool DeviceControlServer::IsResetAllowed(uint16_t resetFlags)
171193
}
172194

173195
const uint16_t supportedResetOps =
174-
(kResetConfigFlag_NetworkConfig | kResetConfigFlag_FabricConfig | kResetConfigFlag_ServiceConfig);
196+
(kResetConfigFlag_NetworkConfig | kResetConfigFlag_FabricConfig |
197+
kResetConfigFlag_ServiceConfig | kResetConfigFlag_OperationalCredentials);
175198

176199
// Otherwise, verify the requested reset operation is supported.
177200
return (resetFlags == kResetConfigFlag_All || (resetFlags & ~supportedResetOps) == 0);
@@ -213,5 +236,3 @@ void DeviceControlServer::OnPlatformEvent(const WeaveDeviceEvent * event)
213236
} // namespace DeviceLayer
214237
} // namespace Weave
215238
} // namespace nl
216-
217-

src/adaptations/device-layer/ESP32/ESP32Config.cpp

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
*
3+
* Copyright (c) 2019-2020 Google LLC.
34
* Copyright (c) 2018 Nest Labs, Inc.
45
* All rights reserved.
56
*
@@ -40,27 +41,32 @@ const char ESP32Config::kConfigNamespace_WeaveConfig[] = "we
4041
const char ESP32Config::kConfigNamespace_WeaveCounters[] = "weave-counters";
4142

4243
// Keys stored in the weave-factory namespace
43-
const ESP32Config::Key ESP32Config::kConfigKey_SerialNum = { kConfigNamespace_WeaveFactory, "serial-num" };
44-
const ESP32Config::Key ESP32Config::kConfigKey_DeviceId = { kConfigNamespace_WeaveFactory, "device-id" };
45-
const ESP32Config::Key ESP32Config::kConfigKey_DeviceCert = { kConfigNamespace_WeaveFactory, "device-cert" };
46-
const ESP32Config::Key ESP32Config::kConfigKey_DevicePrivateKey = { kConfigNamespace_WeaveFactory, "device-key" };
47-
const ESP32Config::Key ESP32Config::kConfigKey_ProductRevision = { kConfigNamespace_WeaveFactory, "product-rev" };
48-
const ESP32Config::Key ESP32Config::kConfigKey_ManufacturingDate = { kConfigNamespace_WeaveFactory, "mfg-date" };
49-
const ESP32Config::Key ESP32Config::kConfigKey_PairingCode = { kConfigNamespace_WeaveFactory, "pairing-code" };
44+
const ESP32Config::Key ESP32Config::kConfigKey_SerialNum = { kConfigNamespace_WeaveFactory, "serial-num" };
45+
const ESP32Config::Key ESP32Config::kConfigKey_MfrDeviceId = { kConfigNamespace_WeaveFactory, "device-id" };
46+
const ESP32Config::Key ESP32Config::kConfigKey_MfrDeviceCert = { kConfigNamespace_WeaveFactory, "device-cert" };
47+
const ESP32Config::Key ESP32Config::kConfigKey_MfrDeviceICACerts = { kConfigNamespace_WeaveFactory, "device-ca-certs" };
48+
const ESP32Config::Key ESP32Config::kConfigKey_MfrDevicePrivateKey = { kConfigNamespace_WeaveFactory, "device-key" };
49+
const ESP32Config::Key ESP32Config::kConfigKey_ProductRevision = { kConfigNamespace_WeaveFactory, "product-rev" };
50+
const ESP32Config::Key ESP32Config::kConfigKey_ManufacturingDate = { kConfigNamespace_WeaveFactory, "mfg-date" };
51+
const ESP32Config::Key ESP32Config::kConfigKey_PairingCode = { kConfigNamespace_WeaveFactory, "pairing-code" };
5052

5153
// Keys stored in the weave-config namespace
52-
const ESP32Config::Key ESP32Config::kConfigKey_FabricId = { kConfigNamespace_WeaveConfig, "fabric-id" };
53-
const ESP32Config::Key ESP32Config::kConfigKey_ServiceConfig = { kConfigNamespace_WeaveConfig, "service-config" };
54-
const ESP32Config::Key ESP32Config::kConfigKey_PairedAccountId = { kConfigNamespace_WeaveConfig, "account-id" };
55-
const ESP32Config::Key ESP32Config::kConfigKey_ServiceId = { kConfigNamespace_WeaveConfig, "service-id" };
56-
const ESP32Config::Key ESP32Config::kConfigKey_FabricSecret = { kConfigNamespace_WeaveConfig, "fabric-secret" };
57-
const ESP32Config::Key ESP32Config::kConfigKey_GroupKeyIndex = { kConfigNamespace_WeaveConfig, "group-key-index" };
58-
const ESP32Config::Key ESP32Config::kConfigKey_LastUsedEpochKeyId = { kConfigNamespace_WeaveConfig, "last-ek-id" };
59-
const ESP32Config::Key ESP32Config::kConfigKey_FailSafeArmed = { kConfigNamespace_WeaveConfig, "fail-safe-armed" };
60-
const ESP32Config::Key ESP32Config::kConfigKey_WiFiStationSecType = { kConfigNamespace_WeaveConfig, "sta-sec-type" };
54+
const ESP32Config::Key ESP32Config::kConfigKey_FabricId = { kConfigNamespace_WeaveConfig, "fabric-id" };
55+
const ESP32Config::Key ESP32Config::kConfigKey_ServiceConfig = { kConfigNamespace_WeaveConfig, "service-config" };
56+
const ESP32Config::Key ESP32Config::kConfigKey_PairedAccountId = { kConfigNamespace_WeaveConfig, "account-id" };
57+
const ESP32Config::Key ESP32Config::kConfigKey_ServiceId = { kConfigNamespace_WeaveConfig, "service-id" };
58+
const ESP32Config::Key ESP32Config::kConfigKey_FabricSecret = { kConfigNamespace_WeaveConfig, "fabric-secret" };
59+
const ESP32Config::Key ESP32Config::kConfigKey_GroupKeyIndex = { kConfigNamespace_WeaveConfig, "group-key-index" };
60+
const ESP32Config::Key ESP32Config::kConfigKey_LastUsedEpochKeyId = { kConfigNamespace_WeaveConfig, "last-ek-id" };
61+
const ESP32Config::Key ESP32Config::kConfigKey_FailSafeArmed = { kConfigNamespace_WeaveConfig, "fail-safe-armed" };
62+
const ESP32Config::Key ESP32Config::kConfigKey_WiFiStationSecType = { kConfigNamespace_WeaveConfig, "sta-sec-type" };
63+
const ESP32Config::Key ESP32Config::kConfigKey_OperationalDeviceId = { kConfigNamespace_WeaveConfig, "op-device-id" };
64+
const ESP32Config::Key ESP32Config::kConfigKey_OperationalDeviceCert = { kConfigNamespace_WeaveConfig, "op-device-cert" };
65+
const ESP32Config::Key ESP32Config::kConfigKey_OperationalDeviceICACerts = { kConfigNamespace_WeaveConfig, "op-device-ca-certs" };
66+
const ESP32Config::Key ESP32Config::kConfigKey_OperationalDevicePrivateKey = { kConfigNamespace_WeaveConfig, "op-device-key" };
6167

6268
// Prefix used for NVS keys that contain Weave group encryption keys.
63-
const char ESP32Config::kGroupKeyNamePrefix[] = "gk-";
69+
const char ESP32Config::kGroupKeyNamePrefix[] = "gk-";
6470

6571

6672
WEAVE_ERROR ESP32Config::ReadConfigValue(Key key, bool & val)
@@ -126,15 +132,15 @@ WEAVE_ERROR ESP32Config::ReadConfigValue(Key key, uint64_t & val)
126132
SuccessOrExit(err);
127133
needClose = true;
128134

129-
// Special case the DeviceId value, optionally allowing it to be read as a blob containing a 64-bit
130-
// big-endian integer, instead of a u64 value.
135+
// Special case the MfrDeviceId value, optionally allowing it to be read as a blob containing
136+
// a 64-bit big-endian integer, instead of a u64 value.
131137
//
132138
// The ESP32 development environment provides a tool for pre-populating the NVS partition using
133139
// values from a CSV file. This tool is convenient for provisioning devices during manufacturing.
134-
// However currently the tool does not support pre-populating u64 values such as DeviceId. Thus
135-
// we allow DeviceId to be stored as a blob instead.
140+
// However currently the tool does not support pre-populating u64 values such as MfrDeviceId.
141+
// Thus we allow MfrDeviceId to be stored as a blob instead.
136142
//
137-
if (key == kConfigKey_DeviceId)
143+
if (key == kConfigKey_MfrDeviceId)
138144
{
139145
uint8_t deviceIdBytes[sizeof(uint64_t)];
140146
size_t deviceIdLen = sizeof(deviceIdBytes);

src/adaptations/device-layer/GenTestDeviceIds.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2018-2019 Google, LLC.
2+
# Copyright (c) 2018-2020 Google, LLC.
33
# All rights reserved.
44
#
55
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,6 +23,7 @@
2323
preamble = '''\
2424
/*
2525
*
26+
* Copyright (c) 2019-2020 Google LLC.
2627
* Copyright (c) 2018 Nest Labs, Inc.
2728
* All rights reserved.
2829
*
@@ -39,8 +40,8 @@
3940
* limitations under the License.
4041
*/
4142
42-
#include <internal/WeaveDeviceInternal.h>
43-
#include <ConfigurationManager.h>
43+
#include <Weave/DeviceLayer/internal/WeaveDeviceInternal.h>
44+
#include <Weave/DeviceLayer/ConfigurationManager.h>
4445
4546
namespace nl {
4647
namespace Weave {
@@ -53,7 +54,26 @@
5354
5455
#if WEAVE_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY
5556
57+
const uint8_t TestDeviceIntermediateCACert[] =
58+
{
59+
0xD6, 0x00, 0x00, 0x04, 0x00, 0x04, 0x00, 0x15, 0x30, 0x01, 0x08, 0x6A, 0x76, 0xA7, 0xB9, 0x50,
60+
0x3C, 0x34, 0x7A, 0x24, 0x02, 0x05, 0x37, 0x03, 0x27, 0x13, 0x01, 0x00, 0x00, 0xEE, 0xEE, 0x30,
61+
0xB4, 0x18, 0x18, 0x26, 0x04, 0x80, 0x62, 0xA9, 0x19, 0x26, 0x05, 0x7F, 0xDE, 0x72, 0x79, 0x37,
62+
0x06, 0x27, 0x13, 0x02, 0x00, 0x00, 0xEE, 0xEE, 0x30, 0xB4, 0x18, 0x18, 0x24, 0x07, 0x02, 0x26,
63+
0x08, 0x15, 0x00, 0x5A, 0x23, 0x30, 0x0A, 0x31, 0x04, 0x3B, 0x9D, 0xC4, 0xE8, 0xCA, 0xC8, 0x33,
64+
0xA0, 0x2E, 0x7B, 0x5D, 0xB5, 0x29, 0xF4, 0xA6, 0xD5, 0xF8, 0x82, 0x26, 0x4C, 0xD2, 0xFB, 0x31,
65+
0x21, 0xE6, 0x84, 0xA5, 0x1C, 0xC9, 0x58, 0x13, 0x72, 0x36, 0x4A, 0x05, 0xA9, 0xC6, 0x27, 0x65,
66+
0xDD, 0x20, 0xDB, 0x30, 0xD4, 0x6B, 0xF8, 0xAD, 0x31, 0x35, 0x83, 0x29, 0x01, 0x29, 0x02, 0x18,
67+
0x35, 0x82, 0x29, 0x01, 0x24, 0x02, 0x60, 0x18, 0x35, 0x81, 0x30, 0x02, 0x08, 0x44, 0xE3, 0x40,
68+
0x38, 0xA9, 0xD4, 0xB5, 0xA7, 0x18, 0x35, 0x80, 0x30, 0x02, 0x08, 0x42, 0x0C, 0xAC, 0xF6, 0xB4,
69+
0x64, 0x71, 0xE6, 0x18, 0x35, 0x0C, 0x30, 0x01, 0x18, 0x57, 0x63, 0xAA, 0xD5, 0x6A, 0x91, 0xCE,
70+
0x35, 0xAB, 0x2A, 0x44, 0x77, 0x31, 0x3C, 0xBA, 0xFC, 0x77, 0x5F, 0x3E, 0xFE, 0xCB, 0xA2, 0x65,
71+
0x4B, 0x30, 0x02, 0x19, 0x00, 0xF4, 0x54, 0x79, 0x8C, 0xAA, 0x07, 0x13, 0x0B, 0xAF, 0xA8, 0x8F,
72+
0xCB, 0x0B, 0x2F, 0x80, 0x8D, 0xA3, 0x57, 0xBB, 0xC7, 0xA0, 0xFF, 0x54, 0xD5, 0x18, 0x18, 0x18,
73+
};
74+
5675
const uint16_t TestDeviceCertLength = sizeof(TestDeviceCert);
76+
const uint16_t TestDeviceIntermediateCACertLength = sizeof(TestDeviceIntermediateCACert);
5777
const uint16_t TestDevicePrivateKeyLength = sizeof(TestDevicePrivateKey);
5878
5979
#endif // WEAVE_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY

src/adaptations/device-layer/TestDeviceIds.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
*
3+
* Copyright (c) 2019-2020 Google LLC.
34
* Copyright (c) 2018 Nest Labs, Inc.
45
* All rights reserved.
56
*
@@ -8805,7 +8806,26 @@ const uint8_t TestDevicePrivateKey[] =
88058806

88068807
#if WEAVE_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY
88078808

8809+
const uint8_t TestDeviceIntermediateCACert[] =
8810+
{
8811+
0xD6, 0x00, 0x00, 0x04, 0x00, 0x04, 0x00, 0x15, 0x30, 0x01, 0x08, 0x6A, 0x76, 0xA7, 0xB9, 0x50,
8812+
0x3C, 0x34, 0x7A, 0x24, 0x02, 0x05, 0x37, 0x03, 0x27, 0x13, 0x01, 0x00, 0x00, 0xEE, 0xEE, 0x30,
8813+
0xB4, 0x18, 0x18, 0x26, 0x04, 0x80, 0x62, 0xA9, 0x19, 0x26, 0x05, 0x7F, 0xDE, 0x72, 0x79, 0x37,
8814+
0x06, 0x27, 0x13, 0x02, 0x00, 0x00, 0xEE, 0xEE, 0x30, 0xB4, 0x18, 0x18, 0x24, 0x07, 0x02, 0x26,
8815+
0x08, 0x15, 0x00, 0x5A, 0x23, 0x30, 0x0A, 0x31, 0x04, 0x3B, 0x9D, 0xC4, 0xE8, 0xCA, 0xC8, 0x33,
8816+
0xA0, 0x2E, 0x7B, 0x5D, 0xB5, 0x29, 0xF4, 0xA6, 0xD5, 0xF8, 0x82, 0x26, 0x4C, 0xD2, 0xFB, 0x31,
8817+
0x21, 0xE6, 0x84, 0xA5, 0x1C, 0xC9, 0x58, 0x13, 0x72, 0x36, 0x4A, 0x05, 0xA9, 0xC6, 0x27, 0x65,
8818+
0xDD, 0x20, 0xDB, 0x30, 0xD4, 0x6B, 0xF8, 0xAD, 0x31, 0x35, 0x83, 0x29, 0x01, 0x29, 0x02, 0x18,
8819+
0x35, 0x82, 0x29, 0x01, 0x24, 0x02, 0x60, 0x18, 0x35, 0x81, 0x30, 0x02, 0x08, 0x44, 0xE3, 0x40,
8820+
0x38, 0xA9, 0xD4, 0xB5, 0xA7, 0x18, 0x35, 0x80, 0x30, 0x02, 0x08, 0x42, 0x0C, 0xAC, 0xF6, 0xB4,
8821+
0x64, 0x71, 0xE6, 0x18, 0x35, 0x0C, 0x30, 0x01, 0x18, 0x57, 0x63, 0xAA, 0xD5, 0x6A, 0x91, 0xCE,
8822+
0x35, 0xAB, 0x2A, 0x44, 0x77, 0x31, 0x3C, 0xBA, 0xFC, 0x77, 0x5F, 0x3E, 0xFE, 0xCB, 0xA2, 0x65,
8823+
0x4B, 0x30, 0x02, 0x19, 0x00, 0xF4, 0x54, 0x79, 0x8C, 0xAA, 0x07, 0x13, 0x0B, 0xAF, 0xA8, 0x8F,
8824+
0xCB, 0x0B, 0x2F, 0x80, 0x8D, 0xA3, 0x57, 0xBB, 0xC7, 0xA0, 0xFF, 0x54, 0xD5, 0x18, 0x18, 0x18,
8825+
};
8826+
88088827
const uint16_t TestDeviceCertLength = sizeof(TestDeviceCert);
8828+
const uint16_t TestDeviceIntermediateCACertLength = sizeof(TestDeviceIntermediateCACert);
88098829
const uint16_t TestDevicePrivateKeyLength = sizeof(TestDevicePrivateKey);
88108830

88118831
#endif // WEAVE_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY

0 commit comments

Comments
 (0)