Skip to content

Commit 7b50ad3

Browse files
committed
Add ECC508 key slot CSR generation support
1 parent cbdacc4 commit 7b50ad3

File tree

3 files changed

+530
-0
lines changed

3 files changed

+530
-0
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#include <ArduinoBearSSL.h>
2+
#include <utility/ECC508.h>
3+
#include <utility/ECC508CSR.h>
4+
5+
void setup() {
6+
Serial.begin(9600);
7+
while (!Serial);
8+
9+
if (!ECC508.begin()) {
10+
Serial.println("No ECC508 present!");
11+
while (1);
12+
}
13+
14+
Serial.println("Hi there, in order to generate a new CSR for your board, we'll need the following information ...");
15+
Serial.println();
16+
17+
String country = promptAndReadLine("Country Name (2 letter code): ");
18+
String stateOrProvince = promptAndReadLine("State or Province Name (full name): ");
19+
String locality = promptAndReadLine("Locality Name (eg, city): ");
20+
String organization = promptAndReadLine("Organization Name (eg, company): ");
21+
String organizationalUnit = promptAndReadLine("Organizational Unit Name (eg, section): ");
22+
String common = promptAndReadLine("Common Name (e.g. server FQDN or YOUR name): ");
23+
String slot = promptAndReadLine("What ECC508 slots would you like to use? (0 - 7): ");
24+
String generateNewKey = promptAndReadLine("Would you like to generate a new private key? (y/N): ");
25+
26+
Serial.println();
27+
28+
generateNewKey.toLowerCase();
29+
30+
if (!ECC508CSR.begin(slot.toInt(), generateNewKey.startsWith("y"))) {
31+
Serial.println("Error starting CSR generation!");
32+
while (1);
33+
}
34+
35+
ECC508CSR.setCountryName(country);
36+
ECC508CSR.setStateProvinceName(stateOrProvince);
37+
ECC508CSR.setLocalityName(locality);
38+
ECC508CSR.setOrganizationName(organization);
39+
ECC508CSR.setOrganizationalUnitName(organizationalUnit);
40+
ECC508CSR.setCommonName(common);
41+
42+
String csr = ECC508CSR.end();
43+
44+
if (!csr) {
45+
Serial.println("Error generating CSR!");
46+
while (1);
47+
}
48+
49+
Serial.println("Here's your CSR, enjoy!");
50+
Serial.println();
51+
Serial.println(csr);
52+
}
53+
54+
void loop() {
55+
// do nothing
56+
}
57+
58+
59+
String promptAndReadLine(const char* prompt) {
60+
Serial.print(prompt);
61+
String s = readLine();
62+
Serial.println(s);
63+
64+
return s;
65+
}
66+
67+
String readLine() {
68+
String line;
69+
70+
while (1) {
71+
if (Serial.available()) {
72+
char c = Serial.read();
73+
74+
if (c == '\r') {
75+
// ignore
76+
} else if (c == '\n') {
77+
break;
78+
}
79+
80+
line += c;
81+
}
82+
}
83+
84+
return line;
85+
}

0 commit comments

Comments
 (0)