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

Commit 7f72212

Browse files
committed
Added Operational Device Credentials Generation Function for the Weave Device Layer.
-- If needed, this function is called early during Weave stack initialization to provision device with initial set of operational credentials. -- In a special case, when device doesn't have operational credentials but it is already paired to account, a flag will be set that manufacturer-assigned credentials should be used as operational credentials.
1 parent efbed8f commit 7f72212

File tree

6 files changed

+294
-86
lines changed

6 files changed

+294
-86
lines changed

src/adaptations/device-layer/DeviceControlServer.cpp

100644100755
Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,11 @@ WEAVE_ERROR DeviceControlServer::OnResetConfig(uint16_t resetFlags)
7474
// service provisioning data, if present.
7575
if (((resetFlags & kResetConfigFlag_ServiceConfig) != 0)
7676
#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)
77+
// Service config and operational credentials are closely corelated:
78+
// 1. Reset service config when requested to clear operational credentials.
79+
// 2. Clear and generate new operational credentials when requested to reset
80+
// service config.
81+
|| ((resetFlags & kResetConfigFlag_OperationalCredentials) != 0)
8082
#endif // WEAVE_DEVICE_CONFIG_ENABLE_JUST_IN_TIME_PROVISIONING
8183
)
8284
{
@@ -116,21 +118,6 @@ WEAVE_ERROR DeviceControlServer::OnResetConfig(uint16_t resetFlags)
116118
ThreadStackMgr().ClearThreadProvision();
117119
#endif // WEAVE_DEVICE_CONFIG_ENABLE_THREAD
118120
}
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
134121
}
135122

136123
return err;

src/adaptations/device-layer/include/Weave/DeviceLayer/ConfigurationManager.h

100644100755
Lines changed: 12 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,6 @@ class ConfigurationManager
9696
WEAVE_ERROR StoreManufacturingDate(const char * mfgDate, size_t mfgDateLen);
9797
WEAVE_ERROR StoreProductRevision(uint16_t productRev);
9898
WEAVE_ERROR StoreFabricId(uint64_t fabricId);
99-
#if WEAVE_DEVICE_CONFIG_ENABLE_JUST_IN_TIME_PROVISIONING
100-
WEAVE_ERROR StoreDeviceId(uint64_t deviceId);
101-
WEAVE_ERROR StoreDeviceCertificate(const uint8_t * cert, size_t certLen);
102-
WEAVE_ERROR StoreDeviceIntermediateCACerts(const uint8_t * certs, size_t certsLen);
103-
WEAVE_ERROR StoreDevicePrivateKey(const uint8_t * key, size_t keyLen);
104-
#endif
10599
WEAVE_ERROR StoreManufacturerDeviceId(uint64_t deviceId);
106100
WEAVE_ERROR StoreManufacturerDeviceCertificate(const uint8_t * cert, size_t certLen);
107101
WEAVE_ERROR StoreManufacturerDeviceIntermediateCACerts(const uint8_t * certs, size_t certsLen);
@@ -124,9 +118,6 @@ class ConfigurationManager
124118
bool IsPairedToAccount();
125119
bool IsMemberOfFabric();
126120
bool IsFullyProvisioned();
127-
#if WEAVE_DEVICE_CONFIG_ENABLE_JUST_IN_TIME_PROVISIONING
128-
bool OperationalDeviceCredentialsProvisioned();
129-
#endif
130121

131122
void InitiateFactoryReset();
132123

@@ -155,7 +146,9 @@ class ConfigurationManager
155146
WEAVE_ERROR ReadPersistedStorageValue(::nl::Weave::Platform::PersistedStorage::Key key, uint32_t & value);
156147
WEAVE_ERROR WritePersistedStorageValue(::nl::Weave::Platform::PersistedStorage::Key key, uint32_t value);
157148
#if WEAVE_DEVICE_CONFIG_ENABLE_JUST_IN_TIME_PROVISIONING
158-
WEAVE_ERROR ClearOperationalDeviceCredentials(void);
149+
WEAVE_ERROR GenerateOperationalDeviceCredentials(void);
150+
WEAVE_ERROR StoreOperationalDeviceCertificates(const uint8_t * cert, size_t certLen, const uint8_t * icaCerts, size_t icaCertsLen);
151+
bool AreOperationalDeviceCredentialsProvisioned(void);
159152
void UseManufacturerCredentialsAsOperational(bool val);
160153
#endif
161154

