Skip to content

Commit

Permalink
Fix assert_hostname=False (#3055)
Browse files Browse the repository at this point in the history
Co-authored-by: Quentin Pradet <quentin.pradet@gmail.com>
  • Loading branch information
sg3-141-592 and pquentin committed Jun 2, 2023
1 parent bfbd47e commit 52d2eb1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog/3051.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed `assert_hostname=False` to correctly skip hostname check.
2 changes: 2 additions & 0 deletions src/urllib3/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,8 @@ def _ssl_wrap_socket_and_match_hostname(
# `ssl` can't verify fingerprints or alternate hostnames
assert_fingerprint
or assert_hostname
# assert_hostname can be set to False to disable hostname checking
or assert_hostname is False
# We still support OpenSSL 1.0.2, which prevents us from verifying
# hostnames easily: https://github.com/pyca/pyopenssl/pull/933
or ssl_.IS_PYOPENSSL
Expand Down
26 changes: 26 additions & 0 deletions test/with_dummyserver/test_https.py
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,32 @@ def test_hostname_checks_common_name_respected(
err.reason.args[0], (ssl.SSLCertVerificationError, CertificateError)
)

def test_assert_hostname_invalid_san(
self, no_localhost_san_server: ServerConfig
) -> None:
"""Ensure SAN errors are not raised while assert_hostname is false"""
with HTTPSConnectionPool(
no_localhost_san_server.host,
no_localhost_san_server.port,
cert_reqs="CERT_REQUIRED",
ca_certs=no_localhost_san_server.ca_certs,
assert_hostname=False,
) as https_pool:
https_pool.request("GET", "/")

def test_assert_hostname_invalid_cn(
self, no_san_server_with_different_commmon_name: ServerConfig
) -> None:
"""Ensure CN errors are not raised while assert_hostname is false"""
with HTTPSConnectionPool(
no_san_server_with_different_commmon_name.host,
no_san_server_with_different_commmon_name.port,
cert_reqs="CERT_REQUIRED",
ca_certs=no_san_server_with_different_commmon_name.ca_certs,
assert_hostname=False,
) as https_pool:
https_pool.request("GET", "/")


class TestHTTPS_IPV4SAN:
def test_can_validate_ip_san(self, ipv4_san_server: ServerConfig) -> None:
Expand Down

0 comments on commit 52d2eb1

Please sign in to comment.