diff --git a/laravel/cli/dependencies.php b/laravel/cli/dependencies.php index ce57c823..a4e112ec 100644 --- a/laravel/cli/dependencies.php +++ b/laravel/cli/dependencies.php @@ -25,6 +25,16 @@ IoC::register('task: bundle', function() return new Tasks\Bundle\Bundler; }); +/** + * The key task is responsible for generating a secure, random + * key for use by the application when encrypting strings or + * setting the hash values on cookie signatures. + */ +IoC::singleton('task: key', function() +{ + return new Tasks\Key; +}); + /** * The bundle repository is responsible for communicating with * the Laravel bundle sources to get information regarding any diff --git a/laravel/cli/tasks/key.php b/laravel/cli/tasks/key.php new file mode 100644 index 00000000..cc325b6b --- /dev/null +++ b/laravel/cli/tasks/key.php @@ -0,0 +1,53 @@ +path = APP_PATH.'config/application'.EXT; + } + + /** + * Generate a random key for the application. + * + * @param array $arguments + * @return void + */ + public function generate($arguments = array()) + { + // By default the Crypter class uses AES-256 encryption which uses + // a 32 byte input vector, so that is the length of string we will + // generate for the application token unless another length is + // specified through the CLI. + $key = Str::random(array_get($arguments, 0, 32)); + + $config = str_replace("'key' => '',", "'key' => '{$key}',", File::get($this->path), $count); + + File::put($this->path, $config); + + if ($count > 0) + { + echo "Configuration updated with secure key!"; + } + else + { + echo "An application key already exists!"; + } + } + +} \ No newline at end of file diff --git a/laravel/core.php b/laravel/core.php index 6c799e7e..84e58f51 100644 --- a/laravel/core.php +++ b/laravel/core.php @@ -91,6 +91,7 @@ Autoloader::$mappings = array( 'Laravel\\CLI\\Tasks\\Migrate\\Migrator' => SYS_PATH.'cli/tasks/migrate/migrator'.EXT, 'Laravel\\CLI\\Tasks\\Migrate\\Resolver' => SYS_PATH.'cli/tasks/migrate/resolver'.EXT, 'Laravel\\CLI\\Tasks\\Migrate\\Database' => SYS_PATH.'cli/tasks/migrate/database'.EXT, + 'Laravel\\CLI\\Tasks\\Key' => SYS_PATH.'cli/tasks/key'.EXT, 'Laravel\\Database\\Connection' => SYS_PATH.'database/connection'.EXT, 'Laravel\\Database\\Expression' => SYS_PATH.'database/expression'.EXT,