Skip to content

Commit 5e0e737

Browse files
authored
Merge pull request #3 from pennam/provisioning-id
Add primitives to compute provisioningID
2 parents 8299fa9 + 6bcbda8 commit 5e0e737

20 files changed

+993
-0
lines changed

examples/boardID/boardID.ino

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
This file is part of the Arduino_CloudUtils library.
3+
4+
Copyright (c) 2024 Arduino SA
5+
6+
This Source Code Form is subject to the terms of the Mozilla Public
7+
License, v. 2.0. If a copy of the MPL was not distributed with this
8+
file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
*/
10+
11+
#include <Arduino_BPId.h>
12+
13+
void setup() {
14+
Serial.begin(9600);
15+
while (!Serial);
16+
17+
#ifdef ARDUINO_OPTA
18+
Ethernet.begin(NULL,0,0);
19+
#endif
20+
21+
}
22+
23+
void loop() {
24+
Serial.println(arduino::bpid::get());
25+
delay(2000);
26+
}

examples/sha256/buffer.h

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#pragma once
2+
3+
/*
4+
* The following buffer is an hex dump of 1k of random data generated as
5+
* head -c 1k /dev/urandom > /tmp/test
6+
* and dumped with the following command `hexdump extras/test/test_files/test-1k -e '32/1 "0x%02X, ""\n"'`
7+
* The SHA256 is known 1a7004279b162a6321de07de9d0362a66833b16f9acf870a69331e219eeafc7c /tmp/test
8+
*/
9+
10+
uint8_t buffer[] = {
11+
0x58, 0x1A, 0x10, 0xDD, 0x00, 0xBE, 0xE1, 0x2B, 0xE5, 0xA9, 0x62, 0xAF, 0x59, 0x66, 0x9C, 0x84, 0x50, 0x91, 0x30, 0x8E, 0x8F, 0xE4, 0x82, 0xE7, 0xDA, 0x9F, 0x90, 0x7A, 0xA2, 0x78, 0xCF, 0x7D,
12+
0x40, 0x0E, 0x15, 0x5D, 0x2E, 0xF8, 0x6F, 0xA2, 0xEC, 0x50, 0xF1, 0xC9, 0x20, 0x71, 0xB9, 0xB7, 0xE8, 0x54, 0x06, 0x9E, 0x9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, 0x94, 0xF4, 0x70, 0x94, 0xF3, 0x25,
41+
0xA5, 0x42, 0xC5, 0x2E, 0xD3, 0x09, 0xF1, 0x3B, 0x8E, 0x6C, 0x30, 0x29, 0xD0, 0xD4, 0x62, 0x8C, 0xA3, 0x40, 0x21, 0xFA, 0x93, 0x0E, 0x48, 0x81, 0x20, 0x32, 0x1D, 0xF7, 0xD5, 0xF4, 0x50, 0x64,
42+
0x68, 0x15, 0x98, 0xFF, 0x3B, 0xD9, 0x64, 0x50, 0x9C, 0x74, 0x0C, 0x25, 0x1E, 0xED, 0xFF, 0x87, 0x84, 0x0B, 0x6D, 0x0F, 0xF3, 0x5E, 0xF9, 0xB6, 0x84, 0x6E, 0x3D, 0xF4, 0x00, 0x37, 0x4D, 0x68,
43+
};

examples/sha256/sha256.ino

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
This file is part of the Arduino_CloudUtils library.
3+
4+
Copyright (c) 2024 Arduino SA
5+
6+
This Source Code Form is subject to the terms of the Mozilla Public
7+
License, v. 2.0. If a copy of the MPL was not distributed with this
8+
file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
*/
10+
11+
#include <Arduino_SHA256.h>
12+
#include "buffer.h"
13+
14+
void setup() {
15+
Serial.begin(9600);
16+
while(!Serial);
17+
18+
uint8_t sha[SHA256::HASH_SIZE];
19+
20+
SHA256 sha256;
21+
sha256.begin();
22+
sha256.update(buffer, sizeof(buffer));
23+
sha256.finalize(sha);
24+
25+
Serial.println(hexEncode(sha, sizeof(sha)));
26+
27+
/* One-shot */
28+
arduino::sha256::oneshot(buffer, sizeof(buffer), sha);
29+
Serial.println(hexEncode(sha, sizeof(sha)));
30+
}
31+
32+
static String hexEncode(uint8_t* in, uint32_t size) {
33+
String out;
34+
out.reserve((size * 2) + 1);
35+
36+
char* ptr = out.begin();
37+
for (uint32_t i = 0; i < size; i++) {
38+
ptr += sprintf(ptr, "%02X", in[i]);
39+
}
40+
return String(out.c_str());
41+
}
42+
43+
void loop() { }

src/Arduino_BPId.h

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
This file is part of the Arduino_CloudUtils library.
3+
4+
Copyright (c) 2024 Arduino SA
5+
6+
This Source Code Form is subject to the terms of the Mozilla Public
7+
License, v. 2.0. If a copy of the MPL was not distributed with this
8+
file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
*/
10+
#pragma once
11+
12+
#include "./bpid/bpid.h"

