Skip to content

Commit

Permalink
Tests and ECS
Browse files Browse the repository at this point in the history
  • Loading branch information
Spomky committed Apr 14, 2022
1 parent 633e88a commit 348963c
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 43 deletions.
1 change: 0 additions & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
$parameters->set(Option::AUTO_IMPORT_NAMES, true);
$parameters->set(Option::PARALLEL, true);
$parameters->set(Option::IMPORT_SHORT_CLASSES, false);
$parameters->set(Option::IMPORT_DOC_BLOCKS, false);

$services = $containerConfigurator->services();
$services->set(TypedPropertyRector::class);
Expand Down
3 changes: 1 addition & 2 deletions src/Component/Console/EcKeysetGeneratorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Jose\Component\Console;

use InvalidArgumentException;
use function is_int;
use function is_string;
use Jose\Component\Core\JWKSet;
use Jose\Component\KeyManagement\JWKFactory;
Expand All @@ -28,7 +27,7 @@ protected function configure(): void

protected function execute(InputInterface $input, OutputInterface $output): int
{
$quantity = (int)$input->getArgument('quantity');
$quantity = (int) $input->getArgument('quantity');
if ($quantity < 1) {
throw new InvalidArgumentException('Invalid quantity');
}
Expand Down
3 changes: 1 addition & 2 deletions src/Component/Console/OctKeyGeneratorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Jose\Component\Console;

use InvalidArgumentException;
use function is_int;
use Jose\Component\KeyManagement\JWKFactory;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -25,7 +24,7 @@ protected function configure(): void

protected function execute(InputInterface $input, OutputInterface $output): int
{
$size = (int)$input->getArgument('size');
$size = (int) $input->getArgument('size');
if ($size < 1) {
throw new InvalidArgumentException('Invalid size');
}
Expand Down
5 changes: 2 additions & 3 deletions src/Component/Console/OctKeysetGeneratorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Jose\Component\Console;

use InvalidArgumentException;
use function is_int;
use Jose\Component\Core\JWKSet;
use Jose\Component\KeyManagement\JWKFactory;
use Symfony\Component\Console\Input\InputArgument;
Expand All @@ -27,8 +26,8 @@ protected function configure(): void

protected function execute(InputInterface $input, OutputInterface $output): int
{
$quantity = (int)$input->getArgument('quantity');
$size = (int)$input->getArgument('size');
$quantity = (int) $input->getArgument('quantity');
$size = (int) $input->getArgument('size');
if ($quantity < 1) {
throw new InvalidArgumentException('Invalid quantity');
}
Expand Down
3 changes: 1 addition & 2 deletions src/Component/Console/OkpKeysetGeneratorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Jose\Component\Console;

use InvalidArgumentException;
use function is_int;
use function is_string;
use Jose\Component\Core\JWKSet;
use Jose\Component\KeyManagement\JWKFactory;
Expand All @@ -28,7 +27,7 @@ protected function configure(): void

protected function execute(InputInterface $input, OutputInterface $output): int
{
$quantity = (int)$input->getArgument('quantity');
$quantity = (int) $input->getArgument('quantity');
$curve = $input->getArgument('curve');
if ($quantity < 1) {
throw new InvalidArgumentException('Invalid quantity');
Expand Down
3 changes: 1 addition & 2 deletions src/Component/Console/RsaKeyGeneratorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Jose\Component\Console;

use InvalidArgumentException;
use function is_int;
use Jose\Component\KeyManagement\JWKFactory;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -25,7 +24,7 @@ protected function configure(): void

protected function execute(InputInterface $input, OutputInterface $output): int
{
$size = (int)$input->getArgument('size');
$size = (int) $input->getArgument('size');
$args = $this->getOptions($input);
if ($size < 1) {
throw new InvalidArgumentException('Invalid size');
Expand Down
5 changes: 2 additions & 3 deletions src/Component/Console/RsaKeysetGeneratorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Jose\Component\Console;

use InvalidArgumentException;
use function is_int;
use Jose\Component\Core\JWKSet;
use Jose\Component\KeyManagement\JWKFactory;
use Symfony\Component\Console\Input\InputArgument;
Expand All @@ -27,8 +26,8 @@ protected function configure(): void

protected function execute(InputInterface $input, OutputInterface $output): int
{
$quantity = (int)$input->getArgument('quantity');
$size = (int)$input->getArgument('size');
$quantity = (int) $input->getArgument('quantity');
$size = (int) $input->getArgument('size');
if ($quantity < 1) {
throw new InvalidArgumentException('Invalid quantity');
}
Expand Down
14 changes: 7 additions & 7 deletions src/Component/Encryption/Algorithm/KeyEncryption/KeyWrapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ interface KeyWrapping extends KeyEncryptionAlgorithm
/**
* Encrypt the CEK.
*
* @param \Jose\Component\Core\JWK $key The key used to wrap the CEK
* @param string $cek The CEK to encrypt
* @param array $completeHeader The complete header of the JWT
* @param array $additionalHeader The complete header of the JWT
* @param JWK $key The key used to wrap the CEK
* @param string $cek The CEK to encrypt
* @param array $completeHeader The complete header of the JWT
* @param array $additionalHeader The complete header of the JWT
*/
public function wrapKey(JWK $key, string $cek, array $completeHeader, array &$additionalHeader): string;

/**
* Decrypt de CEK.
*
* @param \Jose\Component\Core\JWK $key The key used to wrap the CEK
* @param string $encrypted_cek The CEK to decrypt
* @param array $completeHeader The complete header of the JWT
* @param JWK $key The key used to wrap the CEK
* @param string $encrypted_cek The CEK to decrypt
* @param array $completeHeader The complete header of the JWT
*/
public function unwrapKey(JWK $key, string $encrypted_cek, array $completeHeader): string;
}
35 changes: 18 additions & 17 deletions src/Component/KeyManagement/Analyzer/ZxcvbnKeyAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,29 @@ public function analyze(JWK $jwk, MessageBag $bag): void
return;
}
$k = Base64UrlSafe::decode($k);
if (class_exists(Zxcvbn::class)) {
$zxcvbn = new Zxcvbn();
$strength = $zxcvbn->passwordStrength($k);
if (! class_exists(Zxcvbn::class)) {
return;
}
$zxcvbn = new Zxcvbn();
$strength = $zxcvbn->passwordStrength($k);

switch (true) {
case $strength['score'] < 3:
$bag->add(
Message::high(
'The octet string is weak and easily guessable. Please change your key as soon as possible.'
)
);
switch (true) {
case $strength['score'] < 3:
$bag->add(
Message::high(
'The octet string is weak and easily guessable. Please change your key as soon as possible.'
)
);

break;
break;

case $strength['score'] === 3:
$bag->add(Message::medium('The octet string is safe, but a longer key is preferable.'));
case $strength['score'] === 3:
$bag->add(Message::medium('The octet string is safe, but a longer key is preferable.'));

break;
break;

default:
break;
}
default:
break;
}
}
}
15 changes: 11 additions & 4 deletions tests/Component/Console/KeySetCreationCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ public function iCanCreateAnEllipticCurveKeySetWithCurveP256(): void

$command->run($input, $output);
$content = $output->fetch();
JWKSet::createFromJson($content);
$jwkset = JWKSet::createFromJson($content);
static::assertCount(2, $jwkset, 'Invalid number of keys in the keyset');
}

/**
Expand All @@ -96,6 +97,9 @@ public function iCannotCreateAnOctetKeySetWithoutKeySetSize(): void
$command = new OctKeysetGeneratorCommand();

$command->run($input, $output);
$content = $output->fetch();
$jwkset = JWKSet::createFromJson($content);
static::assertCount(2, $jwkset, 'Invalid number of keys in the keyset');
}

/**
Expand All @@ -113,7 +117,8 @@ public function iCanCreateAnOctetKeySet(): void

$command->run($input, $output);
$content = $output->fetch();
JWKSet::createFromJson($content);
$jwkset = JWKSet::createFromJson($content);
static::assertCount(2, $jwkset, 'Invalid number of keys in the keyset');
}

/**
Expand Down Expand Up @@ -148,7 +153,8 @@ public function iCanCreateAnOctetKeySetPair(): void

$command->run($input, $output);
$content = $output->fetch();
JWKSet::createFromJson($content);
$jwkset = JWKSet::createFromJson($content);
static::assertCount(2, $jwkset, 'Invalid number of keys in the keyset');
}

/**
Expand Down Expand Up @@ -183,6 +189,7 @@ public function iCanCreateAnRsaKeySet(): void

$command->run($input, $output);
$content = $output->fetch();
JWKSet::createFromJson($content);
$jwkset = JWKSet::createFromJson($content);
static::assertCount(2, $jwkset, 'Invalid number of keys in the keyset');
}
}

0 comments on commit 348963c

Please sign in to comment.