38
38
)
39
39
from pymongo .network_layer import AsyncNetworkingInterface , NetworkingInterface , PyMongoProtocol
40
40
from pymongo .pool_options import PoolOptions
41
- from pymongo .ssl_support import HAS_SNI , SSLError
41
+ from pymongo .ssl_support import PYSSLError , SSLError , _has_sni
42
42
43
+ SSLErrors = (PYSSLError , SSLError )
43
44
if TYPE_CHECKING :
44
45
from pymongo .pyopenssl_context import _sslConn
45
46
from pymongo .typings import _Address
@@ -138,7 +139,7 @@ def _raise_connection_failure(
138
139
msg += format_timeout_details (timeout_details )
139
140
if isinstance (error , socket .timeout ):
140
141
raise NetworkTimeout (msg ) from error
141
- elif isinstance (error , SSLError ) and "timed out" in str (error ):
142
+ elif isinstance (error , SSLErrors ) and "timed out" in str (error ):
142
143
# Eventlet does not distinguish TLS network timeouts from other
143
144
# SSLErrors (https://github.com/eventlet/eventlet/issues/692).
144
145
# Luckily, we can work around this limitation because the phrase
@@ -279,7 +280,7 @@ async def _async_configured_socket(
279
280
try :
280
281
# We have to pass hostname / ip address to wrap_socket
281
282
# to use SSLContext.check_hostname.
282
- if HAS_SNI :
283
+ if _has_sni ( False ) :
283
284
loop = asyncio .get_running_loop ()
284
285
ssl_sock = await loop .run_in_executor (
285
286
None ,
@@ -293,7 +294,7 @@ async def _async_configured_socket(
293
294
# Raise _CertificateError directly like we do after match_hostname
294
295
# below.
295
296
raise
296
- except (OSError , SSLError ) as exc :
297
+ except (OSError , * SSLErrors ) as exc :
297
298
sock .close ()
298
299
# We raise AutoReconnect for transient and permanent SSL handshake
299
300
# failures alike. Permanent handshake failures, like protocol
@@ -349,7 +350,7 @@ async def _configured_protocol_interface(
349
350
# Raise _CertificateError directly like we do after match_hostname
350
351
# below.
351
352
raise
352
- except (OSError , SSLError ) as exc :
353
+ except (OSError , * SSLErrors ) as exc :
353
354
# We raise AutoReconnect for transient and permanent SSL handshake
354
355
# failures alike. Permanent handshake failures, like protocol
355
356
# mismatch, will be turned into ServerSelectionTimeoutErrors later.
@@ -458,7 +459,7 @@ def _configured_socket(address: _Address, options: PoolOptions) -> Union[socket.
458
459
try :
459
460
# We have to pass hostname / ip address to wrap_socket
460
461
# to use SSLContext.check_hostname.
461
- if HAS_SNI :
462
+ if _has_sni ( True ) :
462
463
ssl_sock = ssl_context .wrap_socket (sock , server_hostname = host ) # type: ignore[assignment, misc, unused-ignore]
463
464
else :
464
465
ssl_sock = ssl_context .wrap_socket (sock ) # type: ignore[assignment, misc, unused-ignore]
@@ -467,7 +468,7 @@ def _configured_socket(address: _Address, options: PoolOptions) -> Union[socket.
467
468
# Raise _CertificateError directly like we do after match_hostname
468
469
# below.
469
470
raise
470
- except (OSError , SSLError ) as exc :
471
+ except (OSError , * SSLErrors ) as exc :
471
472
sock .close ()
472
473
# We raise AutoReconnect for transient and permanent SSL handshake
473
474
# failures alike. Permanent handshake failures, like protocol
@@ -507,7 +508,7 @@ def _configured_socket_interface(address: _Address, options: PoolOptions) -> Net
507
508
try :
508
509
# We have to pass hostname / ip address to wrap_socket
509
510
# to use SSLContext.check_hostname.
510
- if HAS_SNI :
511
+ if _has_sni ( True ) :
511
512
ssl_sock = ssl_context .wrap_socket (sock , server_hostname = host )
512
513
else :
513
514
ssl_sock = ssl_context .wrap_socket (sock )
@@ -516,7 +517,7 @@ def _configured_socket_interface(address: _Address, options: PoolOptions) -> Net
516
517
# Raise _CertificateError directly like we do after match_hostname
517
518
# below.
518
519
raise
519
- except (OSError , SSLError ) as exc :
520
+ except (OSError , * SSLErrors ) as exc :
520
521
sock .close ()
521
522
# We raise AutoReconnect for transient and permanent SSL handshake
522
523
# failures alike. Permanent handshake failures, like protocol
0 commit comments