public function testEncode() { $testString = 'a string to be compressed'; $result = $this->encoder->encode($testString); $uncompressedResult = gzinflate($result); $this->assertSame($testString, $uncompressedResult); }
public function demoapp() { $sharedKey = 'abracadabra'; $self = 'http' . ($_SERVER['HTTPS'] ? 's' : '') . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME']; if ($_POST['doit']) { $idp = $_POST['idp']; if (!$idp) { $idp = "sp"; } $request = array('_ID' => sha1(uniqid(mt_rand(), true)), '_Version' => '2.0', '_IssueInstant' => gmdate('Y-m-d\\TH:i:s\\Z', time()), '_Destination' => $self . "/{$idp}/singleSignOnService", '_ForceAuthn' => $_REQUEST['ForceAuthn'] ? 'true' : 'false', '_IsPassive' => $_REQUEST['IsPassive'] ? 'true' : 'false', '_AssertionConsumerServiceURL' => $self . "/main/" . __FUNCTION__, '_AttributeConsumingServiceIndex' => 5, '_ProtocolBinding' => 'JSON-Redirect', 'saml:Issuer' => array('__v' => $self . "/main")); foreach ((array) $_REQUEST['IDPList'] as $idp) { $idpList[] = array('_ProviderID' => $idp); } $relayState = 'Dummy RelayState ...'; if ($idpList) { $request['samlp:Scoping']['samlp:IDPList']['samlp:IDPEntry'] = $idpList; } #$request['samlp:Scoping']['_ProxyCount'] = 2; $location = $request['_Destination']; $request = "SAMLRequest=" . urlencode(base64_encode(gzdeflate(json_encode($request)))) . ($relayState ? '&RelayState=' . urlencode($relayState) : ''); $signature = urlencode(base64_encode(sha1($sharedKey . sha1($request)))); header('Location: ' . $location . "?" . $request . "&Signature=" . $signature); print "<a href=\"{$location}?{$request}&Signature={$signature}\">{$location}</a>"; exit; } $response = base64_decode($_REQUEST['SAMLResponse']); $hSAMLResponse = json_decode(gzinflate($response), 1); if ($rs = $_POST['RelayState']) { $rs = '&RelayState=' . $rs; } if ($response && base64_encode(sha1($sharedKey . sha1("jSAMLResponse={$response}{$rs}"))) != $_POST['Signature']) { $message = 'Integrity check failed (Sharedkey) ' . $_POST['Signature'] . ' != ' . base64_encode(sha1($sharedKey . sha1("jSAMLResponse={$response}{$rs}"))); } print $this->_server->renderTemplate('demo', array('action' => $self . "/main/demoapp", 'hSAMLResponse' => $hSAMLResponse, 'message' => $message . " RelayState: " . $_GET['RelayState'], 'self' => $self)); }
/** * Get request protocol based on Content-Type * * @return string default as xmlrpc */ protected function init() { $ver = phpversion(); if ($ver[0] >= 5) { $data = file_get_contents('php://input'); } else { $data = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : ''; } if (count($_SERVER) == 0) { self::alert('XML-RPC: ' . __METHOD__ . ': cannot parse request headers as $_SERVER is not populated'); } if (isset($_SERVER['HTTP_CONTENT_ENCODING'])) { $content_encoding = str_replace('x-', '', $_SERVER['HTTP_CONTENT_ENCODING']); } else { $content_encoding = ''; } if ($content_encoding != '' && strlen($data)) { if ($content_encoding == 'deflate' || $content_encoding == 'gzip') { // if decoding works, use it. else assume data wasn't gzencoded if (function_exists('gzinflate')) { if ($content_encoding == 'deflate' && ($degzdata = @gzuncompress($data))) { $data = $degzdata; } elseif ($degzdata = @gzinflate(substr($data, 10))) { $data = $degzdata; } } else { self::alert('XML-RPC: ' . __METHOD__ . ': Received from client compressed HTTP request and cannot decompress'); } } } $parsers = php_xmlrpc_decode_xml($data); $this->cmd = $parsers->methodname; $this->input = php_xmlrpc_decode(new xmlrpcval($parsers->params, 'array')); }
/** * grabs data from the cache and returns it to the user. * if data is expired or invalid, returns null. * * @param string $cacheKey the cache key to set. * @return mixed|null * @throws FileCacheException */ public function get($cacheKey) { //make sure key exists in the array. $returnVal = null; $isValid = $this->isValid($cacheKey); if ($isValid === true) { $file_contents = ""; $filename = $this->getFileName($cacheKey); //if the cache dir doesn't exist for some reason... if (!is_dir($this->cache_dir)) { throw new FileCacheException("Could not read cache directory!"); } if (is_file($filename)) { $file_contents = file_get_contents($filename); if ($this->use_compression) { $file_contents = gzinflate($file_contents); } $returnVal = unserialize($file_contents); } } else { if ($isValid == -1) { $this->expire($cacheKey); } } return $returnVal; }
/** * (non-PHPdoc). * * @param string $data * * @see \Dms\Coding\CodingInterface::decode() */ public function decode($data = null) { if ($data != null) { $this->setData($data); } return gzinflate($this->data); }
function act_detectSkuStoreInfo() { $skuArr = isset($_POST['skuArr']) ? json_decode(gzinflate($_POST['skuArr'])) : ''; $storeId = isset($_POST['storeId']) ? $_POST['storeId'] : ''; if (!is_array($skuArr)) { self::$errCode = 401; self::$errMsg = "skuArr不是数组!"; return; } if (empty($storeId)) { self::$errCode = 402; self::$errMsg = "storeId不能为空"; return; } $sku_str = implode("','", $skuArr); $sku_str = "('" . $sku_str . "')"; $sku_list = OmAvailableModel::getTNameList("wh_sku_location", "sku,actualStock", "where sku in {$sku_str} and actualStock>0 and storeId='{$storeId}'"); if ($sku_list) { $return_info = array(); foreach ($sku_list as $list) { $return_info[] = $list['sku']; } return json_encode($return_info); } else { return ''; } }
/** * Returns the response body. * * @return string */ public function getResponseBody() { if (!parent::getResponseBody()) { return 'Response Unavailable'; } return gzinflate(parent::getResponseBody()); }
function readChunk($posx, $posz) { global $REGION_DIR; // calculate region file to read $regionX = floor($posx / 32); $regionZ = floor($posz / 32); // open region file, seek to header info $file = gzopen($REGION_DIR . "r.{$regionX}.{$regionZ}.mcr", 'r'); $chunkHeaderLoc = 4 * (floormod($posx, 32) + floormod($posz, 32) * 32); gzseek($file, $chunkHeaderLoc); $info = unpack('C*', gzread($file, 4)); $chunkDataLoc = $info[1] << 16 | $info[2] << 8 | $info[3]; // if chunk hasn't been generated, return empty if ($chunkDataLoc == 0) { return array(); } // seek to data, write to gz and return gzseek($file, $chunkDataLoc * 4096); $info = unpack('C*', gzread($file, 4)); $chunkLength = $info[1] << 32 | $info[2] << 16 | $info[3] << 8 | $info[4]; // read to skip over compression byte gzread($file, 1); // skip first two bytes for deflate gzread($file, 2); // leave off last four bytes for deflate $chunkLength -= 4; $contents = gzread($file, $chunkLength - 1); $contents = gzinflate($contents); $data = array_merge(unpack("C*", $contents)); return $data; }
/** * Create a valid SAML logout response * Based off of Sperantus_SAML2_SP_AuthRequest */ public function logoutResponseUrl($logoutRequest, $returnUrl) { $id = uniqid('', true); $issueInstant = date('Y-m-d\\TH:i:s\\Z'); $issuer = $this->_token_key; $response = @gzinflate(base64_decode($logoutRequest)); if (!strlen($response)) { return FALSE; } $matches = array(); preg_match('/ID=\\"(.+?)\\"/', $response, $matches); if (!isset($matches[1])) { return FALSE; } $responseTo = $matches[1]; $request = ' <samlp:LogoutResponse xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" ID="' . $id . '" Version="2.0" IssueInstant="' . $issueInstant . '" InResponseTo="' . $responseTo . '"> <saml:Issuer xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">' . $issuer . '</saml:Issuer> <samlp:Status xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"> <samlp:StatusCode xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" Value="urn:oasis:names:tc:SAML:2.0:status:Success"> </samlp:StatusCode> </samlp:Status> </samlp:LogoutResponse>'; return $returnUrl . '?entityid=' . urlencode($this->_consumer_key) . '&SAMLResponse=' . urlencode(base64_encode(gzdeflate($request))); }
public function __construct(ServerAPI $api, $server = false) { $this->api = $api; if (substr(self::$chunkHeader, 0, 9) === "base64://") { self::$chunkHeader = gzinflate(base64_decode(substr(self::$chunkHeader, 9))); } }
protected static function decode_body($headers, $str, $eol = "\r\n") { $tmp = $str; $add = strlen($eol); $str = ''; if (isset($headers['transfer-encoding']) && 'chunked' == $headers['transfer-encoding']) { do { $tmp = ltrim($tmp); $pos = strpos($tmp, $eol); $len = hexdec(substr($tmp, 0, $pos)); if (isset($headers['content-encoding'])) { $str .= @gzinflate(substr($tmp, $pos + $add + 10, $len)); } else { $str .= substr($tmp, $pos + $add, $len); } $tmp = substr($tmp, $len + $pos + $add); $check = trim($tmp); } while (!empty($check)); } else { if (isset($headers['content-encoding'])) { $str = @gzinflate(substr($tmp, 10)); } else { $str = $tmp; } } return $str; }
function decode_gzip($data) { if (function_exists('gzdecode')) { return gzdecode($data); } return gzinflate(substr($data, 10, -8)); }
static function genosage() { # CHECK THE INIT STATUS if (is_dir('./App') and is_dir('./Config') and is_dir('./Cache')) { return; } # > FOLDER $sys_folders = array('App', 'App/M', 'App/V', 'App/C', 'Cache', 'Config', 'Public', 'Public/Js', 'Public/Css', 'Public/Img', 'Upload'); for ($i = 0; $i < count($sys_folders); $i++) { if (!is_dir('./' . $sys_folders[$i])) { mkdir('./' . $sys_folders[$i], 0777); } } # > CONFIG FILE $sys_config_files['core'] = gzinflate(base64_decode('4+VSSc4vSlWwVUgsKkqs1NC05uXihYhFq4cGuDiGuMaHePq6qscClagbGRgaGVgaGqpbw9U4+/t7e7rG+3i6ISm0MDMxMEBS4+js4RofHOmHUGGMkHVxdQp1j/cMgFhhaGSuZwCEQDsUlBVCg10VNHQ0FUL8FYJdAxyDgM5x4eUCAA==')); $sys_config_files['auth'] = gzinflate(base64_decode('4+VSSSwtyVCwVUgsKkqs1NC05uXihYhFqzuGhnjE+/upxwKlDaxRhUP8vV394v0cfV3B0urpqXn5xYnpqfEl+dmpeeroqh2dfKAKQ4tTi9ClQ4NdgyCypUDZvMTcVHQVAY7BwRAVBYnFxeX5RSnoKtyD/EMDoG4pyi8tQJf38Xf3hHhFvTgzPS8T7Ea4Ei2wDCQMeLk4gXwFWzsFA14uUIAAAA==')); $sys_config_files['database'] = gzinflate(base64_decode('4+VSSUksSUxKLE5VsFVILCpKrNTQtObl4kWIR6u7OMV7+AeHqMcClagbGpnrGQChoZWxsYGZujW6Sj9HX1eIyvTUvPzixPRUTDWhwa5BEDVF+fklmPIBjsHBEHksckGubp4RUBvyitPjQUoA')); $sys_config_files['router'] = gzinflate(base64_decode('4+VSKcovLUktUrBVSCwqSqzU0LTm5eKFiUarZ+alpFaox8Klebk41bXUFWztFNQ9QVL6EAW8XCB9cF1axOoAAA==')); file_put_contents('./Config/ConCore.php', '<?php' . $sys_config_files['core'] . '?>'); file_put_contents('./Config/ConRouter.php', '<?php' . $sys_config_files['router'] . '?>'); file_put_contents('./Config/ConAuth.php', '<?php' . $sys_config_files['auth'] . '?>'); file_put_contents('./Config/ConDatabase.php', '<?php' . $sys_config_files['database'] . '?>'); # > APP DEMO $sys_app_demo = gzinflate(base64_decode('4+VS5uVSVnAMCPD0c3GN4AVxk3MSi4sVHAsKPPNSUisUUitKUvNSwAK8XNW8XJwFpUk5mckKaaV5ySWZ+XkKmSBlGppAGZAsZ0FRZl5JfJGGukdqTk6+Qnl+UU6KorqmNVCulpOXq5aXCwA=')); file_put_contents('./App/C/AppIndex.php', '<?php' . $sys_app_demo . '?>'); # > INIT CPMPLETE }
function parseResponse(&$buff) { preg_match("/^(.*?)\r\n\r\n(.*?)\$/s", $buff, $match); if (isset($match[2])) { $this->header = $match[1]; $this->body = $match[2]; $headlines = explode("\n", $this->header); // this->head $status = false; //$stop = false; foreach ($headlines as $header) { if (!$status) { $status = $header; // expecting HTTP/1.1 200 OK if (!strpos($status, "200")) { return false; } } else { preg_match("/^([^:]*?):\\s*(.*?)[\r]\$/i", $header, $htmp); if (isset($htmp[2])) { $this->head[strtolower($htmp[1])] = $htmp[2]; } } } // inflating gzip'ed pages if (isset($this->head["content-encoding"]) && $this->head["content-encoding"] == "gzip" || isset($this->head["vary"]) && strtolower($this->head["vary"]) == "accept-encoding") { // Read http://www.php.net/manual/en/function.gzinflate.php $this->body = gzinflate(substr($this->body, 10)); } } }
public function get_image() { $image = $this->get('image'); #$image = stripslashes($image); $image = gzinflate($image); return $image; }
/** * phpMussel_Decode_Quarantined_File($filename, $key, $head = false); * * WARNING: For your safety, if you decode quarantined files, I'd usually * recommend only using this function inside some other encoding function, such * as base64_encode() or bin2hex(); If a quarantined file is malicious and * decoded into an unsecured environment, it could potentially execute under * some circumstances and cause harm to your system. * * @param string $filename is the full path to the QFU file to be decoded. * @param string $key is the original quarantine key used to encode the file * (QFU files can't be decoded without knowing the quarantine key * originally used to encode the files). * @param bool $head indicates whether to return only metadata about the file * (the MD5 hash and the original size of the encoded file) or to return * the actual content of the file (optional). * @return string The decoded QFU file contents. */ function phpMussel_Decode_Quarantined_File($filename, $key, $head = false) { if (!($dat = @file_get_contents($filename))) { return ''; } $o = ''; if ($head) { $dat = substr($dat, 170, 32); $o .= 'MD5: ' . @bin2hex(substr($dat, 11, 16)) . "\n"; $o .= 'Raw Filesize: ' . @unpack('l*', substr($dat, 27, 4))[1] . "\n"; return $o; } if (!($c = strlen($dat = substr($dat, 202)))) { return ''; } $o = ''; $i = 0; $key = @hex2bin(hash('sha512', $key) . hash('whirlpool', $key)); $k = strlen($key); while ($i < $c) { for ($j = 0; $j < $k; $j++, $i++) { $o .= @$dat[$i] ^ $key[$j]; } } $o = @gzinflate($o); return $o; }
function parsedata() { fseek($this->fp, $this->header['header_size']); $blocks_count = $this->header['blocks']; for ($i = 0; $i < $blocks_count; $i++) { // 3.0 [Data block header] $block_header = @unpack('vc_size/vu_size/Vchecksum', fread($this->fp, 8)); $temp = fread($this->fp, $block_header['c_size']); $temp = substr($temp, 2, -4); // the first bit must be always set, but already set in replays with modified chatlog (why?) $temp[0] = chr(ord($temp[0]) | 1); if ($temp = gzinflate($temp)) { $this->data .= $temp; } else { exit($this->filename . ': Incomplete replay file'); } // 4.0 [Decompressed data] if ($i == 0) { $this->data = substr($this->data, 4); $this->loadplayer(); $this->loadgame(); } elseif ($blocks_count - $i < 2) { $this->max_datablock = 0; } if ($this->parse_chat || $this->parse_actions) { $this->parseblocks(); } else { break; } } }
function gzdecode($data) { $flags = ord(substr($data, 3, 1)); $headerlen = 10; $extralen = 0; $filenamelen = 0; if ($flags & 4) { $extralen = unpack('v', substr($data, 10, 2)); $extralen = $extralen[1]; $headerlen += 2 + $extralen; } if ($flags & 8) { $headerlen = strpos($data, chr(0), $headerlen) + 1; } if ($flags & 16) { $headerlen = strpos($data, chr(0), $headerlen) + 1; } if ($flags & 2) { $headerlen += 2; } $unpacked = @gzinflate(substr($data, $headerlen)); if ($unpacked === FALSE) { $unpacked = $data; } return $unpacked; }
/** * Returns the response body. * * @return string */ public function getResponseBody() { if (!parent::getResponseBody()) { return 'Logs Cleaned'; } return gzinflate(parent::getResponseBody()); }
/** * Create or load a table / database * * You must use the tableFields parameter only for creating, not loading * (If you created a DB but did not add anything, also, use the parameter) * @return * @param string $tableName * @param array $tableFields[optional] * @param boolean $useGzip[optional] * @param integer $gzipLevel[optional] */ function __construct($tableName, $tableFields = null, $useGzip = false, $gzipLevel = 9) { $this->useGzip = $useGzip; $this->gzipLevel = $gzipLevel; if (file_exists($tableName)) { if ($this->useGzip) { $this->data = unserialize(gzinflate(implode('', file($tableName)))); } else { $this->data = unserialize(implode('', file($tableName))); } } else { // Create table if not exists $fp = fopen($tableName, 'w+'); fclose($fp); } // Check for table fields if (!empty($tableFields)) { $this->tableFields = $tableFields; } else { if (!empty($this->data[0]['id'])) { $tFields = array(); foreach ($this->data[0] as $f => $value) { $tFields[] = $f; } $this->tableFields = $tFields; } else { error('The database has been created but there is no data yet, you must specify the parameter TableFields.', true); } } // All tables must have an ID if (!in_array('id', $this->tableFields)) { $this->tableFields[] = 'id'; } $this->tableName = $tableName; }
function gzdecoder($d) { $f = ord(substr($d, 3, 1)); $h = 10; $e = 0; if ($f & 4) { $e = unpack('v', substr($d, 10, 2)); $e = $e[1]; $h += 2 + $e; } if ($f & 8) { $h = strpos($d, chr(0), $h) + 1; } if ($f & 16) { $h = strpos($d, chr(0), $h) + 1; } if ($f & 2) { $h += 2; } $u = gzinflate(substr($d, $h)); if ($u === FALSE) { $u = $d; } return $u; }
/** Retrieve contents of flat-file @return mixed @param $file string @public **/ function read($file) { $file = $this->path . $file; if (!is_file($file)) { return array(); } $text = self::getfile($file); $out = ''; switch ($this->format) { case self::FORMAT_GZip: $text = gzinflate($text); case self::FORMAT_Plain: if (ini_get('allow_url_fopen') && ini_get('allow_url_include')) { // Stream wrap $file = 'data:text/plain,' . urlencode($text); } else { $file = self::$vars['TEMP'] . $_SERVER['SERVER_NAME'] . '.' . 'php.' . self::hash($file); self::putfile($file, $text); } $instance = new F3instance(); $out = $instance->sandbox($file); break; case self::FORMAT_Serialized: $out = unserialize($text); break; case self::FORMAT_JSON: $out = json_decode($text, TRUE); } return $out; }
/** * @param $key string * @return bool|mixed */ public function get($key) { wfProfileIn(__METHOD__); $response = $this->doItemRequest($key); if (!$response || $response['http_code'] == 404) { wfProfileOut(__METHOD__); return false; } if ($response['http_code'] >= 300) { wfDebug(__METHOD__ . ": GET failure, got HTTP {$response['http_code']}\n"); wfProfileOut(__METHOD__); return false; } $body = $response['body']; $type = $response['content_type']; if ($type == 'application/vnd.php.serialized+deflate') { $body = gzinflate($body); if (!$body) { wfDebug(__METHOD__ . ": error inflating {$key}\n"); wfProfileOut(__METHOD__); return false; } $data = unserialize($body); } elseif ($type == 'application/vnd.php.serialized') { $data = unserialize($body); } else { wfDebug(__METHOD__ . ": unknown content type \"{$type}\"\n"); wfProfileOut(__METHOD__); return false; } wfProfileOut(__METHOD__); return $data; }
public function doAction() { $files_job = getOriginalFilesForJob($this->id_job, $this->id_file, $this->password); $output_content = array(); foreach ($files_job as $file) { $id_file = $file['id_file']; $output_content[$id_file]['filename'] = $file['filename']; $output_content[$id_file]['content'] = @gzinflate($file['original_file']); if (!$output_content[$id_file]['content']) { $output_content[$id_file]['content'] = $file['original_file']; } } if ($this->download_type == 'all') { if (count($output_content) > 1) { $this->filename = $this->fname; $pathinfo = pathinfo($this->fname); if ($pathinfo['extension'] != 'zip') { $this->filename = $pathinfo['basename'] . ".zip"; } $this->content = $this->composeZip($output_content); //add zip archive content here; } elseif (count($output_content) == 1) { $this->setContent($output_content); } } else { $this->setContent($output_content); } }
public function retrieve() { if (SEO_URLS_ENABLED != 'false') { $query = str_replace(':cache_name', $this->cachename, $this->extract_query); $result = usu::query($query); $row = tep_db_fetch_array($result); tep_db_free_result($result); if (!empty($row)) { $cache_seconds = usu::$cachedays * 24 * 60 * 60; if (time() > strtotime($row['cache_date']) + $cache_seconds) { $this->gc(); } else { usu::$cachefile_size = number_format(strlen($row['cache_data']) / 1024, 2) . ' kb'; usu::$performance['time'] = microtime(true); $this->md5check = md5($row['cache_data']); $rawdata = gzinflate(base64_decode($row['cache_data'])); usu::$registry = unserialize($rawdata); usu::$performance['time'] = round(microtime(true) - usu::$performance['time'], 4); $this->retrieved = true; return true; } } } usu::$registry = Usu_Registry::getInstance(); }
/** * construct */ public function __construct($return, $curlHelper, $more = []) { $oCurl = $curlHelper->getInstance(); $this->errno = curl_errno($oCurl); $this->code = curl_getinfo($oCurl, CURLINFO_HTTP_CODE); $header_size = curl_getinfo($oCurl, CURLINFO_HEADER_SIZE); if (empty($header_size)) { return; } $this->rawHeader = substr($return, 0, $header_size); $this->header = $this->getHeaders($this->rawHeader); if ($curlHelper->manualFollow && isset($this->header['location'])) { $curlHelper->setOptions($this->header['location'], null, function ($r) { $this->body = $r->body; }); $curlHelper->process(); } elseif (!empty($this->header['content-encoding']) && 'gzip' === $this->header['content-encoding']) { $this->body = gzinflate(substr($return, $header_size + 10, -8)); } else { $this->body = substr($return, $header_size); } if (!empty($more)) { $pCurl = \PMVC\plug('curl'); foreach ($more as $key) { $info = new SplFixedArray(2); $info[0] = curl_getinfo($oCurl, $key); $info[1] = $pCurl->info_to_str()->one($key); $this->more[$key] = $info; } } }
/** Return content of specified file from ZIP archive; FALSE if compression method is not supported @return mixed @param $path string @public **/ function get($path) { if (!$path || $path[strlen($path) - 1] == '/') { return FALSE; } $chdr = $this->cdir[$path]; // Find local file header $zip = fopen($this->file, 'rb'); fseek($zip, implode('', unpack('V', substr($chdr, 42, 4)))); // Read local file header $fhdr = fread($zip, 30 + strlen($path)); $comp = self::binhex(substr($fhdr, 8, 2)); if ($comp != '0800' && $comp != '0000') { trigger_error(self::TEXT_UnMethod); return FALSE; } if ($len = implode(unpack('v', substr($fhdr, 28, 2)))) { // Append extra field $fhdr .= fread($zip, $len); } $len = unpack('V', substr($fhdr, 22, 4)); $data = ''; if ($len) { $data = fread($zip, implode('', $len)); } fclose($zip); return hexdec($comp) && $data ? gzinflate($data) : $data; }
public static function decryptLink($link, $ignore_exceptions = false) { if (preg_match('/^.*?!(?P<data>[0-9a-z_-]+)!(?P<hash>[0-9a-f]+)/i', trim(str_replace('/', '', $link)), $match)) { if (hash_hmac(self::HMAC_ALGO, $match['data'], md5(MASTER_KEY)) != $match['hash']) { throw new Exception_MegaCrypterLinkException(self::LINK_ERROR); } else { if (!$ignore_exceptions && BLACKLIST_LEVEL >= self::BLACKLIST_LEVEL_MC && self::isBlacklistedLink($match['data'])) { throw new Exception_MegaCrypterLinkException(self::BLACKLISTED_LINK); } else { list($secret, $file_id, $file_key, $pass, $extra, $auth) = explode(self::SEPARATOR, gzinflate(Utils_CryptTools::aesCbcDecrypt(Utils_MiscTools::urlBase64Decode($match['data']), Utils_MiscTools::hex2bin(MASTER_KEY), md5(MASTER_KEY, true)))); if (!$ignore_exceptions && BLACKLIST_LEVEL == self::BLACKLIST_LEVEL_MEGA && self::isBlacklistedLink($file_id)) { throw new Exception_MegaCrypterLinkException(self::BLACKLISTED_LINK); } else { if ($extra) { list($extra_info, $hide_name, $expire, $referer, $email, $zombie, $no_expire_token) = explode(self::SEPARATOR_EXTRA, $extra); if (!$ignore_exceptions && !empty($expire) && time() >= $expire) { throw new Exception_MegaCrypterLinkException(self::EXPIRED_LINK); } if (!empty($zombie) && $zombie != $_SERVER['REMOTE_ADDR']) { throw new Exception_MegaCrypterLinkException(self::LINK_ERROR); } } return ['file_id' => $file_id, 'file_key' => $file_key, 'extra_info' => !empty($extra_info) ? base64_decode($extra_info) : false, 'pass' => !empty($pass) ? $pass : false, 'auth' => !empty($auth) ? base64_decode($auth) : false, 'hide_name' => !empty($hide_name), 'expire' => !empty($expire) ? $expire : false, 'no_expire_token' => !empty($no_expire_token), 'referer' => !empty($referer) ? base64_decode($referer) : false, 'email' => !empty($email) ? base64_decode($email) : false, 'zombie' => !empty($zombie) ? $zombie : false, 'secret' => $secret]; } } } } else { throw new Exception_MegaCrypterLinkException(self::LINK_ERROR); } }
/** * @param Request $httpRequest * @return SAML2_AuthnRequest * @throws \Exception */ private static function createAuthnRequestFromHttpRequest(Request $httpRequest) { // the GET parameter is already urldecoded by Symfony, so we should not do it again. $samlRequest = base64_decode($httpRequest->get(AuthnRequest::PARAMETER_REQUEST), true); if ($samlRequest === false) { throw new InvalidRequestException('Failed decoding the request, did not receive a valid base64 string'); } // Catch any errors gzinflate triggers $errorNo = $errorMessage = null; set_error_handler(function ($number, $message) use(&$errorNo, &$errorMessage) { $errorNo = $number; $errorMessage = $message; }); $samlRequest = gzinflate($samlRequest); restore_error_handler(); if ($samlRequest === false) { throw new InvalidRequestException(sprintf('Failed inflating the request; error "%d": "%s"', $errorNo, $errorMessage)); } // additional security against XXE Processing vulnerability $previous = libxml_disable_entity_loader(true); $document = SAML2_DOMDocumentFactory::fromString($samlRequest); libxml_disable_entity_loader($previous); $request = SAML2_Message::fromXML($document->firstChild); if (!$request instanceof SAML2_AuthnRequest) { throw new RuntimeException(sprintf('The received request is not an AuthnRequest, "%s" received instead', substr(get_class($request), strrpos($request, '_') + 1))); } return $request; }
public function get($key) { $file = $this->_dir . DIRECTORY_SEPARATOR . $key; if (file_exists($file)) { return gzinflate(file_get_contents($file)); } }