private static function _checkCreateKeyFile($date) { vmSetStartTime('check'); static $existingKeys = false; $keyPath = self::_getEncryptSafepath(); if (!$existingKeys) { $dir = opendir($keyPath); if (is_resource($dir)) { $existingKeys = array(); while (false !== ($file = readdir($dir))) { if ($file != '.' && $file != '..') { if (!is_dir($keyPath . DS . $file)) { $ext = Jfile::getExt($file); if ($ext == 'ini' and file_exists($keyPath . DS . $file)) { $content = parse_ini_file($keyPath . DS . $file); if ($content and is_array($content) and isset($content['unixtime'])) { $key = $content['unixtime']; unset($content['unixtime']); $existingKeys[$key] = $content; //vmdebug('Reading '.$keyPath .DS. $file,$content); } } else { vmdebug('Resource says there is file, but does not exists? ' . $keyPath . DS . $file); } } else { //vmdebug('Directory in they keyfolder? '.$keyPath .DS. $file); } } else { //vmdebug('Directory in the keyfolder '.$keyPath .DS. $file); } } } else { static $warn = false; if (!$warn) { vmWarn('Key folder in safepath unaccessible ' . $keyPath); } $warn = true; } } if ($existingKeys and is_array($existingKeys) and count($existingKeys) > 0) { ksort($existingKeys); if (!empty($date)) { $key = ''; foreach ($existingKeys as $unixDate => $values) { if ($unixDate - 30 >= $date) { vmdebug('$unixDate ' . $unixDate . ' >= $date ' . $date); continue; } vmdebug('$unixDate < $date'); //$usedKey = $values; $key = $values['key']; } vmdebug('Use key file ', $key); //include($keyPath .DS. $usedKey.'.php'); } else { $usedKey = end($existingKeys); $key = $usedKey['key']; } vmTime('my time', 'check'); return $key; } else { $usedKey = date("ymd"); $filename = $keyPath . DS . $usedKey . '.ini'; if (!JFile::exists($filename)) { if (JVM_VERSION < 3) { $token = JUtility::getHash(JUserHelper::genRandomPassword()); } else { $token = JApplication::getHash(JUserHelper::genRandomPassword()); } $salt = JUserHelper::getSalt('crypt-md5'); $hashedToken = md5($token . $salt); $key = base64_encode($hashedToken); //$options = array('costs'=>VmConfig::get('cryptCost',8)); /*if(!function_exists('password_hash')){ require(JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'password_compat.php'); } if(function_exists('password_hash')){ $key = password_hash($key, PASSWORD_BCRYPT, $options); }*/ $date = JFactory::getDate(); $today = $date->toUnix(); //$key = pack('H*',$key); $content = ';<?php die(); */ [keys] key = "' . $key . '" unixtime = "' . $today . '" date = "' . date("Y-m-d H:i:s") . '" ; */ ?>'; $result = JFile::write($filename, $content); vmTime('my time', 'check'); return $key; } } vmTime('my time', 'check'); //return pack('H*',$key); }
private static function _checkCreateKeyFile($date) { jimport('joomla.filesystem.file'); vmSetStartTime('check'); static $existingKeys = false; $keyPath = self::_getEncryptSafepath(); if (!$existingKeys) { $dir = opendir($keyPath); if (is_resource($dir)) { $existingKeys = array(); while (false !== ($file = readdir($dir))) { if ($file != '.' && $file != '..') { if (!is_dir($keyPath . DS . $file)) { $ext = Jfile::getExt($file); if ($ext == 'ini' and file_exists($keyPath . DS . $file)) { $content = parse_ini_file($keyPath . DS . $file); if ($content and is_array($content) and isset($content['unixtime'])) { $key = $content['unixtime']; unset($content['unixtime']); $existingKeys[$key] = $content; //vmdebug('Reading '.$keyPath .DS. $file,$content); } } else { //vmdebug('Resource says there is file, but does not exists? '.$keyPath .DS. $file); } } else { //vmdebug('Directory in they keyfolder? '.$keyPath .DS. $file); } } else { //vmdebug('Directory in the keyfolder '.$keyPath .DS. $file); } } } else { static $warn = false; if (!$warn) { vmWarn('Key folder in safepath unaccessible ' . $keyPath); } $warn = true; } } if ($existingKeys and is_array($existingKeys) and count($existingKeys) > 0) { ksort($existingKeys); if (!empty($date)) { $key = ''; foreach ($existingKeys as $unixDate => $values) { if ($unixDate - 30 >= $date) { vmdebug('$unixDate ' . $unixDate . ' >= $date ' . $date); continue; } vmdebug('$unixDate < $date ' . $date); $key = $values['key']; $usedKey = $values; } if (!isset($usedKey['b64']) or $usedKey['b64']) { vmdebug('Doing base64_decode ', $usedKey); $key = base64_decode($key); } } else { $usedKey = end($existingKeys); $key = $usedKey['key']; //No key means, we wanna encrypt something, when it has not the new attribute, //it is an old key and must be replaced $ksize = tsmConfig::get('keysize', 24); if (empty($key) or !isset($usedKey['b64']) or !isset($usedKey['size']) or $usedKey['size'] != $ksize) { $key = self::_createKeyFile($keyPath, $ksize); $existingKeys[$key['unixtime']] = $key; return $key['key']; } } //vmdebug('Length of key',strlen($key)); //vmTime('my time','check'); return $key; } else { $key = self::_createKeyFile($keyPath, tsmConfig::get('keysize', 24)); $existingKeys[$key['unixtime']] = $key; return $key['key']; } }