diff --git a/Doc/library/ssl.rst b/Doc/library/ssl.rst index e2d3c3f..0498c11 100644 --- a/Doc/library/ssl.rst +++ b/Doc/library/ssl.rst @@ -366,7 +366,7 @@ Certificate handling >>> import ssl >>> ssl.cert_time_to_seconds("May 9 00:00:00 2007 GMT") - 1178694000.0 + 1178668800 >>> import time >>> time.ctime(ssl.cert_time_to_seconds("May 9 00:00:00 2007 GMT")) 'Wed May 9 00:00:00 2007' diff --git a/Lib/ssl.py b/Lib/ssl.py index 052a118..f81ef91 100644 --- a/Lib/ssl.py +++ b/Lib/ssl.py @@ -852,7 +852,8 @@ def cert_time_to_seconds(cert_time): a Python time value in seconds past the epoch.""" import time - return time.mktime(time.strptime(cert_time, "%b %d %H:%M:%S %Y GMT")) + import calendar + return calendar.timegm(time.strptime(cert_time, "%b %d %H:%M:%S %Y GMT")) PEM_HEADER = "-----BEGIN CERTIFICATE-----" PEM_FOOTER = "-----END CERTIFICATE-----" diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py index 6eb88d7..0352722 100644 --- a/Lib/test/test_ssl.py +++ b/Lib/test/test_ssl.py @@ -960,6 +960,10 @@ class ContextTests(unittest.TestCase): self.assertEqual(ctx.cert_store_stats(), {'x509_ca': 1, 'crl': 0, 'x509': 2}) + def test_cert_time_to_seconds(self): + tsec = ssl.cert_time_to_seconds("May 9 00:00:00 2007 GMT") + self.assertEqual(tsec, 1178668800) + def test_get_ca_certs(self): ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1) self.assertEqual(ctx.get_ca_certs(), [])