Skip to content

Commit 3978fa9

Browse files
authored
Merge pull request #187 from web-token/GMPDepFix
[WIP] Fixes GMP requirement
2 parents 5569893 + aeb0f42 commit 3978fa9

File tree

24 files changed

+219
-83
lines changed

24 files changed

+219
-83
lines changed

phpstan.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ parameters:
1919
- '#Parameter \#1 \$value of static method Jose\\Component\\Core\\Util\\BigInteger::createFromGMPResource\(\) expects GMP, resource given\.#'
2020
- '#Return type \(void\) of method Jose\\Bundle\\JoseFramework\\Routing\\JWKSetLoader::getResolver\(\) should be compatible with return type \(Symfony\\Component\\Config\\Loader\\LoaderResolverInterface\) of method Symfony\\Component\\Config\\Loader\\LoaderInterface::getResolver\(\)#'
2121
- '#Instanceof between Jose\\Component\\Core\\JWK and Jose\\Component\\Core\\JWK will always evaluate to true\.#'
22-
- '#Function openssl_pkey_derive not found\.#'
2322
includes:
2423
- vendor/phpstan/phpstan-phpunit/extension.neon
2524
- vendor/phpstan/phpstan-phpunit/rules.neon

src/Bundle/JoseFramework/DependencyInjection/Source/Signature/SignatureSource.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
use Jose\Component\Signature\Algorithm\HMAC;
2222
use Jose\Component\Signature\Algorithm\HS1;
2323
use Jose\Component\Signature\Algorithm\None;
24-
use Jose\Component\Signature\Algorithm\RSA;
24+
use Jose\Component\Signature\Algorithm\RSAPSS;
2525
use Jose\Component\Signature\JWSBuilderFactory;
2626
use Jose\Component\Signature\JWSVerifierFactory;
2727
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
@@ -125,7 +125,7 @@ public function getCompilerPasses(): array
125125
private function getAlgorithmsFiles(): array
126126
{
127127
return [
128-
RSA::class => 'signature_rsa.php',
128+
RSAPSS::class => 'signature_rsa.php',
129129
ECDSA::class => 'signature_ecdsa.php',
130130
EdDSA::class => 'signature_eddsa.php',
131131
HMAC::class => 'signature_hmac.php',

src/Bundle/JoseFramework/Resources/config/Algorithms/signature_rsa.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,17 @@
3333
->tag('jose.algorithm', ['alias' => 'RS512'])
3434
;
3535

36-
$container->set(Algorithm\PS256::class)
37-
->tag('jose.algorithm', ['alias' => 'PS256'])
38-
;
39-
40-
$container->set(Algorithm\PS384::class)
41-
->tag('jose.algorithm', ['alias' => 'PS384'])
42-
;
43-
44-
$container->set(Algorithm\PS512::class)
45-
->tag('jose.algorithm', ['alias' => 'PS512'])
46-
;
36+
if (extension_loaded('gmp')) {
37+
$container->set(Algorithm\PS256::class)
38+
->tag('jose.algorithm', ['alias' => 'PS256'])
39+
;
40+
41+
$container->set(Algorithm\PS384::class)
42+
->tag('jose.algorithm', ['alias' => 'PS384'])
43+
;
44+
45+
$container->set(Algorithm\PS512::class)
46+
->tag('jose.algorithm', ['alias' => 'PS512'])
47+
;
48+
}
4749
};

src/Bundle/JoseFramework/Resources/config/analyzers.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* of the MIT license. See the LICENSE file for details.
1212
*/
1313

14+
use Jose\Component\Core\Util\Ecc\NistCurve;
1415
use Jose\Component\KeyManagement\Analyzer;
1516
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
1617
use ZxcvbnPhp\Zxcvbn;
@@ -37,13 +38,16 @@
3738
$container->set(Analyzer\OctAnalyzer::class);
3839
$container->set(Analyzer\MixedKeyTypes::class);
3940
$container->set(Analyzer\MixedPublicAndPrivateKeys::class);
40-
$container->set(Analyzer\ES256KeyAnalyzer::class);
41-
$container->set(Analyzer\ES384KeyAnalyzer::class);
42-
$container->set(Analyzer\ES512KeyAnalyzer::class);
4341
$container->set(Analyzer\HS256KeyAnalyzer::class);
4442
$container->set(Analyzer\HS384KeyAnalyzer::class);
4543
$container->set(Analyzer\HS512KeyAnalyzer::class);
4644

45+
if (class_exists(NistCurve::class)) {
46+
$container->set(Analyzer\ES256KeyAnalyzer::class);
47+
$container->set(Analyzer\ES384KeyAnalyzer::class);
48+
$container->set(Analyzer\ES512KeyAnalyzer::class);
49+
}
50+
4751
if (class_exists(Zxcvbn::class)) {
4852
$container->set(Analyzer\ZxcvbnKeyAnalyzer::class);
4953
}

src/Component/Encryption/Serializer/JSONFlattenedSerializer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function unserialize(string $input): JWE
9090

9191
private function checkData(?array $data): void
9292
{
93-
if ($data === null || !isset($data['ciphertext']) || isset($data['recipients'])) {
93+
if (null === $data || !isset($data['ciphertext']) || isset($data['recipients'])) {
9494
throw new InvalidArgumentException('Unsupported input.');
9595
}
9696
}

src/Component/Encryption/Serializer/JSONGeneralSerializer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function unserialize(string $input): JWE
9999

100100
private function checkData(?array $data): void
101101
{
102-
if ($data === null || !isset($data['ciphertext']) || !isset($data['recipients'])) {
102+
if (null === $data || !isset($data['ciphertext']) || !isset($data['recipients'])) {
103103
throw new InvalidArgumentException('Unsupported input.');
104104
}
105105
}

src/Component/KeyManagement/Analyzer/ES256KeyAnalyzer.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,17 @@
1616
use Base64Url\Base64Url;
1717
use Jose\Component\Core\JWK;
1818
use Jose\Component\Core\Util\Ecc\NistCurve;
19+
use RuntimeException;
1920

2021
final class ES256KeyAnalyzer implements KeyAnalyzer
2122
{
23+
public function __construct()
24+
{
25+
if (!class_exists(NistCurve::class)) {
26+
throw new RuntimeException('Please install web-token/jwt-util-ecc to use this key analyzer');
27+
}
28+
}
29+
2230
public function analyze(JWK $jwk, MessageBag $bag): void
2331
{
2432
if ('EC' !== $jwk->get('kty')) {

src/Component/KeyManagement/Analyzer/ES384KeyAnalyzer.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,17 @@
1616
use Base64Url\Base64Url;
1717
use Jose\Component\Core\JWK;
1818
use Jose\Component\Core\Util\Ecc\NistCurve;
19+
use RuntimeException;
1920

2021
final class ES384KeyAnalyzer implements KeyAnalyzer
2122
{
23+
public function __construct()
24+
{
25+
if (!class_exists(NistCurve::class)) {
26+
throw new RuntimeException('Please install web-token/jwt-util-ecc to use this key analyzer');
27+
}
28+
}
29+
2230
public function analyze(JWK $jwk, MessageBag $bag): void
2331
{
2432
if ('EC' !== $jwk->get('kty')) {

src/Component/KeyManagement/Analyzer/ES512KeyAnalyzer.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,17 @@
1616
use Base64Url\Base64Url;
1717
use Jose\Component\Core\JWK;
1818
use Jose\Component\Core\Util\Ecc\NistCurve;
19+
use RuntimeException;
1920

2021
final class ES512KeyAnalyzer implements KeyAnalyzer
2122
{
23+
public function __construct()
24+
{
25+
if (!class_exists(NistCurve::class)) {
26+
throw new RuntimeException('Please install web-token/jwt-util-ecc to use this key analyzer');
27+
}
28+
}
29+
2230
public function analyze(JWK $jwk, MessageBag $bag): void
2331
{
2432
if ('EC' !== $jwk->get('kty')) {

src/Component/KeyManagement/composer.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,9 @@
2121
},
2222
"require": {
2323
"ext-openssl": "*",
24-
"ext-gmp": "*",
2524
"psr/http-factory": "^1.0",
2625
"psr/http-client": "^1.0",
27-
"web-token/jwt-core": "^2.0",
28-
"web-token/jwt-util-ecc": "^2.0"
26+
"web-token/jwt-core": "^2.0"
2927
},
3028
"require-dev": {
3129
"php-http/message-factory": "^1.0",
@@ -34,6 +32,7 @@
3432
"phpunit/phpunit": "^8.0"
3533
},
3634
"suggest": {
35+
"web-token/jwt-util-ecc": "To use EC key analyzers.",
3736
"php-http/message-factory": "To enable JKU/X5U support.",
3837
"php-http/httplug": "To enable JKU/X5U support."
3938
},

0 commit comments

Comments
 (0)