From 27fb633bbe45321eecd8225c32a2fd16882633a9 Mon Sep 17 00:00:00 2001 From: Nataliia Solomko Date: Tue, 13 Aug 2024 13:15:15 +0300 Subject: T5743: HTTPS API ability to import PKI certificates --- python/vyos/configsession.py | 11 +++++++++++ python/vyos/pki.py | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) (limited to 'python') diff --git a/python/vyos/configsession.py b/python/vyos/configsession.py index ccf2ce8f2..7d51b94e4 100644 --- a/python/vyos/configsession.py +++ b/python/vyos/configsession.py @@ -34,6 +34,9 @@ MIGRATE_LOAD_CONFIG = ['/usr/libexec/vyos/vyos-load-config.py'] SAVE_CONFIG = ['/usr/libexec/vyos/vyos-save-config.py'] INSTALL_IMAGE = ['/usr/libexec/vyos/op_mode/image_installer.py', '--action', 'add', '--no-prompt', '--image-path'] +IMPORT_PKI = ['/opt/vyatta/bin/vyatta-op-cmd-wrapper', 'import'] +IMPORT_PKI_NO_PROMPT = ['/usr/libexec/vyos/op_mode/pki.py', + '--action', 'import', '--no-prompt'] REMOVE_IMAGE = ['/usr/libexec/vyos/op_mode/image_manager.py', '--action', 'delete', '--no-prompt', '--image-name'] SET_DEFAULT_IMAGE = ['/usr/libexec/vyos/op_mode/image_manager.py', @@ -239,6 +242,14 @@ class ConfigSession(object): out = self.__run_command(REMOVE_IMAGE + [name]) return out + def import_pki(self, path): + out = self.__run_command(IMPORT_PKI + path) + return out + + def import_pki_no_prompt(self, path): + out = self.__run_command(IMPORT_PKI_NO_PROMPT + path) + return out + def set_default_image(self, name): out = self.__run_command(SET_DEFAULT_IMAGE + [name]) return out diff --git a/python/vyos/pki.py b/python/vyos/pki.py index 27fe793a8..5a0e2ddda 100644 --- a/python/vyos/pki.py +++ b/python/vyos/pki.py @@ -271,7 +271,7 @@ def load_private_key(raw_data, passphrase=None, wrap_tags=True): try: return serialization.load_pem_private_key(bytes(raw_data, 'utf-8'), password=passphrase) - except ValueError: + except (ValueError, TypeError): return False def load_openssh_public_key(raw_data, type): -- cgit v1.2.3