88use SimpleSAML \Module \oidc \ModuleConfig ;
99use SimpleSAML \Module \oidc \Repositories \ClientRepository ;
1010use SimpleSAML \Module \oidc \Server \Exceptions \OidcServerException ;
11- use SimpleSAML \Module \oidc \Services \JsonWebTokenBuilderService ;
1211use SimpleSAML \Module \oidc \Services \LoggerService ;
1312use SimpleSAML \Module \oidc \Services \OpMetadataService ;
1413use SimpleSAML \Module \oidc \Utils \FederationCache ;
15- use SimpleSAML \Module \oidc \Utils \FingerprintGenerator ;
1614use SimpleSAML \Module \oidc \Utils \Routes ;
17- use SimpleSAML \OpenID \Algorithms \SignatureAlgorithmEnum ;
1815use SimpleSAML \OpenID \Codebooks \ClaimsEnum ;
1916use SimpleSAML \OpenID \Codebooks \ClientRegistrationTypesEnum ;
2017use SimpleSAML \OpenID \Codebooks \ContentTypesEnum ;
2118use SimpleSAML \OpenID \Codebooks \EntityTypesEnum ;
2219use SimpleSAML \OpenID \Codebooks \ErrorsEnum ;
2320use SimpleSAML \OpenID \Codebooks \HttpHeadersEnum ;
24- use SimpleSAML \OpenID \Codebooks \JwtTypesEnum ;
2521use SimpleSAML \OpenID \Federation ;
26- use SimpleSAML \OpenID \Jwk ;
2722use SimpleSAML \OpenID \Jwks ;
2823use Symfony \Component \HttpFoundation \Request ;
2924use Symfony \Component \HttpFoundation \Response ;
@@ -38,14 +33,12 @@ class EntityStatementController
3833 */
3934 public function __construct (
4035 protected readonly ModuleConfig $ moduleConfig ,
41- protected readonly JsonWebTokenBuilderService $ jsonWebTokenBuilderService ,
4236 protected readonly Jwks $ jwks ,
4337 protected readonly OpMetadataService $ opMetadataService ,
4438 protected readonly ClientRepository $ clientRepository ,
4539 protected readonly Helpers $ helpers ,
4640 protected readonly Routes $ routes ,
4741 protected readonly Federation $ federation ,
48- protected readonly Jwk $ jwk ,
4942 protected readonly LoggerService $ loggerService ,
5043 protected readonly ?FederationCache $ federationCache ,
5144 ) {
@@ -76,20 +69,14 @@ public function configuration(): Response
7669
7770 $ currentTimestamp = $ this ->helpers ->dateTime ()->getUtc ()->getTimestamp ();
7871
79- $ header = [
80- ClaimsEnum::Kid->value => FingerprintGenerator::forFile (
81- $ this ->moduleConfig ->getFederationCertPath (),
82- ),
83- ];
84-
8572 $ jwks = $ this ->jwks ->jwksDecoratorFactory ()->fromJwkDecorators (
8673 ...$ this ->moduleConfig ->getFederationSignatureKeyPairBag ()->getAllPublicKeys (),
8774 )->jsonSerialize ();
8875
8976 $ payload = [
9077 ClaimsEnum::Iss->value => $ this ->moduleConfig ->getIssuer (),
9178 ClaimsEnum::Iat->value => $ currentTimestamp ,
92- ClaimsEnum::Jti->value => $ this ->helpers ->random ()->getIdentifier (),
79+ ClaimsEnum::Jti->value => $ this ->federation -> helpers () ->random ()->string (),
9380 // This is entity configuration (statement about itself).
9481 ClaimsEnum::Sub->value => $ this ->moduleConfig ->getIssuer (),
9582 ClaimsEnum::Exp->value => $ this ->helpers ->dateTime ()->getUtc ()->add (
@@ -211,16 +198,21 @@ public function configuration(): Response
211198 // Remaining claims, add if / when ready.
212199 // * crit
213200
201+ $ signingKeyPair = $ this ->moduleConfig
202+ ->getFederationSignatureKeyPairBag ()
203+ ->getFirstOrFail ();
204+
205+ $ header = [
206+ ClaimsEnum::Kid->value => $ signingKeyPair ->getKeyPair ()->getKeyId (),
207+ ];
208+
214209 /** @psalm-suppress ArgumentTypeCoercion */
215210 $ entityConfigurationToken = $ this ->federation ->entityStatementFactory ()->fromData (
216- $ this ->jwk ->jwkDecoratorFactory ()->fromPkcs1Or8KeyFile (
217- $ this ->moduleConfig ->getFederationPrivateKeyPath (),
218- ),
219- SignatureAlgorithmEnum::from ($ this ->moduleConfig ->getFederationSigner ()->algorithmId ()),
211+ $ signingKeyPair ->getKeyPair ()->getPrivateKey (),
212+ $ signingKeyPair ->getSignatureAlgorithm (),
220213 $ payload ,
221214 $ header ,
222- )
223- ->getToken ();
215+ )->getToken ();
224216
225217 $ this ->federationCache ?->set(
226218 $ entityConfigurationToken ,
@@ -274,47 +266,60 @@ public function fetch(Request $request): Response
274266 );
275267 }
276268
277- $ builder = $ this ->jsonWebTokenBuilderService -> getFederationJwtBuilder ()
278- -> withHeader (ClaimsEnum::Typ-> value , JwtTypesEnum::EntityStatementJwt-> value )
279- -> relatedTo ( $ subject )
280- -> expiresAt (
281- $ this -> helpers -> dateTime ()-> getUtc ()-> add ( $ this -> moduleConfig -> getFederationEntityStatementDuration ()) ,
282- )->withClaim (
283- ClaimsEnum::Jwks-> value ,
284- $ jwks ,
285- )
286- -> withClaim (
287- ClaimsEnum::Metadata-> value ,
288- [
289- EntityTypesEnum::OpenIdRelyingParty ->value => [
290- ClaimsEnum::ClientName ->value => $ client -> getName (),
291- ClaimsEnum::ClientId ->value => $ client ->getIdentifier (),
292- ClaimsEnum::RedirectUris ->value => $ client ->getRedirectUris (),
293- ClaimsEnum::Scope ->value => implode ( ' ' , $ client ->getScopes () ),
294- ClaimsEnum::ClientRegistrationTypes ->value => $ client ->getClientRegistrationTypes ( ),
295- // Optional claims...
296- ...( array_filter (
297- [
298- ClaimsEnum::BackChannelLogoutUri-> value => $ client -> getBackChannelLogoutUri (),
299- ClaimsEnum::PostLogoutRedirectUris ->value => $ client ->getPostLogoutRedirectUri (),
300- ] ,
301- )) ,
302- // TODO v7 mivanci Continue
303- // https://openid.net/specs/openid-connect-registration-1_0.html#ClientMetadata
304- // https://www.iana.org/assignments/oauth-parameters/oauth-parameters.xhtml#client-metadata
305- ],
269+ $ currentTimestamp = $ this ->helpers -> dateTime ()-> getUtc ()-> getTimestamp ();
270+
271+ $ payload = [
272+ ClaimsEnum::Iss-> value => $ this -> moduleConfig -> getIssuer (),
273+ ClaimsEnum::Iat-> value => $ currentTimestamp ,
274+ ClaimsEnum::Jti-> value => $ this -> helpers -> random ( )->getIdentifier (),
275+
276+ ClaimsEnum::Sub-> value => $ subject ,
277+ ClaimsEnum::Exp-> value => $ this -> helpers -> dateTime ()-> getUtc ()-> add (
278+ $ this -> moduleConfig -> getFederationEntityStatementDuration (),
279+ )-> getTimestamp () ,
280+ ClaimsEnum::Jwks-> value => $ jwks ,
281+ ClaimsEnum::Metadata ->value => [
282+ EntityTypesEnum::OpenIdRelyingParty ->value => [
283+ ClaimsEnum::ClientName ->value => $ client ->getName (),
284+ ClaimsEnum::ClientId ->value => $ client ->getIdentifier (),
285+ ClaimsEnum::RedirectUris ->value => $ client ->getRedirectUris ( ),
286+ ClaimsEnum::Scope ->value => implode ( ' ' , $ client ->getScopes () ),
287+ ClaimsEnum::ClientRegistrationTypes-> value => $ client -> getClientRegistrationTypes (),
288+ // Optional claims ...
289+ ...( array_filter (
290+ [
291+ ClaimsEnum::BackChannelLogoutUri ->value => $ client ->getBackChannelLogoutUri (),
292+ ClaimsEnum::PostLogoutRedirectUris-> value => $ client -> getPostLogoutRedirectUri () ,
293+ ] ,
294+ )),
295+ // TODO v7 mivanci Continue
296+ // https://openid.net/specs/openid-connect-registration-1_0.html#ClientMetadata
297+ // https://www.iana.org/assignments/oauth-parameters/oauth-parameters.xhtml#client-metadata
306298 ],
307- );
299+ ],
300+ ];
308301
309302 // TODO v7 mivanci Continue
310303 // Note: claims which can be present in subordinate statements:
311304 // * metadata_policy
312305 // * constraints
313306 // * metadata_policy_crit
314307
315- $ jws = $ this ->jsonWebTokenBuilderService ->getSignedFederationJwt ($ builder );
308+ $ signingKeyPair = $ this ->moduleConfig
309+ ->getFederationSignatureKeyPairBag ()
310+ ->getFirstOrFail ();
311+
312+
313+ $ header = [
314+ ClaimsEnum::Kid->value => $ signingKeyPair ->getKeyPair ()->getKeyId (),
315+ ];
316316
317- $ subordinateStatementToken = $ jws ->toString ();
317+ $ subordinateStatementToken = $ this ->federation ->entityStatementFactory ()->fromData (
318+ $ signingKeyPair ->getKeyPair ()->getPrivateKey (),
319+ $ signingKeyPair ->getSignatureAlgorithm (),
320+ $ payload ,
321+ $ header ,
322+ )->getToken ();
318323
319324 $ this ->federationCache ?->set(
320325 $ subordinateStatementToken ,
0 commit comments