|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace TMV\JWTModule; |
|
6
|
|
|
|
|
7
|
|
|
use Jose\Component\Checker\ClaimCheckerManagerFactory; |
|
8
|
|
|
use Jose\Component\Checker\HeaderCheckerManagerFactory; |
|
9
|
|
|
use Jose\Component\Core\AlgorithmManagerFactory; |
|
10
|
|
|
use Jose\Component\Encryption\Algorithm\ContentEncryption; |
|
11
|
|
|
use Jose\Component\Encryption\Algorithm\KeyEncryption; |
|
12
|
|
|
use Jose\Component\Encryption\Compression\CompressionMethodManagerFactory; |
|
13
|
|
|
use Jose\Component\Encryption\JWEBuilderFactory; |
|
14
|
|
|
use Jose\Component\Encryption\JWEDecrypterFactory; |
|
15
|
|
|
use Jose\Component\Encryption\JWELoaderFactory; |
|
16
|
|
|
use Jose\Component\Encryption\JWETokenSupport; |
|
17
|
|
|
use Jose\Component\Encryption\Serializer\JWESerializerManagerFactory; |
|
18
|
|
|
use Jose\Component\KeyManagement\JKUFactory; |
|
19
|
|
|
use Jose\Component\KeyManagement\X5UFactory; |
|
20
|
|
|
use Jose\Component\NestedToken\NestedTokenBuilderFactory; |
|
21
|
|
|
use Jose\Component\NestedToken\NestedTokenLoaderFactory; |
|
22
|
|
|
use Jose\Component\Signature\Algorithm as SignatureAlgorithm; |
|
23
|
|
|
use Jose\Component\Signature\JWSBuilderFactory; |
|
24
|
|
|
use Jose\Component\Signature\JWSLoaderFactory; |
|
25
|
|
|
use Jose\Component\Signature\JWSTokenSupport; |
|
26
|
|
|
use Jose\Component\Signature\JWSVerifierFactory; |
|
27
|
|
|
use Jose\Component\Signature\Serializer\JWSSerializerManagerFactory; |
|
28
|
|
|
use Psr\Http\Client\ClientInterface; |
|
29
|
|
|
use Zend\ServiceManager\Factory\InvokableFactory; |
|
30
|
|
|
|
|
31
|
|
|
class ConfigProvider |
|
32
|
104 |
|
{ |
|
33
|
|
|
private function filterExistingClasses(array $services): array |
|
34
|
|
|
{ |
|
35
|
104 |
|
return \array_filter($services, '\class_exists'); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
private function getAlgorithms(): array |
|
39
|
|
|
{ |
|
40
|
|
|
$algorithms = [ |
|
41
|
|
|
'A128CBC-HS256' => ContentEncryption\A128CBCHS256::class, |
|
42
|
|
|
'A192CBC-HS384' => ContentEncryption\A192CBCHS384::class, |
|
43
|
|
|
'A256CBC-HS512' => ContentEncryption\A256CBCHS512::class, |
|
44
|
|
|
'A128GCM' => ContentEncryption\A128GCM::class, |
|
45
|
|
|
'A192GCM' => ContentEncryption\A192GCM::class, |
|
46
|
|
|
'A256GCM' => ContentEncryption\A256GCM::class, |
|
47
|
|
|
'A128GCMKW' => KeyEncryption\A128GCMKW::class, |
|
48
|
|
|
'A192GCMKW' => KeyEncryption\A192GCMKW::class, |
|
49
|
|
|
'A256GCMKW' => KeyEncryption\A256GCMKW::class, |
|
50
|
|
|
'A128KW' => KeyEncryption\A128KW::class, |
|
51
|
|
|
'A192KW' => KeyEncryption\A192KW::class, |
|
52
|
|
|
'A256KW' => KeyEncryption\A256KW::class, |
|
53
|
|
|
'dir' => KeyEncryption\Dir::class, |
|
54
|
|
|
'ECDH-ES' => KeyEncryption\ECDHES::class, |
|
55
|
|
|
'ECDH-ES+A128KW' => KeyEncryption\ECDHESA128KW::class, |
|
56
|
|
|
'ECDH-ES+A192KW' => KeyEncryption\ECDHESA192KW::class, |
|
57
|
|
|
'ECDH-ES+A256KW' => KeyEncryption\ECDHESA256KW::class, |
|
58
|
|
|
'A128CCM-16-64' => ContentEncryption\A128CCM_16_64::class, |
|
59
|
|
|
'A128CCM-16-128' => ContentEncryption\A128CCM_16_128::class, |
|
60
|
|
|
'A128CCM-64-64' => ContentEncryption\A128CCM_64_64::class, |
|
61
|
|
|
'A128CCM-64-128' => ContentEncryption\A128CCM_64_128::class, |
|
62
|
|
|
'A256CCM-16-64' => ContentEncryption\A256CCM_64_64::class, |
|
63
|
|
|
'A256CCM-16-128' => ContentEncryption\A256CCM_64_128::class, |
|
64
|
|
|
'A128CTR' => KeyEncryption\A128CTR::class, |
|
65
|
|
|
'A192CTR' => KeyEncryption\A192CTR::class, |
|
66
|
|
|
'A256CTR' => KeyEncryption\A256CTR::class, |
|
67
|
|
|
'RSA-OAEP-384' => KeyEncryption\RSAOAEP384::class, |
|
68
|
|
|
'RSA-OAEP-512' => KeyEncryption\RSAOAEP512::class, |
|
69
|
|
|
'PBES2-HS256+A128KW' => KeyEncryption\PBES2HS256A128KW::class, |
|
70
|
|
|
'PBES2-HS384+A192KW' => KeyEncryption\PBES2HS384A192KW::class, |
|
71
|
|
|
'PBES2-HS512+A256KW' => KeyEncryption\PBES2HS512A256KW::class, |
|
72
|
|
|
'RSA1_5' => KeyEncryption\RSA15::class, |
|
73
|
|
|
'RSA-OAEP' => KeyEncryption\RSAOAEP::class, |
|
74
|
|
|
'RSA-OAEP-256' => KeyEncryption\RSAOAEP256::class, |
|
75
|
|
|
'ES256' => SignatureAlgorithm\ES256::class, |
|
76
|
|
|
'ES384' => SignatureAlgorithm\ES384::class, |
|
77
|
|
|
'ES512' => SignatureAlgorithm\ES512::class, |
|
78
|
|
|
'EdDSA' => SignatureAlgorithm\EdDSA::class, |
|
79
|
|
|
'HS1' => SignatureAlgorithm\HS1::class, |
|
80
|
|
|
'HS256/64' => SignatureAlgorithm\HS256_64::class, |
|
81
|
|
|
'RS1' => SignatureAlgorithm\RS1::class, |
|
82
|
|
|
'HS256' => SignatureAlgorithm\HS256::class, |
|
83
|
|
|
'HS384' => SignatureAlgorithm\HS384::class, |
|
84
|
|
|
'HS512' => SignatureAlgorithm\HS512::class, |
|
85
|
|
|
'none' => SignatureAlgorithm\None::class, |
|
86
|
|
|
'PS256' => SignatureAlgorithm\PS256::class, |
|
87
|
|
|
'PS384' => SignatureAlgorithm\PS384::class, |
|
88
|
|
|
'PS512' => SignatureAlgorithm\PS512::class, |
|
89
|
|
|
'RS256' => SignatureAlgorithm\RS256::class, |
|
90
|
|
|
'RS384' => SignatureAlgorithm\RS384::class, |
|
91
|
|
|
'RS512' => SignatureAlgorithm\RS512::class, |
|
92
|
|
|
]; |
|
93
|
|
|
|
|
94
|
|
|
return $this->filterExistingClasses($algorithms); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
public function __invoke(): array |
|
98
|
|
|
{ |
|
99
|
|
|
return [ |
|
100
|
|
|
'dependencies' => $this->getDependencies(), |
|
101
|
|
|
'jwt_module' => [ |
|
102
|
|
|
'jku_factory' => [ |
|
103
|
|
|
'http_client' => ClientInterface::class, |
|
104
|
|
|
], |
|
105
|
|
|
'algorithm_manager' => [ |
|
106
|
|
|
'algorithms' => $this->getAlgorithms(), |
|
107
|
|
|
], |
|
108
|
|
|
'header_checker_manager' => [ |
|
109
|
|
|
'checkers' => [ |
|
110
|
|
|
], |
|
111
|
|
|
'token_types' => $this->filterExistingClasses([ |
|
112
|
|
|
JWSTokenSupport::class, |
|
113
|
|
|
JWETokenSupport::class, |
|
114
|
|
|
]), |
|
115
|
|
|
], |
|
116
|
|
|
'claim_checker_manager' => [ |
|
117
|
|
|
'checkers' => $this->filterExistingClasses([ |
|
118
|
|
|
'exp' => \Jose\Component\Checker\ExpirationTimeChecker::class, |
|
119
|
|
|
'iat' => \Jose\Component\Checker\IssuedAtChecker::class, |
|
120
|
|
|
'nbf' => \Jose\Component\Checker\NotBeforeChecker::class, |
|
121
|
|
|
]), |
|
122
|
|
|
], |
|
123
|
|
|
'jws_serializer_manager' => [ |
|
124
|
|
|
'serializers' => $this->filterExistingClasses([ |
|
125
|
|
|
'jws_compact' => \Jose\Component\Signature\Serializer\CompactSerializer::class, |
|
126
|
|
|
'jws_json_flattened' => \Jose\Component\Signature\Serializer\JSONFlattenedSerializer::class, |
|
127
|
|
|
'jws_json_general' => \Jose\Component\Signature\Serializer\JSONGeneralSerializer::class, |
|
128
|
|
|
]), |
|
129
|
|
|
], |
|
130
|
|
|
'jwe_serializer_manager' => [ |
|
131
|
|
|
'serializers' => $this->filterExistingClasses([ |
|
132
|
|
|
'jwe_compact' => \Jose\Component\Encryption\Serializer\CompactSerializer::class, |
|
133
|
|
|
'jwe_json_flattened' => \Jose\Component\Encryption\Serializer\JSONFlattenedSerializer::class, |
|
134
|
|
|
'jwe_json_general' => \Jose\Component\Encryption\Serializer\JSONGeneralSerializer::class, |
|
135
|
|
|
]), |
|
136
|
|
|
], |
|
137
|
|
|
'compression_method_manager' => [ |
|
138
|
|
|
'compression_methods' => $this->filterExistingClasses([ |
|
139
|
|
|
'DEF' => \Jose\Component\Encryption\Compression\Deflate::class, |
|
140
|
|
|
]), |
|
141
|
|
|
], |
|
142
|
|
|
|
|
143
|
|
|
'header_checker' => [], |
|
144
|
|
|
'claim_checker' => [], |
|
145
|
|
|
|
|
146
|
|
|
'jws_loader' => [], |
|
147
|
|
|
'jws_serializer' => [], |
|
148
|
|
|
'jws_builder' => [], |
|
149
|
|
|
'jws_verifier' => [], |
|
150
|
|
|
|
|
151
|
104 |
|
'jwe_loader' => [], |
|
152
|
|
|
'jwe_serializer' => [], |
|
153
|
|
|
'jwe_builder' => [], |
|
154
|
|
|
'jwe_decrypter' => [], |
|
155
|
104 |
|
'nested_token_builder' => [], |
|
156
|
|
|
'nested_token_loader' => [], |
|
157
|
|
|
|
|
158
|
|
|
'keys' => [], |
|
159
|
|
|
'key_sets' => [], |
|
160
|
|
|
], |
|
161
|
|
|
]; |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
public function getDependencies(): array |
|
165
|
|
|
{ |
|
166
|
|
|
return [ |
|
167
|
|
|
'abstract_factories' => [ |
|
168
|
|
|
DIFactory\Checker\HeaderCheckerManagerAbstractFactory::class, |
|
169
|
|
|
DIFactory\Checker\ClaimCheckerManagerAbstractFactory::class, |
|
170
|
|
|
DIFactory\KeyManagement\KeyAbstractFactory::class, |
|
171
|
|
|
DIFactory\KeyManagement\KeySetAbstractFactory::class, |
|
172
|
|
|
DIFactory\Signature\JWSBuilderAbstractFactory::class, |
|
173
|
|
|
DIFactory\Signature\JWSLoaderAbstractFactory::class, |
|
174
|
|
|
DIFactory\Signature\JWSSerializerAbstractFactory::class, |
|
175
|
|
|
DIFactory\Signature\JWSVerifierAbstractFactory::class, |
|
176
|
|
|
DIFactory\Encryption\JWEBuilderAbstractFactory::class, |
|
177
|
|
|
DIFactory\Encryption\JWEDecrypterAbstractFactory::class, |
|
178
|
|
|
DIFactory\Encryption\JWELoaderAbstractFactory::class, |
|
179
|
|
|
DIFactory\Encryption\JWESerializerAbstractFactory::class, |
|
180
|
|
|
DIFactory\NestedToken\NestedTokenLoaderAbstractFactory::class, |
|
181
|
|
|
DIFactory\NestedToken\NestedTokenBuilderAbstractFactory::class, |
|
182
|
|
|
], |
|
183
|
|
|
'factories' => [ |
|
184
|
|
|
AlgorithmManagerFactory::class => DIFactory\Core\AlgorithmManagerFactoryFactory::class, |
|
185
|
|
|
JWSSerializerManagerFactory::class => DIFactory\Signature\JWSSerializerManagerFactoryFactory::class, |
|
186
|
|
|
JWESerializerManagerFactory::class => DIFactory\Encryption\JWESerializerManagerFactoryFactory::class, |
|
187
|
|
|
CompressionMethodManagerFactory::class => DIFactory\Encryption\Compression\CompressionMethodManagerFactoryFactory::class, |
|
188
|
|
|
HeaderCheckerManagerFactory::class => DIFactory\Checker\HeaderCheckerManagerFactoryFactory::class, |
|
189
|
|
|
ClaimCheckerManagerFactory::class => DIFactory\Checker\ClaimCheckerManagerFactoryFactory::class, |
|
190
|
|
|
JWSBuilderFactory::class => DIFactory\Signature\JWSBuilderFactoryFactory::class, |
|
191
|
|
|
JWSVerifierFactory::class => DIFactory\Signature\JWSVerifierFactoryFactory::class, |
|
192
|
|
|
JWSLoaderFactory::class => DIFactory\Signature\JWSLoaderFactoryFactory::class, |
|
193
|
|
|
JWEBuilderFactory::class => DIFactory\Encryption\JWEBuilderFactoryFactory::class, |
|
194
|
|
|
JWEDecrypterFactory::class => DIFactory\Encryption\JWEDecrypterFactoryFactory::class, |
|
195
|
|
|
JWELoaderFactory::class => DIFactory\Encryption\JWELoaderFactoryFactory::class, |
|
196
|
|
|
NestedTokenBuilderFactory::class => DIFactory\NestedToken\NestedTokenBuilderFactoryFactory::class, |
|
197
|
|
|
NestedTokenLoaderFactory::class => DIFactory\NestedToken\NestedTokenLoaderFactoryFactory::class, |
|
198
|
|
|
JKUFactory::class => DIFactory\KeyManagement\JKUFactoryFactory::class, |
|
199
|
|
|
X5UFactory::class => DIFactory\KeyManagement\X5UFactoryFactory::class, |
|
200
|
|
|
// Serializer |
|
201
|
|
|
\Jose\Component\Signature\Serializer\CompactSerializer::class => InvokableFactory::class, |
|
202
|
|
|
\Jose\Component\Signature\Serializer\JSONFlattenedSerializer::class => InvokableFactory::class, |
|
203
|
|
|
\Jose\Component\Signature\Serializer\JSONGeneralSerializer::class => InvokableFactory::class, |
|
204
|
|
|
\Jose\Component\Encryption\Serializer\CompactSerializer::class => InvokableFactory::class, |
|
205
|
|
|
\Jose\Component\Encryption\Serializer\JSONFlattenedSerializer::class => InvokableFactory::class, |
|
206
|
|
|
\Jose\Component\Encryption\Serializer\JSONGeneralSerializer::class => InvokableFactory::class, |
|
207
|
|
|
// Compression |
|
208
|
|
|
\Jose\Component\Encryption\Compression\Deflate::class => InvokableFactory::class, |
|
209
|
|
|
// Claim Checker |
|
210
|
|
|
\Jose\Component\Checker\ExpirationTimeChecker::class => InvokableFactory::class, |
|
211
|
|
|
\Jose\Component\Checker\IssuedAtChecker::class => InvokableFactory::class, |
|
212
|
|
|
\Jose\Component\Checker\NotBeforeChecker::class => InvokableFactory::class, |
|
213
|
|
|
// Analyser |
|
214
|
|
|
\Jose\Component\KeyManagement\Analyzer\KeyAnalyzerManager::class => InvokableFactory::class, |
|
215
|
|
|
\Jose\Component\KeyManagement\Analyzer\AlgorithmAnalyzer::class => InvokableFactory::class, |
|
216
|
|
|
\Jose\Component\KeyManagement\Analyzer\UsageAnalyzer::class => InvokableFactory::class, |
|
217
|
|
|
\Jose\Component\KeyManagement\Analyzer\KeyIdentifierAnalyzer::class => InvokableFactory::class, |
|
218
|
|
|
\Jose\Component\KeyManagement\Analyzer\NoneAnalyzer::class => InvokableFactory::class, |
|
219
|
|
|
\Jose\Component\KeyManagement\Analyzer\OctAnalyzer::class => InvokableFactory::class, |
|
220
|
|
|
\Jose\Component\KeyManagement\Analyzer\RsaAnalyzer::class => InvokableFactory::class, |
|
221
|
|
|
// Token supports |
|
222
|
|
|
JWSTokenSupport::class => InvokableFactory::class, |
|
223
|
|
|
JWETokenSupport::class => InvokableFactory::class, |
|
224
|
|
|
// AESCBC |
|
225
|
|
|
ContentEncryption\A128CBCHS256::class => InvokableFactory::class, |
|
226
|
|
|
ContentEncryption\A192CBCHS384::class => InvokableFactory::class, |
|
227
|
|
|
ContentEncryption\A256CBCHS512::class => InvokableFactory::class, |
|
228
|
|
|
// AESGCM |
|
229
|
|
|
ContentEncryption\A128GCM::class => InvokableFactory::class, |
|
230
|
|
|
ContentEncryption\A192GCM::class => InvokableFactory::class, |
|
231
|
|
|
ContentEncryption\A256GCM::class => InvokableFactory::class, |
|
232
|
|
|
// AEDGCMKW |
|
233
|
|
|
KeyEncryption\A128GCMKW::class => InvokableFactory::class, |
|
234
|
|
|
KeyEncryption\A192GCMKW::class => InvokableFactory::class, |
|
235
|
|
|
KeyEncryption\A256GCMKW::class => InvokableFactory::class, |
|
236
|
|
|
// AEDGCMKW |
|
237
|
|
|
KeyEncryption\A128KW::class => InvokableFactory::class, |
|
238
|
|
|
KeyEncryption\A192KW::class => InvokableFactory::class, |
|
239
|
|
|
KeyEncryption\A256KW::class => InvokableFactory::class, |
|
240
|
|
|
// DIR |
|
241
|
|
|
KeyEncryption\Dir::class => InvokableFactory::class, |
|
242
|
|
|
// ECDH-ES |
|
243
|
|
|
KeyEncryption\ECDHES::class => InvokableFactory::class, |
|
244
|
|
|
KeyEncryption\ECDHESA128KW::class => InvokableFactory::class, |
|
245
|
|
|
KeyEncryption\ECDHESA192KW::class => InvokableFactory::class, |
|
246
|
|
|
KeyEncryption\ECDHESA256KW::class => InvokableFactory::class, |
|
247
|
|
|
// Experimental |
|
248
|
|
|
ContentEncryption\A128CCM_16_64::class => InvokableFactory::class, |
|
249
|
|
|
ContentEncryption\A128CCM_16_128::class => InvokableFactory::class, |
|
250
|
|
|
ContentEncryption\A128CCM_64_64::class => InvokableFactory::class, |
|
251
|
|
|
ContentEncryption\A128CCM_64_128::class => InvokableFactory::class, |
|
252
|
|
|
ContentEncryption\A256CCM_16_64::class => InvokableFactory::class, |
|
253
|
|
|
ContentEncryption\A256CCM_16_128::class => InvokableFactory::class, |
|
254
|
|
|
ContentEncryption\A256CCM_64_64::class => InvokableFactory::class, |
|
255
|
|
|
ContentEncryption\A256CCM_64_128::class => InvokableFactory::class, |
|
256
|
|
|
KeyEncryption\A128CTR::class => InvokableFactory::class, |
|
257
|
|
|
KeyEncryption\A192CTR::class => InvokableFactory::class, |
|
258
|
|
|
KeyEncryption\A256CTR::class => InvokableFactory::class, |
|
259
|
|
|
//KeyEncryption\Chacha20Poly1305::class => InvokableFactory::class, |
|
260
|
|
|
KeyEncryption\RSAOAEP384::class => InvokableFactory::class, |
|
261
|
|
|
KeyEncryption\RSAOAEP512::class => InvokableFactory::class, |
|
262
|
|
|
// PBES2 |
|
263
|
|
|
KeyEncryption\PBES2HS256A128KW::class => InvokableFactory::class, |
|
264
|
|
|
KeyEncryption\PBES2HS384A192KW::class => InvokableFactory::class, |
|
265
|
|
|
KeyEncryption\PBES2HS512A256KW::class => InvokableFactory::class, |
|
266
|
|
|
// RSA |
|
267
|
|
|
KeyEncryption\RSA15::class => InvokableFactory::class, |
|
268
|
|
|
KeyEncryption\RSAOAEP::class => InvokableFactory::class, |
|
269
|
|
|
KeyEncryption\RSAOAEP256::class => InvokableFactory::class, |
|
270
|
|
|
// ECDSA |
|
271
|
|
|
SignatureAlgorithm\ES256::class => InvokableFactory::class, |
|
272
|
|
|
SignatureAlgorithm\ES384::class => InvokableFactory::class, |
|
273
|
|
|
SignatureAlgorithm\ES512::class => InvokableFactory::class, |
|
274
|
|
|
// EdDSA |
|
275
|
|
|
SignatureAlgorithm\EdDSA::class => InvokableFactory::class, |
|
276
|
|
|
// Experimental |
|
277
|
|
|
SignatureAlgorithm\HS1::class => InvokableFactory::class, |
|
278
|
|
|
SignatureAlgorithm\HS256_64::class => InvokableFactory::class, |
|
279
|
|
|
SignatureAlgorithm\RS1::class => InvokableFactory::class, |
|
280
|
|
|
// HMAC |
|
281
|
|
|
SignatureAlgorithm\HS256::class => InvokableFactory::class, |
|
282
|
|
|
SignatureAlgorithm\HS384::class => InvokableFactory::class, |
|
283
|
|
|
SignatureAlgorithm\HS512::class => InvokableFactory::class, |
|
284
|
|
|
// None |
|
285
|
|
|
SignatureAlgorithm\None::class => InvokableFactory::class, |
|
286
|
|
|
// RSA |
|
287
|
|
|
SignatureAlgorithm\PS256::class => InvokableFactory::class, |
|
288
|
|
|
SignatureAlgorithm\PS384::class => InvokableFactory::class, |
|
289
|
|
|
SignatureAlgorithm\PS512::class => InvokableFactory::class, |
|
290
|
|
|
SignatureAlgorithm\RS256::class => InvokableFactory::class, |
|
291
|
|
|
SignatureAlgorithm\RS384::class => InvokableFactory::class, |
|
292
|
|
|
SignatureAlgorithm\RS512::class => InvokableFactory::class, |
|
293
|
|
|
], |
|
294
|
|
|
]; |
|
295
|
|
|
} |
|
296
|
|
|
} |
|
297
|
|
|
|