Skip to content

CI/CD fixed #425

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 3 commits into from
Dec 27, 2022
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
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mu: vendor ## Mutation tests
vendor/bin/infection -s --threads=$(nproc) --min-msi=40 --min-covered-msi=40
vendor/bin/infection -s --threads=$$(nproc) --min-msi=40 --min-covered-msi=40

tests: vendor ## Run all tests
vendor/bin/phpunit --color
Expand All @@ -8,7 +8,7 @@ cc: vendor ## Show test coverage rates (HTML)
vendor/bin/phpunit --coverage-html ./build

cs: vendor ## Fix all files using defined ECS rules
vendor/bin/ecs check --fix
XDEBUG_MODE=off vendor/bin/ecs check --fix

tu: vendor ## Run only unit tests
vendor/bin/phpunit --color --group Unit
Expand All @@ -20,19 +20,19 @@ tf: vendor ## Run only functional tests
vendor/bin/phpunit --color --group Functional

st: vendor ## Run static analyse
vendor/bin/phpstan analyse
XDEBUG_MODE=off vendor/bin/phpstan analyse


################################################

ci-mu: vendor ## Mutation tests (for Github only)
vendor/bin/infection --logger-github -s --threads=$(nproc) --min-msi=40 --min-covered-msi=40
vendor/bin/infection --logger-github -s --threads=$$(nproc) --min-msi=40 --min-covered-msi=40

ci-cc: vendor ## Show test coverage rates (console)
vendor/bin/phpunit --coverage-text

ci-cs: vendor ## Check all files using defined ECS rules
vendor/bin/ecs check
XDEBUG_MODE=off vendor/bin/ecs check

################################################

Expand All @@ -42,7 +42,7 @@ vendor: composer.json composer.lock
composer install

rector: vendor ## Check all files using Rector
vendor/bin/rector process --ansi --dry-run --xdebug
XDEBUG_MODE=off vendor/bin/rector process --ansi --dry-run --xdebug

.DEFAULT_GOAL := help
help:
Expand Down
4 changes: 1 addition & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,13 @@
"php-http/mock-client": "^1.5",
"php-parallel-lint/php-parallel-lint": "^1.3",
"phpbench/phpbench": "^1.2",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan": "^1.8",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-phpunit": "^1.1",
"phpstan/phpstan-strict-rules": "^1.4",
"phpunit/phpunit": "^9.5.23",
"qossmic/deptrac-shim": "^1.0",
"rector/rector": "^0.14",
"rector/rector": "^0.15",
"roave/security-advisories": "dev-latest",
"symfony/browser-kit": "^6.1.3",
"symfony/finder": "^5.4|^6.0",
Expand Down Expand Up @@ -145,7 +144,6 @@
"config": {
"sort-packages": true,
"allow-plugins": {
"phpstan/extension-installer": true,
"infection/extension-installer": true,
"composer/package-versions-deprecated": true
}
Expand Down
7 changes: 2 additions & 5 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Rector\Config\RectorConfig;
use Rector\Core\ValueObject\PhpVersion;
use Rector\Doctrine\Set\DoctrineSetList;
use Rector\Php74\Rector\Property\TypedPropertyRector;
use Rector\PHPUnit\Set\PHPUnitLevelSetList;
use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\Set\ValueObject\LevelSetList;
Expand All @@ -20,7 +19,6 @@
SymfonyLevelSetList::UP_TO_SYMFONY_54,
SymfonySetList::SYMFONY_CODE_QUALITY,
SymfonySetList::SYMFONY_CONSTRUCTOR_INJECTION,
SymfonySetList::SYMFONY_STRICT,
DoctrineSetList::DOCTRINE_CODE_QUALITY,
DoctrineSetList::ANNOTATIONS_TO_ATTRIBUTES,
PHPUnitSetList::PHPUNIT_SPECIFIC_METHOD,
Expand All @@ -33,14 +31,13 @@
$config->parallel();
$config->paths([__DIR__ . '/src', __DIR__ . '/performance', __DIR__ . '/tests']);
$config->skip([
\Rector\Php80\Rector\Class_\AnnotationToAttributeRector::class => __DIR__ . '/tests',
\Rector\PHPUnit\Rector\Class_\AnnotationWithValueToAttributeRector::class => __DIR__ . '/tests',
__DIR__ . '/src/Component/Core/JWKSet.php',
__DIR__ . '/src/Bundle/JoseFramework/DependencyInjection/Source/KeyManagement/JWKSource.php',
__DIR__ . '/src/Bundle/JoseFramework/DependencyInjection/Source/KeyManagement/JWKSetSource.php',
]);
$config->phpVersion(PhpVersion::PHP_81);
$config->importNames();
$config->importShortClasses();

$services = $config->services();
$services->set(TypedPropertyRector::class);
};
24 changes: 11 additions & 13 deletions src/Component/Core/Util/RSAKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,19 @@

