Skip to content

Commit dead3d2

Browse files
committed
Only provide a hostname to SecCreatePolicySSL when verifying
1 parent 6fa65ab commit dead3d2

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/truststore/_macos.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,9 @@ def _verify_peercerts_impl(
367367
trust = None
368368
cf_error = None
369369
try:
370-
if server_hostname is not None:
370+
# Only set a hostname on the policy if we're verifying the hostname
371+
# on the leaf certificate.
372+
if server_hostname is not None and ssl_context.check_hostname:
371373
cf_str_hostname = None
372374
try:
373375
cf_str_hostname = _bytes_to_cf_string(server_hostname.encode("ascii"))
@@ -458,11 +460,6 @@ def _verify_peercerts_impl(
458460
or cf_error_code == CFConst.errSecCertificateExpired
459461
):
460462
is_trusted = True
461-
elif (
462-
not ssl_context.check_hostname
463-
and cf_error_code == CFConst.errSecHostNameMismatch
464-
):
465-
is_trusted = True
466463

467464
# If we're still not trusted then we start to
468465
# construct and raise the SSLCertVerificationError.

0 commit comments

Comments
 (0)