diff options
-rw-r--r-- | src/cryptography/hazmat/backends/openssl/x509.py | 19 | ||||
-rw-r--r-- | src/cryptography/hazmat/bindings/openssl/asn1.py | 1 |
2 files changed, 6 insertions, 14 deletions
diff --git a/src/cryptography/hazmat/backends/openssl/x509.py b/src/cryptography/hazmat/backends/openssl/x509.py index 383322ad..fa4d1a01 100644 --- a/src/cryptography/hazmat/backends/openssl/x509.py +++ b/src/cryptography/hazmat/backends/openssl/x509.py @@ -76,17 +76,8 @@ class _X509Certificate(object): return self._parse_asn1_time(asn1_time) def _parse_asn1_time(self, asn1_time): - assert asn1_time != self._backend._ffi.NULL - generalized_time = self._backend._lib.ASN1_TIME_to_generalizedtime( - asn1_time, self._backend._ffi.NULL - ) - assert generalized_time != self._backend._ffi.NULL - generalized_time = self._backend._ffi.gc( - generalized_time, self._backend._lib.ASN1_GENERALIZEDTIME_free - ) - time = self._backend._ffi.string( - self._backend._lib.ASN1_STRING_data( - self._backend._ffi.cast("ASN1_STRING *", generalized_time) - ) - ).decode("ascii") - return datetime.datetime.strptime(time, "%Y%m%d%H%M%SZ") + bio = self._backend._create_mem_bio() + res = self._backend._lib.ASN1_TIME_print(bio, asn1_time) + assert res == 1 + time = self._backend._read_mem_bio(bio) + return datetime.datetime.strptime(time, "%b %d %H:%M:%S %Y GMT") diff --git a/src/cryptography/hazmat/bindings/openssl/asn1.py b/src/cryptography/hazmat/bindings/openssl/asn1.py index a73dc325..37f95e7e 100644 --- a/src/cryptography/hazmat/bindings/openssl/asn1.py +++ b/src/cryptography/hazmat/bindings/openssl/asn1.py @@ -97,6 +97,7 @@ ASN1_TIME *ASN1_TIME_new(void); void ASN1_TIME_free(ASN1_TIME *); ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *, ASN1_GENERALIZEDTIME **); +int ASN1_TIME_print(BIO *, const ASN1_TIME *); /* ASN1 UTCTIME */ int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *, time_t); |