5
5
#include < ArduinoBearSSL.h>
6
6
#include < ArduinoECCX08.h>
7
7
8
+ const bool DEBUG = true ;
8
9
const int keySlot = 0 ;
9
10
const int compressedCertSlot = 10 ;
10
11
const int serialNumberAndAuthorityKeyIdentifierSlot = 11 ;
@@ -55,7 +56,8 @@ void setup() {
55
56
while (1 );
56
57
}
57
58
58
- ECCX08Cert.setSubjectCommonName (ECCX08.serialNumber ());
59
+ String thingId = promptAndReadLine (" Please enter the thing id: " );
60
+ ECCX08Cert.setSubjectCommonName (thingId);
59
61
60
62
String csr = ECCX08Cert.endCSR ();
61
63
@@ -68,7 +70,6 @@ void setup() {
68
70
Serial.println ();
69
71
Serial.println (csr);
70
72
71
- String thingId = promptAndReadLine (" Please enter the thing id: " );
72
73
String issueYear = promptAndReadLine (" Please enter the issue year of the certificate (2000 - 2031): " );
73
74
String issueMonth = promptAndReadLine (" Please enter the issue month of the certificate (1 - 12): " );
74
75
String issueDay = promptAndReadLine (" Please enter the issue day of the certificate (1 - 31): " );
@@ -78,9 +79,6 @@ void setup() {
78
79
String authorityKeyIdentifier = promptAndReadLine (" Please enter the certificates authority key identifier: " );
79
80
String signature = promptAndReadLine (" Please enter the certificates signature: " );
80
81
81
- serialNumber.toUpperCase ();
82
- signature.toUpperCase ();
83
-
84
82
byte thingIdBytes[72 ];
85
83
byte serialNumberBytes[16 ];
86
84
byte authorityKeyIdentifierBytes[20 ];
@@ -130,6 +128,10 @@ void setup() {
130
128
while (1 );
131
129
}
132
130
131
+ if (!DEBUG) {
132
+ return ;
133
+ }
134
+
133
135
Serial.println (" Compressed cert = " );
134
136
135
137
const byte* certData = ECCX08Cert.bytes ();
@@ -179,8 +181,9 @@ String readLine() {
179
181
return line;
180
182
}
181
183
182
- void hexStringToBytes (const String& in, byte out[], int length) {
184
+ void hexStringToBytes (String& in, byte out[], int length) {
183
185
int inLength = in.length ();
186
+ in.toUpperCase ();
184
187
int outLength = 0 ;
185
188
186
189
for (int i = 0 ; i < inLength && outLength < length; i += 2 ) {
@@ -190,6 +193,6 @@ void hexStringToBytes(const String& in, byte out[], int length) {
190
193
byte highByte = (highChar <= ' 9' ) ? (highChar - ' 0' ) : (highChar + 10 - ' A' );
191
194
byte lowByte = (lowChar <= ' 9' ) ? (lowChar - ' 0' ) : (lowChar + 10 - ' A' );
192
195
193
- out[outLength++] = (highByte << 4 ) | lowByte;
196
+ out[outLength++] = (highByte << 4 ) | ( lowByte & 0xF ) ;
194
197
}
195
198
}
0 commit comments