Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9424bb4

Browse files
committed
Issue #18207: Fix test_ssl for some versions of OpenSSL that ignore seconds
in ASN1_TIME fields.
1 parent 78be6e8 commit 9424bb4

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

Lib/test/test_ssl.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import socket
77
import select
88
import time
9+
import datetime
910
import gc
1011
import os
1112
import errno
@@ -73,6 +74,19 @@ def no_sslv2_implies_sslv3_hello():
7374
# 0.9.7h or higher
7475
return ssl.OPENSSL_VERSION_INFO >= (0, 9, 7, 8, 15)
7576

77+
def asn1time(cert_time):
78+
# Some versions of OpenSSL ignore seconds, see #18207
79+
# 0.9.8.i
80+
if ssl._OPENSSL_API_VERSION == (0, 9, 8, 9, 15):
81+
fmt = "%b %d %H:%M:%S %Y GMT"
82+
dt = datetime.datetime.strptime(cert_time, fmt)
83+
dt = dt.replace(second=0)
84+
cert_time = dt.strftime(fmt)
85+
# %d adds leading zero but ASN1_TIME_print() uses leading space
86+
if cert_time[4] == "0":
87+
cert_time = cert_time[:4] + " " + cert_time[5:]
88+
89+
return cert_time
7690

7791
# Issue #9415: Ubuntu hijacks their OpenSSL and forcefully disables SSLv2
7892
def skip_if_broken_ubuntu_ssl(func):
@@ -142,8 +156,8 @@ def test_parse_cert(self):
142156
(('commonName', 'localhost'),))
143157
)
144158
# Note the next three asserts will fail if the keys are regenerated
145-
self.assertEqual(p['notAfter'], 'Oct 5 23:01:56 2020 GMT')
146-
self.assertEqual(p['notBefore'], 'Oct 8 23:01:56 2010 GMT')
159+
self.assertEqual(p['notAfter'], asn1time('Oct 5 23:01:56 2020 GMT'))
160+
self.assertEqual(p['notBefore'], asn1time('Oct 8 23:01:56 2010 GMT'))
147161
self.assertEqual(p['serialNumber'], 'D7C7381919AFC24E')
148162
self.assertEqual(p['subject'],
149163
((('countryName', 'XY'),),

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,9 @@ Library
409409
Tests
410410
-----
411411

412+
- Issue #18207: Fix test_ssl for some versions of OpenSSL that ignore seconds
413+
in ASN1_TIME fields.
414+
412415
- Issue #18094: test_uuid no more reports skipped tests as passed.
413416

414417
- Issue #17992: Add timeouts to asyncore and asynchat tests so that they won't

0 commit comments

Comments
 (0)