Introduce real Kesystore check
[integration/csit.git] / tests / oom-platform-cert-service / postprocessor / libraries / JksValidator.py
1
2 import jks
3
4 class JksValidator:
5
6   def get_jks_entries(self, jks_path, password_path):
7     store = jks.KeyStore.load(jks_path, open(password_path, 'rb').read())
8     return store.entries
9
10   def assert_jks_truststores_equal(self, result_truststore_path, password_path, expected_truststore_path):
11     result_keys = self.get_jks_entries(result_truststore_path, password_path)
12     expected_keys = self.get_jks_entries(expected_truststore_path, password_path)
13     if len(result_keys) != len(expected_keys):
14       return False
15     for k in result_keys:
16       if not (k in expected_keys and result_keys[k].cert == expected_keys[k].cert):
17         return False
18     return True
19
20   def assert_jks_keystores_equal(self, result_keystore_path, password_path, expected_keystore_path):
21     result_keys = self.get_jks_entries(result_keystore_path, password_path)
22     expected_keys = self.get_jks_entries(expected_keystore_path, password_path)
23     if len(result_keys) != len(expected_keys):
24       return False
25     for k in result_keys:
26       if not (k in expected_keys and result_keys[k].pkey == expected_keys[k].pkey):
27         return False
28     return True