@@ -75,7 +75,7 @@ def getContext(self):
7575
7676
7777@implementer (IPolicyForHTTPS )
78- class ClientTLSOptionsFactory (object ):
78+ class FederationPolicyForHTTPS (object ):
7979 """Factory for Twisted SSLClientConnectionCreators that are used to make connections
8080 to remote servers for federation.
8181
@@ -103,15 +103,15 @@ def __init__(self, config):
103103 # let us do).
104104 minTLS = _TLS_VERSION_MAP [config .federation_client_minimum_tls_version ]
105105
106- self . _verify_ssl = CertificateOptions (
106+ _verify_ssl = CertificateOptions (
107107 trustRoot = trust_root , insecurelyLowerMinimumTo = minTLS
108108 )
109- self ._verify_ssl_context = self . _verify_ssl .getContext ()
110- self ._verify_ssl_context .set_info_callback (self . _context_info_cb )
109+ self ._verify_ssl_context = _verify_ssl .getContext ()
110+ self ._verify_ssl_context .set_info_callback (_context_info_cb )
111111
112- self . _no_verify_ssl = CertificateOptions (insecurelyLowerMinimumTo = minTLS )
113- self ._no_verify_ssl_context = self . _no_verify_ssl .getContext ()
114- self ._no_verify_ssl_context .set_info_callback (self . _context_info_cb )
112+ _no_verify_ssl = CertificateOptions (insecurelyLowerMinimumTo = minTLS )
113+ self ._no_verify_ssl_context = _no_verify_ssl .getContext ()
114+ self ._no_verify_ssl_context .set_info_callback (_context_info_cb )
115115
116116 def get_options (self , host : bytes ):
117117
@@ -136,30 +136,50 @@ def get_options(self, host: bytes):
136136
137137 return SSLClientConnectionCreator (host , ssl_context , should_verify )
138138
139- @staticmethod
140- def _context_info_cb (ssl_connection , where , ret ):
141- """The 'information callback' for our openssl context object."""
142- # we assume that the app_data on the connection object has been set to
143- # a TLSMemoryBIOProtocol object. (This is done by SSLClientConnectionCreator)
144- tls_protocol = ssl_connection .get_app_data ()
145- try :
146- # ... we further assume that SSLClientConnectionCreator has set the
147- # '_synapse_tls_verifier' attribute to a ConnectionVerifier object.
148- tls_protocol ._synapse_tls_verifier .verify_context_info_cb (
149- ssl_connection , where
150- )
151- except : # noqa: E722, taken from the twisted implementation
152- logger .exception ("Error during info_callback" )
153- f = Failure ()
154- tls_protocol .failVerification (f )
155-
156139 def creatorForNetloc (self , hostname , port ):
157140 """Implements the IPolicyForHTTPS interace so that this can be passed
158141 directly to agents.
159142 """
160143 return self .get_options (hostname )
161144
162145
146+ @implementer (IPolicyForHTTPS )
147+ class RegularPolicyForHTTPS (object ):
148+ """Factory for Twisted SSLClientConnectionCreators that are used to make connections
149+ to remote servers, for other than federation.
150+
151+ Always uses the same OpenSSL context object, which uses the default OpenSSL CA
152+ trust root.
153+ """
154+
155+ def __init__ (self ):
156+ trust_root = platformTrust ()
157+ self ._ssl_context = CertificateOptions (trustRoot = trust_root ).getContext ()
158+ self ._ssl_context .set_info_callback (_context_info_cb )
159+
160+ def creatorForNetloc (self , hostname , port ):
161+ return SSLClientConnectionCreator (hostname , self ._ssl_context , True )
162+
163+
164+ def _context_info_cb (ssl_connection , where , ret ):
165+ """The 'information callback' for our openssl context objects.
166+
167+ Note: Once this is set as the info callback on a Context object, the Context should
168+ only be used with the SSLClientConnectionCreator.
169+ """
170+ # we assume that the app_data on the connection object has been set to
171+ # a TLSMemoryBIOProtocol object. (This is done by SSLClientConnectionCreator)
172+ tls_protocol = ssl_connection .get_app_data ()
173+ try :
174+ # ... we further assume that SSLClientConnectionCreator has set the
175+ # '_synapse_tls_verifier' attribute to a ConnectionVerifier object.
176+ tls_protocol ._synapse_tls_verifier .verify_context_info_cb (ssl_connection , where )
177+ except : # noqa: E722, taken from the twisted implementation
178+ logger .exception ("Error during info_callback" )
179+ f = Failure ()
180+ tls_protocol .failVerification (f )
181+
182+
163183@implementer (IOpenSSLClientConnectionCreator )
164184class SSLClientConnectionCreator (object ):
165185 """Creates openssl connection objects for client connections.
0 commit comments