Implement TLS listener support

This commit is contained in:
XANTRONIX Development 2024-12-03 12:14:45 -05:00
parent fefd990d89
commit 21a6f3e3f2

View file

@ -1,5 +1,6 @@
import enum
import socket
import ssl
import threading
from configparser import ConfigParser
@ -18,6 +19,12 @@ class Server():
self.config = config
self.capabilities = ServerCapability.NONE
self.newsgroups = dict()
self.sslctx = None
if config['listen'].get('tls', 'no') == 'yes':
self.sslctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
self.sslctx.load_cert_chain(config['tls']['cert'],
config['tls']['key'])
self._init_newsgroups()
@ -38,14 +45,20 @@ class Server():
listener.bind((host, port))
listener.listen()
if self.sslctx:
listener = self.sslctx.wrap_socket(listener, server_side=True)
while True:
sock, addr = listener.accept()
try:
sock, addr = listener.accept()
def spawn():
session = Session(self, sock)
session.handle()
def spawn():
session = Session(self, sock)
session.handle()
thread = threading.Thread(target=spawn)
thread.start()
thread = threading.Thread(target=spawn)
thread.start()
except:
pass
listener.close()