Skip to content

Commit

Permalink
Use JWKS JSON string as Trust Anchor JWKS config
Browse files Browse the repository at this point in the history
  • Loading branch information
cicnavi committed Dec 18, 2024
1 parent e5e6529 commit 33f2081
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 34 deletions.
32 changes: 7 additions & 25 deletions config-templates/module_oidc.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,32 +327,14 @@
ModuleConfig::OPTION_FEDERATION_ENABLED => false,

// Trust Anchors which are valid for this entity. The key represents the Trust Anchor Entity ID, while the value can
// be the Trust Anchor's JWKS array value, or null. If JWKS is provided, it will be used to validate Trust Anchor
// Configuration Statement in addition to using JWKS acquired during Trust Chain resolution. If JWKS is not
// provided (value null), the validity of Trust Anchor Configuration Statement will "only" be validated
// by the JWKS acquired during Trust Chain resolution, meaning that security will rely "only" on
// protection implied from using TLS on endpoints used during Trust Chain resolution.
// be the Trust Anchor's JWKS JSON object string value, or null. If JWKS is provided, it will be used to validate
// Trust Anchor Configuration Statement in addition to using JWKS acquired during Trust Chain resolution. If
// JWKS is not provided (value null), the validity of Trust Anchor Configuration Statement will "only" be
// validated by the JWKS acquired during Trust Chain resolution, meaning that security will rely "only"
// on protection implied from using TLS on endpoints used during Trust Chain resolution.
ModuleConfig::OPTION_FEDERATION_TRUST_ANCHORS => [
// 'https://ta.example.org/' => [
// 'keys' => [
// [
// 'alg' => 'RS256',
// 'use' => 'sig',
// 'kty' => 'RSA',
// 'n' => 'abc...def',
// 'e' => 'AQAB',
// 'kid' => '123',
// ],
// [
// 'alg' => 'RS256',
// 'use' => 'sig',
// 'kty' => 'RSA',
// 'n' => 'ghi...jkl',
// 'e' => 'AQAB',
// 'kid' => '456',
// ],
// ],
// ],
// phpcs:ignore
// 'https://ta.example.org/' => '{"keys":[{"kty": "RSA","alg": "RS256","use": "sig","kid": "Nzb...9Xs","e": "AQAB","n": "pnXB...ub9J"}]}',
// 'https://ta2.example.org/' => null,
],

Expand Down
11 changes: 3 additions & 8 deletions src/ModuleConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
use SimpleSAML\Error\ConfigurationError;
use SimpleSAML\Module\oidc\Bridges\SspBridge;
use SimpleSAML\Module\oidc\Server\Exceptions\OidcServerException;
use SimpleSAML\OpenID\Codebooks\ClaimsEnum;
use SimpleSAML\OpenID\Codebooks\ScopesEnum;

class ModuleConfig
Expand Down Expand Up @@ -650,20 +649,16 @@ public function getFederationTrustAnchorIds(): array
/**
* @throws \SimpleSAML\Error\ConfigurationError
*/
public function getTrustAnchorJwks(string $trustAnchorId): ?array
public function getTrustAnchorJwksJson(string $trustAnchorId): ?string
{
/** @psalm-suppress MixedAssignment */
$jwks = $this->getFederationTrustAnchors()[$trustAnchorId] ?? null;

if ($jwks === null) {
if (is_null($jwks)) {
return null;
}

if (
is_array($jwks) &&
array_key_exists(ClaimsEnum::Keys->value, $jwks) &&
(!empty($jwks[ClaimsEnum::Keys->value]))
) {
if (is_string($jwks)) {
return $jwks;
}

Expand Down
13 changes: 13 additions & 0 deletions src/Server/RequestRules/Rules/ClientIdRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,19 @@ public function checkRule(
);
}

// Validate TA with locally saved JWKS, if available.
$trustAnchorEntityConfiguration = $trustChain->getResolvedTrustAnchor();
$localTrustAnchorJwksJson = $this->moduleConfig
->getTrustAnchorJwksJson($trustAnchorEntityConfiguration->getIssuer());
if (!is_null($localTrustAnchorJwksJson)) {
/** @psalm-suppress MixedArgument */
$localTrustAnchorJwks = $this->federation->helpers()->json()->decode($localTrustAnchorJwksJson);
if (!is_array($localTrustAnchorJwks)) {
throw OidcServerException::serverError('Unexpected JWKS format.');
}
$trustAnchorEntityConfiguration->verifyWithKeySet($localTrustAnchorJwks);
}

$clientFederationEntity = $trustChain->getResolvedLeaf();

if ($clientFederationEntity->getIssuer() !== $clientEntityId) {
Expand Down
2 changes: 1 addition & 1 deletion templates/config/federation.twig
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
{{ 'JWKS'|trans }}:
{% if jwks|default is not empty %}
<code class="code-box code-box-content">
{{- jwks|json_encode(constant('JSON_PRETTY_PRINT')) -}}
{{- jwks -}}
</code>
{% else %}
{{ 'N/A'|trans }}
Expand Down

0 comments on commit 33f2081

Please sign in to comment.