2009-08-01 15 views
3

J'essaye de m'authentifier avec un serveur XMPP en utilisant SASL.Authentification XMPP SASL sur Ejabberd avec PHP

/** 
    * 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. Quand 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 coutures pour moi 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 au 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>'); 
     }); 
    } 

donc je ne peux pas pourquoi la version PHP ne fonctionne pas.

Répondre

1

Déterminé quel était le problème. EJabberd annoncera SASL PLAIN et DIGEST-MD5 mais n'acceptera en réalité que DIGEST-MD5.

+1

Avez-vous ouvert un rapport de bogue? Cela aiderait d'autres personnes à ne pas avoir le même problème que vous. – cweiske

2

Essayez ceci en Python:

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

Et pour PHP utiliser aussi chr(0) au lieu de "\u0000"