#108: Switching to Laravel's new encryption

This commit is contained in:
Josef Citrine 2016-12-10 19:58:48 +00:00
parent 40e1b050ae
commit 19d6dd7890
5 changed files with 631 additions and 488 deletions

View file

@ -1,58 +0,0 @@
<?php
namespace Poniverse\Ponyfm\Console\Commands;
use DB;
use Illuminate\Console\Command;
use Laravel\LegacyEncrypter\McryptEncrypter;
class MigrateEncryption extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'migrate-encryption';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Migrates from mcrypt to openssl. Needs key and mcryptKey set in config/app.php';
/**
* Create a new command instance.
*
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$key = $this->laravel['config']['app.mcryptKey'];
$cipher = $this->laravel['config']['app.mcryptCipher'];
$legacy = new McryptEncrypter($key, $cipher);
$caches = DB::select('SELECT * FROM cache');
foreach ($caches as $cache) {
$newValue = encrypt(
$legacy->decrypt($cache->value)
);
DB::update('UPDATE cache SET value = ? WHERE key = ?', [$cache->key, $newValue]);
$this->info("Updated {$cache->key}");
}
}
}

View file

@ -23,7 +23,6 @@ namespace Poniverse\Ponyfm\Providers;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Foundation\Application;
use Illuminate\Support\ServiceProvider;
use Laravel\LegacyEncrypter\McryptEncrypter;
use PfmValidator;
use Poniverse;
use Validator;
@ -49,15 +48,6 @@ class AppServiceProvider extends ServiceProvider
*/
public function register()
{
// TODO: Migrate from Mcrypt
$this->app->singleton('encrypter', function ($app) {
$config = $app->make('config')->get('app');
$key = $config['key'];
return new McryptEncrypter($key, $config['cipher']);
});
$this->app->bind(Poniverse::class, function (Application $app) {
return new Poniverse($app['config']->get('poniverse.client_id'), $app['config']->get('poniverse.secret'));
});

View file

@ -24,8 +24,7 @@
"predis/predis": "^1.0",
"ksubileau/color-thief-php": "^1.3",
"graham-campbell/exceptions": "^9.1",
"minishlink/web-push": "^1.0",
"laravel/legacy-encrypter": "^1.0"
"minishlink/web-push": "^1.0"
},
"require-dev": {
"fzaninotto/faker": "~1.4",

1046
composer.lock generated

File diff suppressed because it is too large Load diff

View file

@ -95,7 +95,7 @@ return [
'key' => env('APP_KEY'),
'cipher' => MCRYPT_RIJNDAEL_128,
'cipher' => 'AES-256-CBC',
/*
|--------------------------------------------------------------------------