/** * {@inheritDoc} */ public function unwrap($in, $maxAgeSec) { //TODO remove this once we have a better way to generate a fake token // in the example files if (Config::get('allow_plaintext_token') && count(explode(':', $in)) == 6) { $data = explode(":", $in); $out = array(); $out['o'] = $data[0]; $out['v'] = $data[1]; $out['a'] = $data[2]; $out['d'] = $data[3]; $out['u'] = $data[4]; $out['m'] = $data[5]; } else { //TODO Exception handling like JAVA $bin = base64_decode($in); $cipherText = substr($bin, 0, strlen($bin) - Crypto::$HMAC_SHA1_LEN); $hmac = substr($bin, strlen($cipherText)); Crypto::hmacSha1Verify($this->hmacKey, $cipherText, $hmac); $plain = Crypto::aes128cbcDecrypt($this->cipherKey, $cipherText); $out = $this->deserialize($plain); $this->checkTimestamp($out, $maxAgeSec); } return $out; }
/** * @see BasicBlobCrypter::unwrap(); */ public function unwrap($in, $maxAgeSec) { if ($this->allowPlaintextToken && count(explode(':', $in)) == 7) { $data = explode(":", $in); $out = array(); $out['o'] = $data[0]; $out['v'] = $data[1]; $out['a'] = $data[2]; $out['d'] = $data[3]; $out['u'] = $data[4]; $out['m'] = $data[5]; } else { $bin = base64_decode($in); if (is_callable('mb_substr')) { $cipherText = mb_substr($bin, 0, -Crypto::$HMAC_SHA1_LEN, 'latin1'); $hmac = mb_substr($bin, mb_strlen($cipherText, 'latin1'), Crypto::$HMAC_SHA1_LEN, 'latin1'); } else { $cipherText = substr($bin, 0, -Crypto::$HMAC_SHA1_LEN); $hmac = substr($bin, strlen($cipherText)); } Crypto::hmacSha1Verify($this->hmacKey, $cipherText, $hmac); $plain = base64_decode($cipherText); if ($this->allowPlaintextToken) { $plain = base64_decode($cipherText); } else { $plain = opShindigCrypto::decrypt($this->cipherKey, $cipherText); } $out = $this->deserialize($plain); $this->checkTimestamp($out, $maxAgeSec); } return $out; }
/** * Tests Crypto::hmacSha1Verify() */ public function testHmacSha1Verify() { $string = 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit'; $key = 'Aliquam erat volutpat'; $expected = '%16%E7%E0E%22%08%5C%2B48%85d%FE%DE%C7%3A%C3%0D%11c'; try { Crypto::hmacSha1Verify($key, $string, urldecode($expected)); $success = true; } catch (GeneralSecurityException $e) { $success = false; } $this->assertTrue($success); }
/** * {@inheritDoc} */ public function unwrap($in, $maxAgeSec) { //TODO remove this once we have a better way to generate a fake token in the example files if ($this->allowPlaintextToken && count(explode(':', $in)) >= 7) { //Parses the security token in the form st=o:v:a:d:u:m:c $data = $this->parseToken($in); $out = array(); $out['o'] = $data[0]; $out['v'] = $data[1]; $out['a'] = $data[2]; $out['d'] = $data[3]; $out['u'] = $data[4]; $out['m'] = $data[5]; } else { $bin = base64_decode($in); if (is_callable('mb_substr')) { $cipherText = mb_substr($bin, 0, -Crypto::$HMAC_SHA1_LEN, 'latin1'); $hmac = mb_substr($bin, mb_strlen($cipherText, 'latin1'), Crypto::$HMAC_SHA1_LEN, 'latin1'); } else { $cipherText = substr($bin, 0, -Crypto::$HMAC_SHA1_LEN); $hmac = substr($bin, strlen($cipherText)); } Crypto::hmacSha1Verify($this->hmacKey, $cipherText, $hmac); if (!function_exists('mcrypt_module_open') && $this->allowPlaintextToken) { $plain = base64_decode($cipherText); } else { $plain = Crypto::aes128cbcDecrypt($this->cipherKey, $cipherText); } $out = $this->deserialize($plain); $this->checkTimestamp($out, $maxAgeSec); } return $out; }
/** * {@inheritDoc} */ public function unwrap($in, $maxAgeSec) { //TODO remove this once we have a better way to generate a fake token in the example files if ($this->allowPlaintextToken && count(explode(':', $in)) == 6) { $data = explode(":", $in); $out = array(); $out['o'] = $data[0]; $out['v'] = $data[1]; $out['a'] = $data[2]; $out['d'] = $data[3]; $out['u'] = $data[4]; $out['m'] = $data[5]; } else { $bin = base64_decode($in); $cipherText = substr($bin, 0, strlen($bin) - Crypto::$HMAC_SHA1_LEN); $hmac = substr($bin, strlen($cipherText)); Crypto::hmacSha1Verify($this->hmacKey, $cipherText, $hmac); if (!function_exists('mcrypt_module_open') && $this->allowPlaintextToken) { $plain = base64_decode($cipherText); } else { $plain = Crypto::aes128cbcDecrypt($this->cipherKey, $cipherText); } $out = $this->deserialize($plain); $this->checkTimestamp($out, $maxAgeSec); } return $out; }