/**
  * Dissect country code from phone number.
  *
  * @param  Phone                    $phone
  * @return $this
  * @throws InvalidArgumentException
  * @throws RuntimeException
  */
 public function injectPhoneProperties(Phone $phone)
 {
     if (!file_exists($this->getCountriesPath()) || !is_readable($this->getCountriesPath())) {
         throw new RuntimeException("File doesn't exists or isn't readable.");
     }
     if (($handle = fopen($this->getCountriesPath(), 'rb')) !== false) {
         while (($data = fgetcsv($handle, 1000)) !== false) {
             if (strpos($phone->getPhoneNumber(), $data[1]) === 0) {
                 // Return the first appearance.
                 fclose($handle);
                 $mcc = explode("|", $data[2]);
                 $mcc = $mcc[0];
                 //hook:
                 //fix country code for North America
                 if (substr($data[1], 0, 1) == "1") {
                     $data[1] = "1";
                 }
                 $phone->setCountry($data[0])->setCc($data[1])->setPhone(substr($phone->getPhoneNumber(), strlen($data[1]), strlen($phone->getPhoneNumber())))->setMcc($mcc)->setIso3166(isset($data[3]) ? $data[3] : null)->setIso639(isset($data[4]) ? $data[4] : null)->setMnc(isset($data[5]) ? $data[5] : null);
                 return $this;
             }
         }
         fclose($handle);
     }
     throw new InvalidArgumentException("Phone number not recognized");
 }
Beispiel #2
0
 public function generateRequestToken($country, Phone $phone)
 {
     $waString = "UxYPUgMKRMKDEMKCwprCjcKMRjohaSlXQQ==";
     $noMediaHash = "AAGpM5zvDnFyrsmemfAETcw/kPWMRcCoW96rBU2pphtEOCWNVhSp8QX6";
     $waPrefix = "Y29tLndoYXRzYXBw";
     $signature = "MIIDMjCCAvCgAwIBAgIETCU2pDALBgcqhkjOOAQDBQAwfDELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFDASBgNVBAcTC1NhbnRhIENsYXJhMRYwFAYDVQQKEw1XaGF0c0FwcCBJbmMuMRQwEgYDVQQLEwtFbmdpbmVlcmluZzEUMBIGA1UEAxMLQnJpYW4gQWN0b24wHhcNMTAwNjI1MjMwNzE2WhcNNDQwMjE1MjMwNzE2WjB8MQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEUMBIGA1UEBxMLU2FudGEgQ2xhcmExFjAUBgNVBAoTDVdoYXRzQXBwIEluYy4xFDASBgNVBAsTC0VuZ2luZWVyaW5nMRQwEgYDVQQDEwtCcmlhbiBBY3RvbjCCAbgwggEsBgcqhkjOOAQBMIIBHwKBgQD9f1OBHXUSKVLfSpwu7OTn9hG3UjzvRADDHj+AtlEmaUVdQCJR+1k9jVj6v8X1ujD2y5tVbNeBO4AdNG/yZmC3a5lQpaSfn+gEexAiwk+7qdf+t8Yb+DtX58aophUPBPuD9tPFHsMCNVQTWhaRMvZ1864rYdcq7/IiAxmd0UgBxwIVAJdgUI8VIwvMspK5gqLrhAvwWBz1AoGBAPfhoIXWmz3ey7yrXDa4V7l5lK+7+jrqgvlXTAs9B4JnUVlXjrrUWU/mcQcQgYC0SRZxI+hMKBYTt88JMozIpuE8FnqLVHyNKOCjrh4rs6Z1kW6jfwv6ITVi8ftiegEkO8yk8b6oUZCJqIPf4VrlnwaSi2ZegHtVJWQBTDv+z0kqA4GFAAKBgQDRGYtLgWh7zyRtQainJfCpiaUbzjJuhMgo4fVWZIvXHaSHBU1t5w//S0lDK2hiqkj8KpMWGywVov9eZxZy37V26dEqr/c2m5qZ0E+ynSu7sqUD7kGx/zeIcGT0H+KAVgkGNQCo5Uc0koLRWYHNtYoIvt5R3X6YZylbPftF/8ayWTALBgcqhkjOOAQDBQADLwAwLAIUAKYCp0d6z4QQdyN74JDfQ2WCyi8CFDUM4CaNB+ceVXdKtOrNTQcc0e+t";
     $classesMd5 = "r4WQV17nVTl3+uFlF9mvEg==";
     $k = "PkTwKSZqUfAUyR0rPQ8hYJ0wNsQQ3dW1+3SCnyTXIfEAxxS75FwkDf47wNv/c8pP3p0GXKR6OOQmhyERwx74fw1RYSU10I4r1gyBVDbRJ40pidjM41G1I1oN";
     $KEY = "The piano has been drinking";
     //TODO: This phone prefix split XXX-ZZZZZ... is ok for +34 numbers, but needs to be checked
     //      for other countries
     //$phone1 = substr($phone->getPhoneNumber(), 0, 3);
     $phone2 = substr($phone->getPhoneNumber(), 3);
     // This AES secret is not really needed right now
     $id = base64_decode($waString) . $country . $phone2;
     $salt = substr(base64_decode($noMediaHash), 2, 4);
     $key = static::pbkdf2('sha1', $id, $salt, 16, 16, true);
     $iv = substr(base64_decode($noMediaHash), 6, 16);
     //$data = substr(base64_decode($noMediaHash),22);
     $td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', 'nofb', '');
     mcrypt_generic_init($td, $key, $iv);
     //$aes_secret = mcrypt_generic($td, $data);
     mcrypt_module_close($td);
     // We xor this file because I don't want to have a copyrighted png
     // on my repository
     $f = file_get_contents(__DIR__ . "/../../../data/magic.dat");
     $count = 0;
     $strlen = strlen($f);
     for ($i = 0; $i < $strlen; $i++) {
         $f[$i] = $f[$i] ^ $KEY[$count++];
         if ($count == strlen($KEY) - 1) {
             $count = 0;
         }
     }
     $d = base64_decode($waPrefix) . $f;
     $key2 = static::pbkdf2('sha1', $d, base64_decode($k), 128, 80, true);
     $data = base64_decode($signature) . base64_decode($classesMd5) . $phone->getPhoneNumber();
     $opad = str_repeat(chr(0x5c), 64);
     $ipad = str_repeat(chr(0x36), 64);
     for ($i = 0; $i < 64; $i++) {
         $opad[$i] = $opad[$i] ^ $key2[$i];
         $ipad[$i] = $ipad[$i] ^ $key2[$i];
     }
     $output = hash("sha1", $opad . hash("sha1", $ipad . $data, true), true);
     return base64_encode($output);
 }