@@ -123,8 +123,7 @@ discard block |
||
| 123 | 123 | $this->logger->notice( |
| 124 | 124 | sprintf("Deleted %d expired keys", $deletedRows) |
| 125 | 125 | ); |
| 126 | - } |
|
| 127 | - catch (Exception $e) { |
|
| 126 | + } catch (Exception $e) { |
|
| 128 | 127 | $this->logger->error( |
| 129 | 128 | sprintf("Deleting expired keys failed: %s", $e->getMessage()), |
| 130 | 129 | array('exception', $e) |
@@ -157,8 +156,7 @@ discard block |
||
| 157 | 156 | } |
| 158 | 157 | try { |
| 159 | 158 | $sth->execute(array(serialize($value), $expire, $key)); |
| 160 | - } |
|
| 161 | - catch (Exception $e) { |
|
| 159 | + } catch (Exception $e) { |
|
| 162 | 160 | $this->logger->error( |
| 163 | 161 | sprintf('Unable to store key "%s" in PDO StateStorage', $key), |
| 164 | 162 | array('exception' => $e) |
@@ -178,8 +176,7 @@ discard block |
||
| 178 | 176 | try { |
| 179 | 177 | $sth = $this->handle->prepare("DELETE FROM " . $this->tablename . " WHERE `key` = ?"); |
| 180 | 178 | $sth->execute(array($key)); |
| 181 | - } |
|
| 182 | - catch (Exception $e) { |
|
| 179 | + } catch (Exception $e) { |
|
| 183 | 180 | $this->logger->error( |
| 184 | 181 | sprintf('Error deleting key "%s" from PDO StateStorage', $key), |
| 185 | 182 | array('exception' => $e) |
@@ -208,8 +205,7 @@ discard block |
||
| 208 | 205 | try { |
| 209 | 206 | $sth = $this->handle->prepare('SELECT `value` FROM ' . $this->tablename . ' WHERE `key` = ? AND (`expire` >= ? OR `expire` = 0)'); |
| 210 | 207 | $sth->execute(array($key, time())); |
| 211 | - } |
|
| 212 | - catch (Exception $e) { |
|
| 208 | + } catch (Exception $e) { |
|
| 213 | 209 | $this->logger->error( |
| 214 | 210 | sprintf('Error getting value for key "%s" from PDO StateStorage', $key), |
| 215 | 211 | array('exception' => $e) |
@@ -125,13 +125,13 @@ discard block |
||
| 125 | 125 | $cryptoFunction = $components[1]; |
| 126 | 126 | $dataInput = strtolower($components[2]); // lower here so we can do case insensitive comparisons |
| 127 | 127 | |
| 128 | - if(stripos($cryptoFunction, "hotp-sha1")!==false) |
|
| 129 | - $crypto = "sha1"; |
|
| 130 | - elseif(stripos($cryptoFunction, "hotp-sha256")!==false) |
|
| 131 | - $crypto = "sha256"; |
|
| 132 | - elseif(stripos($cryptoFunction, "hotp-sha512")!==false) |
|
| 133 | - $crypto = "sha512"; |
|
| 134 | - else { |
|
| 128 | + if(stripos($cryptoFunction, "hotp-sha1")!==false) { |
|
| 129 | + $crypto = "sha1"; |
|
| 130 | + } elseif(stripos($cryptoFunction, "hotp-sha256")!==false) { |
|
| 131 | + $crypto = "sha256"; |
|
| 132 | + } elseif(stripos($cryptoFunction, "hotp-sha512")!==false) { |
|
| 133 | + $crypto = "sha512"; |
|
| 134 | + } else { |
|
| 135 | 135 | throw new InvalidArgumentException('Unsupported OCRA CryptoFunction'); |
| 136 | 136 | } |
| 137 | 137 | |
@@ -149,56 +149,65 @@ discard block |
||
| 149 | 149 | // Counter |
| 150 | 150 | if($dataInput[0] == "c" ) { |
| 151 | 151 | // Fix the length of the HEX string |
| 152 | - while(strlen($counter) < 16) |
|
| 153 | - $counter = "0" . $counter; |
|
| 152 | + while(strlen($counter) < 16) { |
|
| 153 | + $counter = "0" . $counter; |
|
| 154 | + } |
|
| 154 | 155 | $counterLength=8; |
| 155 | 156 | } |
| 156 | 157 | // Question |
| 157 | 158 | if($dataInput[0] == "q" || |
| 158 | 159 | stripos($dataInput, "-q")!==false) { |
| 159 | - while(strlen($question) < 256) |
|
| 160 | - $question = $question . "0"; |
|
| 160 | + while(strlen($question) < 256) { |
|
| 161 | + $question = $question . "0"; |
|
| 162 | + } |
|
| 161 | 163 | $questionLength=128; |
| 162 | 164 | } |
| 163 | 165 | |
| 164 | 166 | // Password |
| 165 | 167 | if(stripos($dataInput, "psha1")!==false) { |
| 166 | - while(strlen($password) < 40) |
|
| 167 | - $password = "0" . $password; |
|
| 168 | + while(strlen($password) < 40) { |
|
| 169 | + $password = "0" . $password; |
|
| 170 | + } |
|
| 168 | 171 | $passwordLength=20; |
| 169 | 172 | } |
| 170 | 173 | |
| 171 | 174 | if(stripos($dataInput, "psha256")!==false) { |
| 172 | - while(strlen($password) < 64) |
|
| 173 | - $password = "0" . $password; |
|
| 175 | + while(strlen($password) < 64) { |
|
| 176 | + $password = "0" . $password; |
|
| 177 | + } |
|
| 174 | 178 | $passwordLength=32; |
| 175 | 179 | } |
| 176 | 180 | |
| 177 | 181 | if(stripos($dataInput, "psha512")!==false) { |
| 178 | - while(strlen($password) < 128) |
|
| 179 | - $password = "0" . $password; |
|
| 182 | + while(strlen($password) < 128) { |
|
| 183 | + $password = "0" . $password; |
|
| 184 | + } |
|
| 180 | 185 | $passwordLength=64; |
| 181 | 186 | } |
| 182 | 187 | |
| 183 | 188 | // sessionInformation |
| 184 | 189 | if(stripos($dataInput, "s064") !==false) { |
| 185 | - while(strlen($sessionInformation) < 128) |
|
| 186 | - $sessionInformation = "0" . $sessionInformation; |
|
| 190 | + while(strlen($sessionInformation) < 128) { |
|
| 191 | + $sessionInformation = "0" . $sessionInformation; |
|
| 192 | + } |
|
| 187 | 193 | |
| 188 | 194 | $sessionInformationLength=64; |
| 189 | 195 | } else if(stripos($dataInput, "s128") !==false) { |
| 190 | - while(strlen($sessionInformation) < 256) |
|
| 191 | - $sessionInformation = "0" . $sessionInformation; |
|
| 196 | + while(strlen($sessionInformation) < 256) { |
|
| 197 | + $sessionInformation = "0" . $sessionInformation; |
|
| 198 | + } |
|
| 192 | 199 | |
| 193 | 200 | $sessionInformationLength=128; |
| 194 | 201 | } else if(stripos($dataInput, "s256") !==false) { |
| 195 | - while(strlen($sessionInformation) < 512) |
|
| 196 | - $sessionInformation = "0" . $sessionInformation; |
|
| 202 | + while(strlen($sessionInformation) < 512) { |
|
| 203 | + $sessionInformation = "0" . $sessionInformation; |
|
| 204 | + } |
|
| 197 | 205 | |
| 198 | 206 | $sessionInformationLength=256; |
| 199 | 207 | } else if(stripos($dataInput, "s512") !==false) { |
| 200 | - while(strlen($sessionInformation) < 128) |
|
| 201 | - $sessionInformation = "0" . $sessionInformation; |
|
| 208 | + while(strlen($sessionInformation) < 128) { |
|
| 209 | + $sessionInformation = "0" . $sessionInformation; |
|
| 210 | + } |
|
| 202 | 211 | |
| 203 | 212 | $sessionInformationLength=64; |
| 204 | 213 | } else if (stripos($dataInput, "-s") !== false ) { |
@@ -210,8 +219,9 @@ discard block |
||
| 210 | 219 | // to prevent matching the "s" in the password input e.g. "psha1". |
| 211 | 220 | // [C] | QFxx | [PH | Snnn | TG] : Challenge-Response computation |
| 212 | 221 | // [C] | QFxx | [PH | TG] : Plain Signature computation |
| 213 | - while(strlen($sessionInformation) < 128) |
|
| 214 | - $sessionInformation = "0" . $sessionInformation; |
|
| 222 | + while(strlen($sessionInformation) < 128) { |
|
| 223 | + $sessionInformation = "0" . $sessionInformation; |
|
| 224 | + } |
|
| 215 | 225 | |
| 216 | 226 | $sessionInformationLength=64; |
| 217 | 227 | } |
@@ -221,8 +231,9 @@ discard block |
||
| 221 | 231 | // TimeStamp |
| 222 | 232 | if($dataInput[0] == "t" || |
| 223 | 233 | stripos($dataInput, "-t") !== false) { |
| 224 | - while(strlen($timeStamp) < 16) |
|
| 225 | - $timeStamp = "0" . $timeStamp; |
|
| 234 | + while(strlen($timeStamp) < 16) { |
|
| 235 | + $timeStamp = "0" . $timeStamp; |
|
| 236 | + } |
|
| 226 | 237 | $timeStampLength=8; |
| 227 | 238 | } |
| 228 | 239 | |
@@ -289,10 +300,11 @@ discard block |
||
| 289 | 300 | |
| 290 | 301 | $hash = self::_hmac($crypto, $byteKey, $msg); |
| 291 | 302 | |
| 292 | - if ($codeDigits == 0) |
|
| 293 | - $result = $hash; |
|
| 294 | - else |
|
| 295 | - $result = self::_oath_truncate($hash, $codeDigits); |
|
| 303 | + if ($codeDigits == 0) { |
|
| 304 | + $result = $hash; |
|
| 305 | + } else { |
|
| 306 | + $result = self::_oath_truncate($hash, $codeDigits); |
|
| 307 | + } |
|
| 296 | 308 | |
| 297 | 309 | return $result; |
| 298 | 310 | } |