@@ -35,7 +35,7 @@ |
||
35 | 35 | $this->logger = $logger; |
36 | 36 | |
37 | 37 | // Set the OCRA suite |
38 | - $this->_ocraSuite = $config['ocra.suite'] ?? 'OCRA-1:HOTP-SHA1-6:QH10-S'; // Use tiqr server default suite |
|
38 | + $this->_ocraSuite = $config['ocra.suite'] ?? 'OCRA-1:HOTP-SHA1-6:QH10-S'; // Use tiqr server default suite |
|
39 | 39 | $this->_ocraParser = new OATH_OCRAParser($this->_ocraSuite); |
40 | 40 | } |
41 | 41 |
@@ -40,10 +40,10 @@ |
||
40 | 40 | * @param LoggerInterface $logger |
41 | 41 | * @throws Exception An exception if an unknown storage is requested. |
42 | 42 | */ |
43 | - public static function getStorage(string $type="dummy", Array $options=array(), LoggerInterface $logger=null) |
|
43 | + public static function getStorage(string $type = "dummy", Array $options = array(), LoggerInterface $logger = null) |
|
44 | 44 | { |
45 | 45 | if (!$logger) |
46 | - $logger=new \Psr\Log\NullLogger(); |
|
46 | + $logger = new \Psr\Log\NullLogger(); |
|
47 | 47 | |
48 | 48 | switch ($type) { |
49 | 49 | case "dummy": |
@@ -42,8 +42,9 @@ |
||
42 | 42 | */ |
43 | 43 | public static function getStorage(string $type="dummy", Array $options=array(), LoggerInterface $logger=null) |
44 | 44 | { |
45 | - if (!$logger) |
|
46 | - $logger=new \Psr\Log\NullLogger(); |
|
45 | + if (!$logger) { |
|
46 | + $logger=new \Psr\Log\NullLogger(); |
|
47 | + } |
|
47 | 48 | |
48 | 49 | switch ($type) { |
49 | 50 | case "dummy": |
@@ -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,22 +48,22 @@ 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 | - 'camellia-128-cbc' => [ 'tag' => false, 'key' => 16 ], |
|
59 | - 'camellia-192-cbc' => [ 'tag' => false, 'key' => 24 ], |
|
60 | - 'camellia-256-cbc' => [ 'tag' => false, 'key' => 32 ], |
|
61 | - 'aria-128-cbc' => [ 'tag' => false, 'key' => 16 ], |
|
62 | - 'aria-128-gcm' => [ 'tag' => true, 'key' => 16 ], |
|
63 | - 'aria-192-cbc' => [ 'tag' => false, 'key' => 24 ], |
|
64 | - 'aria-192-gcm' => [ 'tag' => true, 'key' => 24 ], |
|
65 | - 'aria-256-cbc' => [ 'tag' => false, 'key' => 32 ], |
|
66 | - '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 | + 'camellia-128-cbc' => ['tag' => false, 'key' => 16], |
|
59 | + 'camellia-192-cbc' => ['tag' => false, 'key' => 24], |
|
60 | + 'camellia-256-cbc' => ['tag' => false, 'key' => 32], |
|
61 | + 'aria-128-cbc' => ['tag' => false, 'key' => 16], |
|
62 | + 'aria-128-gcm' => ['tag' => true, 'key' => 16], |
|
63 | + 'aria-192-cbc' => ['tag' => false, 'key' => 24], |
|
64 | + 'aria-192-gcm' => ['tag' => true, 'key' => 24], |
|
65 | + 'aria-256-cbc' => ['tag' => false, 'key' => 32], |
|
66 | + 'aria-256-gcm' => ['tag' => true, 'key' => 32], |
|
67 | 67 | ]; |
68 | 68 | |
69 | 69 | /** |
@@ -136,12 +136,12 @@ discard block |
||
136 | 136 | // A longer key is not a problem, but could indicate a configuration error |
137 | 137 | $key_length = $this->_supportedCiphers[$this->_cipher]['key']; |
138 | 138 | if (strlen($key) != $key_length) { |
139 | - 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"); |
|
139 | + 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 | 140 | } |
141 | 141 | |
142 | 142 | // openssl_encrypt returns the ciphertext as a base64 encoded string, so we don't need to encode it again |
143 | 143 | // The tag is returned as a binary string, but only if the cipher requires a tag |
144 | - $tag=''; |
|
144 | + $tag = ''; |
|
145 | 145 | if ($this->_supportedCiphers[$this->_cipher]['tag']) { |
146 | 146 | $encrypted = openssl_encrypt($data, $this->_cipher, $key, 0, $iv, $tag, '', 16); |
147 | 147 | } else { |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | $tag = $this->_supportedCiphers[$this->_cipher]['tag'] ? $tag : ''; |
154 | 154 | // Return the encoded ciphertext, including the IV, tag and cipher |
155 | 155 | // <cipher>:<key_id>:iv<>:<tag>:<ciphertext> |
156 | - $encoded = $this->_cipher . ":" . $this->_key_id . ":" . base64_encode($iv) . ":" . base64_encode($tag) . ":" . $encrypted; |
|
156 | + $encoded = $this->_cipher.":".$this->_key_id.":".base64_encode($iv).":".base64_encode($tag).":".$encrypted; |
|
157 | 157 | |
158 | 158 | return $encoded; |
159 | 159 | } |
@@ -192,19 +192,19 @@ discard block |
||
192 | 192 | } |
193 | 193 | |
194 | 194 | // IV |
195 | - $iv = base64_decode($split_data[2],true); |
|
195 | + $iv = base64_decode($split_data[2], true); |
|
196 | 196 | if ($iv === false) { |
197 | 197 | throw new RuntimeException("Error decoding IV"); |
198 | 198 | } |
199 | 199 | |
200 | 200 | // Tag |
201 | - $tag = base64_decode($split_data[3],true); |
|
201 | + $tag = base64_decode($split_data[3], true); |
|
202 | 202 | if ($tag === false) { |
203 | 203 | throw new RuntimeException("Error decoding tag"); |
204 | 204 | } |
205 | 205 | $ciphertext = $split_data[4]; |
206 | 206 | |
207 | - $plaintext=openssl_decrypt($ciphertext, $cipher, $key, 0, $iv, $tag); |
|
207 | + $plaintext = openssl_decrypt($ciphertext, $cipher, $key, 0, $iv, $tag); |
|
208 | 208 | if ($plaintext === false) { |
209 | 209 | throw new RuntimeException("Error decrypting data"); |
210 | 210 | } |
@@ -57,7 +57,7 @@ |
||
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |
60 | - * Decrypts the given data. |
|
60 | + * Decrypts the given data. |
|
61 | 61 | * |
62 | 62 | * @param String $data Data to decrypt. |
63 | 63 | * |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | { |
41 | 41 | $url = $this->_options["url"]."?appId=".$this->_options["appid"]; |
42 | 42 | |
43 | - $url.= "¬ificationToken=".$notificationToken; |
|
43 | + $url .= "¬ificationToken=".$notificationToken; |
|
44 | 44 | |
45 | 45 | $ch = curl_init(); |
46 | 46 | |
@@ -53,12 +53,12 @@ discard block |
||
53 | 53 | $output = curl_exec($ch); |
54 | 54 | curl_close($ch); |
55 | 55 | |
56 | - if (stripos($output, "not found")!==false) { |
|
56 | + if (stripos($output, "not found") !== false) { |
|
57 | 57 | $this->logger->error('Token Exchange failed and responded with: not found', ['full output' => $output]); |
58 | 58 | return false; |
59 | 59 | } |
60 | 60 | |
61 | - if (stripos($output, "error")!==false) { |
|
61 | + if (stripos($output, "error") !== false) { |
|
62 | 62 | $this->logger->error('Token Exchange failed and responded with: error', ['full output' => $output]); |
63 | 63 | return false; |
64 | 64 | } |
@@ -30,13 +30,11 @@ |
||
30 | 30 | notificationtype varchar(10), |
31 | 31 | notificationaddress varchar(256) |
32 | 32 | ); |
33 | - |
|
34 | 33 | * |
35 | 34 | * In version 3.0 the format of the tmpblocktimestamp was changed from a datetime format to an integer. |
36 | 35 | * Because it holds a unix timestamp a 64-bit (8-byte) integer. To upgrade the user table to the new format use: |
37 | 36 | |
38 | 37 | ALTER TABLE user MODIFY tmpblocktimestamp BIGINT; |
39 | - |
|
40 | 38 | */ |
41 | 39 | |
42 | 40 | use Psr\Log\LoggerInterface; |
@@ -98,21 +98,21 @@ discard block |
||
98 | 98 | */ |
99 | 99 | private function _getStringValue(string $columnName, string $userId): string |
100 | 100 | { |
101 | - if ( !in_array($columnName, $this->_allowedStringColumns) ) { |
|
101 | + if (!in_array($columnName, $this->_allowedStringColumns)) { |
|
102 | 102 | throw new InvalidArgumentException('Unsupported column name'); |
103 | 103 | } |
104 | 104 | |
105 | 105 | try { |
106 | - $sth = $this->handle->prepare('SELECT ' . $columnName . ' FROM ' . $this->tablename . ' WHERE userid = ?'); |
|
106 | + $sth = $this->handle->prepare('SELECT '.$columnName.' FROM '.$this->tablename.' WHERE userid = ?'); |
|
107 | 107 | $sth->execute(array($userId)); |
108 | - $res=$sth->fetchColumn(); |
|
108 | + $res = $sth->fetchColumn(); |
|
109 | 109 | if ($res === false) { |
110 | 110 | // No result |
111 | 111 | $this->logger->error(sprintf('No result getting "%s" for user "%s"', $columnName, $userId)); |
112 | 112 | throw new RuntimeException('User not found'); |
113 | 113 | } |
114 | 114 | if ($res === NULL) { |
115 | - return ''; // Value unset |
|
115 | + return ''; // Value unset |
|
116 | 116 | } |
117 | 117 | if (!is_string($res)) { |
118 | 118 | $this->logger->error(sprintf('Expected string type while getting "%s" for user "%s"', $columnName, $userId)); |
@@ -136,28 +136,28 @@ discard block |
||
136 | 136 | */ |
137 | 137 | private function _getIntValue(string $columnName, string $userId): int |
138 | 138 | { |
139 | - if ( !in_array($columnName, $this->_allowedIntColumns) ) { |
|
139 | + if (!in_array($columnName, $this->_allowedIntColumns)) { |
|
140 | 140 | throw new InvalidArgumentException('Unsupported column name'); |
141 | 141 | } |
142 | 142 | |
143 | 143 | try { |
144 | - $sth = $this->handle->prepare('SELECT ' . $columnName . ' FROM ' . $this->tablename . ' WHERE userid = ?'); |
|
144 | + $sth = $this->handle->prepare('SELECT '.$columnName.' FROM '.$this->tablename.' WHERE userid = ?'); |
|
145 | 145 | $sth->execute(array($userId)); |
146 | - $res=$sth->fetchColumn(); |
|
146 | + $res = $sth->fetchColumn(); |
|
147 | 147 | if ($res === false) { |
148 | 148 | // No result |
149 | 149 | $this->logger->error(sprintf('No result getting "%s" for user "%s"', $columnName, $userId)); |
150 | 150 | throw new RuntimeException('User not found'); |
151 | 151 | } |
152 | 152 | if ($res === NULL) { |
153 | - return 0; // Value unset |
|
153 | + return 0; // Value unset |
|
154 | 154 | } |
155 | 155 | // Return type for integers depends on the PDO driver, can be string |
156 | 156 | if (!is_numeric($res)) { |
157 | 157 | $this->logger->error(sprintf('Expected int type while getting "%s" for user "%s"', $columnName, $userId)); |
158 | 158 | throw new RuntimeException('Unexpected return type'); |
159 | 159 | } |
160 | - return (int)$res; |
|
160 | + return (int) $res; |
|
161 | 161 | } |
162 | 162 | catch (Exception $e) { |
163 | 163 | $this->logger->error('PDO error getting user', array('exception' => $e, 'userId' => $userId, 'columnName'=>$columnName)); |
@@ -174,11 +174,11 @@ discard block |
||
174 | 174 | */ |
175 | 175 | private function _setStringValue(string $columnName, string $userId, string $value): void |
176 | 176 | { |
177 | - if ( !in_array($columnName, $this->_allowedStringColumns) ) { |
|
177 | + if (!in_array($columnName, $this->_allowedStringColumns)) { |
|
178 | 178 | throw new InvalidArgumentException('Unsupported column name'); |
179 | 179 | } |
180 | 180 | try { |
181 | - $sth = $this->handle->prepare('UPDATE ' . $this->tablename . ' SET ' . $columnName . ' = ? WHERE userid = ?'); |
|
181 | + $sth = $this->handle->prepare('UPDATE '.$this->tablename.' SET '.$columnName.' = ? WHERE userid = ?'); |
|
182 | 182 | $sth->execute(array($value, $userId)); |
183 | 183 | if ($sth->rowCount() == 0) { |
184 | 184 | // Required for mysql which only returns the number of rows that were actually updated |
@@ -202,11 +202,11 @@ discard block |
||
202 | 202 | */ |
203 | 203 | private function _setIntValue(string $columnName, string $userId, int $value): void |
204 | 204 | { |
205 | - if ( !in_array($columnName, $this->_allowedIntColumns) ) { |
|
205 | + if (!in_array($columnName, $this->_allowedIntColumns)) { |
|
206 | 206 | throw new InvalidArgumentException('Unsupported column name'); |
207 | 207 | } |
208 | 208 | try { |
209 | - $sth = $this->handle->prepare('UPDATE ' . $this->tablename . ' SET ' . $columnName . ' = ? WHERE userid = ?'); |
|
209 | + $sth = $this->handle->prepare('UPDATE '.$this->tablename.' SET '.$columnName.' = ? WHERE userid = ?'); |
|
210 | 210 | $sth->execute(array($value, $userId)); |
211 | 211 | if ($sth->rowCount() == 0) { |
212 | 212 | // Required for mysql which only returns the number of rows that were actually updated |
@@ -318,17 +318,17 @@ discard block |
||
318 | 318 | { |
319 | 319 | // Check for blocked |
320 | 320 | if ($this->_getIntValue('blocked', $userId) != 0) { |
321 | - return true; // Blocked |
|
321 | + return true; // Blocked |
|
322 | 322 | } |
323 | 323 | |
324 | 324 | if (0 == $tempBlockDuration) { |
325 | - return false; // No check for temporary block |
|
325 | + return false; // No check for temporary block |
|
326 | 326 | } |
327 | 327 | |
328 | 328 | // Check for temporary block |
329 | 329 | $timestamp = $this->getTemporaryBlockTimestamp($userId); |
330 | 330 | // if no temporary block timestamp is set or if the temporary block is expired, return false |
331 | - if ( 0 == $timestamp || ($timestamp + $tempBlockDuration * 60) < time()) { |
|
331 | + if (0 == $timestamp || ($timestamp + $tempBlockDuration * 60) < time()) { |
|
332 | 332 | return false; |
333 | 333 | } |
334 | 334 | return true; |
@@ -384,7 +384,7 @@ discard block |
||
384 | 384 | $sth->execute(); |
385 | 385 | } |
386 | 386 | catch (Exception $e) { |
387 | - $statusMessage = "Error reading from UserStorage_PDO: ". $e->getMessage(); |
|
387 | + $statusMessage = "Error reading from UserStorage_PDO: ".$e->getMessage(); |
|
388 | 388 | return false; |
389 | 389 | } |
390 | 390 |
@@ -119,8 +119,7 @@ discard block |
||
119 | 119 | throw new RuntimeException('Unexpected return type'); |
120 | 120 | } |
121 | 121 | return $res; |
122 | - } |
|
123 | - catch (Exception $e) { |
|
122 | + } catch (Exception $e) { |
|
124 | 123 | $this->logger->error('PDO error getting user', array('exception' => $e, 'userId' => $userId, 'columnName'=>$columnName)); |
125 | 124 | throw ReadWriteException::fromOriginalException($e); |
126 | 125 | } |
@@ -158,8 +157,7 @@ discard block |
||
158 | 157 | throw new RuntimeException('Unexpected return type'); |
159 | 158 | } |
160 | 159 | return (int)$res; |
161 | - } |
|
162 | - catch (Exception $e) { |
|
160 | + } catch (Exception $e) { |
|
163 | 161 | $this->logger->error('PDO error getting user', array('exception' => $e, 'userId' => $userId, 'columnName'=>$columnName)); |
164 | 162 | throw ReadWriteException::fromOriginalException($e); |
165 | 163 | } |
@@ -186,8 +184,7 @@ discard block |
||
186 | 184 | throw new RuntimeException('User not found'); |
187 | 185 | } |
188 | 186 | } |
189 | - } |
|
190 | - catch (Exception $e) { |
|
187 | + } catch (Exception $e) { |
|
191 | 188 | $this->logger->error('PDO error updating user', array('exception' => $e, 'userId' => $userId, 'columnName'=>$columnName)); |
192 | 189 | throw ReadWriteException::fromOriginalException($e); |
193 | 190 | } |
@@ -214,8 +211,7 @@ discard block |
||
214 | 211 | throw new RuntimeException('User not found'); |
215 | 212 | } |
216 | 213 | } |
217 | - } |
|
218 | - catch (Exception $e) { |
|
214 | + } catch (Exception $e) { |
|
219 | 215 | $this->logger->error('PDO error updating user', array('exception' => $e, 'userId' => $userId, 'columnName'=>$columnName)); |
220 | 216 | throw ReadWriteException::fromOriginalException($e); |
221 | 217 | } |
@@ -232,8 +228,7 @@ discard block |
||
232 | 228 | try { |
233 | 229 | $sth = $this->handle->prepare("INSERT INTO ".$this->tablename." (displayname,userid) VALUES (?,?)"); |
234 | 230 | $sth->execute(array($displayName, $userId)); |
235 | - } |
|
236 | - catch (Exception $e) { |
|
231 | + } catch (Exception $e) { |
|
237 | 232 | $this->logger->error(sprintf('Error creating user "%s"', $userId), array('exception'=>$e)); |
238 | 233 | throw new ReadWriteException('The user could not be saved in the user storage (PDO)'); |
239 | 234 | } |
@@ -248,8 +243,7 @@ discard block |
||
248 | 243 | $sth = $this->handle->prepare("SELECT userid FROM ".$this->tablename." WHERE userid = ?"); |
249 | 244 | $sth->execute(array($userId)); |
250 | 245 | return (false !== $sth->fetchColumn()); |
251 | - } |
|
252 | - catch (Exception $e) { |
|
246 | + } catch (Exception $e) { |
|
253 | 247 | $this->logger->error('PDO error checking user exists', array('exception'=>$e, 'userId'=>$userId)); |
254 | 248 | throw ReadWriteException::fromOriginalException($e); |
255 | 249 | } |
@@ -382,8 +376,7 @@ discard block |
||
382 | 376 | try { |
383 | 377 | $sth = $this->handle->prepare('SELECT displayname, notificationtype, notificationaddress, loginattempts, tmpblockattempts, blocked, tmpblocktimestamp FROM '.$this->tablename.' LIMIT 1'); |
384 | 378 | $sth->execute(); |
385 | - } |
|
386 | - catch (Exception $e) { |
|
379 | + } catch (Exception $e) { |
|
387 | 380 | $statusMessage = "Error reading from UserStorage_PDO: ". $e->getMessage(); |
388 | 381 | return false; |
389 | 382 | } |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | * The default configuration |
52 | 52 | */ |
53 | 53 | const DEFAULT_HOST = '127.0.0.1'; |
54 | - const DEFAULT_PORT = 11211; |
|
54 | + const DEFAULT_PORT = 11211; |
|
55 | 55 | |
56 | 56 | /** |
57 | 57 | * Get the prefix to use for all keys in memcache. |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | /** |
107 | 107 | * @see Tiqr_StateStorage_StateStorageInterface::setValue() |
108 | 108 | */ |
109 | - public function setValue(string $key, $value, int $expire=0): void |
|
109 | + public function setValue(string $key, $value, int $expire = 0): void |
|
110 | 110 | { |
111 | 111 | if (empty($key)) { |
112 | 112 | throw new InvalidArgumentException('Empty key not allowed'); |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | if ($result === false) { |
161 | 161 | // Memcache interface does not provide error information, either the key does not exist or |
162 | 162 | // there was an error communicating with the memcache |
163 | - $this->logger->info( sprintf('Unable to get key "%s" from memcache StateStorage', $key) ); |
|
163 | + $this->logger->info(sprintf('Unable to get key "%s" from memcache StateStorage', $key)); |
|
164 | 164 | return null; |
165 | 165 | } |
166 | 166 | return $result; |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | $key = bin2hex(random_bytes(16)); |
177 | 177 | $this->setValue($key, 'healthcheck', 10); |
178 | 178 | } catch (Exception $e) { |
179 | - $statusMessage = 'Unable to store key in memcache: ' . $e->getMessage(); |
|
179 | + $statusMessage = 'Unable to store key in memcache: '.$e->getMessage(); |
|
180 | 180 | return false; |
181 | 181 | } |
182 | 182 |
@@ -71,6 +71,6 @@ |
||
71 | 71 | */ |
72 | 72 | public function healthCheck(string &$statusMessage = ''): bool |
73 | 73 | { |
74 | - return true; // Health check is always successful when not implemented |
|
74 | + return true; // Health check is always successful when not implemented |
|
75 | 75 | } |
76 | 76 | } |