1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Facile\OpenIDClient\ConformanceTest\RpTest\KeyRotation; |
6
|
|
|
|
7
|
|
|
use Jose\Component\Core\JWK; |
8
|
|
|
use Jose\Component\Core\JWKSet; |
9
|
|
|
use Jose\Component\KeyManagement\JWKFactory; |
10
|
|
|
use PHPUnit\Framework\Assert; |
11
|
|
|
use Facile\OpenIDClient\ConformanceTest\RpTest\AbstractRpTest; |
12
|
|
|
use Facile\OpenIDClient\ConformanceTest\TestInfo; |
13
|
|
|
use Facile\OpenIDClient\Session\AuthSession; |
14
|
|
|
use Facile\OpenIDClient\RequestObject\RequestObjectFactory; |
15
|
|
|
use Facile\OpenIDClient\Service\AuthorizationService; |
16
|
|
|
use function Facile\OpenIDClient\base64url_encode; |
17
|
|
|
use function json_decode; |
18
|
|
|
use function json_encode; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Fetch the issuer's keys from the 'jwks_uri' and make an encrypted authentication request using the issuer's |
22
|
|
|
* encryption keys. |
23
|
|
|
* Fetch the issuer's keys from the jwks_uri again, and make a new encrypted request using the rotated encryption keys. |
24
|
|
|
* |
25
|
|
|
* A successful authentication response to both authentication requests encrypted using rotated encryption keys. |
26
|
|
|
*/ |
27
|
|
|
class RPKeyRotationOPEncKeyTest extends AbstractRpTest |
28
|
|
|
{ |
29
|
|
|
|
30
|
|
|
public function getTestId(): string |
31
|
|
|
{ |
32
|
|
|
return 'rp-key-rotation-op-enc-key'; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function execute(TestInfo $testInfo): void |
36
|
|
|
{ |
37
|
|
|
$jwkSig = JWKFactory::createRSAKey(2048, ['alg' => 'RS256', 'use' => 'sig']); |
38
|
|
|
$jwkEncAlg = JWKFactory::createRSAKey(2048, ['alg' => 'RSA-OAEP', 'use' => 'enc']); |
39
|
|
|
|
40
|
|
|
$jwks = new JWKSet([$jwkSig, $jwkEncAlg]); |
41
|
|
|
$publicJwks = new JWKSet(\array_map(static function (JWK $jwk) { |
42
|
|
|
return $jwk->toPublic(); |
43
|
|
|
}, $jwks->all())); |
44
|
|
|
|
45
|
|
|
$client = $this->registerClient($testInfo, [ |
46
|
|
|
'request_object_signing_alg' => 'RS256', |
47
|
|
|
'request_object_encryption_alg' => 'RSA-OAEP', |
48
|
|
|
'request_object_encryption_enc' => 'A128CBC-HS256', |
49
|
|
|
'jwks' => json_decode(json_encode($publicJwks), true), |
50
|
|
|
], $jwks); |
51
|
|
|
|
52
|
|
|
Assert::assertSame('RS256', $client->getMetadata()->get('request_object_signing_alg')); |
53
|
|
|
Assert::assertSame('RSA-OAEP', $client->getMetadata()->get('request_object_encryption_alg')); |
54
|
|
|
Assert::assertSame('A128CBC-HS256', $client->getMetadata()->get('request_object_encryption_enc')); |
55
|
|
|
|
56
|
|
|
// Get authorization redirect uri |
57
|
|
|
$requestObjectFactory = new RequestObjectFactory(); |
58
|
|
|
$authorizationService = new AuthorizationService(); |
|
|
|
|
59
|
|
|
|
60
|
|
|
$authSession = AuthSession::fromArray([ |
61
|
|
|
'state' => base64url_encode(\random_bytes(32)), |
62
|
|
|
'nonce' => base64url_encode(\random_bytes(32)), |
63
|
|
|
]); |
64
|
|
|
$uri = $authorizationService->getAuthorizationUri($client, [ |
65
|
|
|
'request' => $requestObjectFactory->create($client), |
66
|
|
|
'state' => $authSession->getState(), |
67
|
|
|
'nonce' => $authSession->getNonce(), |
68
|
|
|
]); |
69
|
|
|
|
70
|
|
|
// Simulate a redirect and create the server request |
71
|
|
|
$serverRequest = $this->simulateAuthRedirect($uri, 'application/jwt'); |
72
|
|
|
|
73
|
|
|
$params = $authorizationService->getCallbackParams($serverRequest, $client); |
74
|
|
|
$tokenSet = $authorizationService->callback($client, $params, null, $authSession); |
75
|
|
|
|
76
|
|
|
Assert::assertNotNull($tokenSet->getState()); |
77
|
|
|
|
78
|
|
|
// update issuer JWKSet |
79
|
|
|
$client->getIssuer()->getJwksProvider()->reload(); |
80
|
|
|
|
81
|
|
|
$uri = $authorizationService->getAuthorizationUri($client, [ |
82
|
|
|
'request' => $requestObjectFactory->create($client), |
83
|
|
|
'state' => $authSession->getState(), |
84
|
|
|
'nonce' => $authSession->getNonce(), |
85
|
|
|
]); |
86
|
|
|
|
87
|
|
|
// Simulate a redirect and create the server request |
88
|
|
|
$serverRequest = $this->simulateAuthRedirect($uri); |
89
|
|
|
|
90
|
|
|
$params = $authorizationService->getCallbackParams($serverRequest, $client); |
91
|
|
|
$tokenSet = $authorizationService->callback($client, $params, null, $authSession); |
92
|
|
|
|
93
|
|
|
Assert::assertNotNull($tokenSet->getIdToken()); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.