|
1 | 1 | """Make the custom certificate and private key files used by test_ssl |
2 | 2 | and friends.""" |
3 | 3 |
|
| 4 | +import argparse |
4 | 5 | import os |
5 | 6 | import pprint |
6 | 7 | import shutil |
7 | 8 | import tempfile |
8 | 9 | from subprocess import * |
9 | 10 |
|
10 | 11 | startdate = "20180829142316Z" |
11 | | -enddate = "20371028142316Z" |
| 12 | +enddate_default = "20371028142316Z" |
| 13 | +days_default = "7000" |
| 14 | + |
| 15 | +cmdlineargs = None |
12 | 16 |
|
13 | 17 | req_template = """ |
14 | 18 | [ default ] |
|
79 | 83 | default_startdate = {startdate} |
80 | 84 | enddate = {enddate} |
81 | 85 | default_enddate = {enddate} |
82 | | - default_days = 7000 |
83 | | - default_crl_days = 7000 |
| 86 | + default_days = {days} |
| 87 | + default_crl_days = {days} |
84 | 88 | certificate = pycacert.pem |
85 | 89 | private_key = pycakey.pem |
86 | 90 | serial = $dir/serial |
@@ -130,11 +134,12 @@ def make_cert_key(hostname, sign=False, extra_san='', |
130 | 134 | hostname=hostname, |
131 | 135 | extra_san=extra_san, |
132 | 136 | startdate=startdate, |
133 | | - enddate=enddate |
| 137 | + enddate=cmdlineargs.enddate, |
| 138 | + days=cmdlineargs.days |
134 | 139 | ) |
135 | 140 | with open(req_file, 'w') as f: |
136 | 141 | f.write(req) |
137 | | - args = ['req', '-new', '-nodes', '-days', '7000', |
| 142 | + args = ['req', '-new', '-nodes', '-days', cmdlineargs.days, |
138 | 143 | '-newkey', key, '-keyout', key_file, |
139 | 144 | '-extensions', ext, |
140 | 145 | '-config', req_file] |
@@ -192,7 +197,8 @@ def make_ca(): |
192 | 197 | hostname='our-ca-server', |
193 | 198 | extra_san='', |
194 | 199 | startdate=startdate, |
195 | | - enddate=enddate |
| 200 | + enddate=cmdlineargs.enddate, |
| 201 | + days=cmdlineargs.days |
196 | 202 | ) |
197 | 203 | t.write(req) |
198 | 204 | t.flush() |
@@ -228,6 +234,11 @@ def write_cert_reference(path): |
228 | 234 |
|
229 | 235 |
|
230 | 236 | 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 | + |
231 | 242 | os.chdir(here) |
232 | 243 | cert, key = make_cert_key('localhost', ext='req_x509_extensions_simple') |
233 | 244 | with open('ssl_cert.pem', 'w') as f: |
|
0 commit comments