From 4c4d1e13cb16885d77f3046dbd615ab6eccce0cb Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sat, 29 Jun 2024 18:08:57 +0200 Subject: [PATCH] Load root CA --- python_device/src/api.py | 6 ++++++ python_device/src/args.py | 3 ++- python_device/src/main.py | 14 +++++++++++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/python_device/src/api.py b/python_device/src/api.py index e46155d..50524ad 100644 --- a/python_device/src/api.py +++ b/python_device/src/api.py @@ -5,4 +5,10 @@ def get_secure_origin() -> str: res = requests.get(f"{args.unsecure_origin}/secure_origin") if res.status_code < 200 or res.status_code > 299: raise Exception(f"Get secure origin failed with status {res.status_code}") + return res.text + +def get_root_ca() -> str: + res = requests.get(f"{args.unsecure_origin}/pki/root_ca.pem") + if res.status_code < 200 or res.status_code > 299: + raise Exception(f"Get root CA failed with status {res.status_code}") return res.text \ No newline at end of file diff --git a/python_device/src/args.py b/python_device/src/args.py index e3859ec..b5c6cc2 100644 --- a/python_device/src/args.py +++ b/python_device/src/args.py @@ -9,4 +9,5 @@ parser.add_argument("--storage", help="Change storage location", default="storag args = parser.parse_args() -args.secure_origin_path = os.path.join(args.storage, "SECURE_ORIGIN") \ No newline at end of file +args.secure_origin_path = os.path.join(args.storage, "SECURE_ORIGIN") +args.root_ca_path = os.path.join(args.storage, "root_ca.pem") \ No newline at end of file diff --git a/python_device/src/main.py b/python_device/src/main.py index ee2af42..d5347dc 100644 --- a/python_device/src/main.py +++ b/python_device/src/main.py @@ -16,4 +16,16 @@ if not os.path.isfile(args.secure_origin_path): with open(args.secure_origin_path, "r") as f: args.secure_origin = f.read() -print(f"Secure origin = {args.secure_origin}") \ No newline at end of file +print(f"Secure origin = {args.secure_origin}") + + + +print("Check system root CA") +if not os.path.isfile(args.root_ca_path): + origin = api.get_root_ca() + with open(args.root_ca_path, "w") as f: + f.write(origin) + +with open(args.root_ca_path, "r") as f: + args.root_ca = f.read() +print(f"Root CA = {args.root_ca}") \ No newline at end of file