|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* The MIT License (MIT) |
|
7
|
|
|
* |
|
8
|
|
|
* Copyright (c) 2014-2017 Spomky-Labs |
|
9
|
|
|
* |
|
10
|
|
|
* This software may be modified and distributed under the terms |
|
11
|
|
|
* of the MIT license. See the LICENSE file for details. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Jose\Component\Encryption\Tests; |
|
15
|
|
|
|
|
16
|
|
|
use Base64Url\Base64Url; |
|
17
|
|
|
use Jose\Component\Core\JWAManager; |
|
18
|
|
|
use Jose\Component\Core\JWK; |
|
19
|
|
|
use Jose\Component\Core\JWKSet; |
|
20
|
|
|
use Jose\Component\Encryption\Algorithm\ContentEncryption\A128CBCHS256; |
|
21
|
|
|
use Jose\Component\Encryption\Algorithm\ContentEncryption\A192CBCHS384; |
|
22
|
|
|
use Jose\Component\Encryption\Algorithm\ContentEncryption\A256CBCHS512; |
|
23
|
|
|
use Jose\Component\Encryption\Algorithm\ContentEncryption\A256GCM; |
|
24
|
|
|
use Jose\Component\Encryption\Algorithm\KeyEncryption\Dir; |
|
25
|
|
|
use Jose\Component\Encryption\Algorithm\KeyEncryption\ECDHES; |
|
26
|
|
|
use Jose\Component\Encryption\Algorithm\KeyEncryption\ECDHESA256KW; |
|
27
|
|
|
use Jose\Component\Encryption\Algorithm\KeyEncryption\RSAOAEP256; |
|
28
|
|
|
use Jose\Component\Encryption\Compression\CompressionMethodsManager; |
|
29
|
|
|
use Jose\Component\Encryption\Compression\Deflate; |
|
30
|
|
|
use Jose\Component\Encryption\Decrypter; |
|
31
|
|
|
use Jose\Component\Encryption\JWE; |
|
32
|
|
|
use Jose\Component\Encryption\JWELoader; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* final class EncrypterTest. |
|
36
|
|
|
* |
|
37
|
|
|
* @group Encrypter |
|
38
|
|
|
* @group Functional |
|
39
|
|
|
*/ |
|
40
|
|
|
final class EncrypterTest extends AbstractEncryptionTest |
|
41
|
|
|
{ |
|
42
|
|
|
public function testEncryptWithJWTInput() |
|
43
|
|
|
{ |
|
44
|
|
|
$keyEncryptionAlgorithmManager = JWAManager::create([new RSAOAEP256()]); |
|
45
|
|
|
$contentEncryptionAlgorithmManager = JWAManager::create([new A256CBCHS512()]); |
|
46
|
|
|
$compressionManager = CompressionMethodsManager::create([new Deflate()]); |
|
47
|
|
|
$jweBuilder = $this->getJWEBuilderFactory()->create(['RSA-OAEP-256'], ['A256CBC-HS512'], ['DEF']); |
|
48
|
|
|
$decrypter = new Decrypter($keyEncryptionAlgorithmManager, $contentEncryptionAlgorithmManager, $compressionManager); |
|
49
|
|
|
|
|
50
|
|
|
$jwe = $jweBuilder |
|
51
|
|
|
->withPayload('FOO') |
|
52
|
|
|
->withSharedProtectedHeaders([ |
|
53
|
|
|
'enc' => 'A256CBC-HS512', |
|
54
|
|
|
'alg' => 'RSA-OAEP-256', |
|
55
|
|
|
'zip' => 'DEF', |
|
56
|
|
|
]) |
|
57
|
|
|
->withAAD('foo,bar,baz') |
|
58
|
|
|
->addRecipient($this->getRSARecipientKey()) |
|
59
|
|
|
->build(); |
|
60
|
|
|
|
|
61
|
|
|
$jwe = $jwe->toFlattenedJSON(0); |
|
62
|
|
|
|
|
63
|
|
|
$loaded = JWELoader::load($jwe); |
|
64
|
|
|
|
|
65
|
|
|
$this->assertInstanceOf(JWE::class, $loaded); |
|
66
|
|
|
$this->assertEquals('RSA-OAEP-256', $loaded->getSharedProtectedHeader('alg')); |
|
67
|
|
|
$this->assertEquals('A256CBC-HS512', $loaded->getSharedProtectedHeader('enc')); |
|
68
|
|
|
$this->assertEquals('DEF', $loaded->getSharedProtectedHeader('zip')); |
|
69
|
|
|
$this->assertNull($loaded->getPayload()); |
|
70
|
|
|
$loaded = $decrypter->decryptUsingKeySet($loaded, $this->getPrivateKeySet(), $index); |
|
71
|
|
|
|
|
72
|
|
|
$this->assertEquals(0, $index); |
|
73
|
|
|
$this->assertEquals('FOO', $loaded->getPayload()); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @expectedException \InvalidArgumentException |
|
78
|
|
|
* @expectedExceptionMessage The header contains duplicated entries: ["zip"]. |
|
79
|
|
|
*/ |
|
80
|
|
|
public function testDuplicatedHeader() |
|
81
|
|
|
{ |
|
82
|
|
|
$jweBuilder = $this->getJWEBuilderFactory()->create(['RSA-OAEP-256'], ['A256CBC-HS512'], ['DEF']); |
|
83
|
|
|
|
|
84
|
|
|
$jweBuilder |
|
85
|
|
|
->withPayload('FOO') |
|
86
|
|
|
->withSharedProtectedHeaders([ |
|
87
|
|
|
'enc' => 'A256CBC-HS512', |
|
88
|
|
|
'alg' => 'RSA-OAEP-256', |
|
89
|
|
|
'zip' => 'DEF', |
|
90
|
|
|
]) |
|
91
|
|
|
->addRecipient( |
|
92
|
|
|
$this->getRSARecipientKey(), |
|
93
|
|
|
['zip' => 'DEF'] |
|
94
|
|
|
); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
public function testCreateCompactJWEUsingFactory() |
|
98
|
|
|
{ |
|
99
|
|
|
$keyEncryptionAlgorithmManager = JWAManager::create([new RSAOAEP256()]); |
|
100
|
|
|
$contentEncryptionAlgorithmManager = JWAManager::create([new A256CBCHS512()]); |
|
101
|
|
|
$compressionManager = CompressionMethodsManager::create([new Deflate()]); |
|
102
|
|
|
$jweBuilder = $this->getJWEBuilderFactory()->create(['RSA-OAEP-256'], ['A256CBC-HS512'], ['DEF']); |
|
103
|
|
|
$decrypter = new Decrypter($keyEncryptionAlgorithmManager, $contentEncryptionAlgorithmManager, $compressionManager); |
|
104
|
|
|
|
|
105
|
|
|
$jwe = $jweBuilder |
|
106
|
|
|
->withPayload('FOO') |
|
107
|
|
|
->withSharedProtectedHeaders([ |
|
108
|
|
|
'enc' => 'A256CBC-HS512', |
|
109
|
|
|
'alg' => 'RSA-OAEP-256', |
|
110
|
|
|
'zip' => 'DEF', |
|
111
|
|
|
]) |
|
112
|
|
|
->addRecipient($this->getRSARecipientKey()) |
|
113
|
|
|
->build() |
|
114
|
|
|
->toCompactJSON(0); |
|
115
|
|
|
|
|
116
|
|
|
$loaded = JWELoader::load($jwe); |
|
117
|
|
|
|
|
118
|
|
|
$this->assertInstanceOf(JWE::class, $loaded); |
|
119
|
|
|
$this->assertEquals('RSA-OAEP-256', $loaded->getSharedProtectedHeader('alg')); |
|
120
|
|
|
$this->assertEquals('A256CBC-HS512', $loaded->getSharedProtectedHeader('enc')); |
|
121
|
|
|
$this->assertEquals('DEF', $loaded->getSharedProtectedHeader('zip')); |
|
122
|
|
|
$this->assertNull($loaded->getPayload()); |
|
123
|
|
|
|
|
124
|
|
|
$loaded = $decrypter->decryptUsingKeySet($loaded, $this->getPrivateKeySet(), $index); |
|
125
|
|
|
|
|
126
|
|
|
$this->assertEquals(0, $index); |
|
127
|
|
|
$this->assertEquals('FOO', $loaded->getPayload()); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
public function testCreateFlattenedJWEUsingFactory() |
|
131
|
|
|
{ |
|
132
|
|
|
$keyEncryptionAlgorithmManager = JWAManager::create([new RSAOAEP256()]); |
|
133
|
|
|
$contentEncryptionAlgorithmManager = JWAManager::create([new A256CBCHS512()]); |
|
134
|
|
|
$compressionManager = CompressionMethodsManager::create([new Deflate()]); |
|
135
|
|
|
$jweBuilder = $this->getJWEBuilderFactory()->create(['RSA-OAEP-256'], ['A256CBC-HS512'], ['DEF']); |
|
136
|
|
|
$decrypter = new Decrypter($keyEncryptionAlgorithmManager, $contentEncryptionAlgorithmManager, $compressionManager); |
|
137
|
|
|
|
|
138
|
|
|
$jwe = $jweBuilder |
|
139
|
|
|
->withPayload('FOO') |
|
140
|
|
|
->withSharedProtectedHeaders([ |
|
141
|
|
|
'enc' => 'A256CBC-HS512', |
|
142
|
|
|
'alg' => 'RSA-OAEP-256', |
|
143
|
|
|
'zip' => 'DEF', |
|
144
|
|
|
]) |
|
145
|
|
|
->withSharedHeaders([ |
|
146
|
|
|
'foo' => 'bar', |
|
147
|
|
|
]) |
|
148
|
|
|
->addRecipient( |
|
149
|
|
|
$this->getRSARecipientKey(), |
|
150
|
|
|
[ |
|
151
|
|
|
'plic' => 'ploc', |
|
152
|
|
|
] |
|
153
|
|
|
) |
|
154
|
|
|
->withAAD('A,B,C,D') |
|
155
|
|
|
->build() |
|
156
|
|
|
->toFlattenedJSON(0); |
|
157
|
|
|
|
|
158
|
|
|
$loaded = JWELoader::load($jwe); |
|
159
|
|
|
|
|
160
|
|
|
$this->assertInstanceOf(JWE::class, $loaded); |
|
161
|
|
|
$this->assertEquals('RSA-OAEP-256', $loaded->getSharedProtectedHeader('alg')); |
|
162
|
|
|
$this->assertEquals('A256CBC-HS512', $loaded->getSharedProtectedHeader('enc')); |
|
163
|
|
|
$this->assertEquals('DEF', $loaded->getSharedProtectedHeader('zip')); |
|
164
|
|
|
$this->assertEquals('bar', $loaded->getSharedHeader('foo')); |
|
165
|
|
|
$this->assertEquals('A,B,C,D', $loaded->getAAD()); |
|
166
|
|
|
$this->assertEquals('ploc', $loaded->getRecipient(0)->getHeader('plic')); |
|
167
|
|
|
$this->assertNull($loaded->getPayload()); |
|
168
|
|
|
|
|
169
|
|
|
$loaded = $decrypter->decryptUsingKeySet($loaded, $this->getPrivateKeySet(), $index); |
|
170
|
|
|
|
|
171
|
|
|
$this->assertEquals(0, $index); |
|
172
|
|
|
$this->assertEquals('FOO', $loaded->getPayload()); |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
public function testEncryptAndLoadFlattenedWithAAD() |
|
176
|
|
|
{ |
|
177
|
|
|
$keyEncryptionAlgorithmManager = JWAManager::create([new RSAOAEP256()]); |
|
178
|
|
|
$contentEncryptionAlgorithmManager = JWAManager::create([new A256CBCHS512()]); |
|
179
|
|
|
$compressionManager = CompressionMethodsManager::create([new Deflate()]); |
|
180
|
|
|
$jweBuilder = $this->getJWEBuilderFactory()->create(['RSA-OAEP-256'], ['A256CBC-HS512'], ['DEF']); |
|
181
|
|
|
$decrypter = new Decrypter($keyEncryptionAlgorithmManager, $contentEncryptionAlgorithmManager, $compressionManager); |
|
182
|
|
|
|
|
183
|
|
|
$jwe = $jweBuilder |
|
184
|
|
|
->withPayload(json_encode($this->getKeyToEncrypt())) |
|
185
|
|
|
->withSharedProtectedHeaders([ |
|
186
|
|
|
'enc' => 'A256CBC-HS512', |
|
187
|
|
|
'alg' => 'RSA-OAEP-256', |
|
188
|
|
|
'zip' => 'DEF', |
|
189
|
|
|
]) |
|
190
|
|
|
->addRecipient($this->getRSARecipientKey()) |
|
191
|
|
|
->withAAD('foo,bar,baz') |
|
192
|
|
|
->build() |
|
193
|
|
|
->toFlattenedJSON(0); |
|
194
|
|
|
|
|
195
|
|
|
$loaded = JWELoader::load($jwe); |
|
196
|
|
|
|
|
197
|
|
|
$this->assertInstanceOf(JWE::class, $loaded); |
|
198
|
|
|
$this->assertEquals('RSA-OAEP-256', $loaded->getSharedProtectedHeader('alg')); |
|
199
|
|
|
$this->assertEquals('A256CBC-HS512', $loaded->getSharedProtectedHeader('enc')); |
|
200
|
|
|
$this->assertEquals('DEF', $loaded->getSharedProtectedHeader('zip')); |
|
201
|
|
|
$this->assertNull($loaded->getPayload()); |
|
202
|
|
|
|
|
203
|
|
|
$loaded = $decrypter->decryptUsingKeySet($loaded, $this->getPrivateKeySet(), $index); |
|
204
|
|
|
|
|
205
|
|
|
$this->assertEquals(0, $index); |
|
206
|
|
|
$this->assertEquals($this->getKeyToEncrypt(), JWK::create(json_decode($loaded->getPayload(), true))); |
|
207
|
|
|
} |
|
208
|
|
|
|
|
209
|
|
|
/** |
|
210
|
|
|
* @expectedException \InvalidArgumentException |
|
211
|
|
|
* @expectedExceptionMessage The compression method "FIP" is not supported. |
|
212
|
|
|
*/ |
|
213
|
|
|
public function testCompressionAlgorithmNotSupported() |
|
214
|
|
|
{ |
|
215
|
|
|
$jweBuilder = $this->getJWEBuilderFactory()->create(['RSA-OAEP-256'], ['A256CBC-HS512'], ['DEF']); |
|
216
|
|
|
|
|
217
|
|
|
$jweBuilder |
|
218
|
|
|
->withPayload(json_encode($this->getKeyToEncrypt())) |
|
219
|
|
|
->withSharedProtectedHeaders([ |
|
220
|
|
|
'enc' => 'A256CBC-HS512', |
|
221
|
|
|
'alg' => 'RSA-OAEP-256', |
|
222
|
|
|
'zip' => 'FIP', |
|
223
|
|
|
]) |
|
224
|
|
|
->addRecipient($this->getRSARecipientKey()) |
|
225
|
|
|
->withAAD('foo,bar,baz') |
|
226
|
|
|
->build() |
|
227
|
|
|
->toFlattenedJSON(0); |
|
228
|
|
|
} |
|
229
|
|
|
|
|
230
|
|
|
/** |
|
231
|
|
|
* @expectedException \InvalidArgumentException |
|
232
|
|
|
* @expectedExceptionMessage Foreign key management mode forbidden. |
|
233
|
|
|
*/ |
|
234
|
|
|
public function testForeignKeyManagementModeForbidden() |
|
235
|
|
|
{ |
|
236
|
|
|
$jweBuilder = $this->getJWEBuilderFactory()->create(['dir', 'ECDH-ES+A256KW'], ['A256CBC-HS512'], ['DEF']); |
|
237
|
|
|
|
|
238
|
|
|
$jweBuilder |
|
239
|
|
|
->withPayload('Live long and Prosper.') |
|
240
|
|
|
->withSharedProtectedHeaders([ |
|
241
|
|
|
'enc' => 'A256CBC-HS512', |
|
242
|
|
|
]) |
|
243
|
|
|
->addRecipient($this->getECDHRecipientPublicKey(), ['kid' => 'e9bc097a-ce51-4036-9562-d2ade882db0d', 'alg' => 'ECDH-ES+A256KW']) |
|
244
|
|
|
->addRecipient($this->getDirectKey(), ['kid' => 'DIR_1', 'alg' => 'dir']) |
|
245
|
|
|
->build(); |
|
246
|
|
|
} |
|
247
|
|
|
|
|
248
|
|
|
/** |
|
249
|
|
|
* @expectedException \InvalidArgumentException |
|
250
|
|
|
* @expectedExceptionMessage Key cannot be used to encrypt |
|
251
|
|
|
*/ |
|
252
|
|
|
public function testOperationNotAllowedForTheKey() |
|
253
|
|
|
{ |
|
254
|
|
|
$jweBuilder = $this->getJWEBuilderFactory()->create(['RSA-OAEP-256'], ['A256CBC-HS512'], ['DEF']); |
|
255
|
|
|
|
|
256
|
|
|
$jweBuilder |
|
257
|
|
|
->withPayload('Live long and Prosper.') |
|
258
|
|
|
->withSharedProtectedHeaders([ |
|
259
|
|
|
'enc' => 'A256CBC-HS512', |
|
260
|
|
|
'alg' => 'RSA-OAEP-256', |
|
261
|
|
|
'zip' => 'DEF', |
|
262
|
|
|
]) |
|
263
|
|
|
->addRecipient($this->getSigningKey()) |
|
264
|
|
|
->build(); |
|
265
|
|
|
} |
|
266
|
|
|
|
|
267
|
|
|
/** |
|
268
|
|
|
* @expectedException \InvalidArgumentException |
|
269
|
|
|
* @expectedExceptionMessage Key is only allowed for algorithm "RSA-OAEP". |
|
270
|
|
|
*/ |
|
271
|
|
|
public function testAlgorithmNotAllowedForTheKey() |
|
272
|
|
|
{ |
|
273
|
|
|
$jweBuilder = $this->getJWEBuilderFactory()->create(['RSA-OAEP-256'], ['A256CBC-HS512'], ['DEF']); |
|
274
|
|
|
|
|
275
|
|
|
$jweBuilder |
|
276
|
|
|
->withPayload('Live long and Prosper.') |
|
277
|
|
|
->withSharedProtectedHeaders([ |
|
278
|
|
|
'enc' => 'A256CBC-HS512', |
|
279
|
|
|
'alg' => 'RSA-OAEP-256', |
|
280
|
|
|
'zip' => 'DEF', |
|
281
|
|
|
]) |
|
282
|
|
|
->addRecipient($this->getRSARecipientKeyWithAlgorithm()) |
|
283
|
|
|
->build(); |
|
284
|
|
|
} |
|
285
|
|
|
|
|
286
|
|
|
public function testEncryptAndLoadFlattenedWithDeflateCompression() |
|
287
|
|
|
{ |
|
288
|
|
|
$keyEncryptionAlgorithmManager = JWAManager::create([new RSAOAEP256()]); |
|
289
|
|
|
$contentEncryptionAlgorithmManager = JWAManager::create([new A128CBCHS256()]); |
|
290
|
|
|
$compressionManager = CompressionMethodsManager::create([new Deflate()]); |
|
291
|
|
|
$jweBuilder = $this->getJWEBuilderFactory()->create(['RSA-OAEP-256'], ['A128CBC-HS256'], ['DEF']); |
|
292
|
|
|
$decrypter = new Decrypter($keyEncryptionAlgorithmManager, $contentEncryptionAlgorithmManager, $compressionManager); |
|
293
|
|
|
|
|
294
|
|
|
$jwe = $jweBuilder |
|
295
|
|
|
->withPayload(json_encode($this->getKeySetToEncrypt())) |
|
296
|
|
|
->withSharedProtectedHeaders([ |
|
297
|
|
|
'kid' => '123456789', |
|
298
|
|
|
'enc' => 'A128CBC-HS256', |
|
299
|
|
|
'alg' => 'RSA-OAEP-256', |
|
300
|
|
|
'zip' => 'DEF', |
|
301
|
|
|
]) |
|
302
|
|
|
->addRecipient($this->getRSARecipientKey()) |
|
303
|
|
|
->build() |
|
304
|
|
|
->toCompactJSON(0); |
|
305
|
|
|
|
|
306
|
|
|
$loaded = JWELoader::load($jwe); |
|
307
|
|
|
|
|
308
|
|
|
$this->assertInstanceOf(JWE::class, $loaded); |
|
309
|
|
|
$this->assertEquals('RSA-OAEP-256', $loaded->getSharedProtectedHeader('alg')); |
|
310
|
|
|
$this->assertEquals('A128CBC-HS256', $loaded->getSharedProtectedHeader('enc')); |
|
311
|
|
|
$this->assertEquals('DEF', $loaded->getSharedProtectedHeader('zip')); |
|
312
|
|
|
$this->assertNull($loaded->getPayload()); |
|
313
|
|
|
|
|
314
|
|
|
$loaded = $decrypter->decryptUsingKeySet($loaded, $this->getPrivateKeySet(), $index); |
|
315
|
|
|
|
|
316
|
|
|
$this->assertEquals(0, $index); |
|
317
|
|
|
$this->assertEquals($this->getKeySetToEncrypt(), JWKSet::createFromKeyData(json_decode($loaded->getPayload(), true))); |
|
318
|
|
|
} |
|
319
|
|
|
|
|
320
|
|
|
/** |
|
321
|
|
|
* @expectedException \InvalidArgumentException |
|
322
|
|
|
* @expectedExceptionMessage Parameter "alg" is missing. |
|
323
|
|
|
*/ |
|
324
|
|
|
public function testAlgParameterIsMissing() |
|
325
|
|
|
{ |
|
326
|
|
|
$jweBuilder = $this->getJWEBuilderFactory()->create([], ['A256CBC-HS512'], ['DEF']); |
|
327
|
|
|
|
|
328
|
|
|
$jweBuilder |
|
329
|
|
|
->withPayload(json_encode($this->getKeyToEncrypt())) |
|
330
|
|
|
->withSharedProtectedHeaders([ |
|
331
|
|
|
'kid' => '123456789', |
|
332
|
|
|
'enc' => 'A256CBC-HS512', |
|
333
|
|
|
'zip' => 'DEF', |
|
334
|
|
|
]) |
|
335
|
|
|
->addRecipient($this->getRSARecipientKey()) |
|
336
|
|
|
->build(); |
|
337
|
|
|
} |
|
338
|
|
|
|
|
339
|
|
|
/** |
|
340
|
|
|
* @expectedException \InvalidArgumentException |
|
341
|
|
|
* @expectedExceptionMessage Parameter "enc" is missing. |
|
342
|
|
|
*/ |
|
343
|
|
|
public function testEncParameterIsMissing() |
|
344
|
|
|
{ |
|
345
|
|
|
$jweBuilder = $this->getJWEBuilderFactory()->create(['RSA-OAEP-256'], [], ['DEF']); |
|
346
|
|
|
|
|
347
|
|
|
$jweBuilder |
|
348
|
|
|
->withPayload(json_encode($this->getKeyToEncrypt())) |
|
349
|
|
|
->withSharedProtectedHeaders([ |
|
350
|
|
|
'kid' => '123456789', |
|
351
|
|
|
'alg' => 'RSA-OAEP-256', |
|
352
|
|
|
'zip' => 'DEF', |
|
353
|
|
|
]) |
|
354
|
|
|
->addRecipient($this->getRSARecipientKey()) |
|
355
|
|
|
->build(); |
|
356
|
|
|
} |
|
357
|
|
|
|
|
358
|
|
|
/** |
|
359
|
|
|
* @expectedException \InvalidArgumentException |
|
360
|
|
|
* @expectedExceptionMessage The key encryption algorithm "A256CBC-HS512" is not supported or not a key encryption algorithm instance. |
|
361
|
|
|
*/ |
|
362
|
|
|
public function testNotAKeyEncryptionAlgorithm() |
|
363
|
|
|
{ |
|
364
|
|
|
$jweBuilder = $this->getJWEBuilderFactory()->create(['A256CBC-HS512'], ['A256CBC-HS512'], ['DEF']); |
|
365
|
|
|
|
|
366
|
|
|
$jweBuilder |
|
367
|
|
|
->withPayload(json_encode($this->getKeyToEncrypt())) |
|
368
|
|
|
->withSharedProtectedHeaders([ |
|
369
|
|
|
'kid' => '123456789', |
|
370
|
|
|
'enc' => 'A256CBC-HS512', |
|
371
|
|
|
'alg' => 'A256CBC-HS512', |
|
372
|
|
|
'zip' => 'DEF', |
|
373
|
|
|
]) |
|
374
|
|
|
->addRecipient($this->getRSARecipientKey()) |
|
375
|
|
|
->build(); |
|
376
|
|
|
} |
|
377
|
|
|
|
|
378
|
|
|
/** |
|
379
|
|
|
* @expectedException \InvalidArgumentException |
|
380
|
|
|
* @expectedExceptionMessage The content encryption algorithm "RSA-OAEP-256" is not supported or not a content encryption algorithm instance. |
|
381
|
|
|
*/ |
|
382
|
|
|
public function testNotAContentEncryptionAlgorithm() |
|
383
|
|
|
{ |
|
384
|
|
|
$jweBuilder = $this->getJWEBuilderFactory()->create(['RSA-OAEP-256'], ['RSA-OAEP-256'], ['DEF']); |
|
385
|
|
|
|
|
386
|
|
|
$jweBuilder |
|
387
|
|
|
->withPayload(json_encode($this->getKeyToEncrypt())) |
|
388
|
|
|
->withSharedProtectedHeaders([ |
|
389
|
|
|
'kid' => '123456789', |
|
390
|
|
|
'enc' => 'RSA-OAEP-256', |
|
391
|
|
|
'alg' => 'RSA-OAEP-256', |
|
392
|
|
|
'zip' => 'DEF', |
|
393
|
|
|
]) |
|
394
|
|
|
->addRecipient($this->getRSARecipientKey()) |
|
395
|
|
|
->build(); |
|
396
|
|
|
} |
|
397
|
|
|
|
|
398
|
|
|
public function testEncryptAndLoadCompactWithDirectKeyEncryption() |
|
399
|
|
|
{ |
|
400
|
|
|
$keyEncryptionAlgorithmManager = JWAManager::create([new Dir()]); |
|
401
|
|
|
$contentEncryptionAlgorithmManager = JWAManager::create([new A192CBCHS384()]); |
|
402
|
|
|
$compressionManager = CompressionMethodsManager::create([new Deflate()]); |
|
403
|
|
|
$jweBuilder = $this->getJWEBuilderFactory()->create(['dir'], ['A192CBC-HS384'], ['DEF']); |
|
404
|
|
|
$decrypter = new Decrypter($keyEncryptionAlgorithmManager, $contentEncryptionAlgorithmManager, $compressionManager); |
|
405
|
|
|
|
|
406
|
|
|
$jwe = $jweBuilder |
|
407
|
|
|
->withPayload(json_encode($this->getKeyToEncrypt())) |
|
408
|
|
|
->withSharedProtectedHeaders([ |
|
409
|
|
|
'kid' => 'DIR_1', |
|
410
|
|
|
'enc' => 'A192CBC-HS384', |
|
411
|
|
|
'alg' => 'dir', |
|
412
|
|
|
]) |
|
413
|
|
|
->addRecipient($this->getDirectKey()) |
|
414
|
|
|
->build() |
|
415
|
|
|
->toFlattenedJSON(0); |
|
416
|
|
|
|
|
417
|
|
|
$loaded = JWELoader::load($jwe); |
|
418
|
|
|
|
|
419
|
|
|
$this->assertInstanceOf(JWE::class, $loaded); |
|
420
|
|
|
$this->assertEquals('dir', $loaded->getSharedProtectedHeader('alg')); |
|
421
|
|
|
$this->assertEquals('A192CBC-HS384', $loaded->getSharedProtectedHeader('enc')); |
|
422
|
|
|
$this->assertFalse($loaded->hasSharedHeader('zip')); |
|
423
|
|
|
$this->assertNull($loaded->getPayload()); |
|
424
|
|
|
|
|
425
|
|
|
$loaded = $decrypter->decryptUsingKeySet($loaded, $this->getSymmetricKeySet(), $index); |
|
426
|
|
|
|
|
427
|
|
|
$this->assertEquals(0, $index); |
|
428
|
|
|
$this->assertEquals($this->getKeyToEncrypt(), JWK::create(json_decode($loaded->getPayload(), true))); |
|
429
|
|
|
} |
|
430
|
|
|
|
|
431
|
|
|
public function testEncryptAndLoadCompactKeyAgreement() |
|
432
|
|
|
{ |
|
433
|
|
|
$keyEncryptionAlgorithmManager = JWAManager::create([new ECDHES()]); |
|
434
|
|
|
$contentEncryptionAlgorithmManager = JWAManager::create([new A192CBCHS384()]); |
|
435
|
|
|
$compressionManager = CompressionMethodsManager::create([new Deflate()]); |
|
436
|
|
|
$jweBuilder = $this->getJWEBuilderFactory()->create(['ECDH-ES'], ['A192CBC-HS384'], ['DEF']); |
|
437
|
|
|
$decrypter = new Decrypter($keyEncryptionAlgorithmManager, $contentEncryptionAlgorithmManager, $compressionManager); |
|
438
|
|
|
|
|
439
|
|
|
$payload = json_encode(['user_id' => '1234', 'exp' => time() + 3600]); |
|
440
|
|
|
$jwe = $jweBuilder |
|
441
|
|
|
->withPayload($payload) |
|
442
|
|
|
->withSharedProtectedHeaders([ |
|
443
|
|
|
'kid' => 'e9bc097a-ce51-4036-9562-d2ade882db0d', |
|
444
|
|
|
'enc' => 'A192CBC-HS384', |
|
445
|
|
|
'alg' => 'ECDH-ES', |
|
446
|
|
|
]) |
|
447
|
|
|
->addRecipient($this->getECDHRecipientPublicKey()) |
|
448
|
|
|
->build() |
|
449
|
|
|
->toFlattenedJSON(0); |
|
450
|
|
|
|
|
451
|
|
|
$loaded = JWELoader::load($jwe); |
|
452
|
|
|
|
|
453
|
|
|
$this->assertInstanceOf(JWE::class, $loaded); |
|
454
|
|
|
$this->assertEquals('ECDH-ES', $loaded->getSharedProtectedHeader('alg')); |
|
455
|
|
|
$this->assertEquals('A192CBC-HS384', $loaded->getSharedProtectedHeader('enc')); |
|
456
|
|
|
$this->assertFalse($loaded->hasSharedProtectedHeader('zip')); |
|
457
|
|
|
$this->assertNull($loaded->getPayload()); |
|
458
|
|
|
|
|
459
|
|
|
$loaded = $decrypter->decryptUsingKeySet($loaded, $this->getPrivateKeySet(), $index); |
|
460
|
|
|
|
|
461
|
|
|
$this->assertEquals(0, $index); |
|
462
|
|
|
$this->assertEquals($payload, $loaded->getPayload()); |
|
463
|
|
|
} |
|
464
|
|
|
|
|
465
|
|
|
public function testEncryptAndLoadCompactKeyAgreementWithWrappingCompact() |
|
466
|
|
|
{ |
|
467
|
|
|
$keyEncryptionAlgorithmManager = JWAManager::create([new ECDHESA256KW()]); |
|
468
|
|
|
$contentEncryptionAlgorithmManager = JWAManager::create([new A256CBCHS512()]); |
|
469
|
|
|
$compressionManager = CompressionMethodsManager::create([new Deflate()]); |
|
470
|
|
|
$jweBuilder = $this->getJWEBuilderFactory()->create(['ECDH-ES+A256KW'], ['A256CBC-HS512'], ['DEF']); |
|
471
|
|
|
$decrypter = new Decrypter($keyEncryptionAlgorithmManager, $contentEncryptionAlgorithmManager, $compressionManager); |
|
472
|
|
|
|
|
473
|
|
|
$jwe = $jweBuilder |
|
474
|
|
|
->withPayload('Live long and Prosper.') |
|
475
|
|
|
->withSharedProtectedHeaders([ |
|
476
|
|
|
'kid' => 'e9bc097a-ce51-4036-9562-d2ade882db0d', |
|
477
|
|
|
'enc' => 'A256CBC-HS512', |
|
478
|
|
|
'alg' => 'ECDH-ES+A256KW', |
|
479
|
|
|
]) |
|
480
|
|
|
->addRecipient($this->getECDHRecipientPublicKey()) |
|
481
|
|
|
->build() |
|
482
|
|
|
->toFlattenedJSON(0); |
|
483
|
|
|
|
|
484
|
|
|
$loaded = JWELoader::load($jwe); |
|
485
|
|
|
|
|
486
|
|
|
$this->assertInstanceOf(JWE::class, $loaded); |
|
487
|
|
|
$this->assertEquals('ECDH-ES+A256KW', $loaded->getSharedProtectedHeader('alg')); |
|
488
|
|
|
$this->assertEquals('A256CBC-HS512', $loaded->getSharedProtectedHeader('enc')); |
|
489
|
|
|
$this->assertFalse($loaded->hasSharedProtectedHeader('zip')); |
|
490
|
|
|
$this->assertFalse($loaded->hasSharedHeader('zip')); |
|
491
|
|
|
$this->assertNull($loaded->getPayload()); |
|
492
|
|
|
|
|
493
|
|
|
$loaded = $decrypter->decryptUsingKeySet($loaded, $this->getPrivateKeySet(), $index); |
|
494
|
|
|
|
|
495
|
|
|
$this->assertEquals(0, $index); |
|
496
|
|
|
$this->assertTrue(is_string($loaded->getPayload())); |
|
497
|
|
|
$this->assertEquals('Live long and Prosper.', $loaded->getPayload()); |
|
498
|
|
|
} |
|
499
|
|
|
|
|
500
|
|
|
public function testEncryptAndLoadWithGCMAndAAD() |
|
501
|
|
|
{ |
|
502
|
|
|
$jweBuilder = $this->getJWEBuilderFactory()->create(['ECDH-ES+A256KW'], ['A256GCM'], ['DEF']); |
|
503
|
|
|
|
|
504
|
|
|
$jwe = $jweBuilder |
|
505
|
|
|
->withPayload('Live long and Prosper.') |
|
506
|
|
|
->withSharedProtectedHeaders([ |
|
507
|
|
|
'kid' => 'e9bc097a-ce51-4036-9562-d2ade882db0d', |
|
508
|
|
|
'enc' => 'A256GCM', |
|
509
|
|
|
'alg' => 'ECDH-ES+A256KW', |
|
510
|
|
|
]) |
|
511
|
|
|
->withAAD('foo,bar,baz') |
|
512
|
|
|
->addRecipient($this->getECDHRecipientPublicKey()) |
|
513
|
|
|
->build() |
|
514
|
|
|
->toFlattenedJSON(0); |
|
515
|
|
|
|
|
516
|
|
|
$loaded = JWELoader::load($jwe); |
|
517
|
|
|
|
|
518
|
|
|
$keyEncryptionAlgorithmManager = JWAManager::create([new ECDHESA256KW()]); |
|
519
|
|
|
$contentEncryptionAlgorithmManager = JWAManager::create([new A256GCM()]); |
|
520
|
|
|
$compressionManager = CompressionMethodsManager::create([new Deflate()]); |
|
521
|
|
|
$decrypter = new Decrypter($keyEncryptionAlgorithmManager, $contentEncryptionAlgorithmManager, $compressionManager); |
|
522
|
|
|
|
|
523
|
|
|
$this->assertInstanceOf(JWE::class, $loaded); |
|
524
|
|
|
$this->assertEquals('ECDH-ES+A256KW', $loaded->getSharedProtectedHeader('alg')); |
|
525
|
|
|
$this->assertEquals('A256GCM', $loaded->getSharedProtectedHeader('enc')); |
|
526
|
|
|
$this->assertFalse($loaded->hasSharedProtectedHeader('zip')); |
|
527
|
|
|
$this->assertFalse($loaded->hasSharedHeader('zip')); |
|
528
|
|
|
$this->assertNull($loaded->getPayload()); |
|
529
|
|
|
|
|
530
|
|
|
$loaded = $decrypter->decryptUsingKeySet($loaded, $this->getPrivateKeySet(), $index); |
|
531
|
|
|
|
|
532
|
|
|
$this->assertEquals(0, $index); |
|
533
|
|
|
$this->assertTrue(is_string($loaded->getPayload())); |
|
534
|
|
|
$this->assertEquals('Live long and Prosper.', $loaded->getPayload()); |
|
535
|
|
|
} |
|
536
|
|
|
|
|
537
|
|
|
public function testEncryptAndLoadCompactKeyAgreementWithWrapping() |
|
538
|
|
|
{ |
|
539
|
|
|
$keyEncryptionAlgorithmManager = JWAManager::create([new RSAOAEP256(), new ECDHESA256KW()]); |
|
540
|
|
|
$contentEncryptionAlgorithmManager = JWAManager::create([new A256CBCHS512()]); |
|
541
|
|
|
$compressionManager = CompressionMethodsManager::create([new Deflate()]); |
|
542
|
|
|
$jweBuilder = $this->getJWEBuilderFactory()->create(['RSA-OAEP-256', 'ECDH-ES+A256KW'], ['A256CBC-HS512'], ['DEF']); |
|
543
|
|
|
$decrypter = new Decrypter($keyEncryptionAlgorithmManager, $contentEncryptionAlgorithmManager, $compressionManager); |
|
544
|
|
|
|
|
545
|
|
|
$jwe = $jweBuilder |
|
546
|
|
|
->withPayload('Live long and Prosper.') |
|
547
|
|
|
->withSharedProtectedHeaders([ |
|
548
|
|
|
'enc' => 'A256CBC-HS512', |
|
549
|
|
|
]) |
|
550
|
|
|
->withAAD('foo,bar,baz') |
|
551
|
|
|
->addRecipient($this->getECDHRecipientPublicKey(), ['kid' => 'e9bc097a-ce51-4036-9562-d2ade882db0d', 'alg' => 'ECDH-ES+A256KW']) |
|
552
|
|
|
->addRecipient($this->getRSARecipientKey(), ['kid' => '123456789', 'alg' => 'RSA-OAEP-256']) |
|
553
|
|
|
->build() |
|
554
|
|
|
->toJSON(); |
|
555
|
|
|
|
|
556
|
|
|
$loaded = JWELoader::load($jwe); |
|
557
|
|
|
|
|
558
|
|
|
$this->assertEquals(2, $loaded->countRecipients()); |
|
559
|
|
|
|
|
560
|
|
|
$this->assertInstanceOf(JWE::class, $loaded); |
|
561
|
|
|
$this->assertEquals('A256CBC-HS512', $loaded->getSharedProtectedHeader('enc')); |
|
562
|
|
|
$this->assertEquals('ECDH-ES+A256KW', $loaded->getRecipient(0)->getHeader('alg')); |
|
563
|
|
|
$this->assertEquals('RSA-OAEP-256', $loaded->getRecipient(1)->getHeader('alg')); |
|
564
|
|
|
$this->assertFalse($loaded->hasSharedHeader('zip')); |
|
565
|
|
|
$this->assertFalse($loaded->hasSharedProtectedHeader('zip')); |
|
566
|
|
|
$this->assertNull($loaded->getPayload()); |
|
567
|
|
|
|
|
568
|
|
|
$loaded = $decrypter->decryptUsingKeySet($loaded, $this->getPrivateKeySet(), $index); |
|
569
|
|
|
|
|
570
|
|
|
$this->assertEquals(0, $index); |
|
571
|
|
|
$this->assertTrue(is_string($loaded->getPayload())); |
|
572
|
|
|
$this->assertEquals('Live long and Prosper.', $loaded->getPayload()); |
|
573
|
|
|
} |
|
574
|
|
|
|
|
575
|
|
|
/** |
|
576
|
|
|
* @return JWK |
|
577
|
|
|
*/ |
|
578
|
|
|
private function getKeyToEncrypt() |
|
579
|
|
|
{ |
|
580
|
|
|
$key = JWK::create([ |
|
581
|
|
|
'kty' => 'EC', |
|
582
|
|
|
'use' => 'enc', |
|
583
|
|
|
'crv' => 'P-256', |
|
584
|
|
|
'x' => 'f83OJ3D2xF1Bg8vub9tLe1gHMzV76e8Tus9uPHvRVEU', |
|
585
|
|
|
'y' => 'x_FEzRu9m36HLN_tue659LNpXW6pCyStikYjKIWI5a0', |
|
586
|
|
|
'd' => 'jpsQnnGQmL-YBIffH1136cspYG6-0iY7X1fCE9-E9LI', |
|
587
|
|
|
]); |
|
588
|
|
|
|
|
589
|
|
|
return $key; |
|
590
|
|
|
} |
|
591
|
|
|
|
|
592
|
|
|
/** |
|
593
|
|
|
* @return JWKSet |
|
594
|
|
|
*/ |
|
595
|
|
|
private function getKeySetToEncrypt() |
|
596
|
|
|
{ |
|
597
|
|
|
$key = JWK::create([ |
|
598
|
|
|
'kty' => 'EC', |
|
599
|
|
|
'use' => 'enc', |
|
600
|
|
|
'crv' => 'P-256', |
|
601
|
|
|
'x' => 'f83OJ3D2xF1Bg8vub9tLe1gHMzV76e8Tus9uPHvRVEU', |
|
602
|
|
|
'y' => 'x_FEzRu9m36HLN_tue659LNpXW6pCyStikYjKIWI5a0', |
|
603
|
|
|
'd' => 'jpsQnnGQmL-YBIffH1136cspYG6-0iY7X1fCE9-E9LI', |
|
604
|
|
|
]); |
|
605
|
|
|
|
|
606
|
|
|
$key_set = JWKSet::createFromKeys([$key]); |
|
607
|
|
|
|
|
608
|
|
|
return $key_set; |
|
609
|
|
|
} |
|
610
|
|
|
|
|
611
|
|
|
/** |
|
612
|
|
|
* @return JWK |
|
613
|
|
|
*/ |
|
614
|
|
|
private function getRSARecipientKey() |
|
615
|
|
|
{ |
|
616
|
|
|
$key = JWK::create([ |
|
617
|
|
|
'kty' => 'RSA', |
|
618
|
|
|
'use' => 'enc', |
|
619
|
|
|
'n' => 'tpS1ZmfVKVP5KofIhMBP0tSWc4qlh6fm2lrZSkuKxUjEaWjzZSzs72gEIGxraWusMdoRuV54xsWRyf5KeZT0S-I5Prle3Idi3gICiO4NwvMk6JwSBcJWwmSLFEKyUSnB2CtfiGc0_5rQCpcEt_Dn5iM-BNn7fqpoLIbks8rXKUIj8-qMVqkTXsEKeKinE23t1ykMldsNaaOH-hvGti5Jt2DMnH1JjoXdDXfxvSP_0gjUYb0ektudYFXoA6wekmQyJeImvgx4Myz1I4iHtkY_Cp7J4Mn1ejZ6HNmyvoTE_4OuY1uCeYv4UyXFc1s1uUyYtj4z57qsHGsS4dQ3A2MJsw', |
|
620
|
|
|
'e' => 'AQAB', |
|
621
|
|
|
]); |
|
622
|
|
|
|
|
623
|
|
|
return $key; |
|
624
|
|
|
} |
|
625
|
|
|
|
|
626
|
|
|
/** |
|
627
|
|
|
* @return JWK |
|
628
|
|
|
*/ |
|
629
|
|
|
private function getRSARecipientKeyWithAlgorithm() |
|
630
|
|
|
{ |
|
631
|
|
|
$key = JWK::create([ |
|
632
|
|
|
'kty' => 'RSA', |
|
633
|
|
|
'use' => 'enc', |
|
634
|
|
|
'alg' => 'RSA-OAEP', |
|
635
|
|
|
'n' => 'tpS1ZmfVKVP5KofIhMBP0tSWc4qlh6fm2lrZSkuKxUjEaWjzZSzs72gEIGxraWusMdoRuV54xsWRyf5KeZT0S-I5Prle3Idi3gICiO4NwvMk6JwSBcJWwmSLFEKyUSnB2CtfiGc0_5rQCpcEt_Dn5iM-BNn7fqpoLIbks8rXKUIj8-qMVqkTXsEKeKinE23t1ykMldsNaaOH-hvGti5Jt2DMnH1JjoXdDXfxvSP_0gjUYb0ektudYFXoA6wekmQyJeImvgx4Myz1I4iHtkY_Cp7J4Mn1ejZ6HNmyvoTE_4OuY1uCeYv4UyXFc1s1uUyYtj4z57qsHGsS4dQ3A2MJsw', |
|
636
|
|
|
'e' => 'AQAB', |
|
637
|
|
|
]); |
|
638
|
|
|
|
|
639
|
|
|
return $key; |
|
640
|
|
|
} |
|
641
|
|
|
|
|
642
|
|
|
/** |
|
643
|
|
|
* @return JWK |
|
644
|
|
|
*/ |
|
645
|
|
|
private function getSigningKey() |
|
646
|
|
|
{ |
|
647
|
|
|
$key = JWK::create([ |
|
648
|
|
|
'kty' => 'EC', |
|
649
|
|
|
'key_ops' => ['sign', 'verify'], |
|
650
|
|
|
'crv' => 'P-256', |
|
651
|
|
|
'x' => 'f83OJ3D2xF1Bg8vub9tLe1gHMzV76e8Tus9uPHvRVEU', |
|
652
|
|
|
'y' => 'x_FEzRu9m36HLN_tue659LNpXW6pCyStikYjKIWI5a0', |
|
653
|
|
|
'd' => 'jpsQnnGQmL-YBIffH1136cspYG6-0iY7X1fCE9-E9LI', |
|
654
|
|
|
]); |
|
655
|
|
|
|
|
656
|
|
|
return $key; |
|
657
|
|
|
} |
|
658
|
|
|
|
|
659
|
|
|
/** |
|
660
|
|
|
* @return JWK |
|
661
|
|
|
*/ |
|
662
|
|
|
private function getECDHRecipientPublicKey() |
|
663
|
|
|
{ |
|
664
|
|
|
$key = JWK::create([ |
|
665
|
|
|
'kty' => 'EC', |
|
666
|
|
|
'key_ops' => ['encrypt', 'decrypt'], |
|
667
|
|
|
'crv' => 'P-256', |
|
668
|
|
|
'x' => 'f83OJ3D2xF1Bg8vub9tLe1gHMzV76e8Tus9uPHvRVEU', |
|
669
|
|
|
'y' => 'x_FEzRu9m36HLN_tue659LNpXW6pCyStikYjKIWI5a0', |
|
670
|
|
|
]); |
|
671
|
|
|
|
|
672
|
|
|
return $key; |
|
673
|
|
|
} |
|
674
|
|
|
|
|
675
|
|
|
/** |
|
676
|
|
|
* @return JWK |
|
677
|
|
|
*/ |
|
678
|
|
|
private function getDirectKey() |
|
679
|
|
|
{ |
|
680
|
|
|
$key = JWK::create([ |
|
681
|
|
|
'kid' => 'DIR_1', |
|
682
|
|
|
'key_ops' => ['encrypt', 'decrypt'], |
|
683
|
|
|
'kty' => 'oct', |
|
684
|
|
|
'k' => Base64Url::encode(hex2bin('00112233445566778899AABBCCDDEEFF000102030405060708090A0B0C0D0E0F')), |
|
685
|
|
|
]); |
|
686
|
|
|
|
|
687
|
|
|
return $key; |
|
688
|
|
|
} |
|
689
|
|
|
|
|
690
|
|
|
/** |
|
691
|
|
|
* @return JWKSet |
|
692
|
|
|
*/ |
|
693
|
|
|
private function getPrivateKeySet(): JWKSet |
|
694
|
|
|
{ |
|
695
|
|
|
$keys = ['keys' => [ |
|
696
|
|
|
[ |
|
697
|
|
|
'kty' => 'EC', |
|
698
|
|
|
'crv' => 'P-256', |
|
699
|
|
|
'x' => 'weNJy2HscCSM6AEDTDg04biOvhFhyyWvOHQfeF_PxMQ', |
|
700
|
|
|
'y' => 'e8lnCO-AlStT-NJVX-crhB7QRYhiix03illJOVAOyck', |
|
701
|
|
|
'd' => 'VEmDZpDXXK8p8N0Cndsxs924q6nS1RXFASRl6BfUqdw', |
|
702
|
|
|
], |
|
703
|
|
|
[ |
|
704
|
|
|
'kty' => 'EC', |
|
705
|
|
|
'crv' => 'P-256', |
|
706
|
|
|
'x' => 'gI0GAILBdu7T53akrFmMyGcsF3n5dO7MmwNBHKW5SV0', |
|
707
|
|
|
'y' => 'SLW_xSffzlPWrHEVI30DHM_4egVwt3NQqeUD7nMFpps', |
|
708
|
|
|
'd' => '0_NxaRPUMQoAJt50Gz8YiTr8gRTwyEaCumd-MToTmIo', |
|
709
|
|
|
], |
|
710
|
|
|
[ |
|
711
|
|
|
'kid' => '2010-12-29', |
|
712
|
|
|
'kty' => 'RSA', |
|
713
|
|
|
'n' => 'ofgWCuLjybRlzo0tZWJjNiuSfb4p4fAkd_wWJcyQoTbji9k0l8W26mPddxHmfHQp-Vaw-4qPCJrcS2mJPMEzP1Pt0Bm4d4QlL-yRT-SFd2lZS-pCgNMsD1W_YpRPEwOWvG6b32690r2jZ47soMZo9wGzjb_7OMg0LOL-bSf63kpaSHSXndS5z5rexMdbBYUsLA9e-KXBdQOS-UTo7WTBEMa2R2CapHg665xsmtdVMTBQY4uDZlxvb3qCo5ZwKh9kG4LT6_I5IhlJH7aGhyxXFvUK-DWNmoudF8NAco9_h9iaGNj8q2ethFkMLs91kzk2PAcDTW9gb54h4FRWyuXpoQ', |
|
714
|
|
|
'e' => 'AQAB', |
|
715
|
|
|
'd' => 'Eq5xpGnNCivDflJsRQBXHx1hdR1k6Ulwe2JZD50LpXyWPEAeP88vLNO97IjlA7_GQ5sLKMgvfTeXZx9SE-7YwVol2NXOoAJe46sui395IW_GO-pWJ1O0BkTGoVEn2bKVRUCgu-GjBVaYLU6f3l9kJfFNS3E0QbVdxzubSu3Mkqzjkn439X0M_V51gfpRLI9JYanrC4D4qAdGcopV_0ZHHzQlBjudU2QvXt4ehNYTCBr6XCLQUShb1juUO1ZdiYoFaFQT5Tw8bGUl_x_jTj3ccPDVZFD9pIuhLhBOneufuBiB4cS98l2SR_RQyGWSeWjnczT0QU91p1DhOVRuOopznQ', |
|
716
|
|
|
], |
|
717
|
|
|
[ |
|
718
|
|
|
'kid' => 'e9bc097a-ce51-4036-9562-d2ade882db0d', |
|
719
|
|
|
'kty' => 'EC', |
|
720
|
|
|
'crv' => 'P-256', |
|
721
|
|
|
'x' => 'f83OJ3D2xF1Bg8vub9tLe1gHMzV76e8Tus9uPHvRVEU', |
|
722
|
|
|
'y' => 'x_FEzRu9m36HLN_tue659LNpXW6pCyStikYjKIWI5a0', |
|
723
|
|
|
'd' => 'jpsQnnGQmL-YBIffH1136cspYG6-0iY7X1fCE9-E9LI', |
|
724
|
|
|
], |
|
725
|
|
|
[ |
|
726
|
|
|
'kid' => '123456789', |
|
727
|
|
|
'kty' => 'RSA', |
|
728
|
|
|
'n' => 'tpS1ZmfVKVP5KofIhMBP0tSWc4qlh6fm2lrZSkuKxUjEaWjzZSzs72gEIGxraWusMdoRuV54xsWRyf5KeZT0S-I5Prle3Idi3gICiO4NwvMk6JwSBcJWwmSLFEKyUSnB2CtfiGc0_5rQCpcEt_Dn5iM-BNn7fqpoLIbks8rXKUIj8-qMVqkTXsEKeKinE23t1ykMldsNaaOH-hvGti5Jt2DMnH1JjoXdDXfxvSP_0gjUYb0ektudYFXoA6wekmQyJeImvgx4Myz1I4iHtkY_Cp7J4Mn1ejZ6HNmyvoTE_4OuY1uCeYv4UyXFc1s1uUyYtj4z57qsHGsS4dQ3A2MJsw', |
|
729
|
|
|
'e' => 'AQAB', |
|
730
|
|
|
'p' => '5BGU1c7af_5sFyfsa-onIJgo5BZu8uHvz3Uyb8OA0a-G9UPO1ShLYjX0wUfhZcFB7fwPtgmmYAN6wKGVce9eMAbX4PliPk3r-BcpZuPKkuLk_wFvgWAQ5Hqw2iEuwXLV0_e8c2gaUt_hyMC5-nFc4v0Bmv6NT6Pfry-UrK3BKWc', |
|
731
|
|
|
'd' => 'Kp0KuZwCZGL1BLgsVM-N0edMNitl9wN5Hf2WOYDoIqOZNAEKzdJuenIMhITJjRFUX05GVL138uyp2js_pqDdY9ipA7rAKThwGuDdNphZHech9ih3DGEPXs-YpmHqvIbCd3GoGm38MKwxYkddEpFnjo8rKna1_BpJthrFxjDRhw9DxJBycOdH2yWTyp62ZENPvneK40H2a57W4QScTgfecZqD59m2fGUaWaX5uUmIxaEmtGoJnd9RE4oywKhgN7_TK7wXRlqA4UoRPiH2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EzgdRhajnu0ferB0d53vM9mE15j2C', |
|
776
|
|
|
], |
|
777
|
|
|
]]; |
|
778
|
|
|
|
|
779
|
|
|
return JWKSet::createFromKeyData($keys); |
|
780
|
|
|
} |
|
781
|
|
|
|
|
782
|
|
|
/** |
|
783
|
|
|
* @return JWKSet |
|
784
|
|
|
*/ |
|
785
|
|
|
private function getSymmetricKeySet(): JWKSet |
|
786
|
|
|
{ |
|
787
|
|
|
$keys = ['keys' => [ |
|
788
|
|
|
[ |
|
789
|
|
|
'kid' => 'DIR_1', |
|
790
|
|
|
'kty' => 'oct', |
|
791
|
|
|
'k' => Base64Url::encode(hex2bin('00112233445566778899AABBCCDDEEFF000102030405060708090A0B0C0D0E0F')), |
|
792
|
|
|
], |
|
793
|
|
|
[ |
|
794
|
|
|
'kty' => 'oct', |
|
795
|
|
|
'k' => 'f5aN5V6iihwQVqP-tPNNtkIJNCwUb9-JukCIKkF0rNfxqxA771RJynYAT2xtzAP0MYaR7U5fMP_wvbRQq5l38Q', |
|
796
|
|
|
], |
|
797
|
|
|
[ |
|
798
|
|
|
'kty' => 'oct', |
|
799
|
|
|
'k' => 'GawgguFyGrWKav7AX4VKUg', |
|
800
|
|
|
], |
|
801
|
|
|
[ |
|
802
|
|
|
'kty' => 'oct', |
|
803
|
|
|
'k' => 'AyM1SysPpbyDfgZld3umj1qzKObwVMkoqQ-EstJQLr_T-1qS0gZH75aKtMN3Yj0iPS4hcgUuTwjAzZr1Z9CAow', |
|
804
|
|
|
], |
|
805
|
|
|
]]; |
|
806
|
|
|
|
|
807
|
|
|
return JWKSet::createFromKeyData($keys); |
|
808
|
|
|
} |
|
809
|
|
|
} |
|
810
|
|
|
|