diff options
author | Erik Johnston <erik@matrix.org> | 2019-01-24 18:52:34 +0000 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2019-01-24 18:52:34 +0000 |
commit | efb8ed1d453fc9f76f9e9225532281963b7ea53c (patch) | |
tree | 62626873812dfce5f24b556b406b47a47159b214 /synapse/crypto/context_factory.py | |
parent | Replace missed usages of FrozenEvent (diff) | |
parent | Merge pull request #4448 from matrix-org/erikj/get_pdu_versions (diff) | |
download | synapse-efb8ed1d453fc9f76f9e9225532281963b7ea53c.tar.xz |
Merge branch 'develop' of github.com:matrix-org/synapse into erikj/require_format_version
Diffstat (limited to 'synapse/crypto/context_factory.py')
-rw-r--r-- | synapse/crypto/context_factory.py | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/synapse/crypto/context_factory.py b/synapse/crypto/context_factory.py index 6ba3eca7b2..286ad80100 100644 --- a/synapse/crypto/context_factory.py +++ b/synapse/crypto/context_factory.py @@ -17,6 +17,7 @@ from zope.interface import implementer from OpenSSL import SSL, crypto 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 from twisted.python.failure import Failure @@ -98,8 +99,14 @@ class ClientTLSOptions(object): def __init__(self, hostname, ctx): self._ctx = ctx - self._hostname = hostname - self._hostnameBytes = _idnaBytes(hostname) + + if isIPAddress(hostname) or isIPv6Address(hostname): + self._hostnameBytes = hostname.encode('ascii') + self._sendSNI = False + else: + self._hostnameBytes = _idnaBytes(hostname) + self._sendSNI = True + ctx.set_info_callback( _tolerateErrors(self._identityVerifyingInfoCallback) ) @@ -111,7 +118,9 @@ class ClientTLSOptions(object): return connection def _identityVerifyingInfoCallback(self, connection, where, ret): - if where & SSL.SSL_CB_HANDSHAKE_START: + # Literal IPv4 and IPv6 addresses are not permitted + # as host names according to the RFCs + if where & SSL.SSL_CB_HANDSHAKE_START and self._sendSNI: connection.set_tlsext_host_name(self._hostnameBytes) |