Skip to content

Update provisioning sketch based on ArduinoIoTCloud library 1.6.0 #99

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

Merged
merged 14 commits into from
Aug 5, 2022
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix and cleanup certificate serial number parsing
  • Loading branch information
pennam committed Aug 4, 2022
commit 3666fec0b38cd12f43cb3ac6aa3f720f4679e42a
20 changes: 9 additions & 11 deletions firmware/provision/CryptoProvision/CryptoProvision.ino
Original file line number Diff line number Diff line change
Expand Up @@ -428,28 +428,26 @@ void processCommand() {

if (cmdCode == COMMAND::SET_CERT_SERIAL) {
// extract payload from [1] to [payloadLength]
// this will be the device_id used to generate a valid CSR
// this will be the certificate serial number included in the device certificate
Serial1.println("set CERT Serial");
byte certSerialBytes[msgLength - CRC_SIZE];
byte certSerialBytes[msgLength - CRC_SIZE - 1];

for (uint8_t i = 1; i < msgLength - CRC_SIZE; i++) {
certSerialBytes[i - 1] = payloadBuffer[i];
}

// clear device ID string
// this will be sent to the host
String certSerialString = "";
Serial1.print("Serial Number from host: ");
char charBuffer[2];
for (uint8_t i = 0; i < msgLength - CRC_SIZE - 1; i++) {
Serial1.print(certSerialBytes[i], HEX);
sprintf(charBuffer, "%02X", certSerialBytes[i]);
certSerialString += charBuffer;//String(deviceIDBytes[i], 16);
}
Serial1.println();

Serial1.println(certSerialString);

Cert.setSerialNumber(certSerialBytes, sizeof(certSerialBytes));
if(!Cert.setSerialNumber(certSerialBytes, sizeof(certSerialBytes))) {
Serial1.println("set CERT Error");
char response[] = {char(RESPONSE::RESPONSE_ERROR)};
sendData(MESSAGE_TYPE::RESPONSE, response, 1);
return;
}

char response[] = {char(RESPONSE::RESPONSE_ACK)};
sendData(MESSAGE_TYPE::RESPONSE, response, 1);
Expand Down