Skip to content

Commit 496df6c

Browse files
committed
Revert "pythongh-119400: make_ssl_certs: update reference test data automatically, pass in expiration dates as parameters python#119400 (pythonGH-119401)"
This reverts commit 1ff1b89.
1 parent e53259a commit 496df6c

File tree

6 files changed

+72
-72
lines changed

6 files changed

+72
-72
lines changed

Lib/test/certdata/keycert.pem.reference

Lines changed: 0 additions & 13 deletions
This file was deleted.

Lib/test/certdata/keycert3.pem.reference

Lines changed: 0 additions & 15 deletions
This file was deleted.

Lib/test/certdata/make_ssl_certs.py

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
"""Make the custom certificate and private key files used by test_ssl
22
and friends."""
33

4-
import argparse
54
import os
65
import pprint
76
import shutil
87
import tempfile
98
from subprocess import *
109

1110
startdate = "20180829142316Z"
12-
enddate_default = "20371028142316Z"
13-
days_default = "7000"
11+
enddate = "20371028142316Z"
1412

1513
req_template = """
1614
[ default ]
@@ -81,8 +79,8 @@
8179
default_startdate = {startdate}
8280
enddate = {enddate}
8381
default_enddate = {enddate}
84-
default_days = {days}
85-
default_crl_days = {days}
82+
default_days = 7000
83+
default_crl_days = 7000
8684
certificate = pycacert.pem
8785
private_key = pycakey.pem
8886
serial = $dir/serial
@@ -119,7 +117,7 @@
119117
here = os.path.abspath(os.path.dirname(__file__))
120118

121119

122-
def make_cert_key(cmdlineargs, hostname, sign=False, extra_san='',
120+
def make_cert_key(hostname, sign=False, extra_san='',
123121
ext='req_x509_extensions_full', key='rsa:3072'):
124122
print("creating cert for " + hostname)
125123
tempnames = []
@@ -132,12 +130,11 @@ def make_cert_key(cmdlineargs, hostname, sign=False, extra_san='',
132130
hostname=hostname,
133131
extra_san=extra_san,
134132
startdate=startdate,
135-
enddate=cmdlineargs.enddate,
136-
days=cmdlineargs.days
133+
enddate=enddate
137134
)
138135
with open(req_file, 'w') as f:
139136
f.write(req)
140-
args = ['req', '-new', '-nodes', '-days', cmdlineargs.days,
137+
args = ['req', '-new', '-nodes', '-days', '7000',
141138
'-newkey', key, '-keyout', key_file,
142139
'-extensions', ext,
143140
'-config', req_file]
@@ -178,7 +175,7 @@ def make_cert_key(cmdlineargs, hostname, sign=False, extra_san='',
178175
def unmake_ca():
179176
shutil.rmtree(TMP_CADIR)
180177

181-
def make_ca(cmdlineargs):
178+
def make_ca():
182179
os.mkdir(TMP_CADIR)
183180
with open(os.path.join('cadir','index.txt'),'a+') as f:
184181
pass # empty file
@@ -195,8 +192,7 @@ def make_ca(cmdlineargs):
195192
hostname='our-ca-server',
196193
extra_san='',
197194
startdate=startdate,
198-
enddate=cmdlineargs.enddate,
199-
days=cmdlineargs.days
195+
enddate=enddate
200196
)
201197
t.write(req)
202198
t.flush()
@@ -223,22 +219,14 @@ def make_ca(cmdlineargs):
223219
shutil.copy('capath/ceff1710.0', 'capath/b1930218.0')
224220

225221

226-
def write_cert_reference(path):
222+
def print_cert(path):
227223
import _ssl
228-
refdata = pprint.pformat(_ssl._test_decode_cert(path))
229-
print(refdata)
230-
with open(path + '.reference', 'w') as f:
231-
print(refdata, file=f)
224+
pprint.pprint(_ssl._test_decode_cert(path))
232225

233226

234227
if __name__ == '__main__':
235-
parser = argparse.ArgumentParser(description='Make the custom certificate and private key files used by test_ssl and friends.')
236-
parser.add_argument('--days', default=days_default)
237-
parser.add_argument('--enddate', default=enddate_default)
238-
cmdlineargs = parser.parse_args()
239-
240228
os.chdir(here)
241-
cert, key = make_cert_key(cmdlineargs, 'localhost', ext='req_x509_extensions_simple')
229+
cert, key = make_cert_key('localhost', ext='req_x509_extensions_simple')
242230
with open('ssl_cert.pem', 'w') as f:
243231
f.write(cert)
244232
with open('ssl_key.pem', 'w') as f:
@@ -255,24 +243,24 @@ def write_cert_reference(path):
255243
f.write(cert)
256244

257245
# For certificate matching tests
258-
make_ca(cmdlineargs)
259-
cert, key = make_cert_key(cmdlineargs, 'fakehostname', ext='req_x509_extensions_simple')
246+
make_ca()
247+
cert, key = make_cert_key('fakehostname', ext='req_x509_extensions_simple')
260248
with open('keycert2.pem', 'w') as f:
261249
f.write(key)
262250
f.write(cert)
263251

264-
cert, key = make_cert_key(cmdlineargs, 'localhost', sign=True)
252+
cert, key = make_cert_key('localhost', sign=True)
265253
with open('keycert3.pem', 'w') as f:
266254
f.write(key)
267255
f.write(cert)
268256

269-
cert, key = make_cert_key(cmdlineargs, 'fakehostname', sign=True)
257+
cert, key = make_cert_key('fakehostname', sign=True)
270258
with open('keycert4.pem', 'w') as f:
271259
f.write(key)
272260
f.write(cert)
273261

274262
cert, key = make_cert_key(
275-
cmdlineargs, 'localhost-ecc', sign=True, key='param:secp384r1.pem'
263+
'localhost-ecc', sign=True, key='param:secp384r1.pem'
276264
)
277265
with open('keycertecc.pem', 'w') as f:
278266
f.write(key)
@@ -292,7 +280,7 @@ def write_cert_reference(path):
292280
'RID.1 = 1.2.3.4.5',
293281
]
294282

295-
cert, key = make_cert_key(cmdlineargs, 'allsans', sign=True, extra_san='\n'.join(extra_san))
283+
cert, key = make_cert_key('allsans', sign=True, extra_san='\n'.join(extra_san))
296284
with open('allsans.pem', 'w') as f:
297285
f.write(key)
298286
f.write(cert)
@@ -309,17 +297,17 @@ def write_cert_reference(path):
309297
]
310298

311299
# IDN SANS, signed
312-
cert, key = make_cert_key(cmdlineargs, 'idnsans', sign=True, extra_san='\n'.join(extra_san))
300+
cert, key = make_cert_key('idnsans', sign=True, extra_san='\n'.join(extra_san))
313301
with open('idnsans.pem', 'w') as f:
314302
f.write(key)
315303
f.write(cert)
316304

317-
cert, key = make_cert_key(cmdlineargs, 'nosan', sign=True, ext='req_x509_extensions_nosan')
305+
cert, key = make_cert_key('nosan', sign=True, ext='req_x509_extensions_nosan')
318306
with open('nosan.pem', 'w') as f:
319307
f.write(key)
320308
f.write(cert)
321309

322310
unmake_ca()
323-
print("Writing out reference data for Lib/test/test_ssl.py and Lib/test/test_asyncio/utils.py")
324-
write_cert_reference('keycert.pem')
325-
write_cert_reference('keycert3.pem')
311+
print("update Lib/test/test_ssl.py and Lib/test/test_asyncio/utils.py")
312+
print_cert('keycert.pem')
313+
print_cert('keycert3.pem')

Lib/test/test_asyncio/utils.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import unittest
1616
import weakref
1717
import warnings
18-
from ast import literal_eval
1918
from unittest import mock
2019

2120
from http.server import HTTPServer
@@ -57,8 +56,24 @@ def data_file(*filename):
5756
ONLYKEY = data_file('certdata', 'ssl_key.pem')
5857
SIGNED_CERTFILE = data_file('certdata', 'keycert3.pem')
5958
SIGNING_CA = data_file('certdata', 'pycacert.pem')
60-
with open(data_file('certdata', 'keycert3.pem.reference')) as file:
61-
PEERCERT = literal_eval(file.read())
59+
PEERCERT = {
60+
'OCSP': ('http://testca.pythontest.net/testca/ocsp/',),
61+
'caIssuers': ('http://testca.pythontest.net/testca/pycacert.cer',),
62+
'crlDistributionPoints': ('http://testca.pythontest.net/testca/revocation.crl',),
63+
'issuer': ((('countryName', 'XY'),),
64+
(('organizationName', 'Python Software Foundation CA'),),
65+
(('commonName', 'our-ca-server'),)),
66+
'notAfter': 'Oct 28 14:23:16 2037 GMT',
67+
'notBefore': 'Aug 29 14:23:16 2018 GMT',
68+
'serialNumber': 'CB2D80995A69525C',
69+
'subject': ((('countryName', 'XY'),),
70+
(('localityName', 'Castle Anthrax'),),
71+
(('organizationName', 'Python Software Foundation'),),
72+
(('commonName', 'localhost'),)),
73+
'subjectAltName': (('DNS', 'localhost'),),
74+
'version': 3
75+
}
76+
6277

6378
def simple_server_sslcontext():
6479
server_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)

Lib/test/test_ssl.py

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import sys
44
import unittest
55
import unittest.mock
6-
from ast import literal_eval
76
from test import support
87
from test.support import import_helper
98
from test.support import os_helper
@@ -83,8 +82,21 @@ def data_file(*name):
8382
CAFILE_NEURONIO = data_file("capath", "4e1295a3.0")
8483
CAFILE_CACERT = data_file("capath", "5ed36f99.0")
8584

86-
with open(data_file('keycert.pem.reference')) as file:
87-
CERTFILE_INFO = literal_eval(file.read())
85+
CERTFILE_INFO = {
86+
'issuer': ((('countryName', 'XY'),),
87+
(('localityName', 'Castle Anthrax'),),
88+
(('organizationName', 'Python Software Foundation'),),
89+
(('commonName', 'localhost'),)),
90+
'notAfter': 'Jan 24 04:21:36 2043 GMT',
91+
'notBefore': 'Nov 25 04:21:36 2023 GMT',
92+
'serialNumber': '53E14833F7546C29256DD0F034F776C5E983004C',
93+
'subject': ((('countryName', 'XY'),),
94+
(('localityName', 'Castle Anthrax'),),
95+
(('organizationName', 'Python Software Foundation'),),
96+
(('commonName', 'localhost'),)),
97+
'subjectAltName': (('DNS', 'localhost'),),
98+
'version': 3
99+
}
88100

89101
# empty CRL
90102
CRLFILE = data_file("revocation.crl")
@@ -94,8 +106,23 @@ def data_file(*name):
94106
SINGED_CERTFILE_ONLY = data_file("cert3.pem")
95107
SIGNED_CERTFILE_HOSTNAME = 'localhost'
96108

97-
with open(data_file('keycert3.pem.reference')) as file:
98-
SIGNED_CERTFILE_INFO = literal_eval(file.read())
109+
SIGNED_CERTFILE_INFO = {
110+
'OCSP': ('http://testca.pythontest.net/testca/ocsp/',),
111+
'caIssuers': ('http://testca.pythontest.net/testca/pycacert.cer',),
112+
'crlDistributionPoints': ('http://testca.pythontest.net/testca/revocation.crl',),
113+
'issuer': ((('countryName', 'XY'),),
114+
(('organizationName', 'Python Software Foundation CA'),),
115+
(('commonName', 'our-ca-server'),)),
116+
'notAfter': 'Oct 28 14:23:16 2037 GMT',
117+
'notBefore': 'Aug 29 14:23:16 2018 GMT',
118+
'serialNumber': 'CB2D80995A69525C',
119+
'subject': ((('countryName', 'XY'),),
120+
(('localityName', 'Castle Anthrax'),),
121+
(('organizationName', 'Python Software Foundation'),),
122+
(('commonName', 'localhost'),)),
123+
'subjectAltName': (('DNS', 'localhost'),),
124+
'version': 3
125+
}
99126

100127
SIGNED_CERTFILE2 = data_file("keycert4.pem")
101128
SIGNED_CERTFILE2_HOSTNAME = 'fakehostname'

Misc/NEWS.d/next/Build/2024-05-22-13-18-02.gh-issue-119400.WEt83v.rst

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)