Implement TLS listener support
This commit is contained in:
parent
fefd990d89
commit
21a6f3e3f2
1 changed files with 19 additions and 6 deletions
|
@ -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,7 +45,11 @@ class Server():
|
|||
listener.bind((host, port))
|
||||
listener.listen()
|
||||
|
||||
if self.sslctx:
|
||||
listener = self.sslctx.wrap_socket(listener, server_side=True)
|
||||
|
||||
while True:
|
||||
try:
|
||||
sock, addr = listener.accept()
|
||||
|
||||
def spawn():
|
||||
|
@ -47,5 +58,7 @@ class Server():
|
|||
|
||||
thread = threading.Thread(target=spawn)
|
||||
thread.start()
|
||||
except:
|
||||
pass
|
||||
|
||||
listener.close()
|
||||
|
|
Loading…
Add table
Reference in a new issue