| @@ -25,7 +25,7 @@ discard block | ||
| 25 | 25 | */ | 
| 26 | 26 | public function setBaseURL($apiBaseURL) | 
| 27 | 27 |      { | 
| 28 | - $this->_apiBaseURL = rtrim($apiBaseURL, '/') . '/'; | |
| 28 | + $this->_apiBaseURL = rtrim($apiBaseURL, '/').'/'; | |
| 29 | 29 | } | 
| 30 | 30 | |
| 31 | 31 | /** | 
| @@ -78,7 +78,7 @@ discard block | ||
| 78 | 78 | protected function callAPI($resource, $method = "GET", $data = array(), $headers = array()) | 
| 79 | 79 |      { | 
| 80 | 80 | $ch = curl_init(); | 
| 81 | - curl_setopt($ch, CURLOPT_URL, $this->_apiBaseURL . ltrim($resource, '/')); | |
| 81 | + curl_setopt($ch, CURLOPT_URL, $this->_apiBaseURL.ltrim($resource, '/')); | |
| 82 | 82 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | 
| 83 | 83 | |
| 84 | 84 | // Explicitly empty null values, because http_build_query will throw away | 
| @@ -107,7 +107,7 @@ discard block | ||
| 107 | 107 | |
| 108 | 108 | $headerArray = array(); | 
| 109 | 109 |          foreach ($headers as $key => $value) { | 
| 110 | - $headerArray[] = $key . ': ' . $value; | |
| 110 | + $headerArray[] = $key.': '.$value; | |
| 111 | 111 | } | 
| 112 | 112 | |
| 113 | 113 | curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArray); | 
| @@ -35,7 +35,7 @@ | ||
| 35 | 35 | * @param boolean $temporary temporary failure? | 
| 36 | 36 | * @param Exception $parent parent exception | 
| 37 | 37 | */ | 
| 38 | - public function __construct($message, $temporary=false, Exception $parent=null) | |
| 38 | + public function __construct($message, $temporary = false, Exception $parent = null) | |
| 39 | 39 |      { | 
| 40 | 40 | parent::__construct($message, $parent); | 
| 41 | 41 | $this->_temporary = $temporary; | 
| @@ -29,8 +29,8 @@ | ||
| 29 | 29 | * @param string $message exception message | 
| 30 | 30 | * @param Exception $parent parent exception | 
| 31 | 31 | */ | 
| 32 | - public function __construct($message, $parent=null) | |
| 33 | -     { | |
| 34 | - parent::__construct($message, 0, $parent); | |
| 35 | - } | |
| 32 | + public function __construct($message, $parent=null) | |
| 33 | +        { | |
| 34 | + parent::__construct($message, 0, $parent); | |
| 35 | + } | |
| 36 | 36 | } | 
| 37 | 37 | \ No newline at end of file | 
| @@ -29,7 +29,7 @@ | ||
| 29 | 29 | * @param string $message exception message | 
| 30 | 30 | * @param Exception $parent parent exception | 
| 31 | 31 | */ | 
| 32 | - public function __construct($message, $parent=null) | |
| 32 | + public function __construct($message, $parent = null) | |
| 33 | 33 |       { | 
| 34 | 34 | parent::__construct($message, 0, $parent); | 
| 35 | 35 | } | 
| @@ -35,7 +35,7 @@ | ||
| 35 | 35 | * @param boolean $temporary temporary failure? | 
| 36 | 36 | * @param Exception $parent parent exception | 
| 37 | 37 | */ | 
| 38 | - public function __construct($message, $temporary=false, Exception $parent=null) | |
| 38 | + public function __construct($message, $temporary = false, Exception $parent = null) | |
| 39 | 39 |      { | 
| 40 | 40 | parent::__construct($message, $parent); | 
| 41 | 41 | $this->_temporary = $temporary; | 
| @@ -36,11 +36,11 @@ discard block | ||
| 36 | 36 | */ | 
| 37 | 37 | private static function _hmac(string $crypto, string $keyBytes, string $text) : string | 
| 38 | 38 |      { | 
| 39 | - $hash = hash_hmac($crypto, $text, $keyBytes); | |
| 40 | -         if (false === $hash) { | |
| 41 | -             throw new Exception("calculating hash_hmac failed"); | |
| 42 | - } | |
| 43 | - return $hash; | |
| 39 | + $hash = hash_hmac($crypto, $text, $keyBytes); | |
| 40 | +            if (false === $hash) { | |
| 41 | +                throw new Exception("calculating hash_hmac failed"); | |
| 42 | + } | |
| 43 | + return $hash; | |
| 44 | 44 | } | 
| 45 | 45 | |
| 46 | 46 | /** | 
| @@ -99,12 +99,12 @@ discard block | ||
| 99 | 99 | * alternative to "-S064" | 
| 100 | 100 | */ | 
| 101 | 101 | static function generateOCRA(string $ocraSuite, | 
| 102 | - string $key, | |
| 103 | - string $counter, | |
| 104 | - string $question, | |
| 105 | - string $password, | |
| 106 | - string $sessionInformation, | |
| 107 | - string $timeStamp) : string | |
| 102 | + string $key, | |
| 103 | + string $counter, | |
| 104 | + string $question, | |
| 105 | + string $password, | |
| 106 | + string $sessionInformation, | |
| 107 | + string $timeStamp) : string | |
| 108 | 108 |      { | 
| 109 | 109 | $codeDigits = 0; | 
| 110 | 110 | $crypto = ""; | 
| @@ -58,18 +58,18 @@ discard block | ||
| 58 | 58 | private static function _hexStr2Bytes(string $hex, int $maxBytes, string $parameterName) : string | 
| 59 | 59 |      { | 
| 60 | 60 | $len = strlen($hex); | 
| 61 | -        if ( ($len !== 0) && (! ctype_xdigit($hex)) ) { | |
| 61 | +        if (($len !== 0) && (!ctype_xdigit($hex))) { | |
| 62 | 62 |              throw new InvalidArgumentException("Parameter '$parameterName' contains non hex digits"); | 
| 63 | 63 | } | 
| 64 | -        if ( $len % 2 !== 0 ) { | |
| 64 | +        if ($len % 2 !== 0) { | |
| 65 | 65 |              throw new InvalidArgumentException("Parameter '$parameterName' contains odd number of hex digits"); | 
| 66 | 66 | } | 
| 67 | -        if ( $len > $maxBytes * 2) { | |
| 67 | +        if ($len > $maxBytes * 2) { | |
| 68 | 68 |              throw new InvalidArgumentException("Parameter '$parameterName' too long"); | 
| 69 | 69 | } | 
| 70 | 70 | // hex2bin logs PHP warnings when $hex contains invalid characters or has uneven length. Because we | 
| 71 | 71 | // check for these conditions above hex2bin() should always be silent | 
| 72 | - $res=hex2bin($hex); | |
| 72 | + $res = hex2bin($hex); | |
| 73 | 73 |          if (false === $res) { | 
| 74 | 74 |              throw new InvalidArgumentException("Parameter '$parameterName' could not be decoded"); | 
| 75 | 75 | } | 
| @@ -125,83 +125,83 @@ 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) | |
| 128 | + if (stripos($cryptoFunction, "hotp-sha1") !== false) | |
| 129 | 129 | $crypto = "sha1"; | 
| 130 | - elseif(stripos($cryptoFunction, "hotp-sha256")!==false) | |
| 130 | + elseif (stripos($cryptoFunction, "hotp-sha256") !== false) | |
| 131 | 131 | $crypto = "sha256"; | 
| 132 | - elseif(stripos($cryptoFunction, "hotp-sha512")!==false) | |
| 132 | + elseif (stripos($cryptoFunction, "hotp-sha512") !== false) | |
| 133 | 133 | $crypto = "sha512"; | 
| 134 | 134 |          else { | 
| 135 | 135 |              throw new InvalidArgumentException('Unsupported OCRA CryptoFunction'); | 
| 136 | 136 | } | 
| 137 | 137 | |
| 138 | 138 | // The Cryptofucntion must ha a truncation of 0, 4-10 | 
| 139 | - $codeDigits_str = substr($cryptoFunction, strrpos($cryptoFunction, "-")+1); | |
| 140 | -        if (! ctype_digit($codeDigits_str)) { | |
| 139 | + $codeDigits_str = substr($cryptoFunction, strrpos($cryptoFunction, "-") + 1); | |
| 140 | +        if (!ctype_digit($codeDigits_str)) { | |
| 141 | 141 |              throw new InvalidArgumentException('Unsupported OCRA CryptoFunction'); | 
| 142 | 142 | } | 
| 143 | - $codeDigits = (integer)$codeDigits_str; | |
| 143 | + $codeDigits = (integer) $codeDigits_str; | |
| 144 | 144 |          if (($codeDigits != 0) && (($codeDigits < 4) || ($codeDigits > 10))) { | 
| 145 | 145 |              throw new InvalidArgumentException('Unsupported OCRA CryptoFunction'); | 
| 146 | 146 | } | 
| 147 | 147 | |
| 148 | 148 | // The size of the byte array message to be encrypted | 
| 149 | 149 | // Counter | 
| 150 | -        if($dataInput[0] == "c" ) { | |
| 150 | +        if ($dataInput[0] == "c") { | |
| 151 | 151 | // Fix the length of the HEX string | 
| 152 | - while(strlen($counter) < 16) | |
| 153 | - $counter = "0" . $counter; | |
| 154 | - $counterLength=8; | |
| 152 | + while (strlen($counter) < 16) | |
| 153 | + $counter = "0".$counter; | |
| 154 | + $counterLength = 8; | |
| 155 | 155 | } | 
| 156 | 156 | // Question | 
| 157 | - if($dataInput[0] == "q" || | |
| 158 | -                stripos($dataInput, "-q")!==false) { | |
| 159 | - while(strlen($question) < 256) | |
| 160 | - $question = $question . "0"; | |
| 161 | - $questionLength=128; | |
| 157 | + if ($dataInput[0] == "q" || | |
| 158 | +                stripos($dataInput, "-q") !== false) { | |
| 159 | + while (strlen($question) < 256) | |
| 160 | + $question = $question."0"; | |
| 161 | + $questionLength = 128; | |
| 162 | 162 | } | 
| 163 | 163 | |
| 164 | 164 | // Password | 
| 165 | -        if(stripos($dataInput, "psha1")!==false) { | |
| 166 | - while(strlen($password) < 40) | |
| 167 | - $password = "0" . $password; | |
| 168 | - $passwordLength=20; | |
| 165 | +        if (stripos($dataInput, "psha1") !== false) { | |
| 166 | + while (strlen($password) < 40) | |
| 167 | + $password = "0".$password; | |
| 168 | + $passwordLength = 20; | |
| 169 | 169 | } | 
| 170 | 170 | |
| 171 | -        if(stripos($dataInput, "psha256")!==false) { | |
| 172 | - while(strlen($password) < 64) | |
| 173 | - $password = "0" . $password; | |
| 174 | - $passwordLength=32; | |
| 171 | +        if (stripos($dataInput, "psha256") !== false) { | |
| 172 | + while (strlen($password) < 64) | |
| 173 | + $password = "0".$password; | |
| 174 | + $passwordLength = 32; | |
| 175 | 175 | } | 
| 176 | 176 | |
| 177 | -        if(stripos($dataInput, "psha512")!==false) { | |
| 178 | - while(strlen($password) < 128) | |
| 179 | - $password = "0" . $password; | |
| 180 | - $passwordLength=64; | |
| 177 | +        if (stripos($dataInput, "psha512") !== false) { | |
| 178 | + while (strlen($password) < 128) | |
| 179 | + $password = "0".$password; | |
| 180 | + $passwordLength = 64; | |
| 181 | 181 | } | 
| 182 | 182 | |
| 183 | 183 | // sessionInformation | 
| 184 | -        if(stripos($dataInput, "s064") !==false) { | |
| 185 | - while(strlen($sessionInformation) < 128) | |
| 186 | - $sessionInformation = "0" . $sessionInformation; | |
| 184 | +        if (stripos($dataInput, "s064") !== false) { | |
| 185 | + while (strlen($sessionInformation) < 128) | |
| 186 | + $sessionInformation = "0".$sessionInformation; | |
| 187 | 187 | |
| 188 | - $sessionInformationLength=64; | |
| 189 | -        } else if(stripos($dataInput, "s128") !==false) { | |
| 190 | - while(strlen($sessionInformation) < 256) | |
| 191 | - $sessionInformation = "0" . $sessionInformation; | |
| 188 | + $sessionInformationLength = 64; | |
| 189 | +        } else if (stripos($dataInput, "s128") !== false) { | |
| 190 | + while (strlen($sessionInformation) < 256) | |
| 191 | + $sessionInformation = "0".$sessionInformation; | |
| 192 | 192 | |
| 193 | - $sessionInformationLength=128; | |
| 194 | -        } else if(stripos($dataInput, "s256") !==false) { | |
| 195 | - while(strlen($sessionInformation) < 512) | |
| 196 | - $sessionInformation = "0" . $sessionInformation; | |
| 193 | + $sessionInformationLength = 128; | |
| 194 | +        } else if (stripos($dataInput, "s256") !== false) { | |
| 195 | + while (strlen($sessionInformation) < 512) | |
| 196 | + $sessionInformation = "0".$sessionInformation; | |
| 197 | 197 | |
| 198 | - $sessionInformationLength=256; | |
| 199 | -        } else if(stripos($dataInput, "s512") !==false) { | |
| 200 | - while(strlen($sessionInformation) < 128) | |
| 201 | - $sessionInformation = "0" . $sessionInformation; | |
| 198 | + $sessionInformationLength = 256; | |
| 199 | +        } else if (stripos($dataInput, "s512") !== false) { | |
| 200 | + while (strlen($sessionInformation) < 128) | |
| 201 | + $sessionInformation = "0".$sessionInformation; | |
| 202 | 202 | |
| 203 | - $sessionInformationLength=64; | |
| 204 | -        } else if (stripos($dataInput, "-s") !== false ) { | |
| 203 | + $sessionInformationLength = 64; | |
| 204 | +        } else if (stripos($dataInput, "-s") !== false) { | |
| 205 | 205 | // deviation from spec. Officially 's' without a length indicator is not in the reference implementation. | 
| 206 | 206 | // RFC is ambigious. However we have supported this in Tiqr since day 1, so we continue to support it. | 
| 207 | 207 | |
| @@ -210,27 +210,27 @@ discard block | ||
| 210 | 210 | // to prevent matching the "s" in the password input e.g. "psha1". | 
| 211 | 211 | // [C] | QFxx | [PH | Snnn | TG] : Challenge-Response computation | 
| 212 | 212 | // [C] | QFxx | [PH | TG] : Plain Signature computation | 
| 213 | - while(strlen($sessionInformation) < 128) | |
| 214 | - $sessionInformation = "0" . $sessionInformation; | |
| 213 | + while (strlen($sessionInformation) < 128) | |
| 214 | + $sessionInformation = "0".$sessionInformation; | |
| 215 | 215 | |
| 216 | - $sessionInformationLength=64; | |
| 216 | + $sessionInformationLength = 64; | |
| 217 | 217 | } | 
| 218 | 218 | |
| 219 | 219 | |
| 220 | 220 | |
| 221 | 221 | // TimeStamp | 
| 222 | - if($dataInput[0] == "t" || | |
| 222 | + if ($dataInput[0] == "t" || | |
| 223 | 223 |                  stripos($dataInput, "-t") !== false) { | 
| 224 | - while(strlen($timeStamp) < 16) | |
| 225 | - $timeStamp = "0" . $timeStamp; | |
| 226 | - $timeStampLength=8; | |
| 224 | + while (strlen($timeStamp) < 16) | |
| 225 | + $timeStamp = "0".$timeStamp; | |
| 226 | + $timeStampLength = 8; | |
| 227 | 227 | } | 
| 228 | 228 | |
| 229 | 229 | // Put the bytes of "ocraSuite" parameters into the message | 
| 230 | 230 | |
| 231 | - $msg = array_fill(0,$ocraSuiteLength+$counterLength+$questionLength+$passwordLength+$sessionInformationLength+$timeStampLength+1, 0); | |
| 231 | + $msg = array_fill(0, $ocraSuiteLength + $counterLength + $questionLength + $passwordLength + $sessionInformationLength + $timeStampLength + 1, 0); | |
| 232 | 232 | |
| 233 | -        for($i=0;$i<strlen($ocraSuite);$i++) { | |
| 233 | +        for ($i = 0; $i < strlen($ocraSuite); $i++) { | |
| 234 | 234 | $msg[$i] = $ocraSuite[$i]; | 
| 235 | 235 | } | 
| 236 | 236 | |
| @@ -239,9 +239,9 @@ discard block | ||
| 239 | 239 | |
| 240 | 240 | // Put the bytes of "Counter" to the message | 
| 241 | 241 | // Input is HEX encoded | 
| 242 | -        if($counterLength > 0 ) { | |
| 242 | +        if ($counterLength > 0) { | |
| 243 | 243 | $bArray = self::_hexStr2Bytes($counter, $counterLength, 'counter'); | 
| 244 | -            for ($i=0;$i<strlen($bArray);$i++) { | |
| 244 | +            for ($i = 0; $i < strlen($bArray); $i++) { | |
| 245 | 245 | $msg [$i + $ocraSuiteLength + 1] = $bArray[$i]; | 
| 246 | 246 | } | 
| 247 | 247 | } | 
| @@ -249,41 +249,41 @@ discard block | ||
| 249 | 249 | |
| 250 | 250 | // Put the bytes of "question" to the message | 
| 251 | 251 | // Input is text encoded | 
| 252 | -        if($questionLength > 0 ) { | |
| 252 | +        if ($questionLength > 0) { | |
| 253 | 253 | $bArray = self::_hexStr2Bytes($question, $questionLength, 'question'); | 
| 254 | -            for ($i=0;$i<strlen($bArray);$i++) { | |
| 254 | +            for ($i = 0; $i < strlen($bArray); $i++) { | |
| 255 | 255 | $msg [$i + $ocraSuiteLength + 1 + $counterLength] = $bArray[$i]; | 
| 256 | 256 | } | 
| 257 | 257 | } | 
| 258 | 258 | |
| 259 | 259 | // Put the bytes of "password" to the message | 
| 260 | 260 | // Input is HEX encoded | 
| 261 | -        if($passwordLength > 0){ | |
| 261 | +        if ($passwordLength > 0) { | |
| 262 | 262 | $bArray = self::_hexStr2Bytes($password, $passwordLength, 'password'); | 
| 263 | -            for ($i=0;$i<strlen($bArray);$i++) { | |
| 263 | +            for ($i = 0; $i < strlen($bArray); $i++) { | |
| 264 | 264 | $msg [$i + $ocraSuiteLength + 1 + $counterLength + $questionLength] = $bArray[$i]; | 
| 265 | 265 | } | 
| 266 | 266 | } | 
| 267 | 267 | |
| 268 | 268 | // Put the bytes of "sessionInformation" to the message | 
| 269 | 269 | // Input is HEX encoded | 
| 270 | -        if($sessionInformationLength > 0 ){ | |
| 270 | +        if ($sessionInformationLength > 0) { | |
| 271 | 271 | $bArray = self::_hexStr2Bytes($sessionInformation, $sessionInformationLength, 'sessionInformation'); | 
| 272 | -            for ($i=0;$i<strlen($bArray);$i++) { | |
| 272 | +            for ($i = 0; $i < strlen($bArray); $i++) { | |
| 273 | 273 | $msg [$i + $ocraSuiteLength + 1 + $counterLength + $questionLength + $passwordLength] = $bArray[$i]; | 
| 274 | 274 | } | 
| 275 | 275 | } | 
| 276 | 276 | |
| 277 | 277 | // Put the bytes of "time" to the message | 
| 278 | 278 | // Input is HEX encoded value of minutes | 
| 279 | -        if($timeStampLength > 0){ | |
| 279 | +        if ($timeStampLength > 0) { | |
| 280 | 280 | $bArray = self::_hexStr2Bytes($timeStamp, $timeStampLength, 'timeStamp'); | 
| 281 | -            for ($i=0;$i<strlen($bArray);$i++) { | |
| 281 | +            for ($i = 0; $i < strlen($bArray); $i++) { | |
| 282 | 282 | $msg [$i + $ocraSuiteLength + 1 + $counterLength + $questionLength + $passwordLength + $sessionInformationLength] = $bArray[$i]; | 
| 283 | 283 | } | 
| 284 | 284 | } | 
| 285 | 285 | |
| 286 | - $byteKey = self::_hexStr2Bytes($key, strlen($key)/2, 'key'); | |
| 286 | + $byteKey = self::_hexStr2Bytes($key, strlen($key) / 2, 'key'); | |
| 287 | 287 | |
| 288 | 288 |          $msg = implode("", $msg); | 
| 289 | 289 | |
| @@ -308,23 +308,23 @@ discard block | ||
| 308 | 308 | static function _oath_truncate(string $hash, int $length = 6) : string | 
| 309 | 309 |      { | 
| 310 | 310 | // Convert to dec | 
| 311 | - foreach(str_split($hash,2) as $hex) | |
| 311 | + foreach (str_split($hash, 2) as $hex) | |
| 312 | 312 |          { | 
| 313 | - $hmac_result[]=hexdec($hex); | |
| 313 | + $hmac_result[] = hexdec($hex); | |
| 314 | 314 | } | 
| 315 | 315 | |
| 316 | 316 | // Find offset | 
| 317 | 317 | $offset = $hmac_result[count($hmac_result) - 1] & 0xf; | 
| 318 | 318 | |
| 319 | 319 | $v = strval( | 
| 320 | - (($hmac_result[$offset+0] & 0x7f) << 24 ) | | |
| 321 | - (($hmac_result[$offset+1] & 0xff) << 16 ) | | |
| 322 | - (($hmac_result[$offset+2] & 0xff) << 8 ) | | |
| 323 | - ($hmac_result[$offset+3] & 0xff) | |
| 320 | + (($hmac_result[$offset + 0] & 0x7f) << 24) | | |
| 321 | + (($hmac_result[$offset + 1] & 0xff) << 16) | | |
| 322 | + (($hmac_result[$offset + 2] & 0xff) << 8) | | |
| 323 | + ($hmac_result[$offset + 3] & 0xff) | |
| 324 | 324 | ); | 
| 325 | 325 | |
| 326 | 326 | // Prefix truncated string with 0's to ensure it always has the required length | 
| 327 | - $v=str_pad($v, $length, "0", STR_PAD_LEFT); | |
| 327 | + $v = str_pad($v, $length, "0", STR_PAD_LEFT); | |
| 328 | 328 | |
| 329 | 329 | $v = substr($v, strlen($v) - $length); | 
| 330 | 330 | return $v; | 
| @@ -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 | } | 
| @@ -60,7 +60,7 @@ discard block | ||
| 60 | 60 | public function createUser(string $userId, string $displayName) : void | 
| 61 | 61 |      { | 
| 62 | 62 |          $user = array("userId"=>$userId, | 
| 63 | - "displayName"=>$displayName); | |
| 63 | + "displayName"=>$displayName); | |
| 64 | 64 | $this->_saveUser($userId, $user); | 
| 65 | 65 | } | 
| 66 | 66 | |
| @@ -90,7 +90,7 @@ discard block | ||
| 90 | 90 |      { | 
| 91 | 91 |          if ($data = $this->_loadUser($userId)) { | 
| 92 | 92 |              if (isset($data["notificationType"])) { | 
| 93 | - return $data["notificationType"]; | |
| 93 | + return $data["notificationType"]; | |
| 94 | 94 | } | 
| 95 | 95 | } | 
| 96 | 96 | return ''; | 
| @@ -113,7 +113,7 @@ discard block | ||
| 113 | 113 |      { | 
| 114 | 114 |          if ($data = $this->_loadUser($userId)) { | 
| 115 | 115 |              if (isset($data["notificationAddress"])) { | 
| 116 | - return $data["notificationAddress"]; | |
| 116 | + return $data["notificationAddress"]; | |
| 117 | 117 | } | 
| 118 | 118 | } | 
| 119 | 119 |          $this->logger->info('Unable to find notification address for user'); | 
| @@ -170,10 +170,10 @@ | ||
| 170 | 170 | } | 
| 171 | 171 | |
| 172 | 172 |              if ($timestamp + $tempBlockDuration * 60 < time()) { | 
| 173 | - return false; // Temp block expired | |
| 173 | + return false; // Temp block expired | |
| 174 | 174 | } | 
| 175 | 175 | } | 
| 176 | - return true; // Blocked by temp block | |
| 176 | + return true; // Blocked by temp block | |
| 177 | 177 | } | 
| 178 | 178 | |
| 179 | 179 | /** | 
| @@ -128,7 +128,7 @@ | ||
| 128 | 128 | * | 
| 129 | 129 | * Note that the $tempBlockDuration is specified in MINUTES | 
| 130 | 130 | */ | 
| 131 | - public function isBlocked(string $userId, int $tempBlockDuration=0): bool; | |
| 131 | + public function isBlocked(string $userId, int $tempBlockDuration = 0): bool; | |
| 132 | 132 | |
| 133 | 133 | /** | 
| 134 | 134 | * Block or unblock the user account. | 
| @@ -29,7 +29,7 @@ | ||
| 29 | 29 | * @throws ReadWriteException | 
| 30 | 30 | * @throws Exception | 
| 31 | 31 | */ | 
| 32 | - public function setValue(string $key, $value, int $expire=0): void; | |
| 32 | + public function setValue(string $key, $value, int $expire = 0): void; | |
| 33 | 33 | |
| 34 | 34 | /** | 
| 35 | 35 | * Remove $key from the state storage | 
| @@ -54,8 +54,8 @@ | ||
| 54 | 54 | } | 
| 55 | 55 | |
| 56 | 56 |          $envelope = array("expire"=>$expire, | 
| 57 | - "createdAt"=>time(), | |
| 58 | - "value"=>$value); | |
| 57 | + "createdAt"=>time(), | |
| 58 | + "value"=>$value); | |
| 59 | 59 | $filename = $this->getFilenameByKey($key); | 
| 60 | 60 | |
| 61 | 61 |          if (!file_put_contents($filename, serialize($envelope))) { | 
| @@ -47,7 +47,7 @@ discard block | ||
| 47 | 47 | /** | 
| 48 | 48 | * @see Tiqr_StateStorage_StateStorageInterface::setValue() | 
| 49 | 49 | */ | 
| 50 | - public function setValue(string $key, $value, int $expire=0): void | |
| 50 | + public function setValue(string $key, $value, int $expire = 0): void | |
| 51 | 51 |      { | 
| 52 | 52 |          if (empty($key)) { | 
| 53 | 53 |              throw new InvalidArgumentException('Empty key not allowed'); | 
| @@ -109,8 +109,8 @@ discard block | ||
| 109 | 109 | |
| 110 | 110 | private function getPath(): string | 
| 111 | 111 |      { | 
| 112 | -        if (substr($this->path, -1)!=="/") { | |
| 113 | - return $this->path . "/"; | |
| 112 | +        if (substr($this->path, -1) !== "/") { | |
| 113 | + return $this->path."/"; | |
| 114 | 114 | } | 
| 115 | 115 | return $this->path; | 
| 116 | 116 | } | 
| @@ -141,9 +141,9 @@ discard block | ||
| 141 | 141 | // Generate a random key and use it to store a value | 
| 142 | 142 | $key = bin2hex(random_bytes(16)); | 
| 143 | 143 | $this->setValue($key, 'healthcheck', 10); | 
| 144 | - $this->unsetValue($key); // Cleanup | |
| 144 | + $this->unsetValue($key); // Cleanup | |
| 145 | 145 |          } catch (Exception $e) { | 
| 146 | - $statusMessage = 'Tiqr_StateStorage_File: error setting key: ' . $e->getMessage(); | |
| 146 | + $statusMessage = 'Tiqr_StateStorage_File: error setting key: '.$e->getMessage(); | |
| 147 | 147 | return false; | 
| 148 | 148 | } | 
| 149 | 149 | |