home · contact · privacy
De-hardcode cert and key file for PlomSocketSSL.
authorChristian Heller <c.heller@plomlompom.de>
Mon, 2 Nov 2020 03:27:56 +0000 (04:27 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Mon, 2 Nov 2020 03:27:56 +0000 (04:27 +0100)
new2/plomrogue/io.py
new2/plomrogue/io_tcp.py

index 5450c343a031a721c64ae70289719f40729b1a7f..8e0f9bf530548572eb7c07d389d7188e19af47d1 100644 (file)
@@ -1,5 +1,6 @@
 import queue
 import threading
+import inspect
 
 
 
@@ -30,12 +31,15 @@ class GameIO():
         c = threading.Thread(target=self.loop, args=(self.queue,))
         c.start()
 
-    def start_server(self, port, server_class):
+    def start_server(self, port, server_class, certfile=None, keyfile=None):
         """Start server of server_class in talk with game loop.
 
         The server communicates with the game loop via self.queue.
         """
-        server = server_class(self.queue, port)
+        if 'certfile' in list(inspect.signature(server_class.__init__).parameters):
+            server = server_class(self.queue, port, certfile=certfile, keyfile=keyfile)
+        else:
+            server = server_class(self.queue, port)
         self.servers += [server]
         c = threading.Thread(target=server.serve_forever)
         c.start()
@@ -47,7 +51,6 @@ class GameIO():
         signature will only be called if god_mode is set.
 
         """
-        from inspect import signature
         from plomrogue.errors import GameError, ArgError, PlayError
         from plomrogue.misc import quote
 
@@ -62,7 +65,7 @@ class GameIO():
             if command is None:
                 answer(connection_id, 'UNHANDLED_INPUT')
             else:
-                if 'connection_id' in list(signature(command).parameters):
+                if 'connection_id' in list(inspect.signature(command).parameters):
                     command(*args, connection_id=connection_id)
                 elif god_mode:
                     command(*args)
index 78e43f539df4aea810a15c3abe61366d807c4993..5dd2508a8708d5cca43836aceb396d9231ed1d0a 100644 (file)
@@ -102,14 +102,12 @@ class PlomSocket:
 
 class PlomSocketSSL(PlomSocket):
 
-    def __init__(self, *args, server_side=False, **kwargs):
+    def __init__(self, *args, server_side=False, certfile=None, keyfile=None, **kwargs):
         import ssl
-        print('DEBUG', args, kwargs)
         super().__init__(*args, **kwargs)
         if server_side:
             self.socket = ssl.wrap_socket(self.socket, server_side=True,
-                                          certfile="server.pem",
-                                          keyfile="key.pem")
+                                          certfile=certfile, keyfile=keyfile)
         else:
             self.socket = ssl.wrap_socket(self.socket)
 
@@ -150,7 +148,9 @@ class IO_Handler(socketserver.BaseRequestHandler):
         import queue
         import threading
         if self.socket_class == PlomSocketSSL:
-            plom_socket = self.socket_class(self.request, server_side=True)
+            plom_socket = self.socket_class(self.request, server_side=True,
+                                            certfile=self.server.certfile,
+                                            keyfile=self.server.keyfile)
         else:
             plom_socket = self.socket_class(self.request)
         print('CONNECTION FROM:', str(self.client_address))
@@ -202,5 +202,7 @@ class PlomTCPServer(socketserver.ThreadingTCPServer):
 
 class PlomTCPServerSSL(PlomTCPServer):
 
-    def __init__(self, *args, **kwargs):
+    def __init__(self, *args, certfile=None, keyfile=None, **kwargs):
+        self.certfile = certfile
+        self.keyfile = keyfile
         super().__init__(*args, host='0.0.0.0', io_handler=IO_HandlerSSL, **kwargs)