Skip to content

Commit 903e4ee

Browse files
committed
Modify cert generation script to extract cert3.pem.
1 parent 274d9ab commit 903e4ee

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Lib/test/certdata/make_ssl_certs.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,23 @@ def write_cert_reference(path):
231231
print(refdata, file=f)
232232

233233

234+
def extract_cert(pem_cert, index):
235+
result = []
236+
active = False
237+
for line in pem_cert.splitlines():
238+
match = active
239+
if line == '-----BEGIN CERTIFICATE-----':
240+
if index == 0:
241+
active = True
242+
match = True
243+
index -= 1
244+
elif line == '-----END CERTIFICATE-----':
245+
active = False
246+
if match:
247+
result.append(line)
248+
return '\n'.join(result) + '\n'
249+
250+
234251
if __name__ == '__main__':
235252
parser = argparse.ArgumentParser(description='Make the custom certificate and private key files used by test_ssl and friends.')
236253
parser.add_argument('--days', default=days_default)
@@ -266,6 +283,10 @@ def write_cert_reference(path):
266283
f.write(key)
267284
f.write(cert)
268285

286+
cert = extract_cert(cert, 0)
287+
with open('cert3.pem', 'w') as f:
288+
f.write(cert)
289+
269290
cert, key = make_cert_key(cmdlineargs, 'fakehostname', sign=True)
270291
with open('keycert4.pem', 'w') as f:
271292
f.write(key)

0 commit comments

Comments
 (0)