Joanna Jeremicz | c21b008 | 2020-06-15 16:21:55 +0200 | [diff] [blame] | 1 | from cryptography.x509.oid import ExtensionOID |
| 2 | from cryptography import x509 |
| 3 | |
| 4 | class ArtifactParser: |
| 5 | |
| 6 | def __init__(self, mount_path, ext): |
| 7 | self.keystorePassPath = mount_path + '/keystore.pass' |
| 8 | self.keystorePath = mount_path + '/keystore.' + ext |
| 9 | self.truststorePassPath = mount_path + '/truststore.pass' |
| 10 | self.truststorePath = mount_path + '/truststore.' + ext |
| 11 | |
| 12 | def contains_expected_data(self, data): |
| 13 | expectedData = data.expectedData |
| 14 | actualData = data.actualData |
| 15 | return cmp(expectedData, actualData) == 0 |
| 16 | |
| 17 | def get_owner_data_from_certificate(self, certificate): |
| 18 | list = certificate.get_subject().get_components() |
| 19 | return dict((k, v) for k, v in list) |
| 20 | |
| 21 | def get_sans(self, cert): |
| 22 | extension = cert.to_cryptography().extensions.get_extension_for_oid(ExtensionOID.SUBJECT_ALTERNATIVE_NAME) |
| 23 | dnsList = extension.value.get_values_for_type(x509.DNSName) |
Piotr Marcinkiewicz | 3bbc1c7 | 2020-11-19 14:13:45 +0100 | [diff] [blame^] | 24 | return ','.join(map(lambda dns: dns.encode('ascii','ignore'), dnsList)) |
Joanna Jeremicz | c21b008 | 2020-06-15 16:21:55 +0200 | [diff] [blame] | 25 | |
| 26 | def get_envs_as_dict(self, list): |
| 27 | envs = self.get_list_of_pairs_by_mappings(list) |
| 28 | return self.remove_nones_from_dict(envs) |
| 29 | |
| 30 | def remove_nones_from_dict(self, dictionary): |
| 31 | return dict((k, v) for k, v in dictionary.iteritems() if k is not None) |
| 32 | |
| 33 | def get_list_of_pairs_by_mappings(self, list): |
| 34 | mappings = self.get_mappings() |
| 35 | listOfEnvs = map(lambda k: k.split('='), list) |
| 36 | return dict((mappings.get(a[0]), a[1]) for a in listOfEnvs) |
| 37 | |
| 38 | def get_mappings(self): |
| 39 | return {'COMMON_NAME':'CN', 'ORGANIZATION':'O', 'ORGANIZATION_UNIT':'OU', 'LOCATION':'L', 'STATE':'ST', 'COUNTRY':'C', 'SANS':'SANS'} |
| 40 | |