Skip to content

Commit

Permalink
Don't set keylog_filename for empty values
Browse files Browse the repository at this point in the history
  • Loading branch information
sethmlarson committed Oct 4, 2020
1 parent b1f05ae commit 4fb7f32
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
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

0 comments on commit 4fb7f32

Please sign in to comment.