|
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 Jose\Component\Core\JWAManagerFactory; |
|
17
|
|
|
use Jose\Component\Encryption\Algorithm\KeyEncryption; |
|
18
|
|
|
use Jose\Component\Encryption\Algorithm\ContentEncryption; |
|
19
|
|
|
use Jose\Component\Encryption\Compression; |
|
20
|
|
|
use Jose\Component\Encryption\Compression\CompressionMethodsManagerFactory; |
|
21
|
|
|
use Jose\Component\Encryption\JWEBuilderFactory; |
|
22
|
|
|
use PHPUnit\Framework\TestCase; |
|
23
|
|
|
|
|
24
|
|
|
abstract class AbstractEncryptionTest extends TestCase |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* @var JWAManagerFactory |
|
28
|
|
|
*/ |
|
29
|
|
|
private $algorithmManagerFactory; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @return JWAManagerFactory |
|
33
|
|
|
*/ |
|
34
|
|
|
protected function getAlgorithmManagerFactory(): JWAManagerFactory |
|
35
|
|
|
{ |
|
36
|
|
|
if (null === $this->algorithmManagerFactory) { |
|
37
|
|
|
$this->algorithmManagerFactory = new JWAManagerFactory(); |
|
38
|
|
|
$this->algorithmManagerFactory |
|
39
|
|
|
->add('A128GCM', new ContentEncryption\A128GCM()) |
|
40
|
|
|
->add('A192GCM', new ContentEncryption\A192GCM()) |
|
41
|
|
|
->add('A256GCM', new ContentEncryption\A256GCM()) |
|
42
|
|
|
->add('A128CBC-HS256', new ContentEncryption\A128CBCHS256()) |
|
43
|
|
|
->add('A192CBC-HS384', new ContentEncryption\A192CBCHS384()) |
|
44
|
|
|
->add('A256CBC-HS512', new ContentEncryption\A256CBCHS512()) |
|
45
|
|
|
->add('A128GCMKW', new KeyEncryption\A128GCMKW()) |
|
46
|
|
|
->add('A192GCMKW', new KeyEncryption\A192GCMKW()) |
|
47
|
|
|
->add('A256GCMKW', new KeyEncryption\A256GCMKW()) |
|
48
|
|
|
->add('A128KW', new KeyEncryption\A128KW()) |
|
49
|
|
|
->add('A192KW', new KeyEncryption\A192KW()) |
|
50
|
|
|
->add('A256KW', new KeyEncryption\A256KW()) |
|
51
|
|
|
->add('dir', new KeyEncryption\Dir()) |
|
52
|
|
|
->add('ECDH-ES', new KeyEncryption\ECDHES()) |
|
53
|
|
|
->add('ECDH-ES+A128KW', new KeyEncryption\ECDHESA128KW()) |
|
54
|
|
|
->add('ECDH-ES+A192KW', new KeyEncryption\ECDHESA192KW()) |
|
55
|
|
|
->add('ECDH-ES+A256KW', new KeyEncryption\ECDHESA256KW()) |
|
56
|
|
|
->add('PBES2-HS256+A128KW', new KeyEncryption\PBES2HS256A128KW()) |
|
57
|
|
|
->add('PBES2-HS384+A192KW', new KeyEncryption\PBES2HS384A192KW()) |
|
58
|
|
|
->add('PBES2-HS512+A256KW', new KeyEncryption\PBES2HS512A256KW()) |
|
59
|
|
|
->add('RSA1_5', new KeyEncryption\RSA15()) |
|
60
|
|
|
->add('RSA-OAEP', new KeyEncryption\RSAOAEP()) |
|
61
|
|
|
->add('RSA-OAEP-256', new KeyEncryption\RSAOAEP256()); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
return $this->algorithmManagerFactory; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @var CompressionMethodsManagerFactory |
|
69
|
|
|
*/ |
|
70
|
|
|
private $compressionMethodManagerFactory; |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @return CompressionMethodsManagerFactory |
|
74
|
|
|
*/ |
|
75
|
|
|
protected function getCompressionMethodManagerFactory(): CompressionMethodsManagerFactory |
|
76
|
|
|
{ |
|
77
|
|
|
if (null === $this->compressionMethodManagerFactory) { |
|
78
|
|
|
$this->compressionMethodManagerFactory = new CompressionMethodsManagerFactory(); |
|
79
|
|
|
$this->compressionMethodManagerFactory |
|
80
|
|
|
->add('DEF', new Compression\Deflate()) |
|
81
|
|
|
->add('ZLIB', new Compression\ZLib()) |
|
82
|
|
|
->add('GZ', new Compression\GZip()); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
return $this->compressionMethodManagerFactory; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @var JWEBuilderFactory |
|
90
|
|
|
*/ |
|
91
|
|
|
private $jwsBuilderFactory; |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @return JWEBuilderFactory |
|
95
|
|
|
*/ |
|
96
|
|
|
protected function getJWEBuilderFactory(): JWEBuilderFactory |
|
97
|
|
|
{ |
|
98
|
|
|
if (null === $this->jwsBuilderFactory) { |
|
99
|
|
|
$this->jwsBuilderFactory = new JWEBuilderFactory( |
|
100
|
|
|
$this->getAlgorithmManagerFactory(), |
|
101
|
|
|
$this->getCompressionMethodManagerFactory() |
|
102
|
|
|
); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
return $this->jwsBuilderFactory; |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|