File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed
Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -91,7 +91,18 @@ def get_ssl_context(*args):
9191 # Note PROTOCOL_SSLv23 is about the most misleading name imaginable.
9292 # This configures the server and client to negotiate the
9393 # highest protocol version they both support. A very good thing.
94- ctx = SSLContext (ssl .PROTOCOL_SSLv23 )
94+ # PROTOCOL_TLS_CLIENT was added in CPython 3.6, deprecating
95+ # PROTOCOL_SSLv23.
96+ ctx = SSLContext (
97+ getattr (ssl , "PROTOCOL_TLS_CLIENT" , ssl .PROTOCOL_SSLv23 ))
98+ # SSLContext.check_hostname was added in CPython 2.7.9 and 3.4.
99+ # PROTOCOL_TLS_CLIENT enables it by default. Using it
100+ # requires passing server_hostname to wrap_socket, which we already
101+ # do for SNI support. To support older versions of Python we have to
102+ # call match_hostname directly, so we disable check_hostname explicitly
103+ # to avoid calling match_hostname twice.
104+ if hasattr (ctx , "check_hostname" ):
105+ ctx .check_hostname = False
95106 if hasattr (ctx , "options" ):
96107 # Explicitly disable SSLv2, SSLv3 and TLS compression. Note that
97108 # up to date versions of MongoDB 2.4 and above already disable
You can’t perform that action at this time.
0 commit comments