Skip to content

Commit

Permalink
Only provide a hostname to SecCreatePolicySSL when verifying
Browse files Browse the repository at this point in the history
  • Loading branch information
sethmlarson committed Aug 23, 2024
1 parent 6fa65ab commit dead3d2
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/truststore/_macos.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,9 @@ def _verify_peercerts_impl(
trust = None
cf_error = None
try:
if server_hostname is not None:
# Only set a hostname on the policy if we're verifying the hostname
# on the leaf certificate.
if server_hostname is not None and ssl_context.check_hostname:
cf_str_hostname = None
try:
cf_str_hostname = _bytes_to_cf_string(server_hostname.encode("ascii"))
Expand Down Expand Up @@ -458,11 +460,6 @@ def _verify_peercerts_impl(
or cf_error_code == CFConst.errSecCertificateExpired
):
is_trusted = True
elif (
not ssl_context.check_hostname
and cf_error_code == CFConst.errSecHostNameMismatch
):
is_trusted = True

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

0 comments on commit dead3d2

Please sign in to comment.