tls: support certificates with IP SubjectAlternativeName (#4596)

This commit is contained in:
Maximilian Hils 2021-05-14 08:36:42 +02:00 committed by GitHub
parent 5f5e2dc0ee
commit 9f0ee9d53a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,4 +1,5 @@
import io import io
import ipaddress
import os import os
import threading import threading
from enum import Enum from enum import Enum
@ -158,9 +159,16 @@ def create_proxy_server_context(
param, param,
SSL._lib.X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS | SSL._lib.X509_CHECK_FLAG_NEVER_CHECK_SUBJECT SSL._lib.X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS | SSL._lib.X509_CHECK_FLAG_NEVER_CHECK_SUBJECT
) )
SSL._openssl_assert( try:
SSL._lib.X509_VERIFY_PARAM_set1_host(param, hostname.encode(), 0) == 1 ip: bytes = ipaddress.ip_address(hostname).packed
) except ValueError:
SSL._openssl_assert(
SSL._lib.X509_VERIFY_PARAM_set1_host(param, hostname.encode(), 0) == 1
)
else:
SSL._openssl_assert(
SSL._lib.X509_VERIFY_PARAM_set1_ip(param, ip, len(ip)) == 1
)
if ca_path is None and ca_pemfile is None: if ca_path is None and ca_pemfile is None:
ca_pemfile = certifi.where() ca_pemfile = certifi.where()