import ssl


def setup_ssl(root, settings):
    """
        Create an SSL context from a given file root and settings dict
    :param root: Path root for the ssl directory
    :param settings: Webserver settings dictionary
    :return: New ssl context, or None if ssl settings aren't configured
    """
    out = None
    if settings["tokens"].get("ssl_cert"):
        out = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
        cert = root / settings["tokens"]["ssl_cert"]
        key = root / settings["tokens"]["ssl_key"]
        out.load_cert_chain(cert, key)
    return out