|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace SimpleSAML\SAML2\Metadata; |
| 6 | + |
| 7 | +use SimpleSAML\Assert\Assert; |
| 8 | +use SimpleSAML\XMLSecurity\Alg\Encryption\EncryptionAlgorithmFactory; |
| 9 | +use SimpleSAML\XMLSecurity\Alg\KeyTransport\KeyTransportAlgorithmFactory; |
| 10 | +use SimpleSAML\XMLSecurity\Alg\Signature\SignatureAlgorithmFactory; |
| 11 | +use SimpleSAML\XMLSecurity\Key\{PrivateKey, PublicKey, SymmetricKey}; |
| 12 | + |
| 13 | +/** |
| 14 | + * Class holding common configuration for SAML2 entities. |
| 15 | + * |
| 16 | + * @package simplesamlphp/saml2 |
| 17 | + */ |
| 18 | +abstract class AbstractProvider |
| 19 | +{ |
| 20 | + /** |
| 21 | + */ |
| 22 | + protected function __construct( |
| 23 | + protected string $entityId, |
| 24 | + protected EncryptionAlgorithmFactory|KeyTransportAlgorithmFactory|null $encryptionAlgorithmFactory, |
| 25 | + protected SignatureAlgorithmFactory|null $signatureAlgorithmFactory, |
| 26 | + protected string $signatureAlgorithm, |
| 27 | + protected array $validatingKeys, |
| 28 | + protected PrivateKey|null $signingKey, |
| 29 | + protected PublicKey|SymmetricKey|null $encryptionKey, |
| 30 | + protected array $decryptionKeys, |
| 31 | + protected array $IDPList, |
| 32 | + ) { |
| 33 | + Assert::validURI($entityId); |
| 34 | + Assert::validURI($signatureAlgorithm); |
| 35 | + Assert::allIsInstanceOfAny($decryptionKeys, [SymmetricKey::class, PrivateKey::class]); |
| 36 | + Assert::allIsInstanceOf($validatingKeys, PublicKey::class); |
| 37 | + Assert::allValidURI($IDPList); |
| 38 | + } |
| 39 | + |
| 40 | + |
| 41 | + /** |
| 42 | + * Retrieve the SignatureAlgorithmFactory used for signing and verifying messages. |
| 43 | + */ |
| 44 | + public function getSignatureAlgorithmFactory(): ?SignatureAlgorithmFactory |
| 45 | + { |
| 46 | + return $this->signatureAlgorithmFactory; |
| 47 | + } |
| 48 | + |
| 49 | + |
| 50 | + /** |
| 51 | + * Retrieve the EncryptionAlgorithmFactory used for encrypting and decrypting messages. |
| 52 | + */ |
| 53 | + public function getEncryptionAlgorithmFactory(): EncryptionAlgorithmFactory|KeyTransportAlgorithmFactory|null |
| 54 | + { |
| 55 | + return $this->encryptionAlgorithmFactory; |
| 56 | + } |
| 57 | + |
| 58 | + |
| 59 | + /** |
| 60 | + * Retrieve the signature slgorithm to be used for signing messages. |
| 61 | + */ |
| 62 | + public function getSignatureAlgorithm(): string |
| 63 | + { |
| 64 | + return $this->signatureAlgorithm; |
| 65 | + } |
| 66 | + |
| 67 | + |
| 68 | + /** |
| 69 | + * Get the private key to use for signing messages. |
| 70 | + * |
| 71 | + * @return \SimpleSAML\XMLSecurity\Key\PrivateKey|null |
| 72 | + */ |
| 73 | + public function getSigningKey(): ?PrivateKey |
| 74 | + { |
| 75 | + return $this->signingKey; |
| 76 | + } |
| 77 | + |
| 78 | + |
| 79 | + /** |
| 80 | + * Get the validating keys to verify a message signature with. |
| 81 | + * |
| 82 | + * @return array<\SimpleSAML\XMLSecurity\Key\PublicKey> |
| 83 | + */ |
| 84 | + public function getValidatingKeys(): array |
| 85 | + { |
| 86 | + return $this->validatingKeys; |
| 87 | + } |
| 88 | + |
| 89 | + |
| 90 | + /** |
| 91 | + * Get the private key to use for signing messages. |
| 92 | + * |
| 93 | + * @return \SimpleSAML\XMLSecurity\Key\PublicKey|\SimpleSAML\XMLSecurity\Key\SymmetricKey|null |
| 94 | + */ |
| 95 | + public function getEncryptionKey(): PublicKey|SymmetricKey|null |
| 96 | + { |
| 97 | + return $this->encryptionKey; |
| 98 | + } |
| 99 | + |
| 100 | + |
| 101 | + /** |
| 102 | + * Get the decryption keys to decrypt the assertion with. |
| 103 | + * |
| 104 | + * @return array<\SimpleSAML\XMLSecurity\Key\PrivateKey|\SimpleSAML\XMLSecurity\Key\SymmetricKey> |
| 105 | + */ |
| 106 | + public function getDecryptionKeys(): array |
| 107 | + { |
| 108 | + return $this->decryptionKeys; |
| 109 | + } |
| 110 | + |
| 111 | + |
| 112 | + /** |
| 113 | + * Retrieve the configured entity ID for this entity |
| 114 | + */ |
| 115 | + public function getEntityId(): string |
| 116 | + { |
| 117 | + return $this->entityId; |
| 118 | + } |
| 119 | + |
| 120 | + |
| 121 | + /** |
| 122 | + * Retrieve the configured IDPList for this entity. |
| 123 | + * |
| 124 | + * @return string[] |
| 125 | + */ |
| 126 | + public function getIDPList(): array |
| 127 | + { |
| 128 | + return $this->IDPList; |
| 129 | + } |
| 130 | +} |
0 commit comments