8000 make_ssl_certs: make it possible to pass in expiration dates from com… · python/cpython@0fcc8a2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0fcc8a2

Browse files
committed
make_ssl_certs: make it possible to pass in expiration dates from command line
Note that the defaults are same as they were, so if nothing is specified, the script works exactly as before. Signed-off-by: Alexander Kanavin <alex.kanavin@gmail.com>
1 parent 6c899df commit 0fcc8a2

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

Lib/test/certdata/make_ssl_certs.py

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

4+
import argparse
45
import os
56
import pprint
67
import shutil
78
import tempfile
89
from subprocess import *
910

1011
startdate = "20180829142316Z"
11-
enddate = "20371028142316Z"
12+
enddate_default = "20371028142316Z"
13+
days_default = "7000"
14+
15+
cmdlineargs = None
1216

1317
req_template = """
1418
[ default ]
@@ -79,8 +83,8 @@
7983
default_startdate = {startdate}
8084
enddate = {enddate}
8185
default_enddate = {enddate}
82-
default_days = 7000
83-
default_crl_days = 7000
86+
default_days = {days}
87+
default_crl_days = {days}
8488
certificate = pycacert.pem
8589
private_key = pycakey.pem
8690
serial = $dir/serial
@@ -130,11 +134,12 @@ def make_cert_key(hostname, sign=False, extra_san='',
130134
hostname=hostname,
131135
extra_san=extra_san,
132136
startdate=startdate,
133-
enddate=enddate
137+
enddate=cmdlineargs.enddate,
138+
days=cmdlineargs.days
134139
)
135140
with open(req_file, 'w') as f:
136141
f.write(req)
137-
args = ['req', '-new', '-nodes', '-days', '7000',
142+
args = ['req', '-new', '-nodes', '-days', cmdlineargs.days,
138143
'-newkey', key, '-keyout', key_file,
139144
'-extensions', ext,
140145
'-config', req_file]
@@ -192,7 +197,8 @@ def make_ca():
192197
hostname='our-ca-server',
193198
extra_san='',
194199
startdate=startdate,
195-
enddate=enddate
200+
enddate=cmdlineargs.enddate,
201+
days=cmdlineargs.days
196202
)
197203
t.write(req)
198204
t.flush()
@@ -228,6 +234,11 @@ def write_cert_reference(path):
228234

229235

230236
if __name__ == '__main__':
237+
parser = argparse.ArgumentParser(description='Make the custom certificate and private key files used by test_ssl and friends.')
238+
parser.add_argument('--days', default=days_default)
239+
parser.add_argument('--enddate', default=enddate_default)
240+
cmdlineargs = parser.parse_args()
241+
231242
os.chdir(here)
232243
cert, key = make_cert_key('localhost', ext='req_x509_extensions_simple')
233244
with open('ssl_cert.pem', 'w') as f:

0 commit comments

Comments
 (0)
0