diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..13566b8
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/haigha2.iml b/.idea/haigha2.iml
new file mode 100644
index 0000000..269e1a8
--- /dev/null
+++ b/.idea/haigha2.iml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
new file mode 100644
index 0000000..c73d219
--- /dev/null
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml
new file mode 100644
index 0000000..105ce2d
--- /dev/null
+++ b/.idea/inspectionProfiles/profiles_settings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..a802c0f
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..e83155a
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/haigha2/ssl_connection.py b/haigha2/ssl_connection.py
index 9abbea1..f80e2a0 100644
--- a/haigha2/ssl_connection.py
+++ b/haigha2/ssl_connection.py
@@ -36,7 +36,7 @@ def _initialize_transport(self, transport_type):
raise Exception("Transport type is '{transport_type}' but {transport_type} not installed".format(
transport_type=transport_type))
return transport_class
-
+
def verify_hostname(self, host_name):
cert = self._transport._sock.getpeercert()
if not cert:
diff --git a/haigha2/transports/eventlet_transport.py b/haigha2/transports/eventlet_transport.py
index b1e6ea6..16991db 100644
--- a/haigha2/transports/eventlet_transport.py
+++ b/haigha2/transports/eventlet_transport.py
@@ -13,7 +13,10 @@
from eventlet.timeout import Timeout as EventletTimeout
from eventlet.green import socket as eventlet_socket
from eventlet.green import ssl as eventlet_ssl
- from eventlet.green.ssl import GreenSSLSocket, timeout_exc, CERT_NONE, PROTOCOL_SSLv23
+ if sys.version_info >= (3, 12):
+ from eventlet.green.ssl import GreenSSLSocket, timeout_exc, CERT_REQUIRED, PROTOCOL_TLS
+ else:
+ from eventlet.green.ssl import GreenSSLSocket, timeout_exc, CERT_NONE, PROTOCOL_SSLv23
from eventlet.greenio import SOCKET_CLOSED, GreenSocket
from eventlet.hubs import trampoline
from eventlet.support import get_errno, PY33
@@ -37,7 +40,10 @@
_original_sslsocket = __ssl.SSLSocket
-_original_wrap_socket = __ssl.wrap_socket
+if sys.version_info >= (3, 12):
+ _original_wrap_socket = __ssl.SSLContext.wrap_socket
+else:
+ _original_wrap_socket = __ssl.wrap_socket
_original_sslcontext = getattr(__ssl, 'SSLContext', None)
_is_under_py_3_7 = sys.version_info < (3, 7)
@@ -120,7 +126,8 @@ def recv(self, *args, **kwargs):
try:
return super(FixedGreenSSLSocket, self).recv(*args, **kwargs)
except timeout_exc as e:
- if e.msg == 'timed out':
+ # GC-89692 -> e has no attribute 'msg'
+ if isinstance(e, socket.timeout) :
raise socket.timeout('timed out')
raise
@@ -139,9 +146,16 @@ def _original_ssl_context(*args, **kwargs):
class FixedEventletGreenSSLSocket(FixedGreenSSLSocket):
+ if sys.version_info >= (3, 12):
+ default_cert_reqs = CERT_REQUIRED
+ default_ssl_version = PROTOCOL_TLS
+ else:
+ default_cert_reqs = CERT_NONE
+ default_ssl_version = PROTOCOL_SSLv23
+
def __new__(cls, sock=None, keyfile=None, certfile=None,
- server_side=False, cert_reqs=CERT_NONE,
- ssl_version=PROTOCOL_SSLv23, ca_certs=None,
+ server_side=False, cert_reqs=default_cert_reqs,
+ ssl_version=default_ssl_version, ca_certs=None,
do_handshake_on_connect=True, *args, **kw):
if _is_under_py_3_7:
return super(FixedEventletGreenSSLSocket, cls).__new__(cls)
@@ -161,23 +175,38 @@ def __new__(cls, sock=None, keyfile=None, certfile=None,
session=kw.get('session'),
)
else:
- ret = _original_wrap_socket(
- sock=sock.fd,
- keyfile=keyfile,
- certfile=certfile,
- server_side=server_side,
- cert_reqs=cert_reqs,
- ssl_version=ssl_version,
- ca_certs=ca_certs,
- do_handshake_on_connect=False,
- ciphers=kw.get('ciphers'),
- )
+ if sys.version_info >= (3, 12):
+ ret = cls._wrap_socket(
+ sock=sock.fd,
+ keyfile=keyfile,
+ certfile=certfile,
+ server_side=server_side,
+ cert_reqs=cert_reqs,
+ ssl_version=ssl_version,
+ ca_certs=ca_certs,
+ do_handshake_on_connect=False,
+ ciphers=kw.get('ciphers'),
+ server_hostname=kw.get('server_hostname')
+ )
+ else:
+ ret = _original_wrap_socket(
+ sock=sock.fd,
+ keyfile=keyfile,
+ certfile=certfile,
+ server_side=server_side,
+ cert_reqs=cert_reqs,
+ ssl_version=ssl_version,
+ ca_certs=ca_certs,
+ do_handshake_on_connect=False,
+ ciphers=kw.get('ciphers'),
+ )
ret.keyfile = keyfile
ret.certfile = certfile
ret.cert_reqs = cert_reqs
ret.ssl_version = ssl_version
ret.ca_certs = ca_certs
- ret.server_hostname = kw.get('server_hostname')
+ if sys.version_info < (3, 12):
+ ret.server_hostname = kw.get('server_hostname')
ret.__class__ = FixedEventletGreenSSLSocket
return ret
@@ -217,6 +246,29 @@ def connect(self, addr):
if self.do_handshake_on_connect:
self.do_handshake()
+
+ @staticmethod
+ def _wrap_socket(sock, keyfile, certfile, server_side, cert_reqs,
+ ssl_version, ca_certs, do_handshake_on_connect, ciphers, server_hostname):
+ context = _original_sslcontext(protocol=ssl_version)
+ context.options |= cert_reqs
+ if certfile or keyfile:
+ context.load_cert_chain(
+ certfile=certfile,
+ keyfile=keyfile,
+ )
+ if ca_certs:
+ context.load_verify_locations(cafile=ca_certs)
+ if ciphers:
+ context.set_ciphers(ciphers)
+ context.check_hostname = True
+ context.load_default_certs()
+ return context.wrap_socket(
+ server_hostname=server_hostname,
+ sock=sock,
+ server_side=server_side,
+ do_handshake_on_connect=do_handshake_on_connect,
+ )
class SSLEventletTransport(EventletTransport):
diff --git a/haigha2/transports/gevent_transport.py b/haigha2/transports/gevent_transport.py
index e3260a3..4437673 100644
--- a/haigha2/transports/gevent_transport.py
+++ b/haigha2/transports/gevent_transport.py
@@ -11,7 +11,10 @@
try:
import gevent
import gevent.ssl
- import gevent._socket2
+ try:
+ import gevent._socket3
+ except:
+ import gevent._socket2
import gevent.socket
import gevent.ssl
from gevent.event import Event