Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Require ECDH key exchange & remove dh_params (#4429)
Browse files Browse the repository at this point in the history
* remove dh_params and set better cipher string
  • Loading branch information
hawkowl committed Jan 22, 2019
1 parent 83f335b commit 23b0813
Show file tree
Hide file tree
Showing 8 changed files with 6 additions and 57 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ is configured to use TLS with a self-signed certificate. If you would like
to do initial test with a client without having to setup a reverse proxy,
you can temporarly use another certificate. (Note that a self-signed
certificate is fine for `Federation`_). You can do so by changing
``tls_certificate_path``, ``tls_private_key_path`` and ``tls_dh_params_path``
``tls_certificate_path`` and ``tls_private_key_path``
in ``homeserver.yaml``; alternatively, you can use a reverse-proxy, but be sure
to read `Using a reverse proxy with Synapse`_ when doing so.

Expand Down
1 change: 1 addition & 0 deletions changelog.d/4229.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Synapse's cipher string has been updated to require ECDH key exchange. Configuring and generating dh_params is no longer required, and they will be ignored.
3 changes: 0 additions & 3 deletions debian/homeserver.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ tls_certificate_path: "/etc/matrix-synapse/homeserver.tls.crt"
# PEM encoded private key for TLS
tls_private_key_path: "/etc/matrix-synapse/homeserver.tls.key"

# PEM dh parameters for ephemeral keys
tls_dh_params_path: "/etc/matrix-synapse/homeserver.tls.dh"

# Don't bind to the https port
no_tls: False

Expand Down
9 changes: 0 additions & 9 deletions demo/demo.tls.dh

This file was deleted.

1 change: 0 additions & 1 deletion docker/conf/homeserver.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

tls_certificate_path: "/data/{{ SYNAPSE_SERVER_NAME }}.tls.crt"
tls_private_key_path: "/data/{{ SYNAPSE_SERVER_NAME }}.tls.key"
tls_dh_params_path: "/data/{{ SYNAPSE_SERVER_NAME }}.tls.dh"
no_tls: {{ "True" if SYNAPSE_NO_TLS else "False" }}
tls_fingerprints: []

Expand Down
40 changes: 0 additions & 40 deletions synapse/config/tls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# limitations under the License.

import os
import subprocess
from hashlib import sha256

from unpaddedbase64 import encode_base64
Expand All @@ -23,8 +22,6 @@

from ._base import Config

GENERATE_DH_PARAMS = False


class TlsConfig(Config):
def read_config(self, config):
Expand All @@ -42,10 +39,6 @@ def read_config(self, config):
config.get("tls_private_key_path")
)

self.tls_dh_params_path = self.check_file(
config.get("tls_dh_params_path"), "tls_dh_params"
)

self.tls_fingerprints = config["tls_fingerprints"]

# Check that our own certificate is included in the list of fingerprints
Expand All @@ -72,7 +65,6 @@ def default_config(self, config_dir_path, server_name, **kwargs):

tls_certificate_path = base_key_name + ".tls.crt"
tls_private_key_path = base_key_name + ".tls.key"
tls_dh_params_path = base_key_name + ".tls.dh"

return """\
# PEM encoded X509 certificate for TLS.
Expand All @@ -85,9 +77,6 @@ def default_config(self, config_dir_path, server_name, **kwargs):
# PEM encoded private key for TLS
tls_private_key_path: "%(tls_private_key_path)s"
# PEM dh parameters for ephemeral keys
tls_dh_params_path: "%(tls_dh_params_path)s"
# Don't bind to the https port
no_tls: False
Expand Down Expand Up @@ -131,7 +120,6 @@ def read_tls_private_key(self, private_key_path):
def generate_files(self, config):
tls_certificate_path = config["tls_certificate_path"]
tls_private_key_path = config["tls_private_key_path"]
tls_dh_params_path = config["tls_dh_params_path"]

if not self.path_exists(tls_private_key_path):
with open(tls_private_key_path, "wb") as private_key_file:
Expand Down Expand Up @@ -165,31 +153,3 @@ def generate_files(self, config):
cert_pem = crypto.dump_certificate(crypto.FILETYPE_PEM, cert)

certificate_file.write(cert_pem)

if not self.path_exists(tls_dh_params_path):
if GENERATE_DH_PARAMS:
subprocess.check_call([
"openssl", "dhparam",
"-outform", "PEM",
"-out", tls_dh_params_path,
"2048"
])
else:
with open(tls_dh_params_path, "w") as dh_params_file:
dh_params_file.write(
"2048-bit DH parameters taken from rfc3526\n"
"-----BEGIN DH PARAMETERS-----\n"
"MIIBCAKCAQEA///////////JD9qiIWjC"
"NMTGYouA3BzRKQJOCIpnzHQCC76mOxOb\n"
"IlFKCHmONATd75UZs806QxswKwpt8l8U"
"N0/hNW1tUcJF5IW1dmJefsb0TELppjft\n"
"awv/XLb0Brft7jhr+1qJn6WunyQRfEsf"
"5kkoZlHs5Fs9wgB8uKFjvwWY2kg2HFXT\n"
"mmkWP6j9JM9fg2VdI9yjrZYcYvNWIIVS"
"u57VKQdwlpZtZww1Tkq8mATxdGwIyhgh\n"
"fDKQXkYuNs474553LBgOhgObJ4Oi7Aei"
"j7XFXfBvTFLJ3ivL9pVYFxg5lUl86pVq\n"
"5RXSJhiY+gUQFXKOWoqsqmj/////////"
"/wIBAg==\n"
"-----END DH PARAMETERS-----\n"
)
6 changes: 4 additions & 2 deletions synapse/crypto/context_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ def configure_context(context, config):
if not config.no_tls:
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")
# https://hynek.me/articles/hardening-your-web-servers-ssl-ciphers/
context.set_cipher_list(
"ECDH+AESGCM:ECDH+CHACHA20:ECDH+AES256:ECDH+AES128:!aNULL:!SHA1"
)

def getContext(self):
return self._context
Expand Down
1 change: 0 additions & 1 deletion tests/config/test_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ def test_generate_config_generates_files(self):
"lemurs.win.log.config",
"lemurs.win.signing.key",
"lemurs.win.tls.crt",
"lemurs.win.tls.dh",
"lemurs.win.tls.key",
]
),
Expand Down

0 comments on commit 23b0813

Please sign in to comment.