@@ -13,10 +13,10 @@ export const provisioningSketch = {
13
13
#include <ArduinoBearSSL.h>
14
14
#include <ArduinoECCX08.h>
15
15
16
- const int keySlot = 0;
17
- const int compressedCertSlot = 10;
18
- const int serialNumberSlot = 11;
19
- const int thingIdSlot = 12;
16
+ const int keySlot = 0;
17
+ const int compressedCertSlot = 10;
18
+ const int serialNumberAndAuthorityKeyIdentifierSlot = 11;
19
+ const int thingIdSlot = 12;
20
20
21
21
void setup() {
22
22
Serial.begin(9600);
@@ -63,7 +63,8 @@ void setup() {
63
63
while (1);
64
64
}
65
65
66
- ECCX08Cert.setSubjectCommonName(ECCX08.serialNumber());
66
+ String thingId = promptAndReadLine("Please enter the thing id: ");
67
+ ECCX08Cert.setSubjectCommonName(thingId);
67
68
68
69
String csr = ECCX08Cert.endCSR();
69
70
@@ -76,37 +77,37 @@ void setup() {
76
77
Serial.println();
77
78
Serial.println(csr);
78
79
79
- String thingId = promptAndReadLine("Please enter the thing id: ");
80
- String issueYear = promptAndReadLine("Please enter the issue year of the certificate (2000 - 2031): ");
81
- String issueMonth = promptAndReadLine("Please enter the issue month of the certificate (1 - 12): ");
82
- String issueDay = promptAndReadLine("Please enter the issue day of the certificate (1 - 31): ");
83
- String issueHour = promptAndReadLine("Please enter the issue hour of the certificate (0 - 23): ");
84
- String expireYears = promptAndReadLine("Please enter how many years the certificate is valid for (0 - 31): ");
85
- String serialNumber = promptAndReadLine("Please enter the certificates serial number: ");
86
- String signature = promptAndReadLine("Please enter the certificates signature: ");
87
-
88
- serialNumber.toUpperCase();
89
- signature.toUpperCase();
80
+ String issueYear = promptAndReadLine("Please enter the issue year of the certificate (2000 - 2031): ");
81
+ String issueMonth = promptAndReadLine("Please enter the issue month of the certificate (1 - 12): ");
82
+ String issueDay = promptAndReadLine("Please enter the issue day of the certificate (1 - 31): ");
83
+ String issueHour = promptAndReadLine("Please enter the issue hour of the certificate (0 - 23): ");
84
+ String expireYears = promptAndReadLine("Please enter how many years the certificate is valid for (0 - 31): ");
85
+ String serialNumber = promptAndReadLine("Please enter the certificates serial number: ");
86
+ String authorityKeyIdentifier = promptAndReadLine("Please enter the certificates authority key identifier: ");
87
+ String signature = promptAndReadLine("Please enter the certificates signature: ");
90
88
91
89
byte thingIdBytes[72];
92
90
byte serialNumberBytes[16];
91
+ byte authorityKeyIdentifierBytes[20];
93
92
byte signatureBytes[64];
94
93
95
94
thingId.getBytes(thingIdBytes, sizeof(thingIdBytes));
96
95
hexStringToBytes(serialNumber, serialNumberBytes, sizeof(serialNumberBytes));
97
- hexStringToBytes(signature, signatureBytes, 64);
96
+ hexStringToBytes(authorityKeyIdentifier, authorityKeyIdentifierBytes, sizeof(authorityKeyIdentifierBytes));
97
+ hexStringToBytes(signature, signatureBytes, sizeof(signatureBytes));
98
98
99
99
if (!ECCX08.writeSlot(thingIdSlot, thingIdBytes, sizeof(thingIdBytes))) {
100
100
Serial.println("Error storing thing id!");
101
101
while (1);
102
102
}
103
103
104
- if (!ECCX08Cert.beginStorage(compressedCertSlot, serialNumberSlot )) {
104
+ if (!ECCX08Cert.beginStorage(compressedCertSlot, serialNumberAndAuthorityKeyIdentifierSlot )) {
105
105
Serial.println("Error starting ECCX08 storage!");
106
106
while (1);
107
107
}
108
108
109
109
ECCX08Cert.setSignature(signatureBytes);
110
+ ECCX08Cert.setAuthorityKeyIdentifier(authorityKeyIdentifierBytes);
110
111
ECCX08Cert.setSerialNumber(serialNumberBytes);
111
112
ECCX08Cert.setIssueYear(issueYear.toInt());
112
113
ECCX08Cert.setIssueMonth(issueMonth.toInt());
@@ -119,7 +120,7 @@ void setup() {
119
120
while (1);
120
121
}
121
122
122
- if (!ECCX08Cert.beginReconstruction(keySlot, compressedCertSlot, serialNumberSlot )) {
123
+ if (!ECCX08Cert.beginReconstruction(keySlot, compressedCertSlot, serialNumberAndAuthorityKeyIdentifierSlot )) {
123
124
Serial.println("Error starting ECCX08 cert reconstruction!");
124
125
while (1);
125
126
}
@@ -183,8 +184,9 @@ String readLine() {
183
184
return line;
184
185
}
185
186
186
- void hexStringToBytes(const String& in, byte out[], int length) {
187
+ void hexStringToBytes(String& in, byte out[], int length) {
187
188
int inLength = in.length();
189
+ in.toUpperCase();
188
190
int outLength = 0;
189
191
190
192
for (int i = 0; i < inLength && outLength < length; i += 2) {
@@ -194,7 +196,7 @@ void hexStringToBytes(const String& in, byte out[], int length) {
194
196
byte highByte = (highChar <= '9') ? (highChar - '0') : (highChar + 10 - 'A');
195
197
byte lowByte = (lowChar <= '9') ? (lowChar - '0') : (lowChar + 10 - 'A');
196
198
197
- out[outLength++] = (highByte << 4) | lowByte;
199
+ out[outLength++] = (highByte << 4) | ( lowByte & 0xF) ;
198
200
}
199
201
}
200
202
`
0 commit comments