Skip to content

[10.x] Update to phpseclib v3 #1410

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
12 changes: 5 additions & 7 deletions src/Console/KeysCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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'),
Expand All @@ -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.');
}
Expand Down
9 changes: 3 additions & 6 deletions tests/Unit/KeysCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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();
}
}