From 021af099d48002e6dbc1405d32ebc5c54537e257 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Fri, 4 Oct 2024 11:43:47 +0200 Subject: [PATCH] Use openssl CLI tool instead of text manipulation. --- Lib/test/certdata/cert3.pem | 2 +- Lib/test/certdata/make_ssl_certs.py | 21 +-------------------- 2 files changed, 2 insertions(+), 21 deletions(-) diff --git a/Lib/test/certdata/cert3.pem b/Lib/test/certdata/cert3.pem index 034bc43ff1974e..4ab0f5ff133e3f 100644 --- a/Lib/test/certdata/cert3.pem +++ b/Lib/test/certdata/cert3.pem @@ -31,4 +31,4 @@ zqmtEM65ceSP8lo8Zbrcy+AEkCulFaZ92tyjtbe8oN4wTmTLFw06oFLSZzuiOgDV OaphdVKf/pvA6KBpr6izox0KQFIE5z3AAJZfKzMGDDD20xhy7jjQZNMAhjfsT+k4 SeYB/6KafNxq08uoulj7w4Z4R/EGpkXnU96ZHYHmvGN0RnxwI1cpYHCazG8AjsK/ anN9brBi5twTGrn+D8LRBqF5Yn+2MKkD0EdXJdtIENHP+32sPQ== ------END CERTIFICATE----- \ No newline at end of file +-----END CERTIFICATE----- diff --git a/Lib/test/certdata/make_ssl_certs.py b/Lib/test/certdata/make_ssl_certs.py index c9ff76f5b278a2..48f980124e1198 100644 --- a/Lib/test/certdata/make_ssl_certs.py +++ b/Lib/test/certdata/make_ssl_certs.py @@ -231,23 +231,6 @@ 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) @@ -283,9 +266,7 @@ def extract_cert(pem_cert, index): f.write(key) f.write(cert) - cert = extract_cert(cert, 0) - with open('cert3.pem', 'w') as f: - f.write(cert) + check_call(['openssl', 'x509', '-outform', 'pem', '-in', 'keycert3.pem', '-out', 'cert3.pem']) cert, key = make_cert_key(cmdlineargs, 'fakehostname', sign=True) with open('keycert4.pem', 'w') as f: