1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

dist/tools/suit: generate password-protected private key

This commit is contained in:
Benjamin Valentin 2022-05-24 01:10:52 +02:00
parent 08e430bee7
commit 3734839b41

View File

@ -17,17 +17,24 @@ from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey
from cryptography.hazmat.primitives.serialization import Encoding
from cryptography.hazmat.primitives.serialization import PrivateFormat
from cryptography.hazmat.primitives.serialization import NoEncryption
from cryptography.hazmat.primitives.serialization import BestAvailableEncryption
def main():
if len(sys.argv) != 2:
print("usage: gen_key.py <secret filename>")
if len(sys.argv) < 2:
print("usage: gen_key.py <secret filename> [password]")
sys.exit(1)
if len(sys.argv) > 2:
pw = str.encode(sys.argv[2])
crypt = BestAvailableEncryption(pw)
else:
crypt = NoEncryption()
pk = Ed25519PrivateKey.generate()
pem = pk.private_bytes(encoding=Encoding.PEM,
format=PrivateFormat.PKCS8,
encryption_algorithm=NoEncryption()
encryption_algorithm=crypt,
)
with open(sys.argv[1], "wb") as f: