Ϫf7ddlmZmZmZddlmZddlmZmZm Z dZ dZ dZ dZ e jdZe jd Zd ZGd d ej$ZGd dZGddej*ZGddZGddej0ZGddej0ZddZGddej*Zy))errorsasl xmlstream)JID)domishutilityxpathz#urn:ietf:params:xml:ns:xmpp-streamsz urn:ietf:params:xml:ns:xmpp-bindz#urn:ietf:params:xml:ns:xmpp-sessionz"http://jabber.org/features/iq-authz/iq/query/digestz/iq/query/passwordcDt||}tj|SN)BasicAuthenticatorrXmlStreamFactory)jidsecretas G/usr/lib/python3/dist-packages/twisted/words/protocols/jabber/client.pybasicClientFactoryrs3'A  % %a ((c,eZdZdZddZdZddZdZy) IQa Wrapper for a Info/Query packet. This provides the necessary functionality to send IQs and get notified when a result comes back. It's a subclass from L{domish.Element}, so you can use the standard DOM manipulation calls to add data to the outbound request. @type callbacks: L{utility.CallbackList} @cvar callbacks: Callback list to be notified when response comes back ctjj|d|j||d<||_t j |_y)z @type xmlstream: L{xmlstream.XmlStream} @param xmlstream: XmlStream to use for transmission of this IQ @type type: C{str} @param type: IQ type identifier ('get' or 'set') ) jabber:clientiqtypeN)rElement__init__ addUniqueId _xmlstreamr CallbackList callbacks)selfrrs rrz IQ.__init__&sE &=> V # --/rcF|jjd|g|i|y)zW Register a callback for notification when the IQ result is available. TN)r addCallback)r fnargskwargss rr"zIQ.addCallback5s$ #""4=d=f=rNc|dk7r||d<|jjd|dz|j|jj|y)a? Call this method to send this IQ request via the associated XmlStream. @param to: Jabber ID of the entity to send the request to @type to: C{str} @returns: Callback list for this IQ. Any callbacks added to this list will be fired when the result comes back. Ntoz /iq[@id='%s']id)raddOnetimeObserver _resultEventsend)r r's rr+zIQ.send<sN :DJ ** d4j ($*;*;  T"rcH|jj|d|_yr )rcallbackr rs rr*zIQ._resultEventMs #r)setr )__name__ __module__ __qualname____doc__rr"r+r*rrrrs  0>#"rrc<eZdZdZdZdZdZdZdZdZ dZ d Z y ) IQAuthInitializera Non-SASL Authentication initializer for the initiating entity. This protocol is defined in U{JEP-0078} and mainly serves for compatibility with pre-XMPP-1.0 server implementations. @cvar INVALID_USER_EVENT: Token to signal that authentication failed, due to invalid username. @type INVALID_USER_EVENT: L{str} @cvar AUTH_FAILED_EVENT: Token to signal that authentication failed, due to invalid password. @type AUTH_FAILED_EVENT: L{str} z$//event/client/basicauth/invaliduserz#//event/client/basicauth/authfailedc||_yr rr xss rrzIQAuthInitializer.__init__f rcbtj|jd}|jd|jjj}|j jd|j |j}|j|j|j|S)Ngetzjabber:iq:authqueryusernamecontent) rr addElement authenticatorrr?userr+ addCallbacks _cbAuthQuery _ebAuthQuery)r rrds r initializezIQAuthInitializer.initializeis} \\$..% 0 12nn**.. J9 GGI t(($*;*;<rc|jjj}|jjj}tj|jd}|j d|j j d|j|j j d|jtj|rQtj|jj|}|j j dt|n|j j d||j}|j|j |j"|S)Nr/r>r@rAresourcedigestpassword)rrDrrNrrCr?rErL DigestAuthQrymatches hashPasswordsidstrr+rF_cbAuth_ebAuth)r rrrNreplyrMrIs rrGzIQAuthInitializer._cbAuthQueryts nn**..>>//88 T^^U3 45 z388< z3<<@   $++DNN,>,>IF KK " "8S[ " A KK " ":x " @ JJL t||T\\2rc>|jtj|j}|jdk(r2|j j |j|j|S|j j |j|j|S)Nznot-authorized) trapr StanzaErrorvalue conditionrdispatchstanzaINVALID_USER_EVENTAUTH_FAILED_EVENT)r failurees rrHzIQAuthInitializer._ebAuthQueryst U&&' MM ;;* * NN # #AHHd.E.E F NN # #AHHd.D.D Ercyr r4r.s rrTzIQAuthInitializer._cbAuths rc|jtj|jj |j j |j|Sr )rXrrYrr\rZr]r_)r r`s rrUzIQAuthInitializer._ebAuths= U&&'  4 4d6L6LMrN) r0r1r2r3r^r_rrJrGrHrTrUr4rrr6r6Rs4 @= * rr6cbeZdZdZdZej ZejZdZdZ dZ d dZ dZ y) r aO Authenticates an XmlStream against a Jabber server as a Client. This only implements non-SASL authentication, per U{JEP-0078}. Additionally, this authenticator provides the ability to perform inline registration, per U{JEP-0077}. Under normal circumstances, the BasicAuthenticator generates the L{xmlstream.STREAM_AUTHD_EVENT} once the stream has authenticated. However, it can also generate other events, such as: - L{INVALID_USER_EVENT} : Authentication failed, due to invalid username - L{AUTH_FAILED_EVENT} : Authentication failed, due to invalid password - L{REGISTER_FAILED_EVENT} : Registration failed If authentication fails for any reason, you can attempt to register by calling the L{registerAccount} method. If the registration succeeds, a L{xmlstream.STREAM_AUTHD_EVENT} will be fired. Otherwise, one of the above errors will be generated (again). @cvar INVALID_USER_EVENT: See L{IQAuthInitializer.INVALID_USER_EVENT}. @type INVALID_USER_EVENT: L{str} @cvar AUTH_FAILED_EVENT: See L{IQAuthInitializer.AUTH_FAILED_EVENT}. @type AUTH_FAILED_EVENT: L{str} @cvar REGISTER_FAILED_EVENT: Token to signal that registration failed. @type REGISTER_FAILED_EVENT: L{str} rz'//event/client/basicauth/registerfailedcttjj||j||_||_yr )rConnectAuthenticatorrhostrrN)r rrNs rrzBasicAuthenticator.__init__s*&&//chh?  rcd|_tjj||tj|dt |g|_y)N)rrFrequired)versionrrfassociateWithStreamTLSInitiatingInitializerr6 initializersr9s rrlz&BasicAuthenticator.associateWithStreamsB &&::4D  . .rE B b ! rNc|r||j_|r||_t|jd}|j d|j j d|jj|j j d|j|j|j|jy)Nr/)zjabber:iq:registerr?r@rArN) rrErNrrrCr?r"_registerResultEventr+)r r@rNrs rregisterAccountz"BasicAuthenticator.registerAccounts $DHHM $DM  & 56 J > J > t001  rc|ddk(r|jy|jj||jy)Nrresult) streamStartedrr\REGISTER_FAILED_EVENTr.s rrpz'BasicAuthenticator._registerResultEvents6 f: !     NN # #B(B(B Cr)NN) r0r1r2r3 namespacer6r^r_rurrlrqrpr4rrr r sB@ I*==);;E!   Drr ceZdZdZdZdZy)CheckVersionInitializerzU Initializer that checks if the minimum common stream version number is 1.0. c||_yr r8r9s rrz CheckVersionInitializer.__init__r;rc`|jjdkrtjdy)N)rzunsupported-version)rrkr StreamError)r s rrJz"CheckVersionInitializer.initializes+ >> ! !F *##$9: : +rN)r0r1r2r3rrJr4rrrxrxs;rrxc$eZdZdZedfZdZdZy)BindInitializerz Initializer that implements Resource Binding for the initiating entity. This protocol is documented in U{RFC 3920, section 7}. bindcHtj|jd}|jtdf}|jjj j }|r|jd||j}|j|j|S)Nr/rrLrA) rrrC NS_XMPP_BINDrDrrLr+r"onBind)r rrrLrIs rstartzBindInitializer.startsw \\$..% 0}}lF34>>//33<<  OOJO 9 GGI dkk"rc|jrBtt|jj|jj _yyr )rrrSrrrDr.s rrzBindInitializer.onBind s2 77/23rww{{3C/DDNN ( ( , rN)r0r1r2r3rfeaturerrr4rrr~r~sV$GErr~ceZdZdZedfZdZy)SessionInitializerz Initializer that implements session establishment for the initiating entity. This protocol is defined in U{RFC 3921, section 3}. sessionctj|jd}|jtdf|j S)Nr/r)rrrCNS_XMPP_SESSIONr+r.s rrzSessionInitializer.starts3 \\$..% 0  23wwyrN)r0r1r2r3rrrr4rrrrs *GrrNcHt|||}tj|S)a Client factory for XMPP 1.0 (only). This returns a L{xmlstream.XmlStreamFactory} with an L{XMPPAuthenticator} object to perform the stream initialization steps (such as authentication). @see: The notes at L{XMPPAuthenticator} describe how the C{jid} and C{password} parameters are to be used. @param jid: Jabber ID to connect with. @type jid: L{jid.JID} @param password: password to authenticate with. @type password: L{unicode} @param configurationForTLS: An object which creates appropriately configured TLS connections. This is passed to C{startTLS} on the transport and is preferably created using L{twisted.internet.ssl.optionsForClientTLS}. If L{None}, the default is to verify the server certificate against the trust roots as provided by the platform. See L{twisted.internet._sslverify.platformTrust}. @type configurationForTLS: L{IOpenSSLClientConnectionCreator} or L{None} @return: XML stream factory. @rtype: L{xmlstream.XmlStreamFactory} )configurationForTLS)XMPPAuthenticatorrr )rrNrrs rXMPPClientFactoryr"s$6 #x=PQA  % %a ((rc"eZdZdZdZddZdZy)ra Initializes an XmlStream connecting to an XMPP server as a Client. This authenticator performs the initialization steps needed to start exchanging XML stanzas with an XMPP server as an XMPP client. It checks if the server advertises XML stream version 1.0, negotiates TLS (when available), performs SASL authentication, binds a resource and establishes a session. Upon successful stream initialization, the L{xmlstream.STREAM_AUTHD_EVENT} event will be dispatched through the XML stream object. Otherwise, the L{xmlstream.INIT_FAILED_EVENT} event will be dispatched with a failure object. After inspection of the failure, initialization can then be restarted by calling L{ConnectAuthenticator.initializeStream}. For example, in case of authentication failure, a user may be given the opportunity to input the correct password. By setting the L{password} instance variable and restarting initialization, the stream authentication step is then retried, and subsequent steps are performed if successful. @ivar jid: Jabber ID to authenticate with. This may contain a resource part, as a suggestion to the server for resource binding. A server may override this, though. If the resource part is left off, the server will generate a unique resource identifier. The server will always return the full Jabber ID in the resource binding step, and this is stored in this instance variable. @type jid: L{jid.JID} @ivar password: password to be used during SASL authentication. @type password: L{unicode} rNctjj||j||_||_||_y)a3 @param configurationForTLS: An object which creates appropriately configured TLS connections. This is passed to C{startTLS} on the transport and is preferably created using L{twisted.internet.ssl.optionsForClientTLS}. If C{None}, the default is to verify the server certificate against the trust roots as provided by the platform. See L{twisted.internet._sslverify.platformTrust}. @type configurationForTLS: L{IOpenSSLClientConnectionCreator} or C{None} N)rrfrrgrrN_configurationForTLS)r rrNrs rrzXMPPAuthenticator.__init__fs4 &&//chh?  $7!rctjj||t|tj|d|j t j|dt|dt|dg|_ y)z Register with the XML stream. Populates stream's list of initializers, along with their requiredness. This list is used by L{ConnectAuthenticator.initializeStream} to perform the initialization steps. T)rjrriFN) rrfrlrxrmrrSASLInitiatingInitializerr~rrnr9s rrlz%XMPPAuthenticator.associateWithStreamwsn &&::4D $B '  . .Tt7P7P   * *2 = B . rE 2 rr )r0r1r2r3rvrrlr4rrrrAs D I8" rrr )twisted.words.protocols.jabberrrr"twisted.words.protocols.jabber.jidrtwisted.words.xishrrr NS_XMPP_STREAMSrrNS_IQ_AUTH_FEATURE internQueryrOPlaintextAuthQryrrrr6rfr rx BaseFeatureInitiatingInitializerr~rrrr4rrrsBA25571 79!!!"45 $5$$%9:) 66rGGTLD77LD^ ; ;Ei@@E2CC")>I 66I r