Start to implement devices enrollment

This commit is contained in:
2024-07-01 21:10:45 +02:00
parent 378c296e71
commit 9ba4aa5194
21 changed files with 267 additions and 16 deletions

View File

@ -1,13 +1,16 @@
from OpenSSL import crypto
def gen_priv_key():
key = crypto.PKey()
key.generate_key(crypto.TYPE_RSA, 2048)
return crypto.dump_privatekey(crypto.FILETYPE_PEM, key).decode("utf-8")
def parse_priv_key(priv_key: str) -> crypto.PKey:
return crypto.load_privatekey(crypto.FILETYPE_PEM, priv_key)
def gen_csr(priv_key: str, cn: str) -> str:
priv_key = parse_priv_key(priv_key)
@ -15,5 +18,5 @@ def gen_csr(priv_key: str, cn: str) -> str:
req.get_subject().CN = cn
req.set_pubkey(priv_key)
req.sign(priv_key, "sha256")
return crypto.dump_certificate_request(crypto.FILETYPE_PEM, req).decode("utf-8")