Ejemplo n.º 1
0
    def _execute(self, intf, mechanism, token):
        """
        Execute a SASL authentication process.

        :param intf: SASL interface to use
        :type intf: :class:`~.sasl.SASLXMPPInterface`
        :param mechanism: SASL mechanism to use
        :type mechanism: :class:`aiosasl.SASLMechanism`
        :param token: The opaque token argument for the mechanism
        :type token: not :data:`None`
        :raises aiosasl.AuthenticationFailure: if authentication failed due to
                                               bad credentials
        :raises aiosasl.SASLFailure: on other SASL error conditions (such as
                                     protocol violations)
        :return: true if authentication succeeded, false if the mechanism has
                 to be disabled
        :rtype: :class:`bool`

        This executes the SASL authentication process. The more specific
        exceptions are generated by inspecting the
        :attr:`aiosasl.SASLFailure.opaque_error` on exceptinos raised from the
        :class:`~.sasl.SASLXMPPInterface`. Other :class:`aiosasl.SASLFailure`
        exceptions are re-raised without modification.
        """
        sm = aiosasl.SASLStateMachine(intf)
        try:
            yield from mechanism.authenticate(sm, token)
            return True
        except aiosasl.SASLFailure as err:
            if err.opaque_error in self.AUTHENTICATION_FAILURES:
                raise aiosasl.AuthenticationFailure(
                    opaque_error=err.opaque_error, text=err.text)
            elif err.opaque_error in self.MECHANISM_REJECTED_FAILURES:
                return False
            raise
Ejemplo n.º 2
0
        def credential_provider():
            nonlocal password_signalled_abort, nattempt, cached_credentials
            if cached_credentials is not None:
                return client_jid.localpart, cached_credentials

            password = yield from self._password_provider(client_jid, nattempt)
            if password is None:
                password_signalled_abort = True
                raise aiosasl.AuthenticationFailure(
                    "user intervention", text="authentication aborted by user")
            cached_credentials = password
            return client_jid.localpart, password
Ejemplo n.º 3
0
 def _execute(self, intf, mechanism, token):
     """
     Execute SASL negotiation using the given `mechanism` instance and
     `token` using the :class:`~.sasl.SASLXMPPInterface` `intf`.
     """
     sm = aiosasl.SASLStateMachine(intf)
     try:
         yield from mechanism.authenticate(sm, token)
         return True
     except aiosasl.SASLFailure as err:
         if err.opaque_error in self.AUTHENTICATION_FAILURES:
             raise aiosasl.AuthenticationFailure(
                 opaque_error=err.opaque_error, text=err.text)
         elif err.opaque_error in self.MECHANISM_REJECTED_FAILURES:
             return False
         raise