namespace Jose\Component\Core\Util;

use SpomkyLabs\Pki\ASN1\Type\Constructed\Sequence;
use SpomkyLabs\Pki\ASN1\Type\Primitive\BitString;
use SpomkyLabs\Pki\ASN1\Type\Primitive\Integer;
use SpomkyLabs\Pki\ASN1\Type\Primitive\NullType;
use SpomkyLabs\Pki\ASN1\Type\Primitive\ObjectIdentifier;
use SpomkyLabs\Pki\ASN1\Type\Primitive\OctetString;
use SpomkyLabs\Pki\CryptoEncoding\PEM;
use SpomkyLabs\Pki\CryptoTypes\AlgorithmIdentifier\Asymmetric\RSAEncryptionAlgorithmIdentifier;
use function array_key_exists;
use function count;
use InvalidArgumentException;
use function is_array;
use Jose\Component\Core\JWK;
use ParagonIE\ConstantTime\Base64UrlSafe;
use RuntimeException;
use SpomkyLabs\Pki\ASN1\Type\Constructed\Sequence;
use SpomkyLabs\Pki\ASN1\Type\Primitive\BitString;
use SpomkyLabs\Pki\ASN1\Type\Primitive\Integer;
use SpomkyLabs\Pki\ASN1\Type\Primitive\OctetString;
use SpomkyLabs\Pki\CryptoEncoding\PEM;
use SpomkyLabs\Pki\CryptoTypes\AlgorithmIdentifier\Asymmetric\RSAEncryptionAlgorithmIdentifier;
use SpomkyLabs\Pki\CryptoTypes\Asymmetric\RSA\RSAPrivateKey;
use SpomkyLabs\Pki\CryptoTypes\Asymmetric\RSA\RSAPublicKey;

Expand Down Expand Up @@ -182,8 +180,8 @@ public static function exponentiate(self $key, BigInteger $c): BigInteger
throw new RuntimeException();
}
if ($key->isPublic() || $key->getCoefficient() === null || count($key->getPrimes()) === 0 || count(
$key->getExponents()
) === 0) {
$key->getExponents()
) === 0) {
return $c->modPow($key->getExponent(), $key->getModulus());
}

