From 69b0a619e041fb626588cb824f6c99e90685b5ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= <40151420+ldericher@users.noreply.github.com> Date: Wed, 30 Mar 2022 23:59:25 +0000 Subject: [PATCH] test: certify device with id 1 --- api/kiwi_vpn_api/easyrsa.py | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/api/kiwi_vpn_api/easyrsa.py b/api/kiwi_vpn_api/easyrsa.py index 827fad1..6edda1f 100644 --- a/api/kiwi_vpn_api/easyrsa.py +++ b/api/kiwi_vpn_api/easyrsa.py @@ -13,7 +13,7 @@ from passlib import pwd from pydantic import BaseModel from .config import CertificateAlgo, Config, Settings -from .db import Device +from .db import Connection, Device class DistinguishedName(BaseModel): @@ -252,12 +252,25 @@ if __name__ == "__main__": ca = easy_rsa.build_ca() server = easy_rsa.issue("server") - # client = easy_rsa.issue(cert_type="client", cn="kiwi-vpn-client") + client = None + + # check if configured + if (current_config := Config._) is not None: + # connect to database + Connection.connect(current_config.db.uri) + + if (device := Device.get(1)) is not None: + with Connection.session as db: + db.add(device) + dn = DistinguishedName.build(device) + + client = easy_rsa.issue("client", dn) date_format, encoding = "%Y%m%d%H%M%SZ", "ascii" - for cert in (ca, server): - print(cert.get_subject().CN) - print(cert.get_signature_algorithm().decode(encoding)) - print(datetime.strptime( - cert.get_notAfter().decode(encoding), date_format)) + for cert in (ca, server, client): + if cert is not None: + print(cert.get_subject().CN) + print(cert.get_signature_algorithm().decode(encoding)) + print(datetime.strptime( + cert.get_notAfter().decode(encoding), date_format))