|
20 | 20 | CN = {hostname} |
21 | 21 |
|
22 | 22 | [req_x509_extensions] |
23 | | - subjectAltName = DNS:{hostname} |
| 23 | + subjectAltName = @san |
| 24 | +
|
| 25 | + [san] |
| 26 | + DNS.1 = {hostname} |
| 27 | + {extra_san} |
| 28 | +
|
| 29 | + [dir_sect] |
| 30 | + C = XY |
| 31 | + L = Castle Anthrax |
| 32 | + O = Python Software Foundation |
| 33 | + CN = dirname example |
| 34 | +
|
| 35 | + [princ_name] |
| 36 | + realm = EXP:0, GeneralString:KERBEROS.REALM |
| 37 | + principal_name = EXP:1, SEQUENCE:principal_seq |
| 38 | +
|
| 39 | + [principal_seq] |
| 40 | + name_type = EXP:0, INTEGER:1 |
| 41 | + name_string = EXP:1, SEQUENCE:principals |
| 42 | +
|
| 43 | + [principals] |
| 44 | + princ1 = GeneralString:username |
24 | 45 |
|
25 | 46 | [ ca ] |
26 | 47 | default_ca = CA_default |
|
67 | 88 |
|
68 | 89 | here = os.path.abspath(os.path.dirname(__file__)) |
69 | 90 |
|
70 | | -def make_cert_key(hostname, sign=False): |
| 91 | +def make_cert_key(hostname, sign=False, extra_san=''): |
71 | 92 | print("creating cert for " + hostname) |
72 | 93 | tempnames = [] |
73 | 94 | for i in range(3): |
74 | 95 | with tempfile.NamedTemporaryFile(delete=False) as f: |
75 | 96 | tempnames.append(f.name) |
76 | 97 | req_file, cert_file, key_file = tempnames |
77 | 98 | try: |
| 99 | + req = req_template.format(hostname=hostname, extra_san=extra_san) |
78 | 100 | with open(req_file, 'w') as f: |
79 | | - f.write(req_template.format(hostname=hostname)) |
| 101 | + f.write(req) |
80 | 102 | args = ['req', '-new', '-days', '3650', '-nodes', |
81 | 103 | '-newkey', 'rsa:1024', '-keyout', key_file, |
82 | 104 | '-config', req_file] |
@@ -120,7 +142,7 @@ def make_ca(): |
120 | 142 | f.write('unique_subject = no') |
121 | 143 |
|
122 | 144 | with tempfile.NamedTemporaryFile("w") as t: |
123 | | - t.write(req_template.format(hostname='our-ca-server')) |
| 145 | + t.write(req_template.format(hostname='our-ca-server', extra_san='')) |
124 | 146 | t.flush() |
125 | 147 | with tempfile.NamedTemporaryFile() as f: |
126 | 148 | args = ['req', '-new', '-days', '3650', '-extensions', 'v3_ca', '-nodes', |
@@ -171,6 +193,25 @@ def make_ca(): |
171 | 193 | f.write(key) |
172 | 194 | f.write(cert) |
173 | 195 |
|
| 196 | + extra_san = [ |
| 197 | + 'otherName.1 = 1.2.3.4;UTF8:some other identifier', |
| 198 | + 'otherName.2 = 1.3.6.1.5.2.2;SEQUENCE:princ_name', |
| 199 | + |
| 200 | + 'DNS.2 = www.example.org', |
| 201 | + # GEN_X400 |
| 202 | + 'dirName.1 = dir_sect', |
| 203 | + # GEN_EDIPARTY |
| 204 | + 'URI.1 = https://www.python.org/', |
| 205 | + 'IP.1 = 127.0.0.1', |
| 206 | + 'IP.2 = ::1', |
| 207 | + 'RID.1 = 1.2.3.4.5', |
| 208 | + ] |
| 209 | + |
| 210 | + cert, key = make_cert_key('allsans', extra_san='\n'.join(extra_san)) |
| 211 | + with open('allsans.pem', 'w') as f: |
| 212 | + f.write(key) |
| 213 | + f.write(cert) |
| 214 | + |
174 | 215 | unmake_ca() |
175 | 216 | print("\n\nPlease change the values in test_ssl.py, test_parse_cert function related to notAfter,notBefore and serialNumber") |
176 | 217 | check_call(['openssl','x509','-in','keycert.pem','-dates','-serial','-noout']) |
0 commit comments