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