aboutsummaryrefslogtreecommitdiffstats
path: root/tests/oom-platform-cert-service/certservice/libraries/P12ArtifactsValidator.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/oom-platform-cert-service/certservice/libraries/P12ArtifactsValidator.py')
-rw-r--r--tests/oom-platform-cert-service/certservice/libraries/P12ArtifactsValidator.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/oom-platform-cert-service/certservice/libraries/P12ArtifactsValidator.py b/tests/oom-platform-cert-service/certservice/libraries/P12ArtifactsValidator.py
new file mode 100644
index 00000000..b0701718
--- /dev/null
+++ b/tests/oom-platform-cert-service/certservice/libraries/P12ArtifactsValidator.py
@@ -0,0 +1,37 @@
+from OpenSSL import crypto
+from EnvsReader import EnvsReader
+from ArtifactParser import ArtifactParser
+
+class P12ArtifactsValidator:
+
+ def __init__(self, mount_path):
+ self.parser = ArtifactParser(mount_path, "p12")
+
+ def get_and_compare_data_p12(self, path_to_env):
+ data = self.get_data(path_to_env)
+ return data, self.parser.contains_expected_data(data)
+
+ def can_open_keystore_and_truststore_with_pass(self):
+ can_open_keystore = self.can_open_store_file_with_pass_file(self.parser.keystorePassPath, self.parser.keystorePath)
+ can_open_truststore = self.can_open_store_file_with_pass_file(self.parser.truststorePassPath, self.parser.truststorePath)
+
+ return can_open_keystore & can_open_truststore
+
+ def can_open_store_file_with_pass_file(self, pass_file_path, store_file_path):
+ try:
+ self.get_certificate(pass_file_path, store_file_path)
+ return True
+ except:
+ return False
+
+ def get_data(self, path_to_env):
+ envs = self.parser.get_envs_as_dict(EnvsReader().read_env_list_from_file(path_to_env))
+ certificate = self.get_certificate(self.parser.keystorePassPath, self.parser.keystorePath)
+ data = self.parser.get_owner_data_from_certificate(certificate)
+ data['SANS'] = self.parser.get_sans(certificate)
+ return type('', (object,), {"expectedData": envs, "actualData": data})
+
+ def get_certificate(self, pass_file_path, store_file_path):
+ password = open(pass_file_path, 'rb').read()
+ crypto.load_pkcs12(open(store_file_path, 'rb').read(), password)
+ return crypto.load_pkcs12(open(store_file_path, 'rb').read(), password).get_certificate()