diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/cryptography/hazmat/backends/openssl/x509.py | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/cryptography/hazmat/backends/openssl/x509.py b/src/cryptography/hazmat/backends/openssl/x509.py index 26c5edc2..01055c5f 100644 --- a/src/cryptography/hazmat/backends/openssl/x509.py +++ b/src/cryptography/hazmat/backends/openssl/x509.py @@ -96,8 +96,17 @@ class _Certificate(object): return self._parse_asn1_time(asn1_time) def _parse_asn1_time(self, asn1_time): - 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).decode("ascii") - return datetime.datetime.strptime(time, "%b %d %H:%M:%S %Y GMT") + 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") |