def http_server_with_credentials(): # Startup print("Starting server") http_server = server.ThreadedHTTPServer(("", HTTP_PORT), handler.HTTPHandler) http_thread = threading.Thread(target=http_server.serve_forever) http_thread.setDaemon(True) http_thread.start() yield http_server # Teardown print("Stopping server") http_server.shutdown() http_server.server_close()
def mgmt_server(): # Startup print("Starting server") http_server = server.ThreadedHTTPServer(("", MGMT_PORT), handler.DummyHandler) http_thread = threading.Thread(target=http_server.serve_forever) http_thread.setDaemon(True) http_thread.start() yield http_server # Teardown print("Stopping server") http_server.shutdown() http_server.server_close()
def main(): # TODO: make this a bit more customizable handler.HTTPHandler.credentials = CREDENTIALS # Create HTTP Endpoint http_server = server.ThreadedHTTPServer(("", HTTP_PORT), handler.HTTPHandler) LOGGER.info("Serving HTTP server on port: {}".format(HTTP_PORT)) http_thread = threading.Thread(target=http_server.serve_forever) http_thread.setDaemon(True) http_thread.start() # Create HTTPS Endpoint context = ssl.create_default_context(purpose=ssl.Purpose.CLIENT_AUTH) context.load_cert_chain(certfile=SERVER_CRT) https_server = server.ThreadedHTTPServer(("", HTTPS_PORT), handler.HTTPHandler) https_server.socket = context.wrap_socket (https_server.socket, server_side=True) LOGGER.info("Serving HTTPS server on port: {}".format(HTTPS_PORT)) https_thread = threading.Thread(target=https_server.serve_forever) https_thread.setDaemon(True) https_thread.start() # Create HTTPS Mutual Endpoint contextm = ssl.create_default_context(purpose=ssl.Purpose.CLIENT_AUTH) contextm.verify_mode = ssl.CERT_REQUIRED contextm.load_cert_chain(certfile=SERVER_CRT) contextm.load_verify_locations(cafile=CLIENT_CA) httpsm_server = server.ThreadedHTTPServer(("", HTTPSM_PORT), handler.HTTPHandler) httpsm_server.socket = contextm.wrap_socket (httpsm_server.socket, server_side=True) LOGGER.info("Serving HTTPS mutual authentication server on port: {}".format(HTTPSM_PORT)) httpsm_thread = threading.Thread(target=httpsm_server.serve_forever) httpsm_thread.setDaemon(True) httpsm_thread.start() # Create Management Endpoint mgmt_server = server.ThreadedHTTPServer(("", MGMT_PORT), handler.DummyHandler) LOGGER.info("Serving DUMMY server on port: {}".format(MGMT_PORT)) mgmt_server.serve_forever()
def https_server_with_credentials(): # Startup print("Starting server") context = ssl.create_default_context(purpose=ssl.Purpose.CLIENT_AUTH) context.verify_mode = ssl.CERT_NONE context.load_cert_chain(certfile=SERVER_CRT) handler.HTTPHandler.credentials = CREDENTIALS https_server = server.ThreadedHTTPServer(("", HTTPS_PORT), handler.HTTPHandler) https_server.socket = context.wrap_socket (https_server.socket, server_side=True) https_thread = threading.Thread(target=https_server.serve_forever) https_thread.setDaemon(True) https_thread.start() yield https_server # Teardown print("Stopping server") https_server.shutdown() https_server.server_close()