diff --git a/application/config/aliases.php b/application/config/aliases.php index a35a9c38..b3dcb23f 100644 --- a/application/config/aliases.php +++ b/application/config/aliases.php @@ -24,7 +24,7 @@ 'Cache' => 'System\\Cache', 'Config' => 'System\\Config', 'Cookie' => 'System\\Cookie', - 'Crypt' => 'System\\Crypt', + 'Crypter' => 'System\\Crypter', 'DB' => 'System\\DB', 'Eloquent' => 'System\\DB\\Eloquent\\Model', 'File' => 'System\\File', diff --git a/changelog.md b/changelog.md index 3fbd036e..22cc6408 100644 --- a/changelog.md +++ b/changelog.md @@ -3,4 +3,5 @@ # Laravel Change Log ## Version 1.6.0 - Moved **system/db/manager.php** to **system/db.php**. Updated alias appropriately. -- Unspecified optional parameters will be removed from URLs generated using route names. \ No newline at end of file +- Unspecified optional parameters will be removed from URLs generated using route names. +- Fixed bug in Config::set that prevented it from digging deep into arrays. \ No newline at end of file diff --git a/system/crypt.php b/system/crypter.php similarity index 53% rename from system/crypt.php rename to system/crypter.php index 9a62c6d2..37dd97c3 100644 --- a/system/crypt.php +++ b/system/crypter.php @@ -1,20 +1,45 @@ cipher = $cipher; + $this->mode = $mode; + } + + /** + * Create a new Crypter instance. + * + * @param string $cipher + * @param string $mode + * @return Crypt + */ + public static function make($cipher = 'rijndael-256', $mode = 'cbc') + { + return new static($cipher, $mode); + } /** * Encrypt a value using the MCrypt library. @@ -22,11 +47,11 @@ class Crypt { * @param string $value * @return string */ - public static function encrypt($value) + public function encrypt($value) { - $iv = mcrypt_create_iv(static::iv_size(), static::randomizer()); + $iv = mcrypt_create_iv($this->iv_size(), $this->randomizer()); - return base64_encode($iv.mcrypt_encrypt(static::$cipher, static::key(), $value, static::$mode, $iv)); + return base64_encode($iv.mcrypt_encrypt($this->cipher, $this->key(), $value, $this->mode, $iv)); } /** @@ -34,7 +59,7 @@ public static function encrypt($value) * * @return int */ - protected static function randomizer() + protected function randomizer() { if (defined('MCRYPT_DEV_URANDOM')) { @@ -54,16 +79,16 @@ protected static function randomizer() * @param string $value * @return string */ - public static function decrypt($value) + public function decrypt($value) { if ( ! is_string($value = base64_decode($value, true))) { throw new \Exception('Decryption error. Input value is not valid base64 data.'); } - list($iv, $value) = array(substr($value, 0, static::iv_size()), substr($value, static::iv_size())); + list($iv, $value) = array(substr($value, 0, $this->iv_size()), substr($value, $this->iv_size())); - return rtrim(mcrypt_decrypt(static::$cipher, static::key(), $value, static::$mode, $iv), "\0"); + return rtrim(mcrypt_decrypt($this->cipher, $this->key(), $value, $this->mode, $iv), "\0"); } /** @@ -71,7 +96,7 @@ public static function decrypt($value) * * @return string */ - private static function key() + private function key() { if ( ! is_null($key = Config::get('application.key')) and $key !== '') return $key; @@ -85,9 +110,9 @@ private static function key() * * @return int */ - private static function iv_size() + private function iv_size() { - return mcrypt_get_iv_size(static::$cipher, static::$mode); + return mcrypt_get_iv_size($this->cipher, $this->mode); } } \ No newline at end of file diff --git a/system/session/cookie.php b/system/session/cookie.php index cf58827a..9698b4bb 100644 --- a/system/session/cookie.php +++ b/system/session/cookie.php @@ -1,12 +1,26 @@ crypter = new Crypter; + if (Config::get('application.key') == '') { throw new \Exception("You must set an application key before using the Cookie session driver."); @@ -23,7 +37,7 @@ public function load($id) { if (\System\Cookie::has('session_payload')) { - return unserialize(Crypt::decrypt(\System\Cookie::get('session_payload'))); + return unserialize($this->crypter->decrypt(\System\Cookie::get('session_payload'))); } } @@ -39,7 +53,9 @@ public function save($session) { extract(Config::get('session')); - \System\Cookie::put('session_payload', Crypt::encrypt(serialize($session)), $lifetime, $path, $domain, $https, $http_only); + $payload = $this->crypter->encrypt(serialize($session)); + + \System\Cookie::put('session_payload', $payload, $lifetime, $path, $domain, $https, $http_only); } }