Pergunta

Eu estou tentando autenticar com um servidor XMPP usando SASL.

/**
     * Send Authentication, SASL
     * @return Bool
     * @param $username String
     * @param $password String
     */
    function authenticate($username, $password) {
        $this->username = $username;
        $this->password = $password;

        var_dump($username, $password, $this->domain);

        $auth = base64_encode($username.'@'.$this->domain."\u0000".$username."\u0000".$password);
        $xml = '<auth mechanism="PLAIN" xmlns="urn:ietf:params:xml:ns:xmpp-sasl">'.$auth.'</auth>';
        if ($this->write($xml)) {
            if ($xml = $this->listen(1, true)) {
                if (preg_match("/<success/i", $xml)) {
                    $this->authenticated = $this->_sendStream();
                }
            }
        }
        $this->events->trigger('authenticate', $this->authenticated);
        return $this->authenticated;
    }

O servidor XMPP no entanto responde com:

<failure xmlns='urn:ietf:params:xml:ns:xmpp-sasl'><bad-protocol/></failure>

Este é contra um servidor ejabberd. Quando abro o fluxo de XMPP, ele anuncia:

<stream:features><starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/><mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'><mechanism>DIGEST-MD5</mechanism><mechanism>PLAIN</mechanism></mechanisms><register xmlns='http://jabber.org/features/iq-register'/></stream:features>

Por isso, costuras para mim que SASL - PLAIN deve funcionar. Eu tenho uma versão JavaScript, que funciona perfeitamente no servidor OpenFire. (Eu não posso testá-lo em ejabberd no momento)

sendAuthentication: function() {
        clearTimeout(XMPP.sendAuthentication_timer);
        var auth = Base64.encode(XMPP.username+'@'+XMPP.domain+'\u0000'+XMPP.username+'\u0000'+XMPP.password);
        mySocket.events.receive.observe(XMPP.receivedAuthSuccess, function() {
            mySocket.send('<auth mechanism="PLAIN" xmlns="urn:ietf:params:xml:ns:xmpp-sasl">' + auth + '</auth>');
        });
    }

Então eu não posso entender porque a versão do PHP não está funcionando.

Foi útil?

Solução 2

descobri o que era o problema. Ejabberd vai anunciar SASL PLAIN e DIGEST-MD5, mas vai realmente aceitar apenas DIGEST-MD5.

Outras dicas

Tente isso em Python:

Username+"@xmpp.poppen.lab"+ chr(0) + Username + chr(0) + Password

E para PHP também usam chr(0) vez de "\u0000"

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top