forked from DotBots/DotBot-firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request DotBots#283 from aabadie/ota_crypto
OTAP: add basic support for crypto primitives (sha256 hash, ed25519 signature)
- Loading branch information
Showing
44 changed files
with
677 additions
and
97 deletions.
There are no files selected for viewing
This file contains 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 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 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,2 @@ | ||
private_key | ||
public_key.h |
This file contains 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 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,54 @@ | ||
#!/usr/bin/env python | ||
|
||
import os | ||
|
||
from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey | ||
from cryptography.hazmat.primitives.serialization import ( | ||
Encoding, | ||
PrivateFormat, | ||
PublicFormat, | ||
NoEncryption, | ||
) | ||
|
||
PRIVATE_KEY_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), "private_key") | ||
PUBLIC_KEY_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), "../../../drv/ota/public_key.h") | ||
|
||
HEADER_FORMAT = """/* | ||
* PLEASE DON'T EDIT | ||
* | ||
* This file was automatically generated | ||
*/ | ||
#ifndef __{name_upper}_H | ||
#define __{name_upper}_H | ||
#include <stdint.h> | ||
const uint8_t {name}[] = {{ | ||
{data} | ||
}}; | ||
#endif /* __{name_upper}_H */ | ||
""" | ||
|
||
|
||
def save_as_c_array(path, name, data): | ||
data_str = ", ".join([f"0x{data[i:i+2]}" for i in range(0, len(data), 2)]) | ||
print(f"Saving '{name}' to {os.path.abspath(path)}") | ||
with open(path, "w") as f: | ||
f.write(HEADER_FORMAT.format(name=name, name_upper=name.upper(), data=data_str)) | ||
|
||
|
||
def main(): | ||
key_pair = Ed25519PrivateKey.generate() | ||
private_key = key_pair.private_bytes(Encoding.Raw, PrivateFormat.Raw, NoEncryption()) | ||
public_key = key_pair.public_key().public_bytes(Encoding.Raw, PublicFormat.Raw) | ||
|
||
print(f"Generated keys:\n - private key\t: {private_key.hex()}\n - public key\t: {public_key.hex()}") | ||
print(f"Saving 'private key' to {os.path.abspath(PRIVATE_KEY_PATH)}") | ||
with open(PRIVATE_KEY_PATH, "wb") as f: | ||
f.write(private_key) | ||
save_as_c_array(PUBLIC_KEY_PATH, "public_key", public_key.hex()) | ||
|
||
if __name__ == "__main__": | ||
main() |
1 change: 1 addition & 0 deletions
1
dist/scripts/testbed/requirements.txt → dist/scripts/otap/requirements.txt
This file contains 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
click==8.1.7 | ||
cryptography==41.0.5 | ||
tqdm==4.66.1 | ||
pydotbot |
This file contains 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 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 |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
getting_started | ||
applications | ||
examples | ||
testbed | ||
otap | ||
api | ||
``` | ||
|
||
|
This file contains 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
```{include} ../../testbed/README.md | ||
```{include} ../../otap/README.md | ||
:relative-images: | ||
:relative-docs: ../ | ||
``` |
This file contains 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 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 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
Oops, something went wrong.