This class uses MSNP15.\r
\r
In addition to PHP5, the additional php modules required are:\r
-curl pcre mhash mcrypt bcmath\r
+curl pcre mcrypt bcmath\r
\r
*/\r
\r
// Check support\r
if (!function_exists('curl_init')) throw new Exception("curl module not found!\n");\r
if (!function_exists('preg_match')) throw new Exception("pcre module not found!\n");\r
- if (!function_exists('mhash')) throw new Exception("mhash module not found!\n");\r
if (!function_exists('mcrypt_cbc')) throw new Exception("mcrypt module not found!\n");\r
if (!function_exists('bcmod')) throw new Exception("bcmath module not found!\n");\r
\r
if(!empty($message)) {\r
$this->debug_message($message);\r
}\r
- $this->callHandler('ConnectFailed');\r
+ $this->callHandler('ConnectFailed', $message);\r
$this->NSRetryWait($this->retry_wait);\r
}\r
\r
*/\r
\r
private function derive_key($key, $magic) {\r
- $hash1 = mhash(MHASH_SHA1, $magic, $key);\r
- $hash2 = mhash(MHASH_SHA1, $hash1.$magic, $key);\r
- $hash3 = mhash(MHASH_SHA1, $hash1, $key);\r
- $hash4 = mhash(MHASH_SHA1, $hash3.$magic, $key);\r
+ $hash1 = $this->mhash_sha1($magic, $key);\r
+ $hash2 = $this->mhash_sha1($hash1.$magic, $key);\r
+ $hash3 = $this->mhash_sha1($hash1, $key);\r
+ $hash4 = $this->mhash_sha1($hash3.$magic, $key);\r
return $hash2.substr($hash4, 0, 4);\r
}\r
\r
$key3 = $this->derive_key($key1, 'WS-SecureConversationSESSION KEY ENCRYPTION');\r
\r
// get hash of challenge using key2\r
- $hash = mhash(MHASH_SHA1, $challenge, $key2);\r
+ $hash = $this->mhash_sha1($challenge, $key2);\r
\r
// get 8 bytes random data\r
$iv = substr(base64_encode(rand(1000,9999).rand(1000,9999)), 2, 8);\r
$buf .= "$h_str $a_str\n";\r
return $buf;\r
}\r
+\r
+ function mhash_sha1($data, $key)\r
+ {\r
+ if (extension_loaded("mhash"))\r
+ return mhash(MHASH_SHA1, $data, $key);\r
+\r
+ if (function_exists("hash_hmac"))\r
+ return hash_hmac('sha1', $data, $key, true);\r
+\r
+ // RFC 2104 HMAC implementation for php. Hacked by Lance Rushing\r
+ $b = 64;\r
+ if (strlen($key) > $b)\r
+ $key = pack("H*", sha1($key));\r
+ $key = str_pad($key, $b, chr(0x00));\r
+ $ipad = str_pad("", $b, chr(0x36));\r
+ $opad = str_pad("", $b, chr(0x5c));\r
+ $k_ipad = $key ^ $ipad ;\r
+ $k_opad = $key ^ $opad;\r
+\r
+ $sha1_value = sha1($k_opad . pack("H*", sha1($k_ipad . $data)));\r
+\r
+ $hash_data = '';\r
+ $str = join('',explode('\x', $sha1_value));\r
+ $len = strlen($str);\r
+ for ($i = 0; $i < $len; $i += 2)\r
+ $hash_data .= chr(hexdec(substr($str, $i, 2)));\r
+ return $hash_data;\r
+ }\r
}\r