39
39
stacklevel = 2 ,
40
40
)
41
41
try :
42
- import pymongo .ssl_context as _stdssl
42
+ import pymongo .ssl_context as _ssl
43
43
except ImportError :
44
44
HAVE_SSL = False
45
45
55
55
IPADDR_SAFE = True
56
56
57
57
if HAVE_PYSSL :
58
- HAS_SNI = _pyssl .HAS_SNI | _stdssl .HAS_SNI
58
+ # # We have to pass hostname / ip address to wrap_socket
59
+ # # to use SSLContext.check_hostname.
60
+ # if ssl_context.has_sni:
61
+ # ...
62
+ HAS_SNI = _pyssl .HAS_SNI and _ssl .HAS_SNI
59
63
PYSSLError : Any = _pyssl .SSLError
60
- BLOCKING_IO_ERRORS : tuple = _pyssl .BLOCKING_IO_ERRORS + _stdssl .BLOCKING_IO_ERRORS
64
+ BLOCKING_IO_ERRORS : tuple = _pyssl .BLOCKING_IO_ERRORS + _ssl .BLOCKING_IO_ERRORS
61
65
BLOCKING_IO_READ_ERROR : tuple = (
62
66
_pyssl .BLOCKING_IO_READ_ERROR ,
63
- _stdssl .BLOCKING_IO_READ_ERROR ,
67
+ _ssl .BLOCKING_IO_READ_ERROR ,
64
68
)
65
69
BLOCKING_IO_WRITE_ERROR : tuple = (
66
70
_pyssl .BLOCKING_IO_WRITE_ERROR ,
67
- _stdssl .BLOCKING_IO_WRITE_ERROR ,
71
+ _ssl .BLOCKING_IO_WRITE_ERROR ,
68
72
)
69
73
else :
70
- HAS_SNI = _stdssl .HAS_SNI
71
- PYSSLError = _stdssl .SSLError
72
- BLOCKING_IO_ERRORS = _stdssl .BLOCKING_IO_ERRORS
73
- BLOCKING_IO_READ_ERROR = (_stdssl .BLOCKING_IO_READ_ERROR ,)
74
- BLOCKING_IO_WRITE_ERROR = (_stdssl .BLOCKING_IO_WRITE_ERROR ,)
75
- SSLError = _stdssl .SSLError
74
+ HAS_SNI = _ssl .HAS_SNI
75
+ PYSSLError = _ssl .SSLError
76
+ BLOCKING_IO_ERRORS = _ssl .BLOCKING_IO_ERRORS
77
+ BLOCKING_IO_READ_ERROR = (_ssl .BLOCKING_IO_READ_ERROR ,)
78
+ BLOCKING_IO_WRITE_ERROR = (_ssl .BLOCKING_IO_WRITE_ERROR ,)
79
+ SSLError = _ssl .SSLError
76
80
BLOCKING_IO_LOOKUP_ERROR = BLOCKING_IO_READ_ERROR
77
81
78
82
def get_ssl_context (
@@ -84,12 +88,10 @@ def get_ssl_context(
84
88
allow_invalid_hostnames : bool ,
85
89
disable_ocsp_endpoint_check : bool ,
86
90
is_sync : bool ,
87
- ) -> Union [_pyssl .SSLContext , _stdssl .SSLContext ]: # type: ignore[name-defined]
91
+ ) -> Union [_pyssl .SSLContext , _ssl .SSLContext ]: # type: ignore[name-defined]
88
92
"""Create and return an SSLContext object."""
89
93
if is_sync and HAVE_PYSSL :
90
94
_ssl : types .ModuleType = _pyssl
91
- else :
92
- _ssl = _stdssl
93
95
verify_mode = CERT_NONE if allow_invalid_certificates else CERT_REQUIRED
94
96
ctx = _ssl .SSLContext (_ssl .PROTOCOL_SSLv23 )
95
97
if verify_mode != CERT_NONE :
0 commit comments