Authentification SASL XMPP sur Ejabberd avec PHP
Question
J'essaie de m'authentifier auprès d'un serveur XMPP à l'aide de 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;
}
Le serveur XMPP répond cependant avec:
<failure xmlns='urn:ietf:params:xml:ns:xmpp-sasl'><bad-protocol/></failure>
Ceci est contre un serveur Ejabberd. Lorsque j'ouvre le flux XMPP, il annonce:
<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>
Il me semble donc que SASL - PLAIN devrait fonctionner. J'ai une version JavaScript qui fonctionne parfaitement sur le serveur OpenFire. (Je ne peux pas le tester sur Ejabberd pour le moment)
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>');
});
}
Je ne comprends donc pas pourquoi la version PHP ne fonctionne pas.
La solution 2
Déterminé quel était le problème. EJabberd annoncera SASL PLAIN et DIGEST-MD5 mais n'acceptera que DIGEST-MD5.
Autres conseils
Essayez ceci en Python:
Username+"@xmpp.poppen.lab"+ chr(0) + Username + chr(0) + Password
Et pour PHP, utilisez également chr (0)
au lieu de "\ u0000 "
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow