Пример #1
0
    def __init__(self, jid, password = None, server = None, port = 5222,
            auth_methods = ("sasl:DIGEST-MD5", "digest"),
            tls_settings = None, keepalive = 0, owner = None):
        """Initialize a LegacyClientStream object.

        :Parameters:
            - `jid`: local JID.
            - `password`: user's password.
            - `server`: server to use. If not given then address will be derived form the JID.
            - `port`: port number to use. If not given then address will be derived form the JID.
            - `auth_methods`: sallowed authentication methods. SASL authentication mechanisms
              in the list should be prefixed with "sasl:" string.
            - `tls_settings`: settings for StartTLS -- `TLSSettings` instance.
            - `keepalive`: keepalive output interval. 0 to disable.
            - `owner`: `Client`, `Component` or similar object "owning" this stream.
        :Types:
            - `jid`: `pyxmpp.JID`
            - `password`: `unicode`
            - `server`: `unicode`
            - `port`: `int`
            - `auth_methods`: sequence of `str`
            - `tls_settings`: `pyxmpp.TLSSettings`
            - `keepalive`: `int`
        """
        (self.authenticated, self.available_auth_methods, self.auth_stanza,
                self.peer_authenticated, self.auth_method_used,
                self.registration_callback, self.registration_form, self.__register) = (None,) * 8
        ClientStream.__init__(self, jid, password, server, port,
                            auth_methods, tls_settings, keepalive, owner)
        self.__logger=logging.getLogger("pyxmpp.jabber.LegacyClientStream")
Пример #2
0
 def _post_auth(self):
     """Unregister legacy authentication handlers after successfull
     authentication."""
     ClientStream._post_auth(self)
     if not self.initiator:
         self.unset_iq_get_handler("query","jabber:iq:auth")
         self.unset_iq_set_handler("query","jabber:iq:auth")
Пример #3
0
 def _reset(self):
     """Reset the `LegacyClientStream` object state, making the object ready
     to handle new connections."""
     ClientStream._reset(self)
     self.available_auth_methods = None
     self.auth_stanza = None
     self.registration_callback = None
Пример #4
0
 def _reset(self):
     """Reset the `LegacyClientStream` object state, making the object ready
     to handle new connections."""
     ClientStream._reset(self)
     self.available_auth_methods = None
     self.auth_stanza = None
     self.registration_callback = None
Пример #5
0
 def _post_auth(self):
     """Unregister legacy authentication handlers after successfull
     authentication."""
     ClientStream._post_auth(self)
     if not self.initiator:
         self.unset_iq_get_handler("query", "jabber:iq:auth")
         self.unset_iq_set_handler("query", "jabber:iq:auth")
Пример #6
0
 def _post_connect(self):
     """Initialize authentication when the connection is established
     and we are the initiator."""
     if not self.initiator:
         if "plain" in self.auth_methods or "digest" in self.auth_methods:
             self.set_iq_get_handler("query","jabber:iq:auth",
                         self.auth_in_stage1)
             self.set_iq_set_handler("query","jabber:iq:auth",
                         self.auth_in_stage2)
     elif self.registration_callback:
         iq = Iq(stanza_type = "get")
         iq.set_content(Register())
         self.set_response_handlers(iq, self.registration_form_received, self.registration_error)
         self.send(iq)
         return
     ClientStream._post_connect(self)
Пример #7
0
    def _try_auth(self):
        """Try to authenticate using the first one of allowed authentication
        methods left.

        [client only]"""
        if self.authenticated:
            self.__logger.debug("try_auth: already authenticated")
            return
        self.__logger.debug("trying auth: %r" % (self._auth_methods_left,))
        if not self._auth_methods_left:
            raise LegacyAuthenticationError,"No allowed authentication methods available"
        method=self._auth_methods_left[0]
        if method.startswith("sasl:"):
            return ClientStream._try_auth(self)
        elif method not in ("plain","digest"):
            self._auth_methods_left.pop(0)
            self.__logger.debug("Skipping unknown auth method: %s" % method)
            return self._try_auth()
        elif self.available_auth_methods is not None:
            self._auth_methods_left.pop(0)
            if method in self.available_auth_methods:
                self.auth_method_used=method
                if method=="digest":
                    self._digest_auth_stage2(self.auth_stanza)
                else:
                    self._plain_auth_stage2(self.auth_stanza)
                self.auth_stanza=None
                return
            else:
                self.__logger.debug("Skipping unavailable auth method: %s" % method)
                return self._try_auth()
        else:
            self._auth_stage1()
Пример #8
0
    def _try_auth(self):
        """Try to authenticate using the first one of allowed authentication
        methods left.

        [client only]"""
        if self.authenticated:
            self.__logger.debug("try_auth: already authenticated")
            return
        self.__logger.debug("trying auth: %r" % (self._auth_methods_left, ))
        if not self._auth_methods_left:
            raise LegacyAuthenticationError, "No allowed authentication methods available"
        method = self._auth_methods_left[0]
        if method.startswith("sasl:"):
            return ClientStream._try_auth(self)
        elif method not in ("plain", "digest"):
            self._auth_methods_left.pop(0)
            self.__logger.debug("Skipping unknown auth method: %s" % method)
            return self._try_auth()
        elif self.available_auth_methods is not None:
            self._auth_methods_left.pop(0)
            if method in self.available_auth_methods:
                self.auth_method_used = method
                if method == "digest":
                    self._digest_auth_stage2(self.auth_stanza)
                else:
                    self._plain_auth_stage2(self.auth_stanza)
                self.auth_stanza = None
                return
            else:
                self.__logger.debug("Skipping unavailable auth method: %s" %
                                    method)
                return self._try_auth()
        else:
            self._auth_stage1()
Пример #9
0
 def _post_connect(self):
     """Initialize authentication when the connection is established
     and we are the initiator."""
     if not self.initiator:
         if "plain" in self.auth_methods or "digest" in self.auth_methods:
             self.set_iq_get_handler("query", "jabber:iq:auth",
                                     self.auth_in_stage1)
             self.set_iq_set_handler("query", "jabber:iq:auth",
                                     self.auth_in_stage2)
     elif self.registration_callback:
         iq = Iq(stanza_type="get")
         iq.set_content(Register())
         self.set_response_handlers(iq, self.registration_form_received,
                                    self.registration_error)
         self.send(iq)
         return
     ClientStream._post_connect(self)
Пример #10
0
    def __init__(self,
                 jid,
                 password=None,
                 server=None,
                 port=5222,
                 auth_methods=("sasl:DIGEST-MD5", "digest"),
                 tls_settings=None,
                 keepalive=0,
                 owner=None):
        """Initialize a LegacyClientStream object.

        :Parameters:
            - `jid`: local JID.
            - `password`: user's password.
            - `server`: server to use. If not given then address will be derived form the JID.
            - `port`: port number to use. If not given then address will be derived form the JID.
            - `auth_methods`: sallowed authentication methods. SASL authentication mechanisms
              in the list should be prefixed with "sasl:" string.
            - `tls_settings`: settings for StartTLS -- `TLSSettings` instance.
            - `keepalive`: keepalive output interval. 0 to disable.
            - `owner`: `Client`, `Component` or similar object "owning" this stream.
        :Types:
            - `jid`: `pyxmpp.JID`
            - `password`: `unicode`
            - `server`: `unicode`
            - `port`: `int`
            - `auth_methods`: sequence of `str`
            - `tls_settings`: `pyxmpp.TLSSettings`
            - `keepalive`: `int`
        """
        (self.authenticated, self.available_auth_methods, self.auth_stanza,
         self.peer_authenticated, self.auth_method_used,
         self.registration_callback, self.registration_form,
         self.__register) = (None, ) * 8
        ClientStream.__init__(self, jid, password, server, port, auth_methods,
                              tls_settings, keepalive, owner)
        self.__logger = logging.getLogger("pyxmpp.jabber.LegacyClientStream")
Пример #11
0
 def __init__(self, jid, password=None, server=None, port=None,
              auth_methods=("sasl:DIGEST-MD5",), tls_settings=None, keepalive=0, owner=None):
     ClientStream.__init__(
         self, jid=jid, password=password, server=server, port=port, auth_methods=auth_methods,
         tls_settings=tls_settings, keepalive=keepalive, owner=owner)
     self.__logger = logging.getLogger("iabot.xmpp.ClientStreamAsyncore")