Mercurial > libervia-backend
comparison sat/plugins/plugin_xep_0077.py @ 2634:6c89cf856d28
plugin XEP-0077: fixed RegisteringAuthenticator to use TLS if possible
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 04 Jul 2018 07:26:20 +0200 |
parents | 56f94936df1e |
children | 378188abe941 |
comparison
equal
deleted
inserted
replaced
2633:f3bbb6822ab3 | 2634:6c89cf856d28 |
---|---|
21 from sat.core.constants import Const as C | 21 from sat.core.constants import Const as C |
22 from sat.core import exceptions | 22 from sat.core import exceptions |
23 from sat.core.log import getLogger | 23 from sat.core.log import getLogger |
24 | 24 |
25 log = getLogger(__name__) | 25 log = getLogger(__name__) |
26 from twisted.words.protocols.jabber import jid | 26 from twisted.words.protocols.jabber import jid, xmlstream, client |
27 from twisted.words.protocols.jabber import xmlstream | |
28 from twisted.internet import defer, reactor | 27 from twisted.internet import defer, reactor |
29 from sat.tools import xml_tools | 28 from sat.tools import xml_tools |
30 | 29 |
31 from wokkel import data_form | 30 from wokkel import data_form |
32 | 31 |
44 | 43 |
45 # FIXME: this implementation is incomplete | 44 # FIXME: this implementation is incomplete |
46 | 45 |
47 | 46 |
48 class RegisteringAuthenticator(xmlstream.ConnectAuthenticator): | 47 class RegisteringAuthenticator(xmlstream.ConnectAuthenticator): |
49 # FIXME: request IQ is not send to check available fields, while XEP recommand to use it | 48 # FIXME: request IQ is not send to check available fields, |
49 # while XEP recommand to use it | |
50 # FIXME: doesn't handle data form or oob | 50 # FIXME: doesn't handle data form or oob |
51 namespace = 'jabber:client' | |
51 | 52 |
52 def __init__(self, jid_, password, email=None): | 53 def __init__(self, jid_, password, email=None): |
54 log.debug(_(u"Registration asked for {jid}").format(jid=jid_)) | |
53 xmlstream.ConnectAuthenticator.__init__(self, jid_.host) | 55 xmlstream.ConnectAuthenticator.__init__(self, jid_.host) |
54 self.jid = jid_ | 56 self.jid = jid_ |
55 self.password = password | 57 self.password = password |
56 self.email = email | 58 self.email = email |
57 self.registered = defer.Deferred() | 59 self.registered = defer.Deferred() |
58 log.debug(_(u"Registration asked for {jid}").format(jid=jid_)) | 60 |
59 | 61 def associateWithStream(self, xs): |
60 def connectionMade(self): | 62 xmlstream.ConnectAuthenticator.associateWithStream(self, xs) |
61 log.debug(_(u"Connection made with {server}".format(server=self.jid.host))) | 63 xs.addObserver(xmlstream.STREAM_AUTHD_EVENT, self.register) |
62 self.xmlstream.otherEntity = jid.JID(self.jid.host) | 64 |
63 self.xmlstream.namespace = C.NS_CLIENT | 65 xs.initializers = [client.CheckVersionInitializer(xs)] |
64 self.xmlstream.sendHeader() | 66 inits = [ (xmlstream.TLSInitiatingInitializer, False), |
65 | 67 ] |
68 | |
69 for initClass, required in inits: | |
70 init = initClass(xs) | |
71 init.required = required | |
72 xs.initializers.append(init) | |
73 | |
74 def register(self, xmlstream): | |
75 log.debug(_(u"Stream started with {server}, now registering" | |
76 .format(server=self.jid.host))) | |
66 iq = XEP_0077.buildRegisterIQ(self.xmlstream, self.jid, self.password, self.email) | 77 iq = XEP_0077.buildRegisterIQ(self.xmlstream, self.jid, self.password, self.email) |
67 d = iq.send(self.jid.host).addCallbacks(self.registrationCb, self.registrationEb) | 78 d = iq.send(self.jid.host).addCallbacks(self.registrationCb, self.registrationEb) |
68 d.chainDeferred(self.registered) | 79 d.chainDeferred(self.registered) |
69 | 80 |
70 def registrationCb(self, answer): | 81 def registrationCb(self, answer): |