@@ -90,11 +90,11 @@ def get_ssl_context(
90
90
) -> Union [_pyssl .SSLContext , _ssl .SSLContext ]: # type: ignore[name-defined]
91
91
"""Create and return an SSLContext object."""
92
92
if is_sync and HAVE_PYSSL :
93
- _ssl : types .ModuleType = _pyssl
93
+ ssl : types .ModuleType = _pyssl
94
94
else :
95
- _ssl = globals ()[ " _ssl" ]
95
+ ssl = _ssl
96
96
verify_mode = CERT_NONE if allow_invalid_certificates else CERT_REQUIRED
97
- ctx = _ssl .SSLContext (_ssl .PROTOCOL_SSLv23 )
97
+ ctx = ssl .SSLContext (ssl .PROTOCOL_SSLv23 )
98
98
if verify_mode != CERT_NONE :
99
99
ctx .check_hostname = not allow_invalid_hostnames
100
100
else :
@@ -106,20 +106,20 @@ def get_ssl_context(
106
106
# up to date versions of MongoDB 2.4 and above already disable
107
107
# SSLv2 and SSLv3, python disables SSLv2 by default in >= 2.7.7
108
108
# and >= 3.3.4 and SSLv3 in >= 3.4.3.
109
- ctx .options |= _ssl .OP_NO_SSLv2
110
- ctx .options |= _ssl .OP_NO_SSLv3
111
- ctx .options |= _ssl .OP_NO_COMPRESSION
112
- ctx .options |= _ssl .OP_NO_RENEGOTIATION
109
+ ctx .options |= ssl .OP_NO_SSLv2
110
+ ctx .options |= ssl .OP_NO_SSLv3
111
+ ctx .options |= ssl .OP_NO_COMPRESSION
112
+ ctx .options |= ssl .OP_NO_RENEGOTIATION
113
113
if certfile is not None :
114
114
try :
115
115
ctx .load_cert_chain (certfile , None , passphrase )
116
- except _ssl .SSLError as exc :
116
+ except ssl .SSLError as exc :
117
117
raise ConfigurationError (f"Private key doesn't match certificate: { exc } " ) from None
118
118
if crlfile is not None :
119
- if _ssl .IS_PYOPENSSL :
119
+ if ssl .IS_PYOPENSSL :
120
120
raise ConfigurationError ("tlsCRLFile cannot be used with PyOpenSSL" )
121
121
# Match the server's behavior.
122
- ctx .verify_flags = getattr (_ssl , "VERIFY_CRL_CHECK_LEAF" , 0 )
122
+ ctx .verify_flags = getattr (ssl , "VERIFY_CRL_CHECK_LEAF" , 0 )
123
123
ctx .load_verify_locations (crlfile )
124
124
if ca_certs is not None :
125
125
ctx .load_verify_locations (ca_certs )
0 commit comments