1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\SAML2\Configuration; |
6
|
|
|
|
7
|
|
|
use RuntimeException; |
8
|
|
|
|
9
|
|
|
use function array_filter; |
10
|
|
|
use function array_pop; |
11
|
|
|
use function count; |
12
|
|
|
use function sprintf; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Basic configuration wrapper |
16
|
|
|
*/ |
17
|
|
|
final class IdentityProvider extends ArrayAdapter implements CertificateProvider, DecryptionProvider, EntityIdProvider |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @return array|\Traversable|null |
21
|
|
|
*/ |
22
|
|
|
public function getKeys() |
23
|
|
|
{ |
24
|
|
|
return $this->get('keys'); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @return string|null |
30
|
|
|
*/ |
31
|
|
|
public function getCertificateData(): ?string |
32
|
|
|
{ |
33
|
|
|
return $this->get('certificateData'); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @return string|null |
39
|
|
|
*/ |
40
|
|
|
public function getCertificateFile(): ?string |
41
|
|
|
{ |
42
|
|
|
return $this->get('certificateFile'); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @return array|mixed|\Traversable|null |
48
|
|
|
*/ |
49
|
|
|
public function getCertificateFingerprints() |
50
|
|
|
{ |
51
|
|
|
return $this->get('certificateFingerprints'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @return bool|null |
57
|
|
|
*/ |
58
|
|
|
public function isAssertionEncryptionRequired(): ?bool |
59
|
|
|
{ |
60
|
|
|
return $this->get('assertionEncryptionEnabled'); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return string|null |
66
|
|
|
*/ |
67
|
|
|
public function getSharedKey(): ?string |
68
|
|
|
{ |
69
|
|
|
return $this->get('sharedKey'); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @param string $name |
74
|
|
|
* @param bool $required |
75
|
|
|
* @return mixed|null |
76
|
|
|
*/ |
77
|
|
|
public function getPrivateKey(string $name, bool $required = null) |
78
|
|
|
{ |
79
|
|
|
if ($required === null) { |
80
|
|
|
$required = false; |
81
|
|
|
} |
82
|
|
|
$privateKeys = $this->get('privateKeys'); |
83
|
|
|
$key = array_filter($privateKeys, function (PrivateKey $key) use ($name) { |
|
|
|
|
84
|
|
|
return $key->getName() === $name; |
85
|
|
|
}); |
86
|
|
|
|
87
|
|
|
$keyCount = count($key); |
88
|
|
|
if ($keyCount !== 1 && $required) { |
89
|
|
|
throw new RuntimeException(sprintf( |
90
|
|
|
'Attempted to get privateKey by name "%s", found "%d" keys, where only one was expected. Please ' |
91
|
|
|
. 'verify that your configuration is correct', |
92
|
|
|
$name, |
93
|
|
|
$keyCount |
94
|
|
|
)); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
if (!$keyCount) { |
98
|
|
|
return null; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
return array_pop($key); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @return array|null |
107
|
|
|
*/ |
108
|
|
|
public function getBlacklistedAlgorithms(): ?array |
109
|
|
|
{ |
110
|
|
|
return $this->get('blacklistedEncryptionAlgorithms'); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @return string|null |
116
|
|
|
*/ |
117
|
|
|
public function getEntityId(): ?string |
118
|
|
|
{ |
119
|
|
|
return $this->get('entityId'); |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|