Skip to content

Commit 0e9bda0

Browse files
committed
improve uhwid and jwt cbor encoding
1 parent d85fa2b commit 0e9bda0

File tree

7 files changed

+12
-16
lines changed

7 files changed

+12
-16
lines changed

examples/auto-retry/provisioning.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ bool Provisioning::poll() {
7575
//Send UHWID
7676
ProvisioningOutputMessage idMsg;
7777
idMsg.type = MessageOutputType::UHWID;
78-
idMsg.m.uhwid = UHWID;
78+
idMsg.m.uhwid = (byte *) UHWID;
7979
_agentManager->sendMsg(idMsg);
8080
//Send JWT
8181
ProvisioningOutputMessage jwtMsg;

examples/provisioning/ClaimingHandler.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,11 @@ void ClaimingHandlerClass::getIdReqHandler() {
7878
sendStatus(StatusMessage::ERROR);
7979
return;
8080
}
81-
byte _uhwidBytes[33];
81+
byte _uhwidBytes[32];
8282
hexStringToBytes(*_uhwid, _uhwidBytes, _uhwid->length());
83-
_uhwidBytes[32] = '\0';
8483
//Send UHWID
8584
ProvisioningOutputMessage idMsg = {MessageOutputType::UHWID};
86-
idMsg.m.uhwid = (char *)_uhwidBytes;
85+
idMsg.m.uhwid = _uhwidBytes;
8786
_agentManager->sendMsg(idMsg);
8887
//Send JWT
8988
ProvisioningOutputMessage jwtMsg = {MessageOutputType::JWT};

src/ConfiguratorAgents/MessagesDefinitions.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include <settings/settings.h>
1313

1414
#define MAX_UHWID_SIZE 32
15-
#define MAX_JWT_SIZE 268
15+
#define MAX_JWT_SIZE 269
1616

1717
enum class StatusMessage {
1818
NONE = 0,
@@ -60,7 +60,7 @@ struct ProvisioningOutputMessage {
6060
union {
6161
StatusMessage status;
6262
const NetworkOptions *netOptions;
63-
const char *uhwid;
63+
const byte *uhwid; // Must be a pointer to a byte array of MAX_UHWID_SIZE
6464
const char *jwt;
6565
const uint8_t *BLEMacAddress;
6666
} m;

src/ConfiguratorAgents/agents/BoardConfigurationProtocol/BoardConfigurationProtocol.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ bool BoardConfigurationProtocol::sendNewMsg(ProvisioningOutputMessage &msg) {
7676
res = sendNetworkOptions(msg.m.netOptions);
7777
break;
7878
case MessageOutputType::UHWID:
79-
res = sendUhwid(msg.m.uhwid, strlen(msg.m.uhwid));
79+
res = sendUhwid(msg.m.uhwid);
8080
break;
8181
case MessageOutputType::JWT:
8282
res = sendJwt(msg.m.jwt, strlen(msg.m.jwt));
@@ -256,12 +256,8 @@ bool BoardConfigurationProtocol::sendNetworkOptions(const NetworkOptions *netOpt
256256
return res;
257257
}
258258

259-
bool BoardConfigurationProtocol::sendUhwid(const char *uhwid, size_t len) {
259+
bool BoardConfigurationProtocol::sendUhwid(const byte *uhwid) {
260260
bool res = false;
261-
if (len > MAX_UHWID_SIZE) {
262-
DEBUG_ERROR("BoardConfigurationProtocol::%s UHWID too long", __FUNCTION__);
263-
return res;
264-
}
265261

266262
size_t cborDataLen = CBOR_DATA_UHWID_LEN;
267263
uint8_t data[cborDataLen];

src/ConfiguratorAgents/agents/BoardConfigurationProtocol/BoardConfigurationProtocol.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class BoardConfigurationProtocol {
4040
bool sendStatus(StatusMessage msg);
4141
size_t calculateTotalOptionsLength(const NetworkOptions *netOptions);
4242
bool sendNetworkOptions(const NetworkOptions *netOptions);
43-
bool sendUhwid(const char *uhwid, size_t len);
43+
bool sendUhwid(const byte *uhwid);
4444
bool sendJwt(const char *jwt, size_t len);
4545
bool sendBleMacAddress(const uint8_t *mac, size_t len);
4646
TransmissionResult transmitStream();

src/ConfiguratorAgents/agents/BoardConfigurationProtocol/CBORAdapter.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
#include "cbor/MessageDecoder.h"
1212
#include <settings/settings_default.h>
1313

14-
bool CBORAdapter::uhwidToCBOR(const char *uhwid, uint8_t *data, size_t *len) {
14+
bool CBORAdapter::uhwidToCBOR(const byte *uhwid, uint8_t *data, size_t *len) {
1515
CBORMessageEncoder encoder;
1616

17-
if (*len < CBOR_DATA_UHWID_LEN || strlen(uhwid) > MAX_UHWID_SIZE) {
17+
if (*len < CBOR_DATA_UHWID_LEN) {
1818
return false;
1919
}
2020

@@ -35,6 +35,7 @@ bool CBORAdapter::jwtToCBOR(const char *jwt, uint8_t *data, size_t *len) {
3535
CBORMessageEncoder encoder;
3636

3737
if (*len < CBOR_DATA_JWT_LEN || strlen(jwt) > MAX_JWT_SIZE) {
38+
Serial.println("CBORAdapter jwtToCBOR: Invalid jwt size");
3839
return false;
3940
}
4041

src/ConfiguratorAgents/agents/BoardConfigurationProtocol/CBORAdapter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
class CBORAdapter {
2323
public:
24-
static bool uhwidToCBOR(const char *uhwid, uint8_t *data, size_t *len);
24+
static bool uhwidToCBOR(const byte *uhwid, uint8_t *data, size_t *len);
2525
static bool jwtToCBOR(const char *jwt, uint8_t *data, size_t *len);
2626
static bool BLEMacAddressToCBOR(const uint8_t *mac, uint8_t *data, size_t *len);
2727
static bool statusToCBOR(StatusMessage msg, uint8_t *data, size_t *len);

0 commit comments

Comments
 (0)