mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-20 11:49:56 +09:00
Merge branch 'develop' into pr/session-class
This commit is contained in:
commit
6de0bc45db
51 changed files with 358 additions and 96 deletions
|
|
@ -160,7 +160,7 @@ class ConfigParser
|
|||
|
||||
// Create new crypto keys.
|
||||
$config['crypto']['encryption_key'] = Security::getRandom(64, 'alnum');
|
||||
$config['crypto']['authentication_key'] = Security::getRandom(64, 'alnum');
|
||||
$config['crypto']['authentication_key'] = $db_info->secret_key ?: Security::getRandom(64, 'alnum');
|
||||
$config['crypto']['session_key'] = Security::getRandom(64, 'alnum');
|
||||
|
||||
// Convert language configuration.
|
||||
|
|
|
|||
|
|
@ -112,6 +112,40 @@ class Security
|
|||
return \CryptoCompat::decrypt($ciphertext, $key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a digital signature to verify the authenticity of a string.
|
||||
*
|
||||
* @param string $string
|
||||
* @return string
|
||||
*/
|
||||
public static function createSignature($string)
|
||||
{
|
||||
$key = config('crypto.authentication_key');
|
||||
$salt = self::getRandom(8, 'alnum');
|
||||
$hash = substr(base64_encode(hash_hmac('sha256', hash_hmac('sha256', $string, $salt), $key, true)), 0, 32);
|
||||
return $salt . strtr($hash, '+/', '-_');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a signature is valid.
|
||||
*
|
||||
* @param string $string
|
||||
* @param string $signature
|
||||
* @return bool
|
||||
*/
|
||||
public static function verifySignature($string, $signature)
|
||||
{
|
||||
if(strlen($signature) !== 40)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$key = config('crypto.authentication_key');
|
||||
$salt = substr($signature, 0, 8);
|
||||
$hash = substr(base64_encode(hash_hmac('sha256', hash_hmac('sha256', $string, $salt), $key, true)), 0, 32);
|
||||
return self::compareStrings(substr($signature, 8), strtr($hash, '+/', '-_'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a cryptographically secure random string.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -256,17 +256,17 @@ class Storage
|
|||
flock($fp, \LOCK_EX);
|
||||
if (is_resource($content))
|
||||
{
|
||||
$result = stream_copy_to_stream($content, $fp) ? true : false;
|
||||
$result = stream_copy_to_stream($content, $fp);
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = fwrite($fp, $content) ? true : false;
|
||||
$result = fwrite($fp, $content);
|
||||
}
|
||||
fflush($fp);
|
||||
flock($fp, \LOCK_UN);
|
||||
fclose($fp);
|
||||
|
||||
if (!$result)
|
||||
if ($result === false)
|
||||
{
|
||||
trigger_error('Cannot write file: ' . (isset($original_filename) ? $original_filename : $filename), \E_USER_WARNING);
|
||||
return false;
|
||||
|
|
@ -303,7 +303,7 @@ class Storage
|
|||
}
|
||||
|
||||
clearstatcache(true, $filename);
|
||||
return $result;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue