From b28cd974cbdca374c15a8ba6cd3533c2719e2447 Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Thu, 18 Feb 2021 16:06:38 +0100 Subject: [PATCH] Update to phpseclib v3 (#1410) --- composer.json | 2 +- src/Console/KeysCommand.php | 12 +++++------- tests/Unit/KeysCommandTest.php | 9 +++------ 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/composer.json b/composer.json index 319a8c4b8..4eb1089da 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,7 @@ "league/oauth2-server": "^8.2", "lcobucci/jwt": "^3.4|^4.0", "nyholm/psr7": "^1.3", - "phpseclib/phpseclib": "^2.0", + "phpseclib/phpseclib": "^3.0", "symfony/psr-http-message-bridge": "^2.0" }, "require-dev": { diff --git a/src/Console/KeysCommand.php b/src/Console/KeysCommand.php index ac0a5f165..b0851acec 100644 --- a/src/Console/KeysCommand.php +++ b/src/Console/KeysCommand.php @@ -3,9 +3,8 @@ namespace Laravel\Passport\Console; use Illuminate\Console\Command; -use Illuminate\Support\Arr; use Laravel\Passport\Passport; -use phpseclib\Crypt\RSA; +use phpseclib3\Crypt\RSA; class KeysCommand extends Command { @@ -28,10 +27,9 @@ class KeysCommand extends Command /** * Execute the console command. * - * @param \phpseclib\Crypt\RSA $rsa * @return void */ - public function handle(RSA $rsa) + public function handle() { [$publicKey, $privateKey] = [ Passport::keyPath('oauth-public.key'), @@ -41,10 +39,10 @@ public function handle(RSA $rsa) if ((file_exists($publicKey) || file_exists($privateKey)) && ! $this->option('force')) { $this->error('Encryption keys already exist. Use the --force option to overwrite them.'); } else { - $keys = $rsa->createKey($this->input ? (int) $this->option('length') : 4096); + $key = RSA::createKey($this->input ? (int) $this->option('length') : 4096); - file_put_contents($publicKey, Arr::get($keys, 'publickey')); - file_put_contents($privateKey, Arr::get($keys, 'privatekey')); + file_put_contents($publicKey, (string) $key->getPublicKey()); + file_put_contents($privateKey, (string) $key); $this->info('Encryption keys generated successfully.'); } diff --git a/tests/Unit/KeysCommandTest.php b/tests/Unit/KeysCommandTest.php index e85f64a29..991d21564 100644 --- a/tests/Unit/KeysCommandTest.php +++ b/tests/Unit/KeysCommandTest.php @@ -6,7 +6,6 @@ use Laravel\Passport\Console\KeysCommand; use Laravel\Passport\Passport; use Mockery as m; -use phpseclib\Crypt\RSA; use PHPUnit\Framework\TestCase; class KeysCommandTest extends TestCase @@ -41,9 +40,7 @@ public function testPrivateAndPublicKeysAreGenerated() Container::getInstance()->instance('path.storage', self::KEYS); - $rsa = new RSA(); - - $command->handle($rsa); + $command->handle(); $this->assertFileExists(self::PUBLIC_KEY); $this->assertFileExists(self::PRIVATE_KEY); @@ -59,7 +56,7 @@ public function testPrivateAndPublicKeysAreGeneratedInCustomPath() ->with('Encryption keys generated successfully.') ->getMock(); - $command->handle(new RSA); + $command->handle(); $this->assertFileExists(self::PUBLIC_KEY); $this->assertFileExists(self::PRIVATE_KEY); @@ -79,6 +76,6 @@ public function testPrivateAndPublicKeysShouldNotBeGeneratedTwice($command) $command->shouldReceive('error') ->with('Encryption keys already exist. Use the --force option to overwrite them.'); - $command->handle(new RSA); + $command->handle(); } }