@@ -355,30 +348,6 @@ inline WEAVE_ERROR ConfigurationManager::StoreFabricId(uint64_t fabricId)
355348
return static_cast<ImplClass*>(this)->_StoreFabricId(fabricId);
356349
}
357350

358-
#if WEAVE_DEVICE_CONFIG_ENABLE_JUST_IN_TIME_PROVISIONING
359-
360-
inline WEAVE_ERROR ConfigurationManager::StoreDeviceId(uint64_t deviceId)
361-
{
362-
return static_cast<ImplClass*>(this)->_StoreDeviceId(deviceId);
363-
}
364-
365-
inline WEAVE_ERROR ConfigurationManager::StoreDeviceCertificate(const uint8_t * cert, size_t certLen)
366-
{
367-
return static_cast<ImplClass*>(this)->_StoreDeviceCertificate(cert, certLen);
368-
}
369-
370-
inline WEAVE_ERROR ConfigurationManager::StoreDeviceIntermediateCACerts(const uint8_t * certs, size_t certsLen)
371-
{
372-
return static_cast<ImplClass*>(this)->_StoreDeviceIntermediateCACerts(certs, certsLen);
373-
}
374-
375-
inline WEAVE_ERROR ConfigurationManager::StoreDevicePrivateKey(const uint8_t * key, size_t keyLen)
376-
{
377-
return static_cast<ImplClass*>(this)->_StoreDevicePrivateKey(key, keyLen);
378-
}
379-
380-
#endif // WEAVE_DEVICE_CONFIG_ENABLE_JUST_IN_TIME_PROVISIONING
381-
382351
inline WEAVE_ERROR ConfigurationManager::StoreManufacturerDeviceId(uint64_t deviceId)
383352
{
384353
return static_cast<ImplClass*>(this)->_StoreManufacturerDeviceId(deviceId);
@@ -521,14 +490,19 @@ inline WEAVE_ERROR ConfigurationManager::SetFailSafeArmed(bool val)
521490

522491
#if WEAVE_DEVICE_CONFIG_ENABLE_JUST_IN_TIME_PROVISIONING
523492

524-
inline bool ConfigurationManager::OperationalDeviceCredentialsProvisioned()
493+
inline WEAVE_ERROR ConfigurationManager::GenerateOperationalDeviceCredentials(void)
494+
{
495+
return static_cast<ImplClass*>(this)->_GenerateOperationalDeviceCredentials();
496+
}
497+
498+
inline WEAVE_ERROR ConfigurationManager::StoreOperationalDeviceCertificates(const uint8_t * cert, size_t certLen, const uint8_t * icaCerts, size_t icaCertsLen)
525499
{
526-
return static_cast<ImplClass*>(this)->_OperationalDeviceCredentialsProvisioned();
500+
return static_cast<ImplClass*>(this)->_StoreOperationalDeviceCertificates(cert, certLen, icaCerts, icaCertsLen);
527501
}
528502

529-
inline WEAVE_ERROR ConfigurationManager::ClearOperationalDeviceCredentials(void)
503+
inline bool ConfigurationManager::AreOperationalDeviceCredentialsProvisioned()
530504
{
531-
return static_cast<ImplClass*>(this)->_ClearOperationalDeviceCredentials();
505+
return static_cast<ImplClass*>(this)->_AreOperationalDeviceCredentialsProvisioned();
532506
}
533507

534508
inline void ConfigurationManager::UseManufacturerCredentialsAsOperational(bool val)

src/adaptations/device-layer/include/Weave/DeviceLayer/WeaveDeviceConfig.h

100644100755
File mode changed.

src/adaptations/device-layer/include/Weave/DeviceLayer/internal/GenericConfigurationManagerImpl.h

100644100755
Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,6 @@ class GenericConfigurationManagerImpl
7070
WEAVE_ERROR _GetDeviceCertificate(uint8_t * buf, size_t bufSize, size_t & certLen);
7171
WEAVE_ERROR _GetDeviceIntermediateCACerts(uint8_t * buf, size_t bufSize, size_t & certsLen);
7272
WEAVE_ERROR _GetDevicePrivateKey(uint8_t * buf, size_t bufSize, size_t & keyLen);
73-
#if WEAVE_DEVICE_CONFIG_ENABLE_JUST_IN_TIME_PROVISIONING
74-
WEAVE_ERROR _StoreDeviceId(uint64_t deviceId);
75-
WEAVE_ERROR _StoreDeviceCertificate(const uint8_t * cert, size_t certLen);
76-
WEAVE_ERROR _StoreDeviceIntermediateCACerts(const uint8_t * certs, size_t certsLen);
77-
WEAVE_ERROR _StoreDevicePrivateKey(const uint8_t * key, size_t keyLen);
78-
WEAVE_ERROR _ClearOperationalDeviceCredentials(void);
79-
#endif
8073
WEAVE_ERROR _GetManufacturerDeviceId(uint64_t & deviceId);
8174
WEAVE_ERROR _StoreManufacturerDeviceId(uint64_t deviceId);
8275
WEAVE_ERROR _GetManufacturerDeviceCertificate(uint8_t * buf, size_t bufSize, size_t & certLen);
@@ -110,7 +103,9 @@ class GenericConfigurationManagerImpl
110103
bool _IsFullyProvisioned();
111104
WEAVE_ERROR _ComputeProvisioningHash(uint8_t * hashBuf, size_t hashBufSize);
112105
#if WEAVE_DEVICE_CONFIG_ENABLE_JUST_IN_TIME_PROVISIONING
113-
bool _OperationalDeviceCredentialsProvisioned();
106+
WEAVE_ERROR _GenerateOperationalDeviceCredentials(void);
107+
WEAVE_ERROR _StoreOperationalDeviceCertificates(const uint8_t * cert, size_t certLen, const uint8_t * icaCerts, size_t icaCertsLen);
108+
bool _AreOperationalDeviceCredentialsProvisioned(void);
114109
void _UseManufacturerCredentialsAsOperational(bool val);
115110
#endif
116111

@@ -121,22 +116,37 @@ class GenericConfigurationManagerImpl
121116
kFlag_IsServiceProvisioned = 0x01,
122117
kFlag_IsMemberOfFabric = 0x02,
123118
kFlag_IsPairedToAccount = 0x04,
124-
kFlag_OperationalDeviceCredentialsProvisioned = 0x08,
125-
kFlag_UseManufacturerCredentialsAsOperational = 0x10,
119+
kFlag_UseManufacturerCredentialsAsOperational = 0x08,
126120
};
127121

