Skip to content

Commit 021af09

Browse files
committed
Use openssl CLI tool instead of text manipulation.
1 parent 2265e43 commit 021af09

File tree

2 files changed

+2
-21
lines changed

2 files changed

+2
-21
lines changed

Lib/test/certdata/cert3.pem

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/test/certdata/make_ssl_certs.py

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -231,23 +231,6 @@ 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-
251234
if __name__ == '__main__':
252235
parser = argparse.ArgumentParser(description='Make the custom certificate and private key files used by test_ssl and friends.')
253236
parser.add_argument('--days', default=days_default)
@@ -283,9 +266,7 @@ def extract_cert(pem_cert, index):
283266
f.write(key)
284267
f.write(cert)
285268

286-
cert = extract_cert(cert, 0)
287-
with open('cert3.pem', 'w') as f:
288-
f.write(cert)
269+
check_call(['openssl', 'x509', '-outform', 'pem', '-in', 'keycert3.pem', '-out', 'cert3.pem'])
289270

290271
cert, key = make_cert_key(cmdlineargs, 'fakehostname', sign=True)
291272
with open('keycert4.pem', 'w') as f:

0 commit comments

Comments
 (0)