Skip to content

Commit ab98cd8

Browse files
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). (cherry picked from commit b3e7045) Co-authored-by: Victor Stinner <vstinner@python.org>
1 parent 2027f90 commit ab98cd8

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

Lib/test/pythoninfo.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,10 +439,15 @@ def collect_sysconfig(info_add):
439439

440440

441441
def collect_ssl(info_add):
442+
import os
442443
try:
443444
import ssl
444445
except ImportError:
445446
return
447+
try:
448+
import _ssl
449+
except ImportError:
450+
_ssl = None
446451

447452
def format_attr(attr, value):
448453
if attr.startswith('OP_'):
@@ -459,6 +464,32 @@ def format_attr(attr, value):
459464
)
460465
copy_attributes(info_add, ssl, 'ssl.%s', attributes, formatter=format_attr)
461466

467+
for name, ctx in (
468+
('SSLContext', ssl.SSLContext()),
469+
('default_https_context', ssl._create_default_https_context()),
470+
('stdlib_context', ssl._create_stdlib_context()),
471+
):
472+
attributes = (
473+
'minimum_version',
474+
'maximum_version',
475+
'protocol',
476+
'options',
477+
'verify_mode',
478+
)
479+
copy_attributes(info_add, ctx, f'ssl.{name}.%s', attributes)
480+
481+
env_names = ["OPENSSL_CONF", "SSLKEYLOGFILE"]
482+
if _ssl is not None and hasattr(_ssl, 'get_default_verify_paths'):
483+
parts = _ssl.get_default_verify_paths()
484+
env_names.extend((parts[0], parts[2]))
485+
486+
for name in env_names:
487+
try:
488+
value = os.environ[name]
489+
except KeyError:
490+
continue
491+
info_add('ssl.environ[%s]' % name, value)
492+
462493

463494
def collect_socket(info_add):
464495
import socket

0 commit comments

Comments
 (0)