mirror of
https://github.com/element-hq/synapse.git
synced 2024-12-21 12:14:29 +03:00
Don't run validation code if validation is turned off
This commit is contained in:
parent
ee0c7e1ab4
commit
a7d7c5a060
3 changed files with 32 additions and 23 deletions
|
@ -90,10 +90,11 @@ class TlsConfig(Config):
|
||||||
|
|
||||||
# List of custom certificate authorities for federation traffic validation
|
# List of custom certificate authorities for federation traffic validation
|
||||||
self.federation_custom_ca_list = config.get(
|
self.federation_custom_ca_list = config.get(
|
||||||
"federation_custom_ca_list", [],
|
"federation_custom_ca_list", None,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Read in and parse custom CA certificates
|
# Read in and parse custom CA certificates
|
||||||
|
if self.federation_custom_ca_list is not None:
|
||||||
certs = []
|
certs = []
|
||||||
for ca_file in self.federation_custom_ca_list:
|
for ca_file in self.federation_custom_ca_list:
|
||||||
logger.debug("Reading custom CA certificate file: %s", ca_file)
|
logger.debug("Reading custom CA certificate file: %s", ca_file)
|
||||||
|
@ -112,6 +113,7 @@ class TlsConfig(Config):
|
||||||
logger.exception("Failed to parse custom CA certificate off disk!")
|
logger.exception("Failed to parse custom CA certificate off disk!")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
if len(certs) > 0:
|
||||||
self.federation_custom_ca_list = trustRootFromCertificates(certs)
|
self.federation_custom_ca_list = trustRootFromCertificates(certs)
|
||||||
|
|
||||||
# This config option applies to non-federation HTTP clients
|
# This config option applies to non-federation HTTP clients
|
||||||
|
|
|
@ -128,10 +128,17 @@ class ClientTLSOptionsFactory(object):
|
||||||
|
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
self._config = config
|
self._config = config
|
||||||
|
|
||||||
|
# Check if we're using a custom list of a CA certificates
|
||||||
|
if config.federation_custom_ca_list is not None:
|
||||||
self._options_validate = CertificateOptions(
|
self._options_validate = CertificateOptions(
|
||||||
# This option implies verify=True
|
# This option implies verify=True
|
||||||
trustRoot=config.federation_custom_ca_list,
|
trustRoot=config.federation_custom_ca_list,
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
# If not, verify using those provided by the operating environment
|
||||||
|
self._options_validate = CertificateOptions(verify=True)
|
||||||
|
|
||||||
self._options_novalidate = CertificateOptions(verify=False)
|
self._options_novalidate = CertificateOptions(verify=False)
|
||||||
|
|
||||||
def get_options(self, host):
|
def get_options(self, host):
|
||||||
|
|
|
@ -53,7 +53,7 @@ class MatrixFederationAgentTests(TestCase):
|
||||||
|
|
||||||
self.agent = MatrixFederationAgent(
|
self.agent = MatrixFederationAgent(
|
||||||
reactor=self.reactor,
|
reactor=self.reactor,
|
||||||
tls_client_options_factory=ClientTLSOptionsFactory(None),
|
tls_client_options_factory=ClientTLSOptionsFactory(#TODO How to deal with None config in tests???),
|
||||||
_well_known_tls_policy=TrustingTLSPolicyForHTTPS(),
|
_well_known_tls_policy=TrustingTLSPolicyForHTTPS(),
|
||||||
_srv_resolver=self.mock_resolver,
|
_srv_resolver=self.mock_resolver,
|
||||||
_well_known_cache=self.well_known_cache,
|
_well_known_cache=self.well_known_cache,
|
||||||
|
|
Loading…
Reference in a new issue