XMPP Рукопожатие (DIGEST-MD5 SASL) - PullRequest
       20

XMPP Рукопожатие (DIGEST-MD5 SASL)

0 голосов
/ 09 сентября 2010

я получил ejabberd в качестве моего сервера xmpp, и вот мой php-код:

$stripped = strip_tags($returnTwo); // remove the xml tags from the response stanza
$decoded = base64_decode($stripped); // decode the jibberish
$regex = "([0-9]{8,})"; // create regex to extract the nonce
preg_match($regex, $decoded, $noncearr); // extracts nonce
$nonce = $noncearr[0]; // finally, we can put the nonce into a variable to continue...

//   1. Create a string of the form "username:realm:password". Call this string X.
$x = "username:server.dyndns.org:password";
//   2. Compute the 16 octet MD5 hash of X. Call the result Y.
$y = md5($x);
//   3. Create a string of the form "Y:nonce:cnonce:authzid". Call this string A1.
$a = "$y:$nonce:$cnonce:username@server.dyndns.org/webchat";
//   4. Create a string of the form "AUTHENTICATE:digest-uri". Call this string A2.
$a2 = "AUTHENTICATE:xmpp/server.dyndns.org";
//   5. Compute the 32 hex digit MD5 hash of A1. Call the result HA1.
$ha1 = md5($a1);
//   6. Compute the 32 hex digit MD5 hash of A2. Call the result HA2.
$ha2 = md5($a2);
//   7. Create a string of the form "HA1:nonce:nc:cnonce:qop:HA2". Call this string KD.
$kd = "$ha1:$nonce:00000001:$cnonce:auth:$ha2";
//   8. Compute the 32 hex digit MD5 hash of KD. Call the result Z.
$z = md5($kd);
$b64z = base64_encode($z);
$respond = "<response xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>$b64z</response>";

// initialize curl again
$sendThree = curl_init("http://localhost:5280/http-bind");
curl_setopt($sendThree, CURLOPT_POST, 1);
curl_setopt($sendThree, CURLOPT_POSTFIELDS, $respond);
$returnThree = curl_exec($sendThree);
curl_close($sendThree); // close the curl connection

Моя проблема в том, что сервер возвращает «1».Вот и все, без принятия, без ошибок, просто число 1. Шаги до этого все вернуло то, что ожидалось, но с этой частью у меня возникли проблемы.Я новичок в php (это будет только моя вторая страница, созданная с ним), поэтому мне интересно, правильно ли я выполнил шаги SASL или это проблема с ejabberd?

Ответы [ 4 ]

0 голосов
/ 17 октября 2010

проверьте ваш код, у вас есть строка $ ha1 = md5 ($ a1);и только $ допустимый, без "1".

0 голосов
/ 09 сентября 2010

Если у вас все еще возникают проблемы с аутентификацией DIGEST-MD5, я рекомендую вам проверить класс аутентификации XMPP JAXL, который, вероятно, поможет вам http://github.com/abhinavsingh/JAXL/blob/master/xmpp/xmpp.auth.php#L86

0 голосов
/ 10 сентября 2010

хорошо, я разобрался с проблемой: я забыл увеличить свое избавление ... DOI!

и все же удовлетворение приводит к тому, что ..... теперь я получаю ошибку протокола x (

0 голосов
/ 09 сентября 2010

curl_exec возвращает логическое значение в зависимости от того, был ли он успешным.Таким образом, ваша функция возвращает true, которая преобразуется в число 1.

Чтобы получить реальный результат, вы должны добавить эту строку:

curl_setopt($sendThree, CURLOPT_RETURNTRANSFER, true);
...