Skip to content

Commit fee9631

Browse files
committed
Get rid of old JWKS service
1 parent 6f2c287 commit fee9631

12 files changed

Lines changed: 285 additions & 437 deletions

config/module_oidc.php.dist

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,17 @@ $config = [
4646
* sign ID Token JWT.
4747
*/
4848
// (optional) The private key passphrase.
49+
/** @deprecated */
4950
// ModuleConfig::OPTION_PKI_PRIVATE_KEY_PASSPHRASE => 'secret',
5051
// The certificate and private key filenames, with given defaults.
52+
/** @deprecated */
5153
ModuleConfig::OPTION_PKI_PRIVATE_KEY_FILENAME => ModuleConfig::DEFAULT_PKI_PRIVATE_KEY_FILENAME,
5254
ModuleConfig::OPTION_PKI_CERTIFICATE_FILENAME => ModuleConfig::DEFAULT_PKI_CERTIFICATE_FILENAME,
5355

56+
5457
// Token signer, with given default.
5558
// See Lcobucci\JWT\Signer algorithms in https://github.com/lcobucci/jwt/tree/master/src/Signer
59+
/** @deprecated */
5660
ModuleConfig::OPTION_TOKEN_SIGNER => \Lcobucci\JWT\Signer\Rsa\Sha256::class,
5761
// ModuleConfig::OPTION_TOKEN_SIGNER => \Lcobucci\JWT\Signer\Hmac\Sha256::class,
5862
// ModuleConfig::OPTION_TOKEN_SIGNER => \Lcobucci\JWT\Signer\Ecdsa\Sha256::class,
@@ -65,6 +69,7 @@ $config = [
6569
* PKI options.
6670
*/
6771
// // (optional) The (new) private key passphrase.
72+
/** @deprecated */
6873
// ModuleConfig::OPTION_PKI_NEW_PRIVATE_KEY_PASSPHRASE => 'new-secret',
6974
// ModuleConfig::OPTION_PKI_NEW_PRIVATE_KEY_FILENAME => 'new_oidc_module.key',
7075
// ModuleConfig::OPTION_PKI_NEW_CERTIFICATE_FILENAME => 'new_oidc_module.crt',
@@ -83,7 +88,7 @@ $config = [
8388
* to set other default (first) algorithm as needed.
8489
* You can also use this config option to advertise any (new) keys, for
8590
* example, for key-rollover scenarios. Just add those entries later in
86-
* the list, so they can be published on the OP discovery endpoint.
91+
* the list, so they can be published on the OP JWKS discovery endpoint.
8792
*
8893
* The format is array of associative arrays, where each array value
8994
* consists of the following properties (keys):
@@ -516,6 +521,7 @@ $config = [
516521
// The federation private key passphrase (optional).
517522
// ModuleConfig::OPTION_PKI_FEDERATION_PRIVATE_KEY_PASSPHRASE => 'secret',
518523
// The federation certificate and private key filenames, with given defaults.
524+
/** @deprecated */
519525
ModuleConfig::OPTION_PKI_FEDERATION_PRIVATE_KEY_FILENAME =>
520526
ModuleConfig::DEFAULT_PKI_FEDERATION_PRIVATE_KEY_FILENAME,
521527
ModuleConfig::OPTION_PKI_FEDERATION_CERTIFICATE_FILENAME =>
@@ -526,11 +532,38 @@ $config = [
526532
* on how this works.
527533
*/
528534
// The federation (new) private key passphrase (optional).
535+
/** @deprecated */
529536
// ModuleConfig::OPTION_PKI_FEDERATION_NEW_PRIVATE_KEY_PASSPHRASE => 'new-secret',
530537
// ModuleConfig::OPTION_PKI_FEDERATION_NEW_PRIVATE_KEY_FILENAME => 'new_oidc_module_federation.key',
531538
// ModuleConfig::OPTION_PKI_FEDERATION_NEW_CERTIFICATE_FILENAME => 'new_oidc_module_federation.crt',
532539

540+
/**
541+
* Federation signature algorithm and key-pair definitions, representing
542+
* supported algorithms for signing, for example, Entity Statements.
543+
* The first algorithm in the list will be used for signing (the
544+
* first entry represents default algorithm and signing key).
545+
* You can also use this config option to advertise any (new) keys, for
546+
* example, for key-rollover scenarios. Just add those entries later in
547+
* the list, so they can be published in Federation JWKS.
548+
*
549+
* Note that these keys SHOULD NOT be the same as the ones used in the
550+
* protocol (Connect) itself.
551+
*
552+
* The format is the same as for the protocol (Connect) signature key pairs
553+
* (option ModuleConfig::OPTION_PROTOCOL_SIGNATURE_KEY_PAIRS)
554+
*/
555+
ModuleConfig::OPTION_FEDERATION_SIGNATURE_KEY_PAIRS => [
556+
[
557+
ModuleConfig::KEY_ALGORITHM => \SimpleSAML\OpenID\Algorithms\SignatureAlgorithmEnum::ES256,
558+
ModuleConfig::KEY_PRIVATE_KEY_FILENAME => ModuleConfig::DEFAULT_PKI_FEDERATION_PRIVATE_KEY_FILENAME,
559+
ModuleConfig::KEY_PUBLIC_KEY_FILENAME => ModuleConfig::OPTION_PKI_FEDERATION_CERTIFICATE_FILENAME,
560+
// ModuleConfig::KEY_PRIVATE_KEY_PASSWORD => 'private-key-password', // Optional
561+
// ModuleConfig::KEY_KEY_ID => 'ec-connect-signing-key-01', // Optional
562+
],
563+
],
564+
533565
// Federation token signer, with given default.
566+
/** @deprecated */
534567
ModuleConfig::OPTION_FEDERATION_TOKEN_SIGNER => \Lcobucci\JWT\Signer\Rsa\Sha256::class,
535568

536569
// Federation entity statement duration which determines the Expiration Time (exp) claim set in entity

docker/ssp/module_oidc.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@
2323

2424
ModuleConfig::OPTION_TOKEN_SIGNER => \Lcobucci\JWT\Signer\Rsa\Sha256::class,
2525

26+
ModuleConfig::OPTION_PROTOCOL_SIGNATURE_KEY_PAIRS => [
27+
[
28+
ModuleConfig::KEY_ALGORITHM => \SimpleSAML\OpenID\Algorithms\SignatureAlgorithmEnum::RS256,
29+
ModuleConfig::KEY_PRIVATE_KEY_FILENAME => ModuleConfig::DEFAULT_PKI_PRIVATE_KEY_FILENAME,
30+
ModuleConfig::KEY_PUBLIC_KEY_FILENAME => ModuleConfig::DEFAULT_PKI_CERTIFICATE_FILENAME,
31+
// ModuleConfig::KEY_PRIVATE_KEY_PASSWORD => 'private-key-password', // Optional
32+
// ModuleConfig::KEY_KEY_ID => 'rsa-connect-signing-key-2026', // Optional
33+
],
34+
],
35+
2636
ModuleConfig::OPTION_AUTH_SOURCE => 'example-userpass',
2737

2838
ModuleConfig::OPTION_AUTH_USER_IDENTIFIER_ATTRIBUTE => 'uid',

src/Controllers/Federation/EntityStatementController.php

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use SimpleSAML\Module\oidc\ModuleConfig;
99
use SimpleSAML\Module\oidc\Repositories\ClientRepository;
1010
use SimpleSAML\Module\oidc\Server\Exceptions\OidcServerException;
11-
use SimpleSAML\Module\oidc\Services\JsonWebKeySetService;
1211
use SimpleSAML\Module\oidc\Services\JsonWebTokenBuilderService;
1312
use SimpleSAML\Module\oidc\Services\LoggerService;
1413
use SimpleSAML\Module\oidc\Services\OpMetadataService;
@@ -25,6 +24,7 @@
2524
use SimpleSAML\OpenID\Codebooks\JwtTypesEnum;
2625
use SimpleSAML\OpenID\Federation;
2726
use SimpleSAML\OpenID\Jwk;
27+
use SimpleSAML\OpenID\Jwks;
2828
use Symfony\Component\HttpFoundation\Request;
2929
use Symfony\Component\HttpFoundation\Response;
3030

@@ -37,17 +37,17 @@ class EntityStatementController
3737
* @throws \SimpleSAML\Module\oidc\Server\Exceptions\OidcServerException
3838
*/
3939
public function __construct(
40-
private readonly ModuleConfig $moduleConfig,
41-
private readonly JsonWebTokenBuilderService $jsonWebTokenBuilderService,
42-
private readonly JsonWebKeySetService $jsonWebKeySetService,
43-
private readonly OpMetadataService $opMetadataService,
44-
private readonly ClientRepository $clientRepository,
45-
private readonly Helpers $helpers,
46-
private readonly Routes $routes,
47-
private readonly Federation $federation,
48-
private readonly Jwk $jwk,
49-
private readonly LoggerService $loggerService,
50-
private readonly ?FederationCache $federationCache,
40+
protected readonly ModuleConfig $moduleConfig,
41+
protected readonly JsonWebTokenBuilderService $jsonWebTokenBuilderService,
42+
protected readonly Jwks $jwks,
43+
protected readonly OpMetadataService $opMetadataService,
44+
protected readonly ClientRepository $clientRepository,
45+
protected readonly Helpers $helpers,
46+
protected readonly Routes $routes,
47+
protected readonly Federation $federation,
48+
protected readonly Jwk $jwk,
49+
protected readonly LoggerService $loggerService,
50+
protected readonly ?FederationCache $federationCache,
5151
) {
5252
if (!$this->moduleConfig->getFederationEnabled()) {
5353
throw OidcServerException::forbidden('federation capabilities not enabled');
@@ -82,6 +82,10 @@ public function configuration(): Response
8282
),
8383
];
8484

85+
$jwks = $this->jwks->jwksDecoratorFactory()->fromJwkDecorators(
86+
...$this->moduleConfig->getFederationSignatureKeyPairBag()->getAllPublicKeys(),
87+
)->jsonSerialize();
88+
8589
$payload = [
8690
ClaimsEnum::Iss->value => $this->moduleConfig->getIssuer(),
8791
ClaimsEnum::Iat->value => $currentTimestamp,
@@ -91,7 +95,7 @@ public function configuration(): Response
9195
ClaimsEnum::Exp->value => $this->helpers->dateTime()->getUtc()->add(
9296
$this->moduleConfig->getFederationEntityStatementDuration(),
9397
)->getTimestamp(),
94-
ClaimsEnum::Jwks->value => ['keys' => array_values($this->jsonWebKeySetService->federationKeys()),],
98+
ClaimsEnum::Jwks->value => $jwks,
9599
ClaimsEnum::Metadata->value => [
96100
EntityTypesEnum::FederationEntity->value => [
97101
// Common https://openid.net/specs/openid-federation-1_0.html#name-common-metadata-parameters

src/Controllers/JwksController.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,29 @@
1818

1919
use Laminas\Diactoros\Response\JsonResponse;
2020
use SimpleSAML\Module\oidc\Bridges\PsrHttpBridge;
21-
use SimpleSAML\Module\oidc\Services\JsonWebKeySetService;
21+
use SimpleSAML\Module\oidc\ModuleConfig;
22+
use SimpleSAML\OpenID\Jwks;
2223
use Symfony\Component\HttpFoundation\Response;
2324

2425
class JwksController
2526
{
2627
public function __construct(
27-
private readonly JsonWebKeySetService $jsonWebKeySetService,
28-
private readonly PsrHttpBridge $psrHttpBridge,
28+
protected readonly PsrHttpBridge $psrHttpBridge,
29+
protected readonly ModuleConfig $moduleConfig,
30+
protected readonly Jwks $jwks,
2931
) {
3032
}
3133

34+
/**
35+
* @throws \SimpleSAML\Error\ConfigurationError
36+
*/
3237
public function __invoke(): JsonResponse
3338
{
34-
return new JsonResponse([
35-
'keys' => array_values($this->jsonWebKeySetService->protocolKeys()),
36-
]);
39+
return new JsonResponse(
40+
$this->jwks->jwksDecoratorFactory()->fromJwkDecorators(
41+
...$this->moduleConfig->getProtocolSignatureKeyPairBag()->getAllPublicKeys(),
42+
)->jsonSerialize(),
43+
);
3744
}
3845

3946
public function jwks(): Response

0 commit comments

Comments
 (0)