2010-09-08 28 views
0

Ive得到ejabberd作爲我的XMPP服務器,這裏是我的PHP代碼:XMPP握手(DIGEST-MD5 SASL)

$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:[email protected]/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的問題?

+0

如果您使用BOSH,我相信你有包括''標籤。 – 2010-09-08 22:54:02

回答

0

curl_exec根據是否成功返回布爾值。所以,你的函數返回true,它被澆鑄成數1

獲得實際的結果,你必須加入這一行:

curl_setopt($sendThree, CURLOPT_RETURNTRANSFER, true); 
+0

您好,感謝您的答覆,但無論選擇工作 – Jonathan 2010-09-09 01:04:44

+0

對不起,我應該說,他們的工作,但他們並沒有採取它將進入下一步,它應該是來自服務器的成功,失敗或錯誤的編碼響應,最終的響應是: – Jonathan 2010-09-09 01:06:31

+0

您必須包裝您在 2010-09-09 04:01:20

0

如果你仍然面臨着DIGEST-MD5身份驗證問題,我建議你檢查JAXL XMPP身份驗證類,這可能會幫助你http://github.com/abhinavsingh/JAXL/blob/master/xmpp/xmpp.auth.php#L86

+0

生病看看,我可能不得不,但仍處於學習階段,並想知道在後臺發生了什麼,如果這是有道理大聲笑 – Jonathan 2010-09-09 18:32:53

+0

是絕對有道理,但不是重新發明輪子我自己,我建議你挑選一個圖書館,使用它,使用它,查看客戶端庫和服務器端日誌,將它們與RFC進行比較,以瞭解發生了什麼..... – 2010-09-11 23:48:44

0

好吧,我想出了問題: 我忘了增加我的擺脫...... DOI!

,但滿意度eldudes .....現在我得到一個壞的協議誤差x(

0

檢查你的代碼,你有串$ HA1 = MD5($ A1);只有$一個valiable,沒有「 1" 。