@@ -54,7 +54,7 @@ |
||
54 | 54 | if ($prefix === $this->encryption->get_type()) { |
55 | 55 | // Decrypt the secret if it is prefixed with the current encryption type |
56 | 56 | // Remove the encryption type prefix before decrypting |
57 | - return $this->encryption->decrypt( substr($encryptedSecret, $pos+1) ); |
|
57 | + return $this->encryption->decrypt( substr($encryptedSecret, $pos+1) ); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | // Check the decryption array for the encryption type to see if there is an encryption |
@@ -54,13 +54,13 @@ discard block |
||
54 | 54 | if ($prefix === $this->encryption->get_type()) { |
55 | 55 | // Decrypt the secret if it is prefixed with the current encryption type |
56 | 56 | // Remove the encryption type prefix before decrypting |
57 | - return $this->encryption->decrypt( substr($encryptedSecret, $pos+1) ); |
|
57 | + return $this->encryption->decrypt(substr($encryptedSecret, $pos + 1)); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | // Check the decryption array for the encryption type to see if there is an encryption |
61 | 61 | // instance defined for it. If so, use that to decrypt the secret. |
62 | 62 | if (isset($this->decryption[$prefix])) { |
63 | - return $this->decryption[$prefix]->decrypt( substr($encryptedSecret, $pos+1) ); |
|
63 | + return $this->decryption[$prefix]->decrypt(substr($encryptedSecret, $pos + 1)); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | $this->logger->error("Secret for user '$userId' is encrypted with unsupported encryption type '$prefix'"); |
@@ -77,6 +77,6 @@ discard block |
||
77 | 77 | { |
78 | 78 | $encryptedSecret = $this->encryption->encrypt($secret); |
79 | 79 | // Prefix the user secret with the encryption type |
80 | - $this->setUserSecret($userId, $this->encryption->get_type() . ':' . $encryptedSecret); |
|
80 | + $this->setUserSecret($userId, $this->encryption->get_type().':'.$encryptedSecret); |
|
81 | 81 | } |
82 | 82 | } |
@@ -38,7 +38,7 @@ |
||
38 | 38 | * |
39 | 39 | * @return Tiqr_UserSecretStorage_Encryption_Interface |
40 | 40 | */ |
41 | - public static function getEncryption(LoggerInterface $logger, string $type="dummy", array $options=array()): Tiqr_UserSecretStorage_Encryption_Interface |
|
41 | + public static function getEncryption(LoggerInterface $logger, string $type = "dummy", array $options = array()): Tiqr_UserSecretStorage_Encryption_Interface |
|
42 | 42 | { |
43 | 43 | $instance = null; |
44 | 44 | $logger->info(sprintf('Using "%s" as UserSecretStorage encryption type', $type)); |
@@ -160,7 +160,7 @@ |
||
160 | 160 | } |
161 | 161 | |
162 | 162 | /** |
163 | - * Decrypts the given data. |
|
163 | + * Decrypts the given data. |
|
164 | 164 | * |
165 | 165 | * @param string $data Data to decrypt. |
166 | 166 | * @return string decrypted data |
@@ -48,23 +48,23 @@ discard block |
||
48 | 48 | */ |
49 | 49 | |
50 | 50 | private $_supportedCiphers = [ |
51 | - 'aes-128-cbc' => [ 'tag' => false, 'key' => 16 ], |
|
52 | - 'aes-128-gcm' => [ 'tag' => true, 'key' => 16 ], |
|
53 | - 'aes-192-cbc' => [ 'tag' => false, 'key' => 24 ], |
|
54 | - 'aes-192-gcm' => [ 'tag' => true, 'key' => 24 ], |
|
55 | - 'aes-256-cbc' => [ 'tag' => false, 'key' => 32 ], |
|
56 | - 'aes-256-gcm' => [ 'tag' => true, 'key' => 32 ], |
|
57 | - 'chacha20' => [ 'tag' => false, 'key' => 32 ], |
|
58 | - 'chacha20-poly1305' => [ 'tag' => false, 'key' => 32 ], |
|
59 | - 'camellia-128-cbc' => [ 'tag' => false, 'key' => 16 ], |
|
60 | - 'camellia-192-cbc' => [ 'tag' => false, 'key' => 24 ], |
|
61 | - 'camellia-256-cbc' => [ 'tag' => false, 'key' => 32 ], |
|
62 | - 'aria-128-cbc' => [ 'tag' => false, 'key' => 16 ], |
|
63 | - 'aria-128-gcm' => [ 'tag' => true, 'key' => 16 ], |
|
64 | - 'aria-192-cbc' => [ 'tag' => false, 'key' => 24 ], |
|
65 | - 'aria-192-gcm' => [ 'tag' => true, 'key' => 24 ], |
|
66 | - 'aria-256-cbc' => [ 'tag' => false, 'key' => 32 ], |
|
67 | - 'aria-256-gcm' => [ 'tag' => true, 'key' => 32 ], |
|
51 | + 'aes-128-cbc' => ['tag' => false, 'key' => 16], |
|
52 | + 'aes-128-gcm' => ['tag' => true, 'key' => 16], |
|
53 | + 'aes-192-cbc' => ['tag' => false, 'key' => 24], |
|
54 | + 'aes-192-gcm' => ['tag' => true, 'key' => 24], |
|
55 | + 'aes-256-cbc' => ['tag' => false, 'key' => 32], |
|
56 | + 'aes-256-gcm' => ['tag' => true, 'key' => 32], |
|
57 | + 'chacha20' => ['tag' => false, 'key' => 32], |
|
58 | + 'chacha20-poly1305' => ['tag' => false, 'key' => 32], |
|
59 | + 'camellia-128-cbc' => ['tag' => false, 'key' => 16], |
|
60 | + 'camellia-192-cbc' => ['tag' => false, 'key' => 24], |
|
61 | + 'camellia-256-cbc' => ['tag' => false, 'key' => 32], |
|
62 | + 'aria-128-cbc' => ['tag' => false, 'key' => 16], |
|
63 | + 'aria-128-gcm' => ['tag' => true, 'key' => 16], |
|
64 | + 'aria-192-cbc' => ['tag' => false, 'key' => 24], |
|
65 | + 'aria-192-gcm' => ['tag' => true, 'key' => 24], |
|
66 | + 'aria-256-cbc' => ['tag' => false, 'key' => 32], |
|
67 | + 'aria-256-gcm' => ['tag' => true, 'key' => 32], |
|
68 | 68 | ]; |
69 | 69 | |
70 | 70 | /** |
@@ -137,12 +137,12 @@ discard block |
||
137 | 137 | // A longer key is not a problem, but could indicate a configuration error |
138 | 138 | $key_length = $this->_supportedCiphers[$this->_cipher]['key']; |
139 | 139 | if (strlen($key) != $key_length) { |
140 | - throw new RuntimeException("Invalid length of key with key_id '{$this->_key_id}' used with cipher '{$this->_cipher}', expected {$key_length} bytes, got " . strlen($key) . " bytes"); |
|
140 | + throw new RuntimeException("Invalid length of key with key_id '{$this->_key_id}' used with cipher '{$this->_cipher}', expected {$key_length} bytes, got ".strlen($key)." bytes"); |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | // openssl_encrypt returns the ciphertext as a base64 encoded string, so we don't need to encode it again |
144 | 144 | // The tag is returned as a binary string, but only if the cipher requires a tag |
145 | - $tag=''; |
|
145 | + $tag = ''; |
|
146 | 146 | if ($this->_supportedCiphers[$this->_cipher]['tag']) { |
147 | 147 | $encrypted = openssl_encrypt($data, $this->_cipher, $key, 0, $iv, $tag, '', 16); |
148 | 148 | } else { |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | $tag = $this->_supportedCiphers[$this->_cipher]['tag'] ? $tag : ''; |
155 | 155 | // Return the encoded ciphertext, including the IV, tag and cipher |
156 | 156 | // <cipher>:<key_id>:iv<>:<tag>:<ciphertext> |
157 | - $encoded = $this->_cipher . ":" . $this->_key_id . ":" . base64_encode($iv) . ":" . base64_encode($tag) . ":" . $encrypted; |
|
157 | + $encoded = $this->_cipher.":".$this->_key_id.":".base64_encode($iv).":".base64_encode($tag).":".$encrypted; |
|
158 | 158 | |
159 | 159 | return $encoded; |
160 | 160 | } |
@@ -193,19 +193,19 @@ discard block |
||
193 | 193 | } |
194 | 194 | |
195 | 195 | // IV |
196 | - $iv = base64_decode($split_data[2],true); |
|
196 | + $iv = base64_decode($split_data[2], true); |
|
197 | 197 | if ($iv === false) { |
198 | 198 | throw new RuntimeException("Error decoding IV"); |
199 | 199 | } |
200 | 200 | |
201 | 201 | // Tag |
202 | - $tag = base64_decode($split_data[3],true); |
|
202 | + $tag = base64_decode($split_data[3], true); |
|
203 | 203 | if ($tag === false) { |
204 | 204 | throw new RuntimeException("Error decoding tag"); |
205 | 205 | } |
206 | 206 | $ciphertext = $split_data[4]; |
207 | 207 | |
208 | - $plaintext=openssl_decrypt($ciphertext, $cipher, $key, 0, $iv, $tag); |
|
208 | + $plaintext = openssl_decrypt($ciphertext, $cipher, $key, 0, $iv, $tag); |
|
209 | 209 | if ($plaintext === false) { |
210 | 210 | throw new RuntimeException("Error decrypting data"); |
211 | 211 | } |
@@ -97,7 +97,7 @@ |
||
97 | 97 | * ), |
98 | 98 | * ) |
99 | 99 | * ); |
100 | - * |
|
100 | + * |
|
101 | 101 | * |
102 | 102 | * @return Tiqr_UserSecretStorage_Interface |
103 | 103 | * @throws RuntimeException If an unknown type is requested. |