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