|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace SimpleSAML\OpenID\ValueAbstracts; |
| 6 | + |
| 7 | +use SimpleSAML\OpenID\Codebooks\ClaimsEnum; |
| 8 | +use SimpleSAML\OpenID\Exceptions\JwksException; |
| 9 | + |
| 10 | +class TrustAnchorConfig |
| 11 | +{ |
| 12 | + /** |
| 13 | + * @param non-empty-string $entityId Trust Anchor Entity ID |
| 14 | + * @param string|null $jwks Trust Anchor's JWKS JSON object string value, or |
| 15 | + * null. If JWKS is provided, it can be used to validate Trust Anchor |
| 16 | + * Configuration Statement in addition to using JWKS acquired during Trust |
| 17 | + * Chain resolution. If JWKS is not provided, the validity of Trust Anchor |
| 18 | + * Configuration Statement will "only" be validated by the JWKS acquired |
| 19 | + * during Trust Chain resolution. This means that security will rely "only" |
| 20 | + * on protection implied from using TLS on endpoints used during |
| 21 | + * Trust Chain resolution. |
| 22 | + */ |
| 23 | + public function __construct( |
| 24 | + protected readonly string $entityId, |
| 25 | + protected readonly ?string $jwks = null, |
| 26 | + ) { |
| 27 | + } |
| 28 | + |
| 29 | + |
| 30 | + /** |
| 31 | + * @return non-empty-string |
| 32 | + */ |
| 33 | + public function getEntityId(): string |
| 34 | + { |
| 35 | + return $this->entityId; |
| 36 | + } |
| 37 | + |
| 38 | + |
| 39 | + public function getJwks(): ?string |
| 40 | + { |
| 41 | + return $this->jwks; |
| 42 | + } |
| 43 | + |
| 44 | + |
| 45 | + /** |
| 46 | + * @return array{keys:non-empty-array<mixed>}|null |
| 47 | + * @throws \SimpleSAML\OpenID\Exceptions\JwksException |
| 48 | + */ |
| 49 | + public function getJwksAsArray(): ?array |
| 50 | + { |
| 51 | + if (is_string($this->jwks)) { |
| 52 | + $jwks = json_decode($this->jwks, true); |
| 53 | + |
| 54 | + if ( |
| 55 | + is_array($jwks) && |
| 56 | + array_key_exists(ClaimsEnum::Keys->value, $jwks) && |
| 57 | + is_array($jwks[ClaimsEnum::Keys->value]) && |
| 58 | + $jwks[ClaimsEnum::Keys->value] !== [] |
| 59 | + ) { |
| 60 | + return $jwks; |
| 61 | + } |
| 62 | + |
| 63 | + throw new JwksException('Invalid JWKS JSON object.'); |
| 64 | + } |
| 65 | + |
| 66 | + return null; |
| 67 | + } |
| 68 | +} |
0 commit comments