-
Notifications
You must be signed in to change notification settings - Fork 3
Add example for ATECCX08 configuration and locking #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2ac8c5f
Examples: RandomNumber fix serial prints referring to ECCX08
pennam 96ab727
Examples: add dedicated example skecth for ATECCX08 configuration and…
pennam 7249484
Examples: RandomNumber add note about the ConfigurationLocking example
pennam 1580af9
Examples: fix sketch description using SecureElement naming
pennam 85baef4
Examples: ConfigurationLocking fix typo in sketch description
pennam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
Configure and Lock your ATECCX08 SecureElement | ||
|
||
This sketch can be used to apply default configuration and lock | ||
yout ATECCX08 Secure Element. | ||
Default configuration can be found here: | ||
https://github.com/arduino-libraries/ArduinoECCX08/blob/master/src/utility/ECCX08DefaultTLSConfig.h | ||
|
||
SE050 do not have EEPROM configuration and do not need to be locked | ||
to work correctly. secureElement.locked() always returns true for SE050 | ||
and the sketch does nothing. | ||
|
||
The circuit: | ||
- A board equipped with ECC508 or ECC608 or SE050 chip | ||
|
||
This example code is in the public domain. | ||
*/ | ||
|
||
#include <Arduino_SecureElement.h> | ||
|
||
void setup() { | ||
Serial.begin(9600); | ||
while (!Serial); | ||
|
||
SecureElement secureElement; | ||
|
||
if (!secureElement.begin()) { | ||
Serial.println("No SecureElement present!"); | ||
while (1); | ||
} | ||
|
||
String serialNumber = secureElement.serialNumber(); | ||
|
||
Serial.print("SecureElement Serial Number = "); | ||
Serial.println(serialNumber); | ||
Serial.println(); | ||
|
||
if (!secureElement.locked()) { | ||
String lock = promptAndReadLine("The SecureElement on your board is not locked, would you like to PERMANENTLY configure and lock it now? (y/N)", "N"); | ||
lock.toLowerCase(); | ||
|
||
if (!lock.startsWith("y")) { | ||
Serial.println("Unfortunately you can't proceed without locking it :("); | ||
while (1); | ||
} | ||
|
||
if (!secureElement.writeConfiguration()) { | ||
Serial.println("Writing SecureElement configuration failed!"); | ||
while (1); | ||
} | ||
|
||
if (!secureElement.lock()) { | ||
Serial.println("Locking SecureElement configuration failed!"); | ||
while (1); | ||
} | ||
|
||
Serial.println("SecureElement locked successfully"); | ||
Serial.println(); | ||
} else { | ||
#if defined(SECURE_ELEMENT_IS_ECCX08) | ||
Serial.println("SecureElement already locked!"); | ||
Serial.println(); | ||
#else | ||
Serial.println("SecureElement does not need to be locked!"); | ||
Serial.println(); | ||
#endif | ||
} | ||
|
||
} | ||
|
||
void loop() { | ||
// do nothing | ||
} | ||
|
||
String promptAndReadLine(const char* prompt, const char* defaultValue) { | ||
Serial.print(prompt); | ||
Serial.print(" ["); | ||
Serial.print(defaultValue); | ||
Serial.print("]: "); | ||
|
||
String s = readLine(); | ||
|
||
if (s.length() == 0) { | ||
s = defaultValue; | ||
} | ||
|
||
Serial.println(s); | ||
|
||
return s; | ||
} | ||
|
||
String readLine() { | ||
String line; | ||
|
||
while (1) { | ||
if (Serial.available()) { | ||
char c = Serial.read(); | ||
|
||
if (c == '\r') { | ||
// ignore | ||
continue; | ||
} else if (c == '\n') { | ||
break; | ||
} | ||
|
||
line += c; | ||
} | ||
} | ||
|
||
return line; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.