【问题标题】:XMPP Handshake (DIGEST-MD5 SASL)XMPP 握手 (DIGEST-MD5 SASL)
【发布时间】:2010-09-08 22:47:25
【问题描述】:

我得到了 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 的问题?

【问题讨论】:

  • 如果你使用的是BOSH,我相信你必须包含&lt;body /&gt;标签。

标签: php xmpp sasl digest-authentication


【解决方案1】:

curl_exec 根据是否成功返回一个布尔值。所以你的函数返回true,它被转换成数字1。

要获得实际结果,您必须添加以下行:

curl_setopt($sendThree, CURLOPT_RETURNTRANSFER, true);

【讨论】:

  • 对不起,我应该说他们工作了,但他们没有把它带到下一步,这应该是来自服务器的成功、失败或错误的编码响应。得到的响应是:jabber.org/protocol/httpbind'>
  • 您必须根据 BOSH 规范将您发送到 &lt;body xmlns=".."&gt;&lt;/body&gt; 的字符串包装起来:xmpp.org/extensions/xep-0124.html
  • 是的,按照上面cmets的说明,我使用了body标签,但结果是一样的。
【解决方案2】:

如果您仍然面临 DIGEST-MD5 身份验证的问题,我建议您查看 JAXL XMPP 身份验证类,这可能会帮助您解决问题http://github.com/abhinavsingh/JAXL/blob/master/xmpp/xmpp.auth.php#L86

【讨论】:

  • 我会看一下,我可能不得不看,但仍处于学习阶段,想知道后台发生了什么,如果这有意义的话,哈哈
  • 是的,绝对有道理,但与其自己重新发明轮子,我建议您拿起一个库,使用它,玩弄它,查看客户端库和服务器端日志,将它们与 RFC 进行比较以获得感觉正在发生的事情.....
【解决方案3】:

好的,我发现了问题: 我忘了增加我的摆脱... DOI!

然而满足感却难以满足.....现在我得到了一个错误的协议错误 x(

【讨论】:

    【解决方案4】:

    检查你的代码,你有字符串 $ha1 = md5($a1);并且只有 $a 变量,没有“1”。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-07-11
      • 2012-06-11
      • 1970-01-01
      • 2012-10-11
      • 1970-01-01
      • 2018-10-14
      • 1970-01-01
      相关资源
      最近更新 更多