Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't set keylog_filename for empty values #2016

Merged
merged 1 commit into from Oct 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/urllib3/util/ssl_.py
Expand Up @@ -314,9 +314,11 @@ def create_urllib3_context(
context.check_hostname = False

# Enable logging of TLS session keys via defacto standard environment variable
# 'SSLKEYLOGFILE', if the feature is available (Python 3.8+).
# 'SSLKEYLOGFILE', if the feature is available (Python 3.8+). Skip empty values.
if hasattr(context, "keylog_filename"):
context.keylog_filename = os.environ.get("SSLKEYLOGFILE")
sslkeylogfile = os.environ.get("SSLKEYLOGFILE")
if sslkeylogfile:
context.keylog_filename = sslkeylogfile

return context

Expand Down
12 changes: 12 additions & 0 deletions test/with_dummyserver/test_https.py
Expand Up @@ -719,6 +719,18 @@ def test_sslkeylogfile(self, tmpdir, monkeypatch):
keylog_file
)

@pytest.mark.parametrize("sslkeylogfile", [None, ""])
def test_sslkeylogfile_empty(self, monkeypatch, sslkeylogfile):
# Assert that an HTTPS connection doesn't error out when given
# no SSLKEYLOGFILE or an empty value (ie 'SSLKEYLOGFILE=')
if sslkeylogfile is not None:
monkeypatch.setenv("SSLKEYLOGFILE", sslkeylogfile)
else:
monkeypatch.delenv("SSLKEYLOGFILE", raising=False)
with HTTPSConnectionPool(self.host, self.port, ca_certs=DEFAULT_CA) as pool:
r = pool.request("GET", "/")
assert r.status == 200, r.data

def test_alpn_default(self):
"""Default ALPN protocols are sent by default."""
if not has_alpn() or not has_alpn(ssl.SSLContext):
Expand Down