Hopefully fix SSL/TLS handshake getting stuck forever
This commit is contained in:
parent
4b3e9f22e0
commit
ef657a3436
@ -3,9 +3,10 @@ import ssl
|
|||||||
|
|
||||||
global serverThread
|
global serverThread
|
||||||
class serverThread(threading.Thread):
|
class serverThread(threading.Thread):
|
||||||
def __init__(self,socket):
|
def __init__(self,socket,isHttps):
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
self.socket = socket
|
self.socket = socket
|
||||||
|
self.isHttps = isHttps
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
connection = False
|
connection = False
|
||||||
@ -17,6 +18,9 @@ class serverThread(threading.Thread):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
if self.isHttps:
|
||||||
|
connection.settimeout(5)
|
||||||
|
connection.do_handshake()
|
||||||
connection.settimeout(timeout)
|
connection.settimeout(timeout)
|
||||||
if not triggerEvent("onConnection",connection,address): raise excConnectionClosed
|
if not triggerEvent("onConnection",connection,address): raise excConnectionClosed
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -31,15 +35,22 @@ def makeServer(host,port,https):
|
|||||||
print("Opening " +str(host)+ ":" +str(port)+ " (" +str(https)+ ") ...")
|
print("Opening " +str(host)+ ":" +str(port)+ " (" +str(https)+ ") ...")
|
||||||
serverSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
serverSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
serverSocket.bind((host,port))
|
serverSocket.bind((host,port))
|
||||||
serverSocket.settimeout(5)
|
|
||||||
if https:
|
if https:
|
||||||
serverSocket = ssl.wrap_socket(
|
proto = False
|
||||||
|
if sys.version_info >= (3,10):
|
||||||
|
proto = ssl.PROTOCOL_TLS_SERVER
|
||||||
|
else:
|
||||||
|
proto = ssl.PROTOCOL_TLS
|
||||||
|
|
||||||
|
ctx = ssl.SSLContext(proto)
|
||||||
|
ctx.check_hostname = False
|
||||||
|
ctx.load_cert_chain(https)
|
||||||
|
serverSocket = ctx.wrap_socket(
|
||||||
serverSocket,
|
serverSocket,
|
||||||
server_side = True,
|
server_side = True,
|
||||||
certfile = https,
|
do_handshake_on_connect = False
|
||||||
ssl_version = ssl.PROTOCOL_TLS
|
|
||||||
)
|
)
|
||||||
serverSocket.listen(65535)
|
serverSocket.listen(65535)
|
||||||
thread = serverThread(serverSocket)
|
thread = serverThread(serverSocket,not (https == False))
|
||||||
serverThreads.append(thread)
|
serverThreads.append(thread)
|
||||||
thread.start()
|
thread.start()
|
Loading…
Reference in New Issue
Block a user