Skip to content

Commit b3e7045

Browse files
authored
bpo-38338, test.pythoninfo: add more ssl infos (GH-16539)
test.pythoninfo now logs environment variables used by OpenSSL and Python ssl modules, and logs attributes of 3 SSL contexts (SSLContext, default HTTPS context, stdlib context).
1 parent 2ea71a0 commit b3e7045

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

Lib/test/pythoninfo.py

+31
Original file line numberDiff line numberDiff line change
@@ -470,10 +470,15 @@ def collect_sysconfig(info_add):
470470

471471

472472
def collect_ssl(info_add):
473+
import os
473474
try:
474475
import ssl
475476
except ImportError:
476477
return
478+
try:
479+
import _ssl
480+
except ImportError:
481+
_ssl = None
477482

478483
def format_attr(attr, value):
479484
if attr.startswith('OP_'):
@@ -490,6 +495,32 @@ def format_attr(attr, value):
490495
)
491496
copy_attributes(info_add, ssl, 'ssl.%s', attributes, formatter=format_attr)
492497

498+
for name, ctx in (
499+
('SSLContext', ssl.SSLContext()),
500+
('default_https_context', ssl._create_default_https_context()),
501+
('stdlib_context', ssl._create_stdlib_context()),
502+
):
503+
attributes = (
504+
'minimum_version',
505+
'maximum_version',
506+
'protocol',
507+
'options',
508+
'verify_mode',
509+
)
510+
copy_attributes(info_add, ctx, f'ssl.{name}.%s', attributes)
511+
512+
env_names = ["OPENSSL_CONF", "SSLKEYLOGFILE"]
513+
if _ssl is not None and hasattr(_ssl, 'get_default_verify_paths'):
514+
parts = _ssl.get_default_verify_paths()
515+
env_names.extend((parts[0], parts[2]))
516+
517+
for name in env_names:
518+
try:
519+
value = os.environ[name]
520+
except KeyError:
521+
continue
522+
info_add('ssl.environ[%s]' % name, value)
523+
493524

494525
def collect_socket(info_add):
495526
import socket

0 commit comments

Comments
 (0)