Failed Conditions
Push — v7 ( ae6905...7dd7be )
by Florent
03:50
created

testMultipleInstructionsNotAllowedWithFlattenedSerialization()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

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