From c7fa64f5230a7e348bdb1194f4b36fb34267f3bb Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Mon, 1 Mar 2021 11:07:46 +0100 Subject: [PATCH 1/2] Backport support for phpseclib v2 --- composer.json | 4 ++-- src/Console/KeysCommand.php | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index 4eb1089da..0726c28c7 100644 --- a/composer.json +++ b/composer.json @@ -26,10 +26,10 @@ "illuminate/encryption": "^8.2", "illuminate/http": "^8.2", "illuminate/support": "^8.2", - "league/oauth2-server": "^8.2", "lcobucci/jwt": "^3.4|^4.0", + "league/oauth2-server": "^8.2", "nyholm/psr7": "^1.3", - "phpseclib/phpseclib": "^3.0", + "phpseclib/phpseclib": "^2.0|^3.0", "symfony/psr-http-message-bridge": "^2.0" }, "require-dev": { diff --git a/src/Console/KeysCommand.php b/src/Console/KeysCommand.php index b0851acec..18db6cd42 100644 --- a/src/Console/KeysCommand.php +++ b/src/Console/KeysCommand.php @@ -3,8 +3,10 @@ namespace Laravel\Passport\Console; use Illuminate\Console\Command; +use Illuminate\Support\Arr; use Laravel\Passport\Passport; use phpseclib3\Crypt\RSA; +use phpseclib\Crypt\RSA as LegacyRSA; class KeysCommand extends Command { @@ -39,10 +41,17 @@ public function handle() if ((file_exists($publicKey) || file_exists($privateKey)) && ! $this->option('force')) { $this->error('Encryption keys already exist. Use the --force option to overwrite them.'); } else { - $key = RSA::createKey($this->input ? (int) $this->option('length') : 4096); + if (class_exists(LegacyRSA::class)) { + $keys = (new LegacyRSA)->createKey($this->input ? (int) $this->option('length') : 4096); - file_put_contents($publicKey, (string) $key->getPublicKey()); - file_put_contents($privateKey, (string) $key); + file_put_contents($publicKey, Arr::get($keys, 'publickey')); + file_put_contents($privateKey, Arr::get($keys, 'privatekey')); + } else { + $key = RSA::createKey($this->input ? (int) $this->option('length') : 4096); + + file_put_contents($publicKey, (string) $key->getPublicKey()); + file_put_contents($privateKey, (string) $key); + } $this->info('Encryption keys generated successfully.'); } From 969209c9fe3ab1f8686afe664b38e2fc706282d3 Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Mon, 1 Mar 2021 11:08:20 +0100 Subject: [PATCH 2/2] Apply fixes from StyleCI (#1417) --- src/Console/KeysCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Console/KeysCommand.php b/src/Console/KeysCommand.php index 18db6cd42..36ff6e6c6 100644 --- a/src/Console/KeysCommand.php +++ b/src/Console/KeysCommand.php @@ -5,8 +5,8 @@ use Illuminate\Console\Command; use Illuminate\Support\Arr; use Laravel\Passport\Passport; -use phpseclib3\Crypt\RSA; use phpseclib\Crypt\RSA as LegacyRSA; +use phpseclib3\Crypt\RSA; class KeysCommand extends Command {