Skip to content

Commit 45d1feb

Browse files
committed
Moves the weak cipher check to the Crypter
1 parent 74f6694 commit 45d1feb

File tree

2 files changed

+45
-37
lines changed

2 files changed

+45
-37
lines changed

src/Backup/Crypter/OpenSSL.php

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,47 @@ class OpenSSL extends Abstraction implements Simulator, Restorable
5555
*/
5656
private $keepUncrypted;
5757

58+
private $weakAlgorithms = [
59+
'rc2' => true,
60+
'rc2-40' => true,
61+
'rc2-64' => true,
62+
'rc2-128' => true,
63+
'rc2-40-cbc' => true,
64+
'rc2-64-cbc' => true,
65+
'rc2-cbc' => true,
66+
'rc2-cfb' => true,
67+
'rc2-ecb' => true,
68+
'rc2-ofb' => true,
69+
'rc4' => true,
70+
'rc4-40' => true,
71+
'des' => true,
72+
'des-cbc' => true,
73+
'des-cfb' => true,
74+
'des-ecb' => true,
75+
'des-ede' => true,
76+
'des-ede-cbc' => true,
77+
'des-ede-cfb' => true,
78+
'des-ede-ofb' => true,
79+
'des-ede3' => true,
80+
'des-ede3-cbc' => true,
81+
'des-ede3-cfb' => true,
82+
'des-ede3-ofb' => true,
83+
'des-ofb' => true,
84+
'des3' => true,
85+
'desx' => true,
86+
'seed' => true,
87+
'seed-cbc' => true,
88+
'seed-cfb' => true,
89+
'seed-ecb' => true,
90+
'seed-ofb' => true,
91+
];
5892

5993
/**
6094
* @inheritDoc
6195
*/
6296
public function crypt(Target $target, Result $result)
6397
{
64-
if ($this->getExecutable($target)->isUsingWeakAlgorithm()) {
98+
if ($this->isUsingWeakAlgorithm()) {
6599
$name = strtolower(get_class($this));
66100

67101
$result->warn($name . ': The ' . $this->algorithm . ' algorithm is considered weak');
@@ -76,7 +110,7 @@ public function crypt(Target $target, Result $result)
76110
*/
77111
public function simulate(Target $target, Result $result)
78112
{
79-
if ($this->getExecutable($target)->isUsingWeakAlgorithm()) {
113+
if ($this->isUsingWeakAlgorithm()) {
80114
$name = strtolower(get_class($this));
81115

82116
$result->warn($name . ': The ' . $this->algorithm . ' algorithm is considered weak');
@@ -85,6 +119,15 @@ public function simulate(Target $target, Result $result)
85119
return parent::simulate($target, $result);
86120
}
87121

122+
public function isUsingWeakAlgorithm(): bool
123+
{
124+
if (null === $this->algorithm) {
125+
throw new Exception('algorithm is not set');
126+
}
127+
128+
return isset($this->weakAlgorithms[$this->algorithm]);
129+
}
130+
88131
/**
89132
* Setup
90133
*

src/Cli/Executable/OpenSSL.php

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -162,41 +162,6 @@ class OpenSSL extends Abstraction implements Executable
162162
]
163163
];
164164

165-
private $weakAlgorithms = [
166-
'rc2' => true,
167-
'rc2-40' => true,
168-
'rc2-64' => true,
169-
'rc2-128' => true,
170-
'rc2-40-cbc' => true,
171-
'rc2-64-cbc' => true,
172-
'rc2-cbc' => true,
173-
'rc2-cfb' => true,
174-
'rc2-ecb' => true,
175-
'rc2-ofb' => true,
176-
'rc4' => true,
177-
'rc4-40' => true,
178-
'des' => true,
179-
'des-cbc' => true,
180-
'des-cfb' => true,
181-
'des-ecb' => true,
182-
'des-ede' => true,
183-
'des-ede-cbc' => true,
184-
'des-ede-cfb' => true,
185-
'des-ede-ofb' => true,
186-
'des-ede3' => true,
187-
'des-ede3-cbc' => true,
188-
'des-ede3-cfb' => true,
189-
'des-ede3-ofb' => true,
190-
'des-ofb' => true,
191-
'des3' => true,
192-
'desx' => true,
193-
'seed' => true,
194-
'seed-cbc' => true,
195-
'seed-cfb' => true,
196-
'seed-ecb' => true,
197-
'seed-ofb' => true,
198-
];
199-
200165
/**
201166
* Keep the not encrypted file
202167
*

0 commit comments

Comments
 (0)