]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/Msn/extlib/phpmsnclass/msn.class.php
Fix mising require_once (now required here because of rearranging)
[quix0rs-gnu-social.git] / plugins / Msn / extlib / phpmsnclass / msn.class.php
index 9abdce1b618a26a3a77814ff2737241cb3a859af..996c5571c20bd2c0a29458b7b1a00ef654f2e97b 100644 (file)
@@ -12,7 +12,7 @@ Documentation on the MSN protocol can be found at: http://msnpiki.msnfanatic.com
 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
@@ -156,7 +156,6 @@ class MSN {
         // 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
@@ -486,7 +485,7 @@ class MSN {
         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
@@ -2651,10 +2650,10 @@ X-OIM-Sequence-Num: 1
      */\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
@@ -2664,7 +2663,7 @@ X-OIM-Sequence-Num: 1
         $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
@@ -3180,4 +3179,32 @@ X-OIM-Sequence-Num: 1
         $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