From a95cc678e91e301a27eab4c33885b364ada36d67 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 2 Sep 2014 22:33:45 -0600 Subject: [PATCH] Added server.py ssl mode dependant on cert existence --- gns3server/cert_utils/create_cert.sh | 1 + gns3server/server.py | 28 +++++++++++++++++++++++----- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/gns3server/cert_utils/create_cert.sh b/gns3server/cert_utils/create_cert.sh index 89a5bc67..e08e2714 100755 --- a/gns3server/cert_utils/create_cert.sh +++ b/gns3server/cert_utils/create_cert.sh @@ -47,6 +47,7 @@ fail_if_error() { } } + mkdir -p $DST_DIR fail_if_error $? cd $DST_DIR diff --git a/gns3server/server.py b/gns3server/server.py index f23f6abb..2bc4a893 100644 --- a/gns3server/server.py +++ b/gns3server/server.py @@ -33,6 +33,7 @@ import tornado.ioloop import tornado.web import tornado.autoreload import pkg_resources +from os.path import expanduser from pkg_resources import parse_version from .config import Config @@ -136,6 +137,24 @@ class Server(object): JSONRPCWebSocket.register_destination(destination, instance.name) instance.start() # starts the new process + + def _get_cert_info(self): + """ + Finds the cert and key file needed for SSL + """ + + home = expanduser("~") + ssl_dir = "%s/.conf/GNS3Certs/" % (home) + log.debug("Looking for SSL certs in: %s" % (ssl_dir)) + + keyfile = "%s/gns3server.localdomain.com.key" % (ssl_dir) + certfile = "%s/gns3server.localdomain.com.crt" % (ssl_dir) + + if os.path.isfile(keyfile) and os.path.isfile(certfile): + return { "certfile" : certfile, + "keyfile" : keyfile, + } + def run(self): """ Starts the Tornado web server and ZeroMQ server. @@ -160,12 +179,11 @@ class Server(object): zmq.zmq_version())) kwargs = {"address": self._host} - ssl_options={ - "certfile": "/home/michaelgale/nas/workspace/gns3-server/gns3server/certs/gns3server.localdomain.com.crt", - "keyfile": "/home/michaelgale/nas/workspace/gns3-server/gns3server/certs/gns3server.localdomain.com.key", - } + ssl_options = self._get_cert_info() - kwargs['ssl_options'] = ssl_options + if ssl_options: + log.info("Certs found - starting in SSL mode") + kwargs['ssl_options'] = ssl_options if parse_version(tornado.version) >= parse_version("3.1"): kwargs["max_buffer_size"] = 524288000 # 500 MB file upload limit