From 6200630904db2452ecfb551d54974acfad978d17 Mon Sep 17 00:00:00 2001 From: Mark Haines Date: Mon, 1 Sep 2014 17:55:35 +0100 Subject: [PATCH] Add server TLS context factory --- synapse/crypto/context_factory.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 synapse/crypto/context_factory.py diff --git a/synapse/crypto/context_factory.py b/synapse/crypto/context_factory.py new file mode 100644 index 0000000000..fe58d65305 --- /dev/null +++ b/synapse/crypto/context_factory.py @@ -0,0 +1,23 @@ +from twisted.internet import reactor, ssl +from OpenSSL import SSL + + +class ServerContextFactory(ssl.ContextFactory): + """Factory for PyOpenSSL SSL contexts that are used to handle incoming + connections and to make connections to remote servers.""" + + def __init__(self, config): + self._context = SSL.Context(SSL.SSLv23_METHOD) + self.configure_context(self._context, config) + + @staticmethod + def configure_context(context, config): + context.set_options(SSL.OP_NO_SSLv2 | SSL.OP_NO_SSLv3) + context.use_certificate(config.tls_certificate) + context.use_privatekey(config.tls_private_key) + context.load_tmp_dh(config.tls_dh_params_path) + context.set_cipher_list("!ADH:HIGH+kEDH:!AECDH:HIGH+kEECDH") + + def getContext(self): + return self._context +