From b59e807de19a05dd6c1c5b4c9458763511d7a9f7 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Wed, 3 Jul 2024 22:22:36 +0200 Subject: [PATCH] On Python device, automatically delete invalid certificate if status leaves the "Validated" mode --- python_device/src/api.py | 1 + python_device/src/main.py | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/python_device/src/api.py b/python_device/src/api.py index 1baa642..7c88285 100644 --- a/python_device/src/api.py +++ b/python_device/src/api.py @@ -57,6 +57,7 @@ def enroll_device(csr: str): print(res.text) raise Exception(f"Enrollment failed with status {res.status_code}") + def device_certificate() -> str: """ Retrieve device certificate diff --git a/python_device/src/main.py b/python_device/src/main.py index cfcb53a..dde6e7b 100644 --- a/python_device/src/main.py +++ b/python_device/src/main.py @@ -55,6 +55,11 @@ if not os.path.isfile(args.dev_csr_path): print("Check device enrollment...") status = api.device_enrollment_status() +if status != "Validated": + if os.path.isfile(args.dev_crt_path): + print("Delete invalid certificate") + os.unlink(args.dev_crt_path) + if status == "Unknown": print("Device is unknown on the system, need to submit a CSR...") with open(args.dev_csr_path, "r") as f: @@ -80,4 +85,4 @@ if not os.path.isfile(args.dev_crt_path): with open(args.dev_crt_path, "w") as f: f.write(cert) -print("Done. ready to operate.") \ No newline at end of file +print("Done. ready to operate.")