From e577db4635750c7582c1fa4d78d798f3dc4c17b2 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 20 Mar 2021 18:42:38 +0100 Subject: [PATCH] Catch for RSA --- app/Http/Controllers/System/InstallController.php | 12 +++++++++--- app/Support/Http/Controllers/CreateStuff.php | 10 ++++++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/System/InstallController.php b/app/Http/Controllers/System/InstallController.php index e540f432f7..8e1de080a5 100644 --- a/app/Http/Controllers/System/InstallController.php +++ b/app/Http/Controllers/System/InstallController.php @@ -35,7 +35,6 @@ use Illuminate\Http\Request; use Illuminate\Support\Arr; use Laravel\Passport\Passport; use Log; -use phpseclib\Crypt\RSA; /** * Class InstallController @@ -134,8 +133,15 @@ class InstallController extends Controller */ public function keys(): void { - $rsa = new RSA(); - $keys = $rsa->createKey(4096); + // switch on PHP version. + if (7 === PHP_MAJOR_VERSION) { + $rsa = new \phpseclib\Crypt\RSA; + $keys = $rsa->createKey(4096); + } + if (8 === PHP_MAJOR_VERSION) { + $keys = \phpseclib3\Crypt\RSA::createKeys(4096); + } + [$publicKey, $privateKey] = [ Passport::keyPath('oauth-public.key'), diff --git a/app/Support/Http/Controllers/CreateStuff.php b/app/Support/Http/Controllers/CreateStuff.php index 5a0dbdf0e5..7343fcb892 100644 --- a/app/Support/Http/Controllers/CreateStuff.php +++ b/app/Support/Http/Controllers/CreateStuff.php @@ -30,7 +30,6 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\User; use Laravel\Passport\Passport; use Log; -use phpseclib3\Crypt\RSA; /** * Trait CreateStuff @@ -104,7 +103,14 @@ trait CreateStuff */ protected function createOAuthKeys(): void // create stuff { - $keys = RSA::createKey(4096); + // switch on PHP version. + if (7 === PHP_MAJOR_VERSION) { + $rsa = new \phpseclib\Crypt\RSA; + $keys = $rsa->createKey(4096); + } + if (8 === PHP_MAJOR_VERSION) { + $keys = \phpseclib3\Crypt\RSA::createKeys(4096); + } [$publicKey, $privateKey] = [ Passport::keyPath('oauth-public.key'),