Spaces:
Running
Running
Update decode.py
Browse files
decode.py
CHANGED
@@ -50,21 +50,14 @@ def get_key_data(public_key):
|
|
50 |
return data
|
51 |
|
52 |
def general_info(cert, public_key):
|
53 |
-
subject =
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
subject = cert.subject.get_attributes_for_oid(x509.NameOID.COMMON_NAME)[0].value if subject else None
|
62 |
-
sans = cert.extensions.get_extension_for_class(x509.SubjectAlternativeName).value.get_values_for_type(x509.DNSName) if sans else None
|
63 |
-
not_valid_after = get_date(str(cert.not_valid_after_utc)) if not_valid_after else None
|
64 |
-
not_valid_before = get_date(str(cert.not_valid_before_utc)) if not_valid_before else None
|
65 |
-
expiry = check_expiry(str(cert.not_valid_after_utc)) if expiry else None
|
66 |
-
key_data = get_key_data(public_key) if key_data else None
|
67 |
-
signature_algorithm = cert.signature_algorithm_oid._name if signature_algorithm else None
|
68 |
serial_number = f"{cert.serial_number} ({hex(cert.serial_number)})"
|
69 |
gen_info = {
|
70 |
"subject": subject,
|
@@ -80,9 +73,9 @@ def general_info(cert, public_key):
|
|
80 |
|
81 |
def issuer_info(cert):
|
82 |
issuer = None; organization = None; country = None
|
83 |
-
issuer = cert.issuer.get_attributes_for_oid(x509.NameOID.COMMON_NAME)[0].value
|
84 |
-
organization = cert.issuer.get_attributes_for_oid(x509.NameOID.ORGANIZATION_NAME)[0].value
|
85 |
-
country = cert.issuer.get_attributes_for_oid(x509.NameOID.COUNTRY_NAME)[0].value
|
86 |
return {
|
87 |
"issuer": issuer,
|
88 |
"organization": organization,
|
@@ -121,14 +114,14 @@ def extenstions_data(cert):
|
|
121 |
crl_distribution_points.extend(uris)
|
122 |
except x509.ExtensionNotFound:
|
123 |
crl_distribution_points.append("No CRL Distribution Points extension")
|
124 |
-
authorityinfo = cert.extensions.get_extension_for_oid(x509.OID_AUTHORITY_INFORMATION_ACCESS).value
|
125 |
-
ocsp_url = authorityinfo[0].access_location.value
|
126 |
-
ca_issuer_url = authorityinfo[1].access_location.value
|
127 |
authority_info_data = {
|
128 |
"ocsp_url": ocsp_url,
|
129 |
"ca_issuer_url": ca_issuer_url
|
130 |
}
|
131 |
-
subject_alt_name = cert.extensions.get_extension_for_oid(x509.OID_SUBJECT_ALTERNATIVE_NAME).value.get_values_for_type(x509.DNSName)
|
132 |
return {
|
133 |
"authorityKeyIdentifier": authorityKeyIdentifier,
|
134 |
"subjectKeyIdentifier": subjectKeyIdentifier,
|
@@ -148,7 +141,7 @@ def get_openssl_data(cert_file):
|
|
148 |
}
|
149 |
return data
|
150 |
|
151 |
-
def decode_ssl_certificate(cert)
|
152 |
subject = cert.subject.get_attributes_for_oid(x509.NameOID.COMMON_NAME)[0].value
|
153 |
with open(f'{subject}.pem', 'wb') as cert_file:
|
154 |
cert_file.write(cert.public_bytes(Encoding.PEM))
|
@@ -164,4 +157,4 @@ def decode_ssl_certificate(cert) -> dict:
|
|
164 |
"extensions_data": extensions_data_data,
|
165 |
"raw_openssl_data": raw_openssl_data
|
166 |
}
|
167 |
-
return data
|
|
|
50 |
return data
|
51 |
|
52 |
def general_info(cert, public_key):
|
53 |
+
subject = cert.subject.get_attributes_for_oid(x509.NameOID.COMMON_NAME)[0].value
|
54 |
+
print(subject)
|
55 |
+
sans = cert.extensions.get_extension_for_class(x509.SubjectAlternativeName).value.get_values_for_type(x509.DNSName)
|
56 |
+
not_valid_after = get_date(str(cert.not_valid_after_utc))
|
57 |
+
not_valid_before = get_date(str(cert.not_valid_before_utc))
|
58 |
+
expiry = check_expiry(str(cert.not_valid_after_utc))
|
59 |
+
key_data = get_key_data(public_key)
|
60 |
+
signature_algorithm = cert.signature_algorithm_oid._name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
serial_number = f"{cert.serial_number} ({hex(cert.serial_number)})"
|
62 |
gen_info = {
|
63 |
"subject": subject,
|
|
|
73 |
|
74 |
def issuer_info(cert):
|
75 |
issuer = None; organization = None; country = None
|
76 |
+
issuer = cert.issuer.get_attributes_for_oid(x509.NameOID.COMMON_NAME)[0].value
|
77 |
+
organization = cert.issuer.get_attributes_for_oid(x509.NameOID.ORGANIZATION_NAME)[0].value
|
78 |
+
country = cert.issuer.get_attributes_for_oid(x509.NameOID.COUNTRY_NAME)[0].value
|
79 |
return {
|
80 |
"issuer": issuer,
|
81 |
"organization": organization,
|
|
|
114 |
crl_distribution_points.extend(uris)
|
115 |
except x509.ExtensionNotFound:
|
116 |
crl_distribution_points.append("No CRL Distribution Points extension")
|
117 |
+
authorityinfo = cert.extensions.get_extension_for_oid(x509.OID_AUTHORITY_INFORMATION_ACCESS).value
|
118 |
+
ocsp_url = authorityinfo[0].access_location.value
|
119 |
+
ca_issuer_url = authorityinfo[1].access_location.value
|
120 |
authority_info_data = {
|
121 |
"ocsp_url": ocsp_url,
|
122 |
"ca_issuer_url": ca_issuer_url
|
123 |
}
|
124 |
+
subject_alt_name = cert.extensions.get_extension_for_oid(x509.OID_SUBJECT_ALTERNATIVE_NAME).value.get_values_for_type(x509.DNSName)
|
125 |
return {
|
126 |
"authorityKeyIdentifier": authorityKeyIdentifier,
|
127 |
"subjectKeyIdentifier": subjectKeyIdentifier,
|
|
|
141 |
}
|
142 |
return data
|
143 |
|
144 |
+
def decode_ssl_certificate(cert):
|
145 |
subject = cert.subject.get_attributes_for_oid(x509.NameOID.COMMON_NAME)[0].value
|
146 |
with open(f'{subject}.pem', 'wb') as cert_file:
|
147 |
cert_file.write(cert.public_bytes(Encoding.PEM))
|
|
|
157 |
"extensions_data": extensions_data_data,
|
158 |
"raw_openssl_data": raw_openssl_data
|
159 |
}
|
160 |
+
return data
|