views:

55

answers:

4

ive got ejabberd as my xmpp server and here is my php code:

$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

my problem is that the server returns a "1". thats it , no acceptance, no error, just a number 1. the steps before this all returned what was expected, but this part im having trouble with. im new to php (this will only be my second page created with it) so im wondering if i followed the SASL steps correctly or if it is a problem with ejabberd?

A: 

curl_exec returns a boolean depending on if it was successful. So your function is returning true, which gets casted into the number 1.

To get the actual result, you have to add this line:

curl_setopt($sendThree, CURLOPT_RETURNTRANSFER, true);
Casey Hope
hi, thanks for the responses, but neither option worked
Jonathan
sorry, i should say they worked but they did not take it to the next step which should be a success, fail, or bad encode response from the server. the resulting response was: <body xmlns='http://jabber.org/protocol/httpbind'/>
Jonathan
You have to wrap the string you send in `<body xmlns="..">` and `</body>` according to the BOSH specification: http://xmpp.org/extensions/xep-0124.html
Casey Hope
yeah, as instructed in comments above i used the body tag, but result is the same.
Jonathan
A: 

If you are still facing issues with DIGEST-MD5 auth, i recommend you to check JAXL XMPP Auth class which will probably help you out http://github.com/abhinavsingh/JAXL/blob/master/xmpp/xmpp.auth.php#L86

Abhinav Singh
ill take a look, and i might have to, but still in the learning stages and want to know whats going on in the background, if that makes sense lol
Jonathan
yes absolutely makes sense, but instead of reinventing the wheel yourself i recommend you to pick up a library, use it, play with it, see client library and server side logs, compare them with RFC's to get a feel of what's happening.....
Abhinav Singh
A: 

ok, i figured out the problem: i forgot to increment my rid ... DOI!

and yet satisfaction eldudes..... now i get a bad protocol error x(

Jonathan
A: 

check your code, you have string $ha1 = md5($a1); and only $a valiable, without "1".

ChipFind