src/Arduino_HEX.h

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
This file is part of the Arduino_CloudUtils library.
3+
4+
Copyright (c) 2024 Arduino SA
5+
6+
This Source Code Form is subject to the terms of the Mozilla Public
7+
License, v. 2.0. If a copy of the MPL was not distributed with this
8+
file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
*/
10+
#pragma once
11+
12+
#include "./hex/hex.h"

src/Arduino_SHA256.h

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
This file is part of the Arduino_CloudUtils library.
3+
4+
Copyright (c) 2024 Arduino SA
5+
6+
This Source Code Form is subject to the terms of the Mozilla Public
7+
License, v. 2.0. If a copy of the MPL was not distributed with this
8+
file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
*/
10+
#pragma once
11+
12+
#include "./sha256/SHA256.h"

src/bpid/bpid.cpp

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
This file is part of the Arduino_CloudUtils library.
3+
4+
Copyright (c) 2024 Arduino SA
5+
6+
This Source Code Form is subject to the terms of the Mozilla Public
7+
License, v. 2.0. If a copy of the MPL was not distributed with this
8+
file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
*/
10+
11+
#include "bpid.h"
12+
#include "../sha256/SHA256.h"
13+
#include "../hex/hex.h"
14+
15+
namespace arduino { namespace bpid {
16+
17+
bool get(uint8_t* in, uint32_t size) {
18+
if (size < BOARD_PROVISIONING_ID_SIZE) {
19+
return false;
20+
}
21+
uint8_t offset = 0;
22+
if (!arduino::ucid::get(&in[offset], size)) {
23+
return false;
24+
}
25+
offset += arduino::ucid::UC_UID_SIZE;
26+
if (!arduino::mac::get(&in[offset], size - offset)) {
27+
return false;
28+
}
29+
offset += arduino::mac::IFACE_MAC_SIZE;
30+
if (!arduino::csn::get(&in[offset], size - offset)) {
31+
return false;
32+
}
33+
return true;
34+
}
35+
36+
String get() {
37+
uint8_t data[BOARD_PROVISIONING_ID_SIZE];
38+
if (!get(data, sizeof(data))) {
39+
return String("");
40+
}
41+
uint8_t out[SHA256::HASH_SIZE];
42+
arduino::sha256::oneshot(data, sizeof(data), out);
43+
return arduino::hex::encode(out, sizeof(out));
44+
}
45+
46+
}} // arduino::bpid

src/bpid/bpid.h

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
This file is part of the Arduino_CloudUtils library.
3+
4+
Copyright (c) 2024 Arduino SA
5+
6+
This Source Code Form is subject to the terms of the Mozilla Public
7+
License, v. 2.0. If a copy of the MPL was not distributed with this
8+
file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
*/
10+
11+
#pragma once
12+
13+
#include <Arduino.h>
14+
#include "ucid.h"
15+
#include "mac.h"
16+
#include "csn.h"
17+
18+
namespace arduino { namespace bpid {
19+
/*
20+
* This library contains the methods to get board provisioning id
21+
*/
22+
23+
constexpr int BOARD_PROVISIONING_ID_SIZE = arduino::ucid::UC_UID_SIZE +
24+
arduino::mac::IFACE_MAC_SIZE +
25+
arduino::csn::CRYPTO_SN_SIZE;
26+
27+
bool get(uint8_t* in, uint32_t size);
28+
String get();
29+
30+
}} // arduino::bpid

src/bpid/csn.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
This file is part of the Arduino_CloudUtils library.
3+
4+
Copyright (c) 2024 Arduino SA
5+
6+
This Source Code Form is subject to the terms of the Mozilla Public
7+
License, v. 2.0. If a copy of the MPL was not distributed with this
8+
file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
*/
10+
11+
#include "csn.h"
12+
13+
namespace arduino { namespace csn {
14+
15+
bool get(uint8_t *in, uint32_t size) {
16+
if (size < CRYPTO_SN_SIZE) {
17+
return false;
18+
}
19+
SecureElement se;
20+
if (!se.begin() || !se.serialNumber(in)) {
21+
return false;
22+
}
23+
return true;
24+
}
25+
26+
}} // arduino::csn