Expand Down Expand Up @@ -216,9 +214,9 @@ private function populateBigIntegers(): void
$this->convertBase64StringToBigInteger($this->values['q']),
];
if (array_key_exists('dp', $this->values) && array_key_exists('dq', $this->values) && array_key_exists(
'qi',
$this->values
)) {
'qi',
$this->values
)) {
$this->exponents = [
$this->convertBase64StringToBigInteger($this->values['dp']),
$this->convertBase64StringToBigInteger($this->values['dq']),
Expand Down
9 changes: 4 additions & 5 deletions src/Component/KeyManagement/KeyConverter/KeyConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Jose\Component\KeyManagement\KeyConverter;

use SpomkyLabs\Pki\CryptoTypes\Asymmetric\EC\ECPublicKey;
use function array_key_exists;
use function count;
use function extension_loaded;
Expand Down Expand Up @@ -134,10 +133,10 @@ public static function loadFromX5C(array $x5c): array
}
foreach ($x5c as $id => $cert) {
$x5c[$id] = '-----BEGIN CERTIFICATE-----' . PHP_EOL . chunk_split(
(string) $cert,
64,
PHP_EOL
) . '-----END CERTIFICATE-----';
(string) $cert,
64,
PHP_EOL
) . '-----END CERTIFICATE-----';
$x509 = openssl_x509_read($x5c[$id]);
if ($x509 === false) {
throw new InvalidArgumentException('Unable to load the certificate chain');
Expand Down
4 changes: 2 additions & 2 deletions src/EncryptionAlgorithm/Experimental/KeyEncryption/AESCTR.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public function encryptKey(JWK $key, string $cek, array $completeHeader, array &
public function decryptKey(JWK $key, string $encrypted_cek, array $header): string
{
$k = $this->getKey($key);
isset($header['iv']) ||throw new InvalidArgumentException('The header parameter "iv" is missing.');
is_string($header['iv']) ||throw new InvalidArgumentException('The header parameter "iv" is not valid.');
isset($header['iv']) || throw new InvalidArgumentException('The header parameter "iv" is missing.');
is_string($header['iv']) || throw new InvalidArgumentException('The header parameter "iv" is not valid.');
$iv = Base64UrlSafe::decode($header['iv']);

$result = openssl_decrypt($encrypted_cek, $this->getMode(), $k, OPENSSL_RAW_DATA, $iv);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public function encryptKey(JWK $key, string $cek, array $completeHeader, array &
public function decryptKey(JWK $key, string $encrypted_cek, array $header): string
{
$k = $this->getKey($key);
isset($header['nonce']) ||throw new InvalidArgumentException('The header parameter "nonce" is missing.');
is_string($header['nonce']) ||throw new InvalidArgumentException('The header parameter "nonce" is not valid.');
isset($header['nonce']) || throw new InvalidArgumentException('The header parameter "nonce" is missing.');
is_string($header['nonce']) || throw new InvalidArgumentException('The header parameter "nonce" is not valid.');
$nonce = Base64UrlSafe::decode($header['nonce']);
if (mb_strlen($nonce, '8bit') !== 12) {
throw new InvalidArgumentException('The header parameter "nonce" is not valid.');
Expand Down
8 changes: 6 additions & 2 deletions src/EncryptionAlgorithm/KeyEncryption/AESGCMKW/AESGCMKW.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@ public function wrapKey(JWK $key, string $cek, array $completeHeader, array &$ad
public function unwrapKey(JWK $key, string $encrypted_cek, array $completeHeader): string
{
$kek = $this->getKey($key);
(isset($completeHeader['iv']) && is_string($completeHeader['iv'])) || throw new InvalidArgumentException('Parameter "iv" is missing.');
(isset($completeHeader['tag']) && is_string($completeHeader['tag'])) || throw new InvalidArgumentException('Parameter "tag" is missing.');
(isset($completeHeader['iv']) && is_string($completeHeader['iv'])) || throw new InvalidArgumentException(
'Parameter "iv" is missing.'
);
(isset($completeHeader['tag']) && is_string($completeHeader['tag'])) || throw new InvalidArgumentException(
'Parameter "tag" is missing.'
);

$tag = Base64UrlSafe::decode($completeHeader['tag']);
$iv = Base64UrlSafe::decode($completeHeader['iv']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ protected function calculateAgreementKey(JWK $private_key, JWK $public_key): str
}

/**
* @return JWK[]
* @param array<string, mixed> $additional_header_values
* @return JWK[]
*/
protected function getKeysFromPublicKey(
JWK $recipient_key,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,15 @@ public function theJWEEncoderShouldThrowOnUnsupportedFormatWhenDecoding(): void
$serializer->decode($jweString, 'jwe_json_flattened');
}

public function encoderServiceDataProvider(): array
public static function encoderServiceDataProvider(): array
{
return [
'indirect serializer' => ['serializer'],
'direct serializer' => [JWEEncoder::class],
];
}

public function jweFormatDataProvider(): array
public static function jweFormatDataProvider(): array
{
return [
'jwe_compact with indirect serializer' => ['jwe_compact', 'serializer'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function serializerServiceDataProvider(): array
];
}

public function jweFormatDataProvider(): array
public static function jweFormatDataProvider(): array
{
return [
'jwe_compact with indirect serializer' => ['jwe_compact', 'serializer'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public function serializerServiceDataProvider(): array
];
}

public function jwsFormatDataProvider(): array
public static function jwsFormatDataProvider(): array
{
return [
'jws_compact with indirect serializer' => ['jws_compact', 'serializer'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function serializerServiceDataProvider(): array
];
}

public function jwsFormatDataProvider(): array
public static function jwsFormatDataProvider(): array
{
return [
'jws_compact with indirect serializer' => ['jws_compact', 'serializer'],
Expand Down
2 changes: 1 addition & 1 deletion tests/Component/Encryption/RSAKeyWithoutAllPrimesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function encryptionAlgorithmsWithMinimalRsaKey(string $encryption_algorit
static::assertTrue($jweDecrypter->decryptUsingKey($loaded, $key, 0));
}

public function dataEncryptionAlgorithms(): array
public static function dataEncryptionAlgorithms(): array
{
return [['RSA1_5'], ['RSA-OAEP'], ['RSA-OAEP-256']];
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Component/KeyManagement/CertificateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function loadCertificate(string $file, array $expected_values): void
static::assertEqualsCanonicalizing($expected_values, $result);
}

public function dataLoadCertificate(): array
public static function dataLoadCertificate(): array
{
return [
[
Expand Down
9 changes: 3 additions & 6 deletions tests/Component/KeyManagement/JWKFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,11 @@ public function createFromPublicEC512KeyFile(string $filename, string $expectedJ
$jwk = JWKFactory::createFromKeyFile($filename);

// Then
static::assertSame(
$expectedJWK,
json_encode($jwk, JSON_THROW_ON_ERROR)
);
static::assertSame($expectedJWK, json_encode($jwk, JSON_THROW_ON_ERROR));
static::assertSame($content, ECKey::convertPublicKeyToPEM($jwk));
}

public function publicKeysAndPem(): iterable
public static function publicKeysAndPem(): iterable
{
yield [
__DIR__ . '/Keys/EC/public.es256.key',
Expand Down Expand Up @@ -288,7 +285,7 @@ public function loadKeyPEMEncoded(string $filename, array $expectedValues): void
/**
* @return array<int, array<string, mixed>>
*/
public function dataKeys(): array
public static function dataKeys(): array
{
return [
[
Expand Down
2 changes: 1 addition & 1 deletion tests/Component/KeyManagement/Keys/ECKeysTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace Jose\Tests\Component\KeyManagement\Keys;

use Jose\Component\Core\Util\ECKey;
use const DIRECTORY_SEPARATOR;
use InvalidArgumentException;
use Jose\Component\Core\JWK;
use Jose\Component\Core\Util\ECKey;
use Jose\Component\KeyManagement\JWKFactory;
use Jose\Component\KeyManagement\KeyConverter\KeyConverter;
use PHPUnit\Framework\TestCase;
Expand Down
5 changes: 1 addition & 4 deletions tests/Component/KeyManagement/Keys/RSAKeysTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

namespace Jose\Tests\Component\KeyManagement\Keys;

use SpomkyLabs\Pki\ASN1\Type\Constructed\Sequence;
use SpomkyLabs\Pki\ASN1\Type\Primitive\RelativeOID;
use SpomkyLabs\Pki\CryptoEncoding\PEM;
use const DIRECTORY_SEPARATOR;
use InvalidArgumentException;
use Jose\Component\Core\JWK;
Expand Down Expand Up @@ -142,7 +139,7 @@ public function loadPrivateRSAKey(): void
$content = trim(file_get_contents($file));

// When
$rsaKey = RSAKey::createFromPEM('file://'.$file);
$rsaKey = RSAKey::createFromPEM('file://' . $file);

// Then
static::assertEqualsCanonicalizing([
Expand Down
Loading