Skip to content

Commit f2071a1

Browse files
committed
gmp not required for RSxxx algs, only PSxxx
1 parent 32e3919 commit f2071a1

File tree

14 files changed

+177
-72
lines changed

14 files changed

+177
-72
lines changed

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/SignatureAlgorithm/Experimental/RS1.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313

1414
namespace Jose\Component\Signature\Algorithm;
1515

16-
use Jose\Component\Signature\Algorithm\Util\RSA as JoseRSA;
17-
18-
final class RS1 extends RSA
16+
final class RS1 extends RSAPKCS1
1917
{
2018
public function name(): string
2119
{
@@ -26,9 +24,4 @@ protected function getAlgorithm(): string
2624
{
2725
return 'sha1';
2826
}
29-
30-
protected function getSignatureMethod(): int
31-
{
32-
return JoseRSA::SIGNATURE_PKCS1;
33-
}
3427
}

src/SignatureAlgorithm/RSA/PS256.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313

1414
namespace Jose\Component\Signature\Algorithm;
1515

16-
use Jose\Component\Signature\Algorithm\Util\RSA as JoseRSA;
17-
18-
final class PS256 extends RSA
16+
final class PS256 extends RSAPSS
1917
{
2018
public function name(): string
2119
{
@@ -26,9 +24,4 @@ protected function getAlgorithm(): string
2624
{
2725
return 'sha256';
2826
}
29-
30-
protected function getSignatureMethod(): int
31-
{
32-
return JoseRSA::SIGNATURE_PSS;
33-
}
3427
}

src/SignatureAlgorithm/RSA/PS384.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313

1414
namespace Jose\Component\Signature\Algorithm;
1515

16-
use Jose\Component\Signature\Algorithm\Util\RSA as JoseRSA;
17-
18-
final class PS384 extends RSA
16+
final class PS384 extends RSAPSS
1917
{
2018
public function name(): string
2119
{
@@ -26,9 +24,4 @@ protected function getAlgorithm(): string
2624
{
2725
return 'sha384';
2826
}
29-
30-
protected function getSignatureMethod(): int
31-
{
32-
return JoseRSA::SIGNATURE_PSS;
33-
}
3427
}

src/SignatureAlgorithm/RSA/PS512.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313

1414
namespace Jose\Component\Signature\Algorithm;
1515

16-
use Jose\Component\Signature\Algorithm\Util\RSA as JoseRSA;
17-
18-
final class PS512 extends RSA
16+
final class PS512 extends RSAPSS
1917
{
2018
public function name(): string
2119
{
@@ -26,9 +24,4 @@ protected function getAlgorithm(): string
2624
{
2725
return 'sha512';
2826
}
29-
30-
protected function getSignatureMethod(): int
31-
{
32-
return JoseRSA::SIGNATURE_PSS;
33-
}
3427
}

src/SignatureAlgorithm/RSA/RS256.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313

1414
namespace Jose\Component\Signature\Algorithm;
1515

16-
use Jose\Component\Signature\Algorithm\Util\RSA as JoseRSA;
17-
18-
final class RS256 extends RSA
16+
final class RS256 extends RSAPKCS1
1917
{
2018
public function name(): string
2119
{
@@ -26,9 +24,4 @@ protected function getAlgorithm(): string
2624
{
2725
return 'sha256';
2826
}
29-
30-
protected function getSignatureMethod(): int
31-
{
32-
return JoseRSA::SIGNATURE_PKCS1;
33-
}
3427
}

src/SignatureAlgorithm/RSA/RS384.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313

1414
namespace Jose\Component\Signature\Algorithm;
1515

16-
use Jose\Component\Signature\Algorithm\Util\RSA as JoseRSA;
17-
18-
final class RS384 extends RSA
16+
final class RS384 extends RSAPKCS1
1917
{
2018
public function name(): string
2119
{
@@ -26,9 +24,4 @@ protected function getAlgorithm(): string
2624
{
2725
return 'sha384';
2826
}
29-
30-
protected function getSignatureMethod(): int
31-
{
32-
return JoseRSA::SIGNATURE_PKCS1;
33-
}
3427
}

src/SignatureAlgorithm/RSA/RS512.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313

1414
namespace Jose\Component\Signature\Algorithm;
1515

16-
use Jose\Component\Signature\Algorithm\Util\RSA as JoseRSA;
17-
18-
final class RS512 extends RSA
16+
final class RS512 extends RSAPKCS1
1917
{
2018
public function name(): string
2119
{
@@ -26,9 +24,4 @@ protected function getAlgorithm(): string
2624
{
2725
return 'sha512';
2826
}
29-
30-
protected function getSignatureMethod(): int
31-
{
32-
return JoseRSA::SIGNATURE_PKCS1;
33-
}
3427
}

src/SignatureAlgorithm/RSA/RSA.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
use Jose\Component\Core\Util\RSAKey;
1919
use Jose\Component\Signature\Algorithm\Util\RSA as JoseRSA;
2020

21+
/**
22+
* @deprecated Please use either RSAPSS or RSAPKCS1 depending on the padding mode
23+
*/
2124
abstract class RSA implements SignatureAlgorithm
2225
{
2326
public function allowedKeyTypes(): array
@@ -29,6 +32,9 @@ public function verify(JWK $key, string $input, string $signature): bool
2932
{
3033
$this->checkKey($key);
3134
$pub = RSAKey::createFromJWK($key->toPublic());
35+
if (JoseRSA::SIGNATURE_PKCS1 === $this->getSignatureMethod()) {
36+
return 1 === openssl_verify($input, $signature, $pub->toPEM(), $this->getAlgorithm());
37+
}
3238

3339
return JoseRSA::verify($pub, $input, $signature, $this->getAlgorithm(), $this->getSignatureMethod());
3440
}

0 commit comments

Comments
 (0)