55#include < ArduinoBearSSL.h>
66#include < ArduinoECCX08.h>
77
8+ const bool DEBUG = true ;
89const int keySlot = 0 ;
910const int compressedCertSlot = 10 ;
1011const int serialNumberAndAuthorityKeyIdentifierSlot = 11 ;
@@ -55,7 +56,8 @@ void setup() {
5556 while (1 );
5657 }
5758
58- ECCX08Cert.setSubjectCommonName (ECCX08.serialNumber ());
59+ String thingId = promptAndReadLine (" Please enter the thing id: " );
60+ ECCX08Cert.setSubjectCommonName (thingId);
5961
6062 String csr = ECCX08Cert.endCSR ();
6163
@@ -68,7 +70,6 @@ void setup() {
6870 Serial.println ();
6971 Serial.println (csr);
7072
71- String thingId = promptAndReadLine (" Please enter the thing id: " );
7273 String issueYear = promptAndReadLine (" Please enter the issue year of the certificate (2000 - 2031): " );
7374 String issueMonth = promptAndReadLine (" Please enter the issue month of the certificate (1 - 12): " );
7475 String issueDay = promptAndReadLine (" Please enter the issue day of the certificate (1 - 31): " );
@@ -78,9 +79,6 @@ void setup() {
7879 String authorityKeyIdentifier = promptAndReadLine (" Please enter the certificates authority key identifier: " );
7980 String signature = promptAndReadLine (" Please enter the certificates signature: " );
8081
81- serialNumber.toUpperCase ();
82- signature.toUpperCase ();
83-
8482 byte thingIdBytes[72 ];
8583 byte serialNumberBytes[16 ];
8684 byte authorityKeyIdentifierBytes[20 ];
@@ -130,6 +128,10 @@ void setup() {
130128 while (1 );
131129 }
132130
131+ if (!DEBUG) {
132+ return ;
133+ }
134+
133135 Serial.println (" Compressed cert = " );
134136
135137 const byte* certData = ECCX08Cert.bytes ();
@@ -179,8 +181,9 @@ String readLine() {
179181 return line;
180182}
181183
182- void hexStringToBytes (const String& in, byte out[], int length) {
184+ void hexStringToBytes (String& in, byte out[], int length) {
183185 int inLength = in.length ();
186+ in.toUpperCase ();
184187 int outLength = 0 ;
185188
186189 for (int i = 0 ; i < inLength && outLength < length; i += 2 ) {
@@ -190,6 +193,6 @@ void hexStringToBytes(const String& in, byte out[], int length) {
190193 byte highByte = (highChar <= ' 9' ) ? (highChar - ' 0' ) : (highChar + 10 - ' A' );
191194 byte lowByte = (lowChar <= ' 9' ) ? (lowChar - ' 0' ) : (lowChar + 10 - ' A' );
192195
193- out[outLength++] = (highByte << 4 ) | lowByte;
196+ out[outLength++] = (highByte << 4 ) | ( lowByte & 0xF ) ;
194197 }
195198}
0 commit comments