Skip to content

Commit

Permalink
Try using 'SECURITY_FLAG_IGNORE_CERT_CN_INVALID' for Windows hostname…
Browse files Browse the repository at this point in the history
… verification disabling
  • Loading branch information
sethmlarson committed Oct 23, 2024
1 parent 61bb28b commit 3599718
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/truststore/_windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ class CERT_CHAIN_ENGINE_CONFIG(Structure):
CERT_CHAIN_POLICY_IGNORE_ALL_REV_UNKNOWN_FLAGS = 0x00000F00
CERT_CHAIN_POLICY_ALLOW_TESTROOT_FLAG = 0x00008000
CERT_CHAIN_POLICY_TRUST_TESTROOT_FLAG = 0x00004000
SECURITY_FLAG_IGNORE_CERT_CN_INVALID = 0x00001000
AUTHTYPE_SERVER = 2
CERT_CHAIN_POLICY_SSL = 4
FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000
Expand Down Expand Up @@ -443,6 +444,10 @@ def _get_and_verify_cert_chain(
)
ssl_extra_cert_chain_policy_para.dwAuthType = AUTHTYPE_SERVER
ssl_extra_cert_chain_policy_para.fdwChecks = 0
if ssl_context.check_hostname is False:
ssl_extra_cert_chain_policy_para.fdwChecks = (
SECURITY_FLAG_IGNORE_CERT_CN_INVALID
)
if server_hostname:
ssl_extra_cert_chain_policy_para.pwszServerName = c_wchar_p(server_hostname)

Expand All @@ -452,8 +457,6 @@ def _get_and_verify_cert_chain(
)
if ssl_context.verify_mode == ssl.CERT_NONE:
chain_policy.dwFlags |= CERT_CHAIN_POLICY_VERIFY_MODE_NONE_FLAGS
if not ssl_context.check_hostname:
chain_policy.dwFlags |= CERT_CHAIN_POLICY_IGNORE_INVALID_NAME_FLAG
chain_policy.cbSize = sizeof(chain_policy)

pPolicyPara = pointer(chain_policy)
Expand Down

0 comments on commit 3599718

Please sign in to comment.