summary refs log tree commit diff
path: root/synapse/crypto/context_factory.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2014-09-01 19:57:28 +0100
committerErik Johnston <erik@matrix.org>2014-09-01 19:57:28 +0100
commitf452899fe2a1bcf3f9d3313eeb108660b5cbf677 (patch)
treeedae89fefddc1f820f5bcae8409a85c36f1b2a0e /synapse/crypto/context_factory.py
parentFix the tests to include new db calls (diff)
parentMerge branch 'server2server_tls' into develop (diff)
downloadsynapse-f452899fe2a1bcf3f9d3313eeb108660b5cbf677.tar.xz
Merge branch 'develop' of github.com:matrix-org/synapse into room_config
Diffstat (limited to 'synapse/crypto/context_factory.py')
-rw-r--r--synapse/crypto/context_factory.py23
1 files changed, 23 insertions, 0 deletions
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
+