Mercurial > libervia-backend
comparison sat/plugins/plugin_xep_0077.py @ 3354:aafb53248872
plugin XEP-0077: fixed "check_certificate" handling
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 13 Sep 2020 22:49:12 +0200 |
parents | 2cd54c72fae4 |
children | 77ad87763f32 |
comparison
equal
deleted
inserted
replaced
3353:7726916c1ba6 | 3354:aafb53248872 |
---|---|
16 | 16 |
17 # You should have received a copy of the GNU Affero General Public License | 17 # You should have received a copy of the GNU Affero General Public License |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | 19 |
20 from twisted.words.protocols.jabber import jid, xmlstream, client, error as jabber_error | 20 from twisted.words.protocols.jabber import jid, xmlstream, client, error as jabber_error |
21 from twisted.internet import defer, reactor | 21 from twisted.internet import defer, reactor, ssl |
22 from wokkel import data_form | 22 from wokkel import data_form |
23 from sat.core.i18n import _ | 23 from sat.core.i18n import _ |
24 from sat.core.constants import Const as C | 24 from sat.core.constants import Const as C |
25 from sat.core import exceptions | 25 from sat.core import exceptions |
26 from sat.core.log import getLogger | 26 from sat.core.log import getLogger |
62 def associateWithStream(self, xs): | 62 def associateWithStream(self, xs): |
63 xmlstream.ConnectAuthenticator.associateWithStream(self, xs) | 63 xmlstream.ConnectAuthenticator.associateWithStream(self, xs) |
64 xs.addObserver(xmlstream.STREAM_AUTHD_EVENT, self.register) | 64 xs.addObserver(xmlstream.STREAM_AUTHD_EVENT, self.register) |
65 | 65 |
66 xs.initializers = [client.CheckVersionInitializer(xs)] | 66 xs.initializers = [client.CheckVersionInitializer(xs)] |
67 tls_init = xmlstream.TLSInitiatingInitializer(xs) | 67 if self.check_certificate: |
68 tls_init.required = False | 68 tls_required, configurationForTLS = True, None |
69 tls_init.check_certificate = self.check_certificate | 69 else: |
70 tls_required = False | |
71 configurationForTLS = ssl.CertificateOptions(trustRoot=None) | |
72 tls_init = xmlstream.TLSInitiatingInitializer( | |
73 xs, required=tls_required, configurationForTLS=configurationForTLS) | |
74 | |
70 xs.initializers.append(tls_init) | 75 xs.initializers.append(tls_init) |
71 | 76 |
72 def register(self, xmlstream): | 77 def register(self, xmlstream): |
73 log.debug(_("Stream started with {server}, now registering" | 78 log.debug(_("Stream started with {server}, now registering" |
74 .format(server=self.jid.host))) | 79 .format(server=self.jid.host))) |