-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathModuleConfig.php
More file actions
1434 lines (1242 loc) · 50.9 KB
/
Copy pathModuleConfig.php
File metadata and controls
1434 lines (1242 loc) · 50.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
declare(strict_types=1);
/*
* This file is part of the simplesamlphp-module-oidc.
*
* Copyright (C) 2018 by the Spanish Research and Academic Network.
*
* This code was developed by Universidad de Córdoba (UCO https://www.uco.es)
* for the RedIRIS SIR service (SIR: http://www.rediris.es/sir)
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SimpleSAML\Module\oidc;
use DateInterval;
use Defuse\Crypto\Exception\CryptoException;
use Defuse\Crypto\Key;
use SimpleSAML\Configuration;
use SimpleSAML\Error\ConfigurationError;
use SimpleSAML\Module\oidc\Bridges\SspBridge;
use SimpleSAML\Module\oidc\Server\Exceptions\OidcServerException;
use SimpleSAML\OpenID\Algorithms\SignatureAlgorithmBag;
use SimpleSAML\OpenID\Algorithms\SignatureAlgorithmEnum;
use SimpleSAML\OpenID\Codebooks\ClaimsEnum;
use SimpleSAML\OpenID\Codebooks\ResponseModesEnum;
use SimpleSAML\OpenID\Codebooks\ScopesEnum;
use SimpleSAML\OpenID\Codebooks\TrustMarkStatusEndpointUsagePolicyEnum;
use SimpleSAML\OpenID\Serializers\JwsSerializerBag;
use SimpleSAML\OpenID\Serializers\JwsSerializerEnum;
use SimpleSAML\OpenID\SupportedAlgorithms;
use SimpleSAML\OpenID\SupportedSerializers;
use SimpleSAML\OpenID\ValueAbstracts;
use SimpleSAML\OpenID\ValueAbstracts\KeyPairFilenameConfig;
use SimpleSAML\OpenID\ValueAbstracts\SignatureKeyPairBag;
use SimpleSAML\OpenID\ValueAbstracts\SignatureKeyPairConfig;
use SimpleSAML\OpenID\ValueAbstracts\SignatureKeyPairConfigBag;
class ModuleConfig
{
final public const string MODULE_NAME = 'oidc';
protected const string KEY_DESCRIPTION = 'description';
public const string KEY_ALGORITHM = 'algorithm';
public const string KEY_PRIVATE_KEY_FILENAME = 'private_key_filename';
public const string KEY_PUBLIC_KEY_FILENAME = 'public_key_filename';
public const string KEY_PRIVATE_KEY_PASSWORD = 'private_key_password';
public const string KEY_KEY_ID = 'key_id';
final public const string DEFAULT_FILE_NAME = 'module_oidc.php';
final public const string OPTION_PKI_PRIVATE_KEY_PASSPHRASE = 'pass_phrase';
final public const string DEFAULT_PKI_PRIVATE_KEY_FILENAME = 'oidc_module.key';
final public const string DEFAULT_PKI_CERTIFICATE_FILENAME = 'oidc_module.crt';
final public const string OPTION_TOKEN_AUTHORIZATION_CODE_TTL = 'authCodeDuration';
final public const string OPTION_TOKEN_REFRESH_TOKEN_TTL = 'refreshTokenDuration';
final public const string OPTION_TOKEN_ACCESS_TOKEN_TTL = 'accessTokenDuration';
final public const string OPTION_ENCRYPTION_KEY = 'encryption_key';
final public const string OPTION_AUTH_SOURCE = 'auth';
final public const string OPTION_AUTH_USER_IDENTIFIER_ATTRIBUTE = 'useridattr';
final public const string OPTION_AUTH_SAML_TO_OIDC_TRANSLATE_TABLE = 'translate';
final public const string OPTION_AUTH_CUSTOM_SCOPES = 'scopes';
final public const string OPTION_AUTH_ACR_VALUES_SUPPORTED = 'acrValuesSupported';
final public const string OPTION_AUTH_SOURCES_TO_ACR_VALUES_MAP = 'authSourcesToAcrValuesMap';
final public const string OPTION_AUTH_FORCED_ACR_VALUE_FOR_COOKIE_AUTHENTICATION =
'forcedAcrValueForCookieAuthentication';
final public const string OPTION_AUTH_PROCESSING_FILTERS = 'authproc.oidc';
final public const string OPTION_CRON_TAG = 'cron_tag';
final public const string OPTION_ADMIN_UI_PERMISSIONS = 'permissions';
final public const string OPTION_ADMIN_UI_PAGINATION_ITEMS_PER_PAGE = 'items_per_page';
final public const string DEFAULT_PKI_FEDERATION_PRIVATE_KEY_FILENAME = 'oidc_module_federation.key';
final public const string DEFAULT_PKI_FEDERATION_CERTIFICATE_FILENAME = 'oidc_module_federation.crt';
final public const string OPTION_ISSUER = 'issuer';
final public const string OPTION_FEDERATION_ENTITY_STATEMENT_DURATION = 'federation_entity_statement_duration';
final public const string OPTION_FEDERATION_AUTHORITY_HINTS = 'federation_authority_hints';
final public const string OPTION_ORGANIZATION_NAME = 'organization_name';
final public const string OPTION_DISPLAY_NAME = 'display_name';
final public const string OPTION_DESCRIPTION = 'description';
final public const string OPTION_KEYWORDS = 'keywords';
final public const string OPTION_CONTACTS = 'contacts';
final public const string OPTION_LOGO_URI = 'logo_uri';
final public const string OPTION_POLICY_URI = 'policy_uri';
final public const string OPTION_INFORMATION_URI = 'information_uri';
final public const string OPTION_ORGANIZATION_URI = 'organization_uri';
final public const string OPTION_FEDERATION_ENABLED = 'federation_enabled';
final public const string OPTION_FEDERATION_CACHE_ADAPTER = 'federation_cache_adapter';
final public const string OPTION_FEDERATION_CACHE_ADAPTER_ARGUMENTS = 'federation_cache_adapter_arguments';
final public const string OPTION_FEDERATION_CACHE_MAX_DURATION_FOR_FETCHED =
'federation_cache_max_duration_for_fetched';
final public const string OPTION_FEDERATION_TRUST_ANCHORS = 'federation_trust_anchors';
final public const string OPTION_FEDERATION_TRUST_MARK_TOKENS = 'federation_trust_mark_tokens';
final public const string OPTION_FEDERATION_DYNAMIC_TRUST_MARKS = 'federation_dynamic_trust_mark_tokens';
final public const string OPTION_FEDERATION_PARTICIPATION_LIMIT_BY_TRUST_MARKS =
'federation_participation_limit_by_trust_marks';
final public const string OPTION_FEDERATION_TRUST_MARK_STATUS_ENDPOINT_USAGE_POLICY =
'federation_trust_mark_status_endpoint_usage_policy';
final public const string OPTION_FEDERATION_CACHE_DURATION_FOR_PRODUCED = 'federation_cache_duration_for_produced';
final public const string OPTION_PROTOCOL_CACHE_ADAPTER = 'protocol_cache_adapter';
final public const string OPTION_PROTOCOL_CACHE_ADAPTER_ARGUMENTS = 'protocol_cache_adapter_arguments';
final public const string OPTION_PROTOCOL_USER_ENTITY_CACHE_DURATION = 'protocol_user_entity_cache_duration';
final public const string OPTION_PROTOCOL_CLIENT_ENTITY_CACHE_DURATION = 'protocol_client_entity_cache_duration';
final public const string OPTION_PROTOCOL_DISCOVERY_SHOW_CLAIMS_SUPPORTED =
'protocol_discover_show_claims_supported';
final public const string OPTION_VCI_ENABLED = 'vci_enabled';
final public const string OPTION_VCI_CREDENTIAL_CONFIGURATIONS_SUPPORTED =
'vci_credential_configurations_supported';
final public const string OPTION_VCI_USER_ATTRIBUTE_TO_CREDENTIAL_CLAIM_PATH_MAP =
'vci_user_attribute_to_credential_claim_path_map';
final public const string OPTION_API_ENABLED = 'api_enabled';
final public const string OPTION_API_VCI_CREDENTIAL_OFFER_ENDPOINT_ENABLED =
'api_vci_credential_offer_endpoint_enabled';
final public const string OPTION_API_OAUTH2_TOKEN_INTROSPECTION_ENDPOINT_ENABLED =
'api_oauth2_token_introspection_endpoint_enabled';
final public const string OPTION_API_TOKENS = 'api_tokens';
final public const string OPTION_DEFAULT_USERS_EMAIL_ATTRIBUTE_NAME = 'users_email_attribute_name';
final public const string OPTION_AUTH_SOURCES_TO_USERS_EMAIL_ATTRIBUTE_NAME_MAP =
'auth_sources_to_users_email_attribute_name_map';
final public const string OPTION_VCI_ISSUER_STATE_TTL = 'vci_issuer_state_ttl';
final public const string OPTION_VCI_NONCE_TTL = 'vci_nonce_ttl';
final public const string OPTION_VCI_ALLOW_NON_REGISTERED_CLIENTS = 'vci_allow_non_registered_clients';
final public const string OPTION_VCI_ALLOWED_REDIRECT_URI_PREFIXES_FOR_NON_REGISTERED_CLIENTS =
'vci_allowed_redirect_uri_prefixes_for_non_registered_clients';
final public const string OPTION_PROTOCOL_SIGNATURE_KEY_PAIRS = 'protocol_signature_key_pairs';
final public const string OPTION_FEDERATION_SIGNATURE_KEY_PAIRS = 'federation_signature_key_pairs';
final public const string OPTION_TIMESTAMP_VALIDATION_LEEWAY = 'timestamp_validation_leeway';
final public const string OPTION_VCI_SIGNATURE_KEY_PAIRS = 'vci_signature_key_pairs';
final public const string OPTION_VCI_CREDENTIAL_JSON_LD_CONTEXT = 'vci_credential_json_ld_context';
final public const string OPTION_PAR_REQUEST_URI_TTL = 'par_request_uri_ttl';
final public const string OPTION_REQUIRE_PUSHED_AUTHORIZATION_REQUESTS = 'require_pushed_authorization_requests';
final public const string OPTION_REQUIRE_SIGNED_REQUEST_OBJECT = 'require_signed_request_object';
final public const string OPTION_REQUEST_URI_PARAMETER_SUPPORTED = 'request_uri_parameter_supported';
final public const string OPTION_FEDERATION_REQUEST_URI_ALLOWED_PREFIXES =
'federation_request_uri_allowed_prefixes';
final public const string OPTION_REQUEST_URI_FETCH_TIMEOUT = 'request_uri_fetch_timeout';
final public const string OPTION_REQUEST_URI_MAX_SIZE_BYTES = 'request_uri_max_size_bytes';
protected static array $standardScopes = [
ScopesEnum::OpenId->value => [
self::KEY_DESCRIPTION => 'openid',
],
ScopesEnum::OfflineAccess->value => [
self::KEY_DESCRIPTION => 'offline_access',
],
ScopesEnum::Profile->value => [
self::KEY_DESCRIPTION => 'profile',
],
ScopesEnum::Email->value => [
self::KEY_DESCRIPTION => 'email',
],
ScopesEnum::Address->value => [
self::KEY_DESCRIPTION => 'address',
],
ScopesEnum::Phone->value => [
self::KEY_DESCRIPTION => 'phone',
],
];
/**
* @var Configuration Module configuration instance created form module config file.
*/
private readonly Configuration $moduleConfig;
/**
* @var Configuration SimpleSAMLphp configuration instance.
*/
private readonly Configuration $sspConfig;
protected ?SignatureKeyPairBag $protocolSignatureKeyPairBag = null;
protected ?SignatureKeyPairConfigBag $protocolSignatureKeyPairConfigBag = null;
protected ?SignatureKeyPairBag $federationSignatureKeyPairBag = null;
protected ?SignatureKeyPairBag $vciSignatureKeyPairBag = null;
protected ?SignatureKeyPairConfigBag $vciSignatureKeyPairConfigBag = null;
/**
* @throws \Exception
*/
public function __construct(
string $fileName = self::DEFAULT_FILE_NAME, // Primarily used for easy (unit) testing overrides.
array $overrides = [], // Primarily used for easy (unit) testing overrides.
?Configuration $sspConfig = null,
protected readonly SspBridge $sspBridge = new SspBridge(),
protected readonly ValueAbstracts $valueAbstracts = new ValueAbstracts(),
) {
$this->moduleConfig = Configuration::loadFromArray(
array_merge(Configuration::getConfig($fileName)->toArray(), $overrides),
);
$this->sspConfig = $sspConfig ?? Configuration::getInstance();
$this->validate();
}
/**
* @return void
* @throws \Exception
*
* @throws \SimpleSAML\Error\ConfigurationError
*/
private function validate(): void
{
$privateScopes = $this->getPrivateScopes();
array_walk(
$privateScopes,
/**
* @throws \SimpleSAML\Error\ConfigurationError
*/
function (array $scope, string $name): void {
if (in_array($name, array_keys(self::$standardScopes), true)) {
throw new ConfigurationError(
'Can not overwrite protected scope: ' . $name,
self::DEFAULT_FILE_NAME,
);
}
if (!array_key_exists('description', $scope)) {
throw new ConfigurationError(
'Scope [' . $name . '] description not defined',
self::DEFAULT_FILE_NAME,
);
}
},
);
$acrValuesSupported = $this->getAcrValuesSupported();
foreach ($acrValuesSupported as $acrValueSupported) {
if (!is_string($acrValueSupported)) {
throw new ConfigurationError('Config option acrValuesSupported should contain strings only.');
}
}
$authSourcesToAcrValuesMap = $this->getAuthSourcesToAcrValuesMap();
foreach ($authSourcesToAcrValuesMap as $authSource => $acrValues) {
if (!is_string($authSource)) {
throw new ConfigurationError('Config option authSourcesToAcrValuesMap should have string keys ' .
'indicating auth sources.');
}
if (!is_array($acrValues)) {
throw new ConfigurationError('Config option authSourcesToAcrValuesMap should have array ' .
'values containing supported ACRs for each auth source key.');
}
/** @psalm-suppress MixedAssignment */
foreach ($acrValues as $acrValue) {
if (!is_string($acrValue)) {
throw new ConfigurationError('Config option authSourcesToAcrValuesMap should have array ' .
'values with strings only.');
}
if (!in_array($acrValue, $acrValuesSupported, true)) {
throw new ConfigurationError('Config option authSourcesToAcrValuesMap should have ' .
'supported ACR values only.');
}
}
}
$forcedAcrValueForCookieAuthentication = $this->getForcedAcrValueForCookieAuthentication();
if (!is_null($forcedAcrValueForCookieAuthentication)) {
if (!in_array($forcedAcrValueForCookieAuthentication, $acrValuesSupported, true)) {
throw new ConfigurationError('Config option forcedAcrValueForCookieAuthentication should have' .
' null value or string value indicating particular supported ACR.');
}
}
}
public function moduleName(): string
{
return self::MODULE_NAME;
}
/**
* Get SimpleSAMLphp Configuration (config.php) instance.
*/
public function sspConfig(): Configuration
{
return $this->sspConfig;
}
/**
* Get module config Configuration instance.
*/
public function config(): Configuration
{
return $this->moduleConfig;
}
/*****************************************************************************************************************
* OpenID Connect related config.
****************************************************************************************************************/
/**
* @return non-empty-string
* @throws \SimpleSAML\Module\oidc\Server\Exceptions\OidcServerException
*/
public function getIssuer(): string
{
$issuer = $this->config()->getOptionalString(self::OPTION_ISSUER, null) ??
$this->sspBridge->utils()->http()->getSelfURLHost();
if (empty($issuer)) {
throw OidcServerException::serverError('Issuer can not be empty.');
}
return $issuer;
}
public function getAuthCodeDuration(): DateInterval
{
return new DateInterval(
$this->config()->getString(self::OPTION_TOKEN_AUTHORIZATION_CODE_TTL),
);
}
public function getAccessTokenDuration(): DateInterval
{
return new DateInterval(
$this->config()->getString(self::OPTION_TOKEN_ACCESS_TOKEN_TTL),
);
}
public function getRefreshTokenDuration(): DateInterval
{
return new DateInterval(
$this->config()->getString(self::OPTION_TOKEN_REFRESH_TOKEN_TTL),
);
}
public function getParRequestUriTtl(): DateInterval
{
return new DateInterval(
$this->config()->getOptionalString(self::OPTION_PAR_REQUEST_URI_TTL, 'PT10M'),
);
}
public function getRequirePushedAuthorizationRequests(): bool
{
return $this->config()->getOptionalBoolean(self::OPTION_REQUIRE_PUSHED_AUTHORIZATION_REQUESTS, false);
}
public function getRequireSignedRequestObject(): bool
{
return $this->config()->getOptionalBoolean(self::OPTION_REQUIRE_SIGNED_REQUEST_OBJECT, false);
}
/**
* Whether the OP supports passing the Request Object by reference using the https request_uri parameter
* (JWT-Secured Authorization Request by reference / OpenID Federation Authentication Request by reference).
* Note that this does not affect Pushed Authorization Request URIs (urn form), which are always supported.
*/
public function getRequestUriParameterSupported(): bool
{
return $this->config()->getOptionalBoolean(self::OPTION_REQUEST_URI_PARAMETER_SUPPORTED, true);
}
/**
* Allowed https request_uri prefixes for OpenID Federation candidates (clients not registered in storage,
* or registered through OpenID Federation). For such clients the OP must fetch the Request Object before
* it can establish trust, so this is the SSRF / DoS allowlist for that outbound fetch. Registered
* (non-federation) clients are not affected; for them the request_uri must match their registered
* request_uris exactly.
*
* Semantics:
* - null: explicitly allow any request_uri for federation candidates,
* - non-empty array: allow only request_uris starting with one of the given prefixes,
* - empty array (and the default, when the option is not set): deny all federation-candidate fetches.
*
* @return string[]|null
*/
public function getFederationRequestUriAllowedPrefixes(): ?array
{
// Note: we read the raw config here (instead of getOptionalValue) so we can distinguish an explicit
// null (allow any) from an absent option (deny by default), since SimpleSAML\Configuration treats a
// null value the same as an absent one.
$config = $this->config()->toArray();
if (!array_key_exists(self::OPTION_FEDERATION_REQUEST_URI_ALLOWED_PREFIXES, $config)) {
return [];
}
/** @var mixed $value */
$value = $config[self::OPTION_FEDERATION_REQUEST_URI_ALLOWED_PREFIXES];
if (is_null($value)) {
return null;
}
if (!is_array($value)) {
return [];
}
return array_values(array_filter($value, 'is_string'));
}
public function getRequestUriFetchTimeout(): int
{
return $this->config()->getOptionalInteger(self::OPTION_REQUEST_URI_FETCH_TIMEOUT, 5);
}
public function getRequestUriMaxSizeBytes(): int
{
return $this->config()->getOptionalInteger(self::OPTION_REQUEST_URI_MAX_SIZE_BYTES, 102400);
}
/**
* @throws \Exception
*/
public function getDefaultAuthSourceId(): string
{
return $this->config()->getString(self::OPTION_AUTH_SOURCE);
}
/**
* @throws \Exception
*/
public function getUserIdentifierAttribute(): string
{
return $this->config()->getString(ModuleConfig::OPTION_AUTH_USER_IDENTIFIER_ATTRIBUTE);
}
public function getSupportedAlgorithms(): SupportedAlgorithms
{
return new SupportedAlgorithms(
new SignatureAlgorithmBag(
SignatureAlgorithmEnum::RS256,
SignatureAlgorithmEnum::RS384,
SignatureAlgorithmEnum::RS512,
SignatureAlgorithmEnum::ES256,
SignatureAlgorithmEnum::ES384,
SignatureAlgorithmEnum::ES512,
SignatureAlgorithmEnum::PS256,
SignatureAlgorithmEnum::PS384,
SignatureAlgorithmEnum::PS512,
SignatureAlgorithmEnum::EdDSA,
),
);
}
public function getSupportedSerializers(): SupportedSerializers
{
return new SupportedSerializers(
new JwsSerializerBag(
JwsSerializerEnum::Compact,
),
);
}
/**
* @return string[]
*/
public function getSupportedResponseModes(): array
{
return [
ResponseModesEnum::Query->value,
ResponseModesEnum::Fragment->value,
ResponseModesEnum::FormPost->value,
];
}
/**
* @throws ConfigurationError
* @return non-empty-array
*/
public function getProtocolSignatureKeyPairs(): array
{
$signatureKeyPairs = $this->config()->getArray(ModuleConfig::OPTION_PROTOCOL_SIGNATURE_KEY_PAIRS);
if (empty($signatureKeyPairs)) {
throw new ConfigurationError('At least one protocol signature key-pair pair must be provided.');
}
return $signatureKeyPairs;
}
/**
* @throws \SimpleSAML\Error\ConfigurationError
* @psalm-suppress MixedAssignment, ArgumentTypeCoercion
*/
public function getProtocolSignatureKeyPairConfigBag(): SignatureKeyPairConfigBag
{
if ($this->protocolSignatureKeyPairConfigBag instanceof SignatureKeyPairConfigBag) {
return $this->protocolSignatureKeyPairConfigBag;
}
return $this->protocolSignatureKeyPairConfigBag = $this->getSignatureKeyPairConfigBag(
$this->getProtocolSignatureKeyPairs(),
);
}
/**
* @throws \SimpleSAML\Error\ConfigurationError
* @psalm-suppress MixedAssignment, ArgumentTypeCoercion
*/
public function getProtocolSignatureKeyPairBag(): SignatureKeyPairBag
{
if ($this->protocolSignatureKeyPairBag instanceof SignatureKeyPairBag) {
return $this->protocolSignatureKeyPairBag;
}
return $this->protocolSignatureKeyPairBag = $this->valueAbstracts
->signatureKeyPairBagFactory()
->fromConfig($this->getProtocolSignatureKeyPairConfigBag());
}
/**
* Get supported Authentication Context Class References (ACRs).
*
* @return array
* @throws \Exception
*/
public function getAcrValuesSupported(): array
{
return array_values($this->config()->getOptionalArray(self::OPTION_AUTH_ACR_VALUES_SUPPORTED, []));
}
/**
* Get a map of auth sources and their supported ACRs
*
* @return array
* @throws \Exception
*/
public function getAuthSourcesToAcrValuesMap(): array
{
return $this->config()->getOptionalArray(self::OPTION_AUTH_SOURCES_TO_ACR_VALUES_MAP, []);
}
/**
* @return null|string
* @throws \Exception
*/
public function getForcedAcrValueForCookieAuthentication(): ?string
{
/** @psalm-suppress MixedAssignment */
$value = $this->config()
->getOptionalValue(self::OPTION_AUTH_FORCED_ACR_VALUE_FOR_COOKIE_AUTHENTICATION, null);
if (is_null($value)) {
return null;
}
return (string)$value;
}
/**
* @throws \Exception
*/
public function getScopes(): array
{
return array_merge(
self::$standardScopes,
$this->getPrivateScopes(),
// Also include VCI scopes if enabled.
$this->getVciScopes(),
);
}
/**
* @throws \Exception
*/
public function getPrivateScopes(): array
{
return $this->config()->getOptionalArray(self::OPTION_AUTH_CUSTOM_SCOPES, []);
}
/**
* Get the encryption key used to encrypt / decrypt artifacts like
* authorization codes and refresh tokens.
*
* By default (option not set), this returns the SimpleSAMLphp secret salt
* as a string. The underlying League OAuth2 library then derives an
* encryption key from it using a slow, CPU-intensive key derivation
* function (key stretching) on every encrypt / decrypt operation.
*
* If the OPTION_ENCRYPTION_KEY option is set to an ASCII-safe string
* representation of a \Defuse\Crypto\Key, that strong key is used directly,
* which avoids the slow key derivation and is therefore faster. See the
* config template for details on how to generate such a key.
*
* @return \Defuse\Crypto\Key|string
* @throws \SimpleSAML\Error\ConfigurationError
*/
public function getEncryptionKey(): Key|string
{
$encryptionKey = $this->config()->getOptionalString(self::OPTION_ENCRYPTION_KEY, null);
if ($encryptionKey === null || $encryptionKey === '') {
return $this->sspBridge->utils()->config()->getSecretSalt();
}
try {
return Key::loadFromAsciiSafeString($encryptionKey);
} catch (CryptoException $exception) {
throw new ConfigurationError(
sprintf(
'Invalid value for %s. Expected an ASCII-safe string representation of a ' .
'\Defuse\Crypto\Key. Error was: %s',
self::OPTION_ENCRYPTION_KEY,
$exception->getMessage(),
),
);
}
}
/**
* Get autproc filters defined in the OIDC configuration.
*
* @return array
* @throws \Exception
*/
public function getAuthProcFilters(): array
{
return $this->config()->getOptionalArray(self::OPTION_AUTH_PROCESSING_FILTERS, []);
}
public function getProtocolCacheAdapterClass(): ?string
{
return $this->config()->getOptionalString(self::OPTION_PROTOCOL_CACHE_ADAPTER, null);
}
public function getProtocolCacheAdapterArguments(): array
{
return $this->config()->getOptionalArray(self::OPTION_PROTOCOL_CACHE_ADAPTER_ARGUMENTS, []);
}
/**
* Get cache duration for user entities (user data). If not set in configuration, it will fall back to SSP session
* duration.
*
* @throws \Exception
*/
public function getProtocolUserEntityCacheDuration(): DateInterval
{
return new DateInterval(
$this->config()->getOptionalString(
self::OPTION_PROTOCOL_USER_ENTITY_CACHE_DURATION,
null,
) ?? "PT{$this->sspConfig()->getInteger('session.duration')}S",
);
}
/**
* Get cache duration for client entities (user data), with given default
*
* @throws \Exception
*/
public function getProtocolClientEntityCacheDuration(): DateInterval
{
return new DateInterval(
$this->config()->getOptionalString(
self::OPTION_PROTOCOL_CLIENT_ENTITY_CACHE_DURATION,
null,
) ?? 'PT10M',
);
}
public function getProtocolDiscoveryShowClaimsSupported(): bool
{
return $this->config()->getOptionalBoolean(
self::OPTION_PROTOCOL_DISCOVERY_SHOW_CLAIMS_SUPPORTED,
false,
);
}
/*****************************************************************************************************************
* OpenID Federation related config.
****************************************************************************************************************/
public function getFederationEnabled(): bool
{
return $this->config()->getOptionalBoolean(self::OPTION_FEDERATION_ENABLED, false);
}
/**
* @throws \SimpleSAML\Error\ConfigurationError
* @psalm-suppress MixedAssignment, ArgumentTypeCoercion
*/
public function getFederationSignatureKeyPairBag(): SignatureKeyPairBag
{
if ($this->federationSignatureKeyPairBag instanceof SignatureKeyPairBag) {
return $this->federationSignatureKeyPairBag;
}
$signatureKeyPairs = $this->config()->getArray(ModuleConfig::OPTION_FEDERATION_SIGNATURE_KEY_PAIRS);
if (empty($signatureKeyPairs)) {
throw new ConfigurationError('At least one federation signature key-pair pair should be provided.');
}
$signatureKeyPairConfigBag = $this->getSignatureKeyPairConfigBag($signatureKeyPairs);
return $this->federationSignatureKeyPairBag = $this->valueAbstracts
->signatureKeyPairBagFactory()
->fromConfig($signatureKeyPairConfigBag);
}
/**
* @throws \Exception
*/
public function getFederationEntityStatementDuration(): DateInterval
{
return new DateInterval(
$this->config()->getOptionalString(
self::OPTION_FEDERATION_ENTITY_STATEMENT_DURATION,
null,
) ?? 'P1D',
);
}
/**
* @throws \Exception
*/
public function getFederationEntityStatementCacheDurationForProduced(): DateInterval
{
return new DateInterval(
$this->config()->getOptionalString(
self::OPTION_FEDERATION_CACHE_DURATION_FOR_PRODUCED,
null,
) ?? 'PT2M',
);
}
public function getFederationAuthorityHints(): ?array
{
$authorityHints = $this->config()->getOptionalArray(
self::OPTION_FEDERATION_AUTHORITY_HINTS,
null,
);
return empty($authorityHints) ? null : $authorityHints;
}
public function getFederationTrustMarkTokens(): ?array
{
$trustMarks = $this->config()->getOptionalArray(
self::OPTION_FEDERATION_TRUST_MARK_TOKENS,
null,
);
return empty($trustMarks) ? null : $trustMarks;
}
public function getFederationDynamicTrustMarks(): ?array
{
$dynamicTrustMarks = $this->config()->getOptionalArray(
self::OPTION_FEDERATION_DYNAMIC_TRUST_MARKS,
null,
);
return empty($dynamicTrustMarks) ? null : $dynamicTrustMarks;
}
public function getOrganizationName(): ?string
{
return $this->config()->getOptionalString(
self::OPTION_ORGANIZATION_NAME,
null,
);
}
public function getDisplayName(): ?string
{
return $this->config()->getOptionalString(
self::OPTION_DISPLAY_NAME,
null,
);
}
public function getDescription(): ?string
{
return $this->config()->getOptionalString(
self::OPTION_DESCRIPTION,
null,
);
}
/**
* JSON array with one or more strings representing search keywords, tags, categories, or labels that
* apply to this Entity.
*
* @return ?string[]
*/
public function getKeywords(): ?array
{
$keywords = $this->config()->getOptionalArray(
self::OPTION_KEYWORDS,
null,
);
if (is_null($keywords)) {
return null;
}
return array_filter($keywords, fn($keyword) => is_string($keyword));
}
public function getContacts(): ?array
{
return $this->config()->getOptionalArray(
self::OPTION_CONTACTS,
null,
);
}
public function getLogoUri(): ?string
{
return $this->config()->getOptionalString(
self::OPTION_LOGO_URI,
null,
);
}
public function getPolicyUri(): ?string
{
return $this->config()->getOptionalString(
self::OPTION_POLICY_URI,
null,
);
}
public function getInformationUri(): ?string
{
return $this->config()->getOptionalString(
self::OPTION_INFORMATION_URI,
null,
);
}
public function getOrganizationUri(): ?string
{
return $this->config()->getOptionalString(
self::OPTION_ORGANIZATION_URI,
null,
);
}
public function getFederationCacheAdapterClass(): ?string
{
return $this->config()->getOptionalString(self::OPTION_FEDERATION_CACHE_ADAPTER, null);
}
public function getFederationCacheAdapterArguments(): array
{
return $this->config()->getOptionalArray(self::OPTION_FEDERATION_CACHE_ADAPTER_ARGUMENTS, []);
}
public function getFederationCacheMaxDurationForFetched(): DateInterval
{
return new DateInterval(
$this->config()->getOptionalString(self::OPTION_FEDERATION_CACHE_MAX_DURATION_FOR_FETCHED, 'PT6H'),
);
}
/**
* @throws \SimpleSAML\Error\ConfigurationError
*/
public function getFederationTrustAnchors(): array
{
$trustAnchors = $this->config()->getOptionalArray(self::OPTION_FEDERATION_TRUST_ANCHORS, []);
if (empty($trustAnchors) && $this->getFederationEnabled()) {
throw new ConfigurationError('No Trust Anchors have been configured.');
}
return $trustAnchors;
}
/**
* @return non-empty-array<array-key, non-empty-string>
* @psalm-suppress LessSpecificReturnStatement, MoreSpecificReturnType
* @throws \SimpleSAML\Error\ConfigurationError
*/
public function getFederationTrustAnchorIds(): array
{
return array_map('strval', array_keys($this->getFederationTrustAnchors()));
}
/**
* @throws \SimpleSAML\Error\ConfigurationError
*/
public function getTrustAnchorJwksJson(string $trustAnchorId): ?string
{
/** @psalm-suppress MixedAssignment */
$jwks = $this->getFederationTrustAnchors()[$trustAnchorId] ?? null;
if (is_null($jwks)) {
return null;
}
if (is_string($jwks)) {
return $jwks;
}
throw new ConfigurationError(
sprintf('Unexpected JWKS format for Trust Anchor %s: %s', $trustAnchorId, var_export($jwks, true)),
);
}
public function getFederationParticipationLimitByTrustMarks(): array
{
return $this->config()->getOptionalArray(
self::OPTION_FEDERATION_PARTICIPATION_LIMIT_BY_TRUST_MARKS,
[],
);
}
public function getFederationTrustMarkStatusEndpointUsagePolicy(): TrustMarkStatusEndpointUsagePolicyEnum
{
/** @psalm-suppress MixedAssignment */
$policy = $this->config()->getOptionalValue(
self::OPTION_FEDERATION_TRUST_MARK_STATUS_ENDPOINT_USAGE_POLICY,
null,
);
if ($policy instanceof TrustMarkStatusEndpointUsagePolicyEnum) {
return $policy;
}
return TrustMarkStatusEndpointUsagePolicyEnum::RequiredIfEndpointProvidedForNonExpiringTrustMarksOnly;
}
/**
* @throws \SimpleSAML\Error\ConfigurationError
*/
public function getTrustMarksNeededForFederationParticipationFor(string $trustAnchorId): array
{
$participationLimit = $this->getFederationParticipationLimitByTrustMarks()[$trustAnchorId] ?? [];
if (!is_array($participationLimit)) {
throw new ConfigurationError('Invalid configuration for federation participation limit.');
}
return $participationLimit;
}
/**
* @throws \SimpleSAML\Error\ConfigurationError
*/
public function isFederationParticipationLimitedByTrustMarksFor(string $trustAnchorId): bool
{
return !empty($this->getTrustMarksNeededForFederationParticipationFor($trustAnchorId));
}
/*****************************************************************************************************************
* OpenID Verifiable Credential Issuance related config.
****************************************************************************************************************/
public function getVciEnabled(): bool
{
return $this->config()->getOptionalBoolean(self::OPTION_VCI_ENABLED, false);
}
/**
* @throws ConfigurationError
* @return non-empty-array
*/
public function getVciSignatureKeyPairs(): array
{
$signatureKeyPairs = $this->config()->getArray(ModuleConfig::OPTION_VCI_SIGNATURE_KEY_PAIRS);
if (empty($signatureKeyPairs)) {
throw new ConfigurationError('At least one VCI signature key-pair pair must be provided.');
}
return $signatureKeyPairs;
}
/**
* @throws \SimpleSAML\Error\ConfigurationError
* @psalm-suppress MixedAssignment, ArgumentTypeCoercion
*/
public function getVciSignatureKeyPairConfigBag(): SignatureKeyPairConfigBag
{
if ($this->vciSignatureKeyPairConfigBag instanceof SignatureKeyPairConfigBag) {
return $this->vciSignatureKeyPairConfigBag;
}
return $this->vciSignatureKeyPairConfigBag = $this->getSignatureKeyPairConfigBag(
$this->getVciSignatureKeyPairs(),
);
}
/**
* @throws \SimpleSAML\Error\ConfigurationError
* @psalm-suppress MixedAssignment, ArgumentTypeCoercion
*/
public function getVciSignatureKeyPairBag(): SignatureKeyPairBag
{
if ($this->vciSignatureKeyPairBag instanceof SignatureKeyPairBag) {
return $this->vciSignatureKeyPairBag;
}
return $this->vciSignatureKeyPairBag = $this->valueAbstracts
->signatureKeyPairBagFactory()
->fromConfig($this->getVciSignatureKeyPairConfigBag());
}
public function getVciCredentialConfigurationsSupported(): array
{