128122
uint8_t mFlags;
129123

130124
void LogDeviceConfig();
131125
WEAVE_ERROR PersistProvisioningData(ProvisioningDataSet & provData);
132126

127+
#if WEAVE_DEVICE_CONFIG_ENABLE_JUST_IN_TIME_PROVISIONING
128+
WEAVE_ERROR StoreDeviceCertificate(const uint8_t * cert, size_t certLen);
129+
WEAVE_ERROR StoreDevicePrivateKey(const uint8_t * key, size_t keyLen);
130+
131+
// These methods can be overridden by the platform/product specific implementations
132+
// that support secure environment or secure element for secure processing, handling,
133+
// and potentially secure storage of a device private key.
134+
WEAVE_ERROR GenerateOperationalDevicePrivateKey(EncodedECPublicKey& pubKey);
135+
static WEAVE_ERROR GenerateOperationalDeviceECDSASignature(const uint8_t *hash, uint8_t hashLen, EncodedECDSASignature& ecdsaSig);
136+
#endif
137+
133138
private:
134139

135140
ImplClass * Impl() { return static_cast<ImplClass *>(this); }
136141

137142
static void HashLengthAndBase64Value(Platform::Security::SHA256 & hash, const uint8_t * val, uint16_t valLen);
138143

139144
#if WEAVE_DEVICE_CONFIG_ENABLE_JUST_IN_TIME_PROVISIONING
145+
WEAVE_ERROR StoreDeviceId(uint64_t deviceId);
146+
WEAVE_ERROR StoreDeviceIntermediateCACerts(const uint8_t * certs, size_t certsLen);
147+
WEAVE_ERROR GenerateOperationalDeviceId(void);
148+
WEAVE_ERROR GenerateOperationalDeviceCertificate(EncodedECPublicKey& pubKey);
149+
WEAVE_ERROR GenerateOperationalDeviceCertificateAndPrivateKey(void);
140150
bool UseManufacturerCredentialsAsOperational();
141151
#endif
142152
};

0 commit comments

Comments
 (0)