diff --git a/Lib/test/certdata/make_ssl_certs.py b/Lib/test/certdata/make_ssl_certs.py index 5e626baf550c5b1..c9ff76f5b278a25 100644 --- a/Lib/test/certdata/make_ssl_certs.py +++ b/Lib/test/certdata/make_ssl_certs.py @@ -231,6 +231,23 @@ def write_cert_reference(path): print(refdata, file=f) +def extract_cert(pem_cert, index): + result = [] + active = False + for line in pem_cert.splitlines(): + match = active + if line == '-----BEGIN CERTIFICATE-----': + if index == 0: + active = True + match = True + index -= 1 + elif line == '-----END CERTIFICATE-----': + active = False + if match: + result.append(line) + return '\n'.join(result) + '\n' + + if __name__ == '__main__': parser = argparse.ArgumentParser(description='Make the custom certificate and private key files used by test_ssl and friends.') parser.add_argument('--days', default=days_default) @@ -266,6 +283,10 @@ def write_cert_reference(path): f.write(key) f.write(cert) + cert = extract_cert(cert, 0) + with open('cert3.pem', 'w') as f: + f.write(cert) + cert, key = make_cert_key(cmdlineargs, 'fakehostname', sign=True) with open('keycert4.pem', 'w') as f: f.write(key)