src/bpid/csn.h

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
This file is part of the Arduino_CloudUtils library.
3+
4+
Copyright (c) 2024 Arduino SA
5+
6+
This Source Code Form is subject to the terms of the Mozilla Public
7+
License, v. 2.0. If a copy of the MPL was not distributed with this
8+
file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
*/
10+
11+
#pragma once
12+
13+
#include <Arduino.h>
14+
#include <Arduino_SecureElement.h>
15+
16+
namespace arduino { namespace csn {
17+
/*
18+
* This library contains the methods to get board microcontroller id
19+
*/
20+
21+
#if defined(ARDUINO_NANO_RP2040_CONNECT) || \
22+
defined(ARDUINO_SAMD_MKRWIFI1010) || \
23+
defined(ARDUINO_SAMD_NANO_33_IOT) || \
24+
defined(ARDUINO_PORTENTA_H7_M7) || \
25+
defined(ARDUINO_OPTA) || \
26+
defined(ARDUINO_GIGA)
27+
constexpr int CRYPTO_SN_SIZE = 9;
28+
#elif defined(ARDUINO_PORTENTA_C33) || \
29+
defined(ARDUINO_NICLA_VISION)
30+
constexpr int CRYPTO_SN_SIZE = SE05X_SN_LENGTH;
31+
#elif defined(ARDUINO_UNOR4_WIFI)
32+
constexpr int CRYPTO_SN_SIZE = 6;
33+
#else
34+
#error "Unknown board"
35+
#endif
36+
37+
bool get(uint8_t *in, uint32_t size);
38+
39+
}} // arduino::csn

src/bpid/mac.cpp

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
This file is part of the Arduino_CloudUtils library.
3+
4+
Copyright (c) 2024 Arduino SA
5+
6+
This Source Code Form is subject to the terms of the Mozilla Public
7+
License, v. 2.0. If a copy of the MPL was not distributed with this
8+
file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
*/
10+
11+
#include "mac.h"
12+
13+
namespace arduino { namespace mac {
14+
15+
bool get(uint8_t *in, uint32_t size) {
16+
if (size < IFACE_MAC_SIZE) {
17+
return false;
18+
}
19+
#if defined(ARDUINO_SAMD_MKRWIFI1010) || \
20+
defined(ARDUINO_SAMD_NANO_33_IOT)
21+
WiFi.macAddress(in);
22+
#elif defined(ARDUINO_PORTENTA_H7_M7) || \
23+
defined(ARDUINO_NICLA_VISION) || \
24+
defined(ARDUINO_GIGA)
25+
WiFi.macAddress(in);
26+
#elif defined(ARDUINO_PORTENTA_C33) || \
27+
defined(ARDUINO_UNOR4_WIFI)
28+
WiFi.macAddress(in);
29+
#elif defined(ARDUINO_NANO_RP2040_CONNECT)
30+
WiFi.macAddress(in);
31+
#elif defined(ARDUINO_OPTA)
32+
Ethernet.MACAddress(in);
33+
#endif
34+
return true;
35+
}
36+
37+
}} // arduino::mac

src/bpid/mac.h

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
This file is part of the Arduino_CloudUtils library.
3+
4+
Copyright (c) 2024 Arduino SA
5+
6+
This Source Code Form is subject to the terms of the Mozilla Public
7+
License, v. 2.0. If a copy of the MPL was not distributed with this
8+
file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
*/
10+
11+
#pragma once
12+
13+
#if defined(ARDUINO_NANO_RP2040_CONNECT) || \
14+
defined(ARDUINO_SAMD_MKRWIFI1010) || \
15+
defined(ARDUINO_SAMD_NANO_33_IOT) || \
16+
defined(ARDUINO_PORTENTA_H7_M7) || \
17+
defined(ARDUINO_NICLA_VISION) || \
18+
defined(ARDUINO_GIGA)
19+
#include <WiFi.h>
20+
#define IFACE_MAC_ADDR_LENGTH WL_MAC_ADDR_LENGTH
21+
#elif defined(ARDUINO_PORTENTA_C33)
22+
#include <WiFiC3.h>
23+
#define IFACE_MAC_ADDR_LENGTH WL_MAC_ADDR_LENGTH
24+
#elif defined(ARDUINO_UNOR4_WIFI)
25+
#include <WiFi.h>
26+
#define IFACE_MAC_ADDR_LENGTH WL_MAC_ADDR_LENGTH
27+
#elif defined(ARDUINO_OPTA)
28+
#include <Ethernet.h>
29+
#define IFACE_MAC_ADDR_LENGTH 6
30+
#else
31+
#error "Unknown board"
32+
#endif
33+
34+
namespace arduino { namespace mac {
35+
/*
36+
* This library contains the methods to get board mac address
37+
* ARDUINO_NANO_RP2040_CONNECT: reversed
38+
* ARDUINO_SAMD_MKRWIFI1010: reversed
39+
* ARDUINO_SAMD_NANO_33_IOT: reversed
40+
* ARDUINO_PORTENTA_H7_M7: WiFi.setTimeout(0);WiFi.begin("In33dm4c4ddr35", "In33dm4c4ddr35", ENC_TYPE_TKIP) reversed
41+
* ARDUINO_NICLA_VISION:
42+
* ARDUINO_GIGA:
43+
* ARDUINO_PORTENTA_C33: Interface.begin() not reversed
44+
* ARDUINO_UNOR4_WIFI: not reversed
45+
* ARDUINO_OPTA: Ethernet.begin(NULL,0,0); reversed
46+
*/
47+
48+
constexpr int IFACE_MAC_SIZE = IFACE_MAC_ADDR_LENGTH;
49+
50+
bool get(uint8_t *in, uint32_t size);
51+
52+
}} // arduino::mac

0 commit comments

Comments
 (0)