1
1
"""Make the custom certificate and private key files used by test_ssl
2
2
and friends."""
3
3
4
- import argparse
5
4
import os
6
5
import pprint
7
6
import shutil
8
7
import tempfile
9
8
from subprocess import *
10
9
11
10
startdate = "20180829142316Z"
12
- enddate_default = "20371028142316Z"
13
- days_default = "7000"
11
+ enddate = "20371028142316Z"
14
12
15
13
req_template = """
16
14
[ default ]
81
79
default_startdate = {startdate}
82
80
enddate = {enddate}
83
81
default_enddate = {enddate}
84
- default_days = {days}
85
- default_crl_days = {days}
82
+ default_days = 7000
83
+ default_crl_days = 7000
86
84
certificate = pycacert.pem
87
85
private_key = pycakey.pem
88
86
serial = $dir/serial
119
117
here = os .path .abspath (os .path .dirname (__file__ ))
120
118
121
119
122
- def make_cert_key (cmdlineargs , hostname , sign = False , extra_san = '' ,
120
+ def make_cert_key (hostname , sign = False , extra_san = '' ,
123
121
ext = 'req_x509_extensions_full' , key = 'rsa:3072' ):
124
122
print ("creating cert for " + hostname )
125
123
tempnames = []
@@ -132,12 +130,11 @@ def make_cert_key(cmdlineargs, hostname, sign=False, extra_san='',
132
130
hostname = hostname ,
133
131
extra_san = extra_san ,
134
132
startdate = startdate ,
135
- enddate = cmdlineargs .enddate ,
136
- days = cmdlineargs .days
133
+ enddate = enddate
137
134
)
138
135
with open (req_file , 'w' ) as f :
139
136
f .write (req )
140
- args = ['req' , '-new' , '-nodes' , '-days' , cmdlineargs . days ,
137
+ args = ['req' , '-new' , '-nodes' , '-days' , '7000' ,
141
138
'-newkey' , key , '-keyout' , key_file ,
142
139
'-extensions' , ext ,
143
140
'-config' , req_file ]
@@ -178,7 +175,7 @@ def make_cert_key(cmdlineargs, hostname, sign=False, extra_san='',
178
175
def unmake_ca ():
179
176
shutil .rmtree (TMP_CADIR )
180
177
181
- def make_ca (cmdlineargs ):
178
+ def make_ca ():
182
179
os .mkdir (TMP_CADIR )
183
180
with open (os .path .join ('cadir' ,'index.txt' ),'a+' ) as f :
184
181
pass # empty file
@@ -195,8 +192,7 @@ def make_ca(cmdlineargs):
195
192
hostname = 'our-ca-server' ,
196
193
extra_san = '' ,
197
194
startdate = startdate ,
198
- enddate = cmdlineargs .enddate ,
199
- days = cmdlineargs .days
195
+ enddate = enddate
200
196
)
201
197
t .write (req )
202
198
t .flush ()
@@ -223,22 +219,14 @@ def make_ca(cmdlineargs):
223
219
shutil .copy ('capath/ceff1710.0' , 'capath/b1930218.0' )
224
220
225
221
226
- def write_cert_reference (path ):
222
+ def print_cert (path ):
227
223
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 ))
232
225
233
226
234
227
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
-
240
228
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' )
242
230
with open ('ssl_cert.pem' , 'w' ) as f :
243
231
f .write (cert )
244
232
with open ('ssl_key.pem' , 'w' ) as f :
@@ -255,24 +243,24 @@ def write_cert_reference(path):
255
243
f .write (cert )
256
244
257
245
# 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' )
260
248
with open ('keycert2.pem' , 'w' ) as f :
261
249
f .write (key )
262
250
f .write (cert )
263
251
264
- cert , key = make_cert_key (cmdlineargs , 'localhost' , sign = True )
252
+ cert , key = make_cert_key ('localhost' , sign = True )
265
253
with open ('keycert3.pem' , 'w' ) as f :
266
254
f .write (key )
267
255
f .write (cert )
268
256
269
- cert , key = make_cert_key (cmdlineargs , 'fakehostname' , sign = True )
257
+ cert , key = make_cert_key ('fakehostname' , sign = True )
270
258
with open ('keycert4.pem' , 'w' ) as f :
271
259
f .write (key )
272
260
f .write (cert )
273
261
274
262
cert , key = make_cert_key (
275
- cmdlineargs , 'localhost-ecc' , sign = True , key = 'param:secp384r1.pem'
263
+ 'localhost-ecc' , sign = True , key = 'param:secp384r1.pem'
276
264
)
277
265
with open ('keycertecc.pem' , 'w' ) as f :
278
266
f .write (key )
@@ -292,7 +280,7 @@ def write_cert_reference(path):
292
280
'RID.1 = 1.2.3.4.5' ,
293
281
]
294
282
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 ))
296
284
with open ('allsans.pem' , 'w' ) as f :
297
285
f .write (key )
298
286
f .write (cert )
@@ -309,17 +297,17 @@ def write_cert_reference(path):
309
297
]
310
298
311
299
# 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 ))
313
301
with open ('idnsans.pem' , 'w' ) as f :
314
302
f .write (key )
315
303
f .write (cert )
316
304
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' )
318
306
with open ('nosan.pem' , 'w' ) as f :
319
307
f .write (key )
320
308
f .write (cert )
321
309
322
310
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' )
0 commit comments