1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LeKoala\Encrypt; |
4
|
|
|
|
5
|
|
|
use Exception; |
6
|
|
|
use ParagonIE\CipherSweet\EncryptedField; |
7
|
|
|
use ParagonIE\CipherSweet\Exception\InvalidCiphertextException; |
8
|
|
|
|
9
|
|
|
trait HasBaseEncryption |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var Exception |
13
|
|
|
*/ |
14
|
|
|
protected $encryptionException; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
protected $encryptionAad = ''; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @return Exception |
23
|
|
|
*/ |
24
|
|
|
public function getEncryptionException() |
25
|
|
|
{ |
26
|
|
|
return $this->encryptionException; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param CipherSweet $engine |
|
|
|
|
31
|
|
|
* @return EncryptedField |
32
|
|
|
*/ |
33
|
|
|
public function getEncryptedField($engine = null) |
34
|
|
|
{ |
35
|
|
|
if ($engine === null) { |
36
|
|
|
$engine = EncryptHelper::getCipherSweet(); |
37
|
|
|
} |
38
|
|
|
$encryptedField = new EncryptedField($engine, $this->tableName, $this->name); |
39
|
|
|
return $encryptedField; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Decrypt current value using underlying EncryptedField instance |
44
|
|
|
* |
45
|
|
|
* @return string |
46
|
|
|
*/ |
47
|
|
|
public function getDecryptedValue() |
48
|
|
|
{ |
49
|
|
|
if (EncryptHelper::isEncrypted($this->value)) { |
50
|
|
|
return $this->decryptValue($this->value); |
51
|
|
|
} |
52
|
|
|
return $this->value; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param DataObject $record |
|
|
|
|
57
|
|
|
* @return void |
58
|
|
|
*/ |
59
|
|
|
protected function setEncryptionAad($record) |
60
|
|
|
{ |
61
|
|
|
$field = EncryptHelper::getAadSource(); |
62
|
|
|
if (!$field) { |
63
|
|
|
return; |
64
|
|
|
} |
65
|
|
|
if ($record && isset($record->$field)) { |
66
|
|
|
$this->encryptionAad = (string)$record->$field; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Decrypt a value using underlying EncryptedField instance |
72
|
|
|
* |
73
|
|
|
* @param string $value |
74
|
|
|
* @return string |
75
|
|
|
*/ |
76
|
|
|
protected function decryptValue($value) |
77
|
|
|
{ |
78
|
|
|
$decrypted = null; |
|
|
|
|
79
|
|
|
$aad = $this->encryptionAad; |
80
|
|
|
try { |
81
|
|
|
$decrypted = $this->getEncryptedField()->decryptValue($value, $aad); |
82
|
|
|
} catch (InvalidCiphertextException $ex) { |
83
|
|
|
$this->encryptionException = $ex; |
84
|
|
|
// rotate backend ? |
85
|
|
|
if (EncryptHelper::getAutomaticRotation()) { |
86
|
|
|
$encryption = EncryptHelper::getEncryption($value); |
87
|
|
|
$engine = EncryptHelper::getEngineForEncryption($encryption); |
88
|
|
|
$oldEncryptedField = $this->getEncryptedField($engine); |
89
|
|
|
$decrypted = $oldEncryptedField->decryptValue($value, $aad); |
90
|
|
|
} else { |
91
|
|
|
$decrypted = $value; |
92
|
|
|
} |
93
|
|
|
} catch (Exception $ex) { |
94
|
|
|
$this->encryptionException = $ex; |
95
|
|
|
} |
96
|
|
|
return $decrypted; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths