Skip to content

Changes for migration from Provisioning 1.0 to Provisioning 2.0 #547

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions .github/workflows/compile-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ jobs:
- name: Blues Wireless Notecard
- name: ArduinoBLE
- name: Arduino_KVStore
- name: Arduino_NetworkConfigurator
- source-url: https://github.com/arduino-libraries/Arduino_NetworkConfigurator.git
version: c7c6f9d4973222c1126ac3e73959e20870102c1f
sketch-paths: |
- examples/ArduinoIoTCloud-NetConfig
- examples/ArduinoIoTCloud-DeferredOTA
Expand All @@ -213,7 +214,8 @@ jobs:
- name: Blues Wireless Notecard
- name: ArduinoBLE
- name: Arduino_KVStore
- name: Arduino_NetworkConfigurator
- source-url: https://github.com/arduino-libraries/Arduino_NetworkConfigurator.git
version: c7c6f9d4973222c1126ac3e73959e20870102c1f
sketch-paths: |
- examples/ArduinoIoTCloud-NetConfig
- examples/ArduinoIoTCloud-DeferredOTA
Expand All @@ -232,7 +234,8 @@ jobs:
- name: Blues Wireless Notecard
- name: ArduinoBLE
- name: Arduino_KVStore
- name: Arduino_NetworkConfigurator
- source-url: https://github.com/arduino-libraries/Arduino_NetworkConfigurator.git
version: c7c6f9d4973222c1126ac3e73959e20870102c1f
sketch-paths: |
- examples/ArduinoIoTCloud-NetConfig
- examples/ArduinoIoTCloud-DeferredOTA
Expand All @@ -251,7 +254,8 @@ jobs:
- name: Blues Wireless Notecard
- name: ArduinoBLE
- name: Arduino_KVStore
- name: Arduino_NetworkConfigurator
- source-url: https://github.com/arduino-libraries/Arduino_NetworkConfigurator.git
version: c7c6f9d4973222c1126ac3e73959e20870102c1f
sketch-paths: |
- examples/ArduinoIoTCloud-NetConfig
- examples/ArduinoIoTCloud-DeferredOTA
Expand All @@ -269,7 +273,8 @@ jobs:
- name: Blues Wireless Notecard
- name: ArduinoBLE
- name: Arduino_KVStore
- name: Arduino_NetworkConfigurator
- source-url: https://github.com/arduino-libraries/Arduino_NetworkConfigurator.git
version: c7c6f9d4973222c1126ac3e73959e20870102c1f
sketch-paths: |
- examples/ArduinoIoTCloud-NetConfig
- examples/ArduinoIoTCloud-Notecard
Expand All @@ -285,7 +290,8 @@ jobs:
- name: Blues Wireless Notecard
- name: ArduinoBLE
- name: Arduino_KVStore
- name: Arduino_NetworkConfigurator
- source-url: https://github.com/arduino-libraries/Arduino_NetworkConfigurator.git
version: c7c6f9d4973222c1126ac3e73959e20870102c1f
sketch-paths: |
- examples/ArduinoIoTCloud-NetConfig
- examples/ArduinoIoTCloud-Notecard
Expand Down
38 changes: 34 additions & 4 deletions examples/utility/Provisioning_2.0/ClaimingHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void ClaimingHandlerClass::getIdReqHandler() {
idMsg.m.uhwid = _uhwidBytes;
_agentManager.sendMsg(idMsg);

String token = getAIoTCloudJWT(*_secureElement, *_uhwid, _ts, 1);
String token = generateToken();
if (token == "") {
DEBUG_ERROR("CH::%s Error: token not created", __FUNCTION__);
sendStatus(StatusMessage::ERROR);
Expand All @@ -112,6 +112,19 @@ void ClaimingHandlerClass::getIdReqHandler() {
jwtMsg.m.jwt = token.c_str();
_agentManager.sendMsg(jwtMsg);
_ts = 0;

SElementJWS sejws;
String publicKey = sejws.publicKey(*_secureElement, 1, false);
if (publicKey == "") {
DEBUG_ERROR("CH::%s Error: public key not created", __FUNCTION__);
sendStatus(StatusMessage::ERROR);
return;
}

//Send public key
ProvisioningOutputMessage publicKeyMsg = {MessageOutputType::PROV_PUBLIC_KEY};
publicKeyMsg.m.provPublicKey = publicKey.c_str();
_agentManager.sendMsg(publicKeyMsg);
} else {
DEBUG_ERROR("CH::%s Error: timestamp not provided" , __FUNCTION__);
sendStatus(StatusMessage::PARAMS_NOT_FOUND);
Expand Down Expand Up @@ -186,7 +199,24 @@ void ClaimingHandlerClass::getProvSketchVersionRequestCb() {
_receivedEvent = ClaimingReqEvents::GET_PROV_SKETCH_VERSION;
}

bool ClaimingHandlerClass::sendStatus(StatusMessage msg) {
ProvisioningOutputMessage statusMsg = { MessageOutputType::STATUS, { msg } };
return _agentManager.sendMsg(statusMsg);
String ClaimingHandlerClass::generateToken()
{
String token = getAIoTCloudJWT(*_secureElement, *_uhwid, _ts, 1);
if(token == "") {
byte publicKey[64];
DEBUG_INFO("Generating private key");
if(!_secureElement->generatePrivateKey(1, publicKey)){
DEBUG_ERROR("CH::%s Error: private key generation failed", __FUNCTION__);
return "";
}
token = getAIoTCloudJWT(*_secureElement, *_uhwid, _ts, 1);
}

return token;
}

bool ClaimingHandlerClass::sendStatus(StatusMessage msg)
{
ProvisioningOutputMessage statusMsg = {MessageOutputType::STATUS, {msg}};
return _agentManager.sendMsg(statusMsg);
}
1 change: 1 addition & 0 deletions examples/utility/Provisioning_2.0/ClaimingHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class ClaimingHandlerClass {
LEDFeedbackClass &_ledFeedback;
static inline uint64_t _ts;
SecureElement *_secureElement;
String generateToken();

bool sendStatus(StatusMessage msg);
/* Commands handlers */
Expand Down