[Twisted-Python] Jabber client, tls and iqauth
rakdeFR
contact at rkade.fr
Fri Mar 15 09:32:12 MDT 2013
Hi!
I did some searches about my problem and didn't find any thing that
match in the archives.
I'm trying to do a simple jabber client with the twisted framework in
order to automatically send messages.
The server is a prosody server, and enabled the tls and iq auth.
So far, I can connect to the server, and can't login.
If I'm doing a XmlStreamFactory with the basicClientFactory, I have
these initializers/authenticator:
Initializers
[<twisted.words.protocols.jabber.xmlstream.TLSInitiatingInitializer
object at 0x2c1ef50>,
<twisted.words.protocols.jabber.client.IQAuthInitializer object at
0x2c1ef90>]
Authenticator <twisted.words.protocols.jabber.client.BasicAuthenticator
instance at 0x10f2320>
And if I create a XMPPClientFactory, I have these:
Initializers
[<twisted.words.protocols.jabber.client.CheckVersionInitializer object
at 0x2fe7f50>,
<twisted.words.protocols.jabber.xmlstream.TLSInitiatingInitializer
object at 0x2fe7fd0>,
<twisted.words.protocols.jabber.sasl.SASLInitiatingInitializer object at
0x2ff1050>, <twisted.words.protocols.jabber.client.BindInitializer
object at 0x2ff1090>,
<twisted.words.protocols.jabber.client.SessionInitializer object at
0x2ff10d0>]
Authenticator <twisted.words.protocols.jabber.client.XMPPAuthenticator
instance at 0x2fdd320>
So I look up the SEND and RECV message between the client and server,
and I notice that if I do a XMPPClientFactory, it's doing a tls
connection, then say it doesn't have the feature for iq auth.
And if I'm doing a basicClientFactory, I don't have the tls, so when it
tries to logon with iq, the server answers that it needs the tls.
After noticing that, I tried to change the initializers and the
authenticator in the connected function.
But when I'm doing a XMPPClientFactory with a BasicAuthenticator, I
don't have the tls anymore.
What do I need to change in order to have the tls and after the iq auth?
Thank you for your help.
rkadeFR
My current code:
19 class ClientXMPP(object):
20 def __init__(self, jid_user, password_user):
21 self.reactor = reactor
22 XmlStreamFactory = client.basicClientFactory(jid_user,
password_user)
23
XmlStreamFactory.addBootstrap(xmlstream.STREAM_CONNECTED_EVENT,
self.connected)
24 XmlStreamFactory.addBootstrap(xmlstream.STREAM_END_EVENT,
self.disconnected)
25 XmlStreamFactory.addBootstrap(xmlstream.STREAM_AUTHD_EVENT,
self.authenticated)
26 XmlStreamFactory.addBootstrap(xmlstream.INIT_FAILED_EVENT,
self.init_failed)
27 connector = SRVConnector(reactor, 'xmpp-client',
jid_user.host, XmlStreamFactory)
28 connector.connect()
29 self.finished = Deferred()
30
31 def rawDataIn(self, buf):
32 print "RECV: %s" % unicode(buf, 'utf-8').encode('ascii',
'replace')
33
34 def rawDataOut(self, buf):
35 print "SEND: %s" % unicode(buf, 'utf-8').encode('ascii',
'replace')
36
37 def connected(self, xs):
38 xs.rawDataInFn = self.rawDataIn
39 xs.rawDataOutFn = self.rawDataOut
40 print 'Connected.'
41 self.xmlstream = xs
42 #
43 print 'Initializers', xs.initializers
44 print 'Authenticator', xs.authenticator
45 print 'Am I initialized?', xs.initiating
46 # Log trafic out
47
48 def disconnected(self, xs):
49 print 'Disconnected.'
50 self.finished.callback(None)
51
52 def authenticated(self, xs):
53 print "Authenticated."
54 presence = domish.Element((None, 'presence'))
55 xs.send(presence)
56 self.reactor.callLater(5, xs.sendFooter)
57
58 def send(self, message):
59 print 'Send', message
60
61 def init_failed(self, failure):
62 print "Initialization failed. Failure:"
63 print failure
64 # self.xmlstream.sendFooter()
65 # self.xmlstream.authenticator.initializeStream()
More information about the Twisted-Python
mailing list