Skip to content

Commit 33f2081

Browse files
committed
Use JWKS JSON string as Trust Anchor JWKS config
1 parent e5e6529 commit 33f2081

File tree

4 files changed

+24
-34
lines changed

4 files changed

+24
-34
lines changed

config-templates/module_oidc.php

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -327,32 +327,14 @@
327327
ModuleConfig::OPTION_FEDERATION_ENABLED => false,
328328

329329
// Trust Anchors which are valid for this entity. The key represents the Trust Anchor Entity ID, while the value can
330-
// be the Trust Anchor's JWKS array value, or null. If JWKS is provided, it will be used to validate Trust Anchor
331-
// Configuration Statement in addition to using JWKS acquired during Trust Chain resolution. If JWKS is not
332-
// provided (value null), the validity of Trust Anchor Configuration Statement will "only" be validated
333-
// by the JWKS acquired during Trust Chain resolution, meaning that security will rely "only" on
334-
// protection implied from using TLS on endpoints used during Trust Chain resolution.
330+
// be the Trust Anchor's JWKS JSON object string value, or null. If JWKS is provided, it will be used to validate
331+
// Trust Anchor Configuration Statement in addition to using JWKS acquired during Trust Chain resolution. If
332+
// JWKS is not provided (value null), the validity of Trust Anchor Configuration Statement will "only" be
333+
// validated by the JWKS acquired during Trust Chain resolution, meaning that security will rely "only"
334+
// on protection implied from using TLS on endpoints used during Trust Chain resolution.
335335
ModuleConfig::OPTION_FEDERATION_TRUST_ANCHORS => [
336-
// 'https://ta.example.org/' => [
337-
// 'keys' => [
338-
// [
339-
// 'alg' => 'RS256',
340-
// 'use' => 'sig',
341-
// 'kty' => 'RSA',
342-
// 'n' => 'abc...def',
343-
// 'e' => 'AQAB',
344-
// 'kid' => '123',
345-
// ],
346-
// [
347-
// 'alg' => 'RS256',
348-
// 'use' => 'sig',
349-
// 'kty' => 'RSA',
350-
// 'n' => 'ghi...jkl',
351-
// 'e' => 'AQAB',
352-
// 'kid' => '456',
353-
// ],
354-
// ],
355-
// ],
336+
// phpcs:ignore
337+
// 'https://ta.example.org/' => '{"keys":[{"kty": "RSA","alg": "RS256","use": "sig","kid": "Nzb...9Xs","e": "AQAB","n": "pnXB...ub9J"}]}',
356338
// 'https://ta2.example.org/' => null,
357339
],
358340

src/ModuleConfig.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
use SimpleSAML\Error\ConfigurationError;
2525
use SimpleSAML\Module\oidc\Bridges\SspBridge;
2626
use SimpleSAML\Module\oidc\Server\Exceptions\OidcServerException;
27-
use SimpleSAML\OpenID\Codebooks\ClaimsEnum;
2827
use SimpleSAML\OpenID\Codebooks\ScopesEnum;
2928

3029
class ModuleConfig
@@ -650,20 +649,16 @@ public function getFederationTrustAnchorIds(): array
650649
/**
651650
* @throws \SimpleSAML\Error\ConfigurationError
652651
*/
653-
public function getTrustAnchorJwks(string $trustAnchorId): ?array
652+
public function getTrustAnchorJwksJson(string $trustAnchorId): ?string
654653
{
655654
/** @psalm-suppress MixedAssignment */
656655
$jwks = $this->getFederationTrustAnchors()[$trustAnchorId] ?? null;
657656

658-
if ($jwks === null) {
657+
if (is_null($jwks)) {
659658
return null;
660659
}
661660

662-
if (
663-
is_array($jwks) &&
664-
array_key_exists(ClaimsEnum::Keys->value, $jwks) &&
665-
(!empty($jwks[ClaimsEnum::Keys->value]))
666-
) {
661+
if (is_string($jwks)) {
667662
return $jwks;
668663
}
669664

src/Server/RequestRules/Rules/ClientIdRule.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,19 @@ public function checkRule(
141141
);
142142
}
143143

144+
// Validate TA with locally saved JWKS, if available.
145+
$trustAnchorEntityConfiguration = $trustChain->getResolvedTrustAnchor();
146+
$localTrustAnchorJwksJson = $this->moduleConfig
147+
->getTrustAnchorJwksJson($trustAnchorEntityConfiguration->getIssuer());
148+
if (!is_null($localTrustAnchorJwksJson)) {
149+
/** @psalm-suppress MixedArgument */
150+
$localTrustAnchorJwks = $this->federation->helpers()->json()->decode($localTrustAnchorJwksJson);
151+
if (!is_array($localTrustAnchorJwks)) {
152+
throw OidcServerException::serverError('Unexpected JWKS format.');
153+
}
154+
$trustAnchorEntityConfiguration->verifyWithKeySet($localTrustAnchorJwks);
155+
}
156+
144157
$clientFederationEntity = $trustChain->getResolvedLeaf();
145158

146159
if ($clientFederationEntity->getIssuer() !== $clientEntityId) {

templates/config/federation.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
{{ 'JWKS'|trans }}:
6565
{% if jwks|default is not empty %}
6666
<code class="code-box code-box-content">
67-
{{- jwks|json_encode(constant('JSON_PRETTY_PRINT')) -}}
67+
{{- jwks -}}
6868
</code>
6969
{% else %}
7070
{{ 'N/A'|trans }}

0 commit comments

Comments
 (0)