This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Update the TLS cipher string and provide configurability for TLS on outgoing federation #5550
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
30c4f16
add the option for client config and bump the server config
hawkowl 2b41967
changelog
hawkowl 5f1ab1b
fixes
hawkowl 3190043
fix, and make it use python3 for building config
hawkowl fd71127
fix, as well
hawkowl 8fdc630
Merge remote-tracking branch 'origin/develop' into hawkowl/bump-tls
hawkowl c50c06e
fixes
hawkowl 1872924
fixes
hawkowl ed2dd72
Update synapse/config/tls.py
hawkowl e341403
change config name to be better
hawkowl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
The minimum TLS version used for outgoing federation requests can now be set with `federation_client_minimum_tls_version`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Synapse will now only allow TLS v1.2 connections when serving federation, if it terminates TLS. As Synapse's allowed ciphers were only able to be used in TLSv1.2 before, this does not change behaviour. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#!/usr/bin/env python | ||
#!/usr/bin/env python3 | ||
|
||
import argparse | ||
import shutil | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,12 +24,25 @@ | |
from twisted.internet._sslverify import _defaultCurveName | ||
from twisted.internet.abstract import isIPAddress, isIPv6Address | ||
from twisted.internet.interfaces import IOpenSSLClientConnectionCreator | ||
from twisted.internet.ssl import CertificateOptions, ContextFactory, platformTrust | ||
from twisted.internet.ssl import ( | ||
CertificateOptions, | ||
ContextFactory, | ||
TLSVersion, | ||
platformTrust, | ||
) | ||
from twisted.python.failure import Failure | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
_TLS_VERSION_MAP = { | ||
"1": TLSVersion.TLSv1_0, | ||
"1.1": TLSVersion.TLSv1_1, | ||
"1.2": TLSVersion.TLSv1_2, | ||
"1.3": TLSVersion.TLSv1_3, | ||
} | ||
|
||
|
||
class ServerContextFactory(ContextFactory): | ||
"""Factory for PyOpenSSL SSL contexts that are used to handle incoming | ||
connections.""" | ||
|
@@ -43,16 +56,18 @@ def configure_context(context, config): | |
try: | ||
_ecCurve = crypto.get_elliptic_curve(_defaultCurveName) | ||
context.set_tmp_ecdh(_ecCurve) | ||
|
||
except Exception: | ||
logger.exception("Failed to enable elliptic curve for TLS") | ||
context.set_options(SSL.OP_NO_SSLv2 | SSL.OP_NO_SSLv3) | ||
|
||
context.set_options( | ||
SSL.OP_NO_SSLv2 | SSL.OP_NO_SSLv3 | SSL.OP_NO_TLSv1 | SSL.OP_NO_TLSv1_1 | ||
) | ||
context.use_certificate_chain_file(config.tls_certificate_file) | ||
context.use_privatekey(config.tls_private_key) | ||
|
||
# https://hynek.me/articles/hardening-your-web-servers-ssl-ciphers/ | ||
context.set_cipher_list( | ||
"ECDH+AESGCM:ECDH+CHACHA20:ECDH+AES256:ECDH+AES128:!aNULL:!SHA1" | ||
"ECDH+AESGCM:ECDH+CHACHA20:ECDH+AES256:ECDH+AES128:!aNULL:!SHA1:!AESCCM" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this a bad security choice? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AES128-CCM-8 is "not the best", AES128-CCM is just slow. They're not good ciphers that anything will ever pick, and advertising them makes our cipher string longer. (OpenSSL 1.1.1 started advertising it by default, so this update just makes it the same ciphers as when this originally landed) |
||
) | ||
|
||
def getContext(self): | ||
|
@@ -79,10 +94,22 @@ def __init__(self, config): | |
# Use CA root certs provided by OpenSSL | ||
trust_root = platformTrust() | ||
|
||
self._verify_ssl_context = CertificateOptions(trustRoot=trust_root).getContext() | ||
# "insecurelyLowerMinimumTo" is the argument that will go lower than | ||
# Twisted's default, which is why it is marked as "insecure" (since | ||
# Twisted's defaults are reasonably secure). But, since Twisted is | ||
# moving to TLS 1.2 by default, we want to respect the config option if | ||
# it is set to 1.0 (which the alternate option, raiseMinimumTo, will not | ||
# let us do). | ||
minTLS = _TLS_VERSION_MAP[config.federation_client_minimum_tls_version] | ||
|
||
self._verify_ssl = CertificateOptions( | ||
trustRoot=trust_root, insecurelyLowerMinimumTo=minTLS | ||
) | ||
self._verify_ssl_context = self._verify_ssl.getContext() | ||
self._verify_ssl_context.set_info_callback(self._context_info_cb) | ||
|
||
self._no_verify_ssl_context = CertificateOptions().getContext() | ||
self._no_verify_ssl = CertificateOptions(insecurelyLowerMinimumTo=minTLS) | ||
self._no_verify_ssl_context = self._no_verify_ssl.getContext() | ||
self._no_verify_ssl_context.set_info_callback(self._context_info_cb) | ||
|
||
def get_options(self, host): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we setting
NO_TLSv1
? I though the point was to optionally support it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is server, not client. Our server cipher string requires TLS 1.2 anyway to negotiate any of the ciphers, so this just makes the handshake a little simpler.