Skip to content

Commit

Permalink
Update to phpseclib v3 (#1410)
Browse files Browse the repository at this point in the history
  • Loading branch information
driesvints authored Feb 18, 2021
1 parent 8b792b4 commit b28cd97
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
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();
}
}

0 comments on commit b28cd97

Please sign in to comment.