@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | // INVALID_USERID: The client authenticated a different user than the server expected. This error is returned when |
| 110 | 110 | // the application stated an authentication session specifying the userId and later during the authentication |
| 111 | 111 | // provides a different userId |
| 112 | - const AUTH_RESULT_INVALID_USERID = 5; |
|
| 112 | + const AUTH_RESULT_INVALID_USERID = 5; |
|
| 113 | 113 | |
| 114 | 114 | /** |
| 115 | 115 | * The default OCRA Suite (RFC 6287) to use for authentication in Tiqr |
@@ -244,7 +244,7 @@ discard block |
||
| 244 | 244 | * @param int $version The tiqr protocol version to use (defaults to the latest) |
| 245 | 245 | * @throws Exception |
| 246 | 246 | */ |
| 247 | - public function __construct(LoggerInterface $logger, array $options=array(), int $version = 2) |
|
| 247 | + public function __construct(LoggerInterface $logger, array $options = array(), int $version = 2) |
|
| 248 | 248 | { |
| 249 | 249 | $this->_options = $options; // Used to later get settings for Tiqr_Message_* |
| 250 | 250 | $this->logger = $logger; |
@@ -347,7 +347,7 @@ discard block |
||
| 347 | 347 | case 'APNS': |
| 348 | 348 | case 'APNS_DIRECT': |
| 349 | 349 | $apns_version = $this->_options['apns.version'] ?? 2; |
| 350 | - if ($apns_version !=2) |
|
| 350 | + if ($apns_version != 2) |
|
| 351 | 351 | throw new InvalidArgumentException("Unsupported APNS version '$apns_version'"); |
| 352 | 352 | $message = new Tiqr_Message_APNS2($this->_options, $this->logger); |
| 353 | 353 | break; |
@@ -364,7 +364,7 @@ discard block |
||
| 364 | 364 | |
| 365 | 365 | $this->logger->info(sprintf('Creating and sending a %s push notification', $notificationType)); |
| 366 | 366 | $message->setId(time()); |
| 367 | - $message->setText("Please authenticate for " . $this->_name); |
|
| 367 | + $message->setText("Please authenticate for ".$this->_name); |
|
| 368 | 368 | $message->setAddress($notificationAddress); |
| 369 | 369 | $message->setCustomProperty('challenge', $this->_getChallengeUrl($sessionKey)); |
| 370 | 370 | $message->send(); |
@@ -410,13 +410,13 @@ discard block |
||
| 410 | 410 | * @return string The authentication sessionKey |
| 411 | 411 | * @throws Exception when starting the authentication session failed |
| 412 | 412 | */ |
| 413 | - public function startAuthenticationSession(string $userId="", string $sessionId="", string $spIdentifier=""): string |
|
| 413 | + public function startAuthenticationSession(string $userId = "", string $sessionId = "", string $spIdentifier = ""): string |
|
| 414 | 414 | { |
| 415 | - if ($sessionId=="") { |
|
| 415 | + if ($sessionId == "") { |
|
| 416 | 416 | $sessionId = session_id(); |
| 417 | 417 | } |
| 418 | 418 | |
| 419 | - if ($spIdentifier=="") { |
|
| 419 | + if ($spIdentifier == "") { |
|
| 420 | 420 | $spIdentifier = $this->_identifier; |
| 421 | 421 | } |
| 422 | 422 | |
@@ -425,7 +425,7 @@ discard block |
||
| 425 | 425 | |
| 426 | 426 | $data = array("sessionId"=>$sessionId, "challenge"=>$challenge, "spIdentifier" => $spIdentifier); |
| 427 | 427 | |
| 428 | - if ($userId!="") { |
|
| 428 | + if ($userId != "") { |
|
| 429 | 429 | $data["userId"] = $userId; |
| 430 | 430 | } |
| 431 | 431 | |
@@ -449,9 +449,9 @@ discard block |
||
| 449 | 449 | * @return String The enrollment key |
| 450 | 450 | * @throws Exception when start the enrollement session failed |
| 451 | 451 | */ |
| 452 | - public function startEnrollmentSession(string $userId, string $displayName, string $sessionId=""): string |
|
| 452 | + public function startEnrollmentSession(string $userId, string $displayName, string $sessionId = ""): string |
|
| 453 | 453 | { |
| 454 | - if ($sessionId=="") { |
|
| 454 | + if ($sessionId == "") { |
|
| 455 | 455 | $sessionId = session_id(); |
| 456 | 456 | } |
| 457 | 457 | $enrollmentKey = $this->_uniqueSessionKey(); |
@@ -471,9 +471,9 @@ discard block |
||
| 471 | 471 | * @param string $sessionId The application's session identifier (defaults to php session) |
| 472 | 472 | * @throws Exception when resetting the session failed |
| 473 | 473 | */ |
| 474 | - public function resetEnrollmentSession(string $sessionId=""): void |
|
| 474 | + public function resetEnrollmentSession(string $sessionId = ""): void |
|
| 475 | 475 | { |
| 476 | - if ($sessionId=="") { |
|
| 476 | + if ($sessionId == "") { |
|
| 477 | 477 | $sessionId = session_id(); |
| 478 | 478 | } |
| 479 | 479 | |
@@ -508,9 +508,9 @@ discard block |
||
| 508 | 508 | * |
| 509 | 509 | * @throws Exception when an error communicating with the state storage backend was detected |
| 510 | 510 | */ |
| 511 | - public function getEnrollmentStatus(string $sessionId=""): int |
|
| 511 | + public function getEnrollmentStatus(string $sessionId = ""): int |
|
| 512 | 512 | { |
| 513 | - if ($sessionId=="") { |
|
| 513 | + if ($sessionId == "") { |
|
| 514 | 514 | $sessionId = session_id(); |
| 515 | 515 | } |
| 516 | 516 | $status = $this->_getStateValue(self::PREFIX_ENROLLMENT_STATUS, $sessionId); |
@@ -663,7 +663,7 @@ discard block |
||
| 663 | 663 | if (NULL === $data) { |
| 664 | 664 | throw new RuntimeException('Enrollment secret not found'); |
| 665 | 665 | } |
| 666 | - if ( !is_array($data) || !is_string($data["userId"] ?? NULL)) { |
|
| 666 | + if (!is_array($data) || !is_string($data["userId"] ?? NULL)) { |
|
| 667 | 667 | throw new RuntimeException('Invalid enrollment data'); |
| 668 | 668 | } |
| 669 | 669 | |
@@ -703,7 +703,7 @@ discard block |
||
| 703 | 703 | $this->_setEnrollmentStatus($data["sessionId"], self::ENROLLMENT_STATUS_FINALIZED); |
| 704 | 704 | } else { |
| 705 | 705 | $this->logger->error( |
| 706 | - 'Enrollment status is not finalized, enrollmentsecret was not found in state storage. ' . |
|
| 706 | + 'Enrollment status is not finalized, enrollmentsecret was not found in state storage. '. |
|
| 707 | 707 | 'Warning! the method will still return "true" as a result.' |
| 708 | 708 | ); |
| 709 | 709 | } |
@@ -761,9 +761,9 @@ discard block |
||
| 761 | 761 | throw $e; |
| 762 | 762 | } |
| 763 | 763 | |
| 764 | - $sessionId = $state["sessionId"] ?? NULL; // Application's sessionId |
|
| 765 | - $challenge = $state["challenge"] ?? NULL; // The challenge we sent to the Tiqr client |
|
| 766 | - if (!is_string($sessionId) || (!is_string($challenge)) ) { |
|
| 764 | + $sessionId = $state["sessionId"] ?? NULL; // Application's sessionId |
|
| 765 | + $challenge = $state["challenge"] ?? NULL; // The challenge we sent to the Tiqr client |
|
| 766 | + if (!is_string($sessionId) || (!is_string($challenge))) { |
|
| 767 | 767 | throw new RuntimeException('Invalid state for state storage'); |
| 768 | 768 | } |
| 769 | 769 | |
@@ -772,7 +772,7 @@ discard block |
||
| 772 | 772 | $challengeUserId = $state["userId"] ?? NULL; |
| 773 | 773 | |
| 774 | 774 | // If the application requested a specific userId, verify that that is that userId that we're now authenticating |
| 775 | - if ($challengeUserId!==NULL && ($userId !== $challengeUserId)) { |
|
| 775 | + if ($challengeUserId !== NULL && ($userId !== $challengeUserId)) { |
|
| 776 | 776 | $this->logger->error( |
| 777 | 777 | sprintf('Authentication failed: the requested userId "%s" does not match userId "%s" that is being authenticated', |
| 778 | 778 | $challengeUserId, $userId) |
@@ -820,9 +820,9 @@ discard block |
||
| 820 | 820 | * |
| 821 | 821 | * @throws Exception when there was an error communicating with the storage backed |
| 822 | 822 | */ |
| 823 | - public function logout(string $sessionId=""): void |
|
| 823 | + public function logout(string $sessionId = ""): void |
|
| 824 | 824 | { |
| 825 | - if ($sessionId=="") { |
|
| 825 | + if ($sessionId == "") { |
|
| 826 | 826 | $sessionId = session_id(); |
| 827 | 827 | } |
| 828 | 828 | |
@@ -862,9 +862,9 @@ discard block |
||
| 862 | 862 | * |
| 863 | 863 | * Does not throw |
| 864 | 864 | */ |
| 865 | - public function getAuthenticatedUser(string $sessionId=""): ?string |
|
| 865 | + public function getAuthenticatedUser(string $sessionId = ""): ?string |
|
| 866 | 866 | { |
| 867 | - if ($sessionId=="") { |
|
| 867 | + if ($sessionId == "") { |
|
| 868 | 868 | $this->logger->debug('Using the PHP session id, as no session id was provided'); |
| 869 | 869 | $sessionId = session_id(); |
| 870 | 870 | } |
@@ -908,22 +908,22 @@ discard block |
||
| 908 | 908 | $challenge = $state["challenge"] ?? ''; |
| 909 | 909 | $spIdentifier = $state["spIdentifier"] ?? ''; |
| 910 | 910 | |
| 911 | - if ( (strpos($this->_protocolAuth, 'https://') === 0) || (strpos($this->_protocolAuth, 'http://') === 0) ) { |
|
| 911 | + if ((strpos($this->_protocolAuth, 'https://') === 0) || (strpos($this->_protocolAuth, 'http://') === 0)) { |
|
| 912 | 912 | // Create universal Link |
| 913 | - $parameters=array(); |
|
| 913 | + $parameters = array(); |
|
| 914 | 914 | if (!is_null($userId)) { |
| 915 | - $parameters[]='u='.urlencode($userId); |
|
| 915 | + $parameters[] = 'u='.urlencode($userId); |
|
| 916 | 916 | } |
| 917 | - $parameters[]='s='.urlencode($sessionKey); |
|
| 918 | - $parameters[]='q='.urlencode($challenge); |
|
| 919 | - $parameters[]='i='.urlencode($this->getIdentifier()); |
|
| 920 | - $parameters[]='v='.urlencode($this->_protocolVersion); |
|
| 917 | + $parameters[] = 's='.urlencode($sessionKey); |
|
| 918 | + $parameters[] = 'q='.urlencode($challenge); |
|
| 919 | + $parameters[] = 'i='.urlencode($this->getIdentifier()); |
|
| 920 | + $parameters[] = 'v='.urlencode($this->_protocolVersion); |
|
| 921 | 921 | return $this->_protocolAuth.'?'.implode('&', $parameters); |
| 922 | 922 | } |
| 923 | 923 | |
| 924 | 924 | // Create custom URL scheme |
| 925 | 925 | // Last bit is the spIdentifier |
| 926 | - return $this->_protocolAuth."://".(!is_null($userId)?urlencode($userId).'@':'').$this->getIdentifier()."/".$sessionKey."/".$challenge."/".urlencode($spIdentifier)."/".$this->_protocolVersion; |
|
| 926 | + return $this->_protocolAuth."://".(!is_null($userId) ?urlencode($userId).'@' : '').$this->getIdentifier()."/".$sessionKey."/".$challenge."/".urlencode($spIdentifier)."/".$this->_protocolVersion; |
|
| 927 | 927 | } |
| 928 | 928 | |
| 929 | 929 | /** |
@@ -934,7 +934,7 @@ discard block |
||
| 934 | 934 | { |
| 935 | 935 | // The are two formats see: https://tiqr.org/technical/protocol/ |
| 936 | 936 | |
| 937 | - if ( (strpos($this->_protocolEnroll, 'https://') === 0) || (strpos($this->_protocolEnroll, 'http://') === 0) ) { |
|
| 937 | + if ((strpos($this->_protocolEnroll, 'https://') === 0) || (strpos($this->_protocolEnroll, 'http://') === 0)) { |
|
| 938 | 938 | // Create universal Link |
| 939 | 939 | return $this->_protocolEnroll.'?metadata='.urlencode($metadataUrl); |
| 940 | 940 | } |
@@ -953,7 +953,7 @@ discard block |
||
| 953 | 953 | protected function _uniqueSessionKey(): string |
| 954 | 954 | { |
| 955 | 955 | |
| 956 | - return bin2hex( Tiqr_Random::randomBytes(self::SESSION_KEY_LENGTH_BYTES) ); |
|
| 956 | + return bin2hex(Tiqr_Random::randomBytes(self::SESSION_KEY_LENGTH_BYTES)); |
|
| 957 | 957 | } |
| 958 | 958 | |
| 959 | 959 | /** |
@@ -984,7 +984,7 @@ discard block |
||
| 984 | 984 | */ |
| 985 | 985 | protected function _setStateValue(string $key_prefix, string $key, $value, int $expire): void { |
| 986 | 986 | $this->_stateStorage->setValue( |
| 987 | - $key_prefix . $this->_hashKey($key), |
|
| 987 | + $key_prefix.$this->_hashKey($key), |
|
| 988 | 988 | $value, |
| 989 | 989 | $expire |
| 990 | 990 | ); |
@@ -1001,7 +1001,7 @@ discard block |
||
| 1001 | 1001 | |
| 1002 | 1002 | protected function _getStateValue(string $key_prefix, string $key) { |
| 1003 | 1003 | return $this->_stateStorage->getValue( |
| 1004 | - $key_prefix . $this->_hashKey($key) |
|
| 1004 | + $key_prefix.$this->_hashKey($key) |
|
| 1005 | 1005 | ); |
| 1006 | 1006 | } |
| 1007 | 1007 | |
@@ -1015,7 +1015,7 @@ discard block |
||
| 1015 | 1015 | */ |
| 1016 | 1016 | protected function _unsetStateValue(string $key_prefix, string $key): void { |
| 1017 | 1017 | $this->_stateStorage->unsetValue( |
| 1018 | - $key_prefix . $this->_hashKey($key) |
|
| 1018 | + $key_prefix.$this->_hashKey($key) |
|
| 1019 | 1019 | ); |
| 1020 | 1020 | } |
| 1021 | 1021 | |
@@ -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": |
@@ -117,9 +117,9 @@ discard block |
||
| 117 | 117 | */ |
| 118 | 118 | private function cleanExpired(): void { |
| 119 | 119 | try { |
| 120 | - $sth = $this->handle->prepare("DELETE FROM " . $this->tablename . " WHERE `expire` < ? AND NOT `expire` = 0"); |
|
| 120 | + $sth = $this->handle->prepare("DELETE FROM ".$this->tablename." WHERE `expire` < ? AND NOT `expire` = 0"); |
|
| 121 | 121 | $sth->execute(array(time())); |
| 122 | - $deletedRows=$sth->rowCount(); |
|
| 122 | + $deletedRows = $sth->rowCount(); |
|
| 123 | 123 | $this->logger->notice( |
| 124 | 124 | sprintf("Deleted %d expired keys", $deletedRows) |
| 125 | 125 | ); |
@@ -135,12 +135,12 @@ discard block |
||
| 135 | 135 | /** |
| 136 | 136 | * @see Tiqr_StateStorage_StateStorageInterface::setValue() |
| 137 | 137 | */ |
| 138 | - public function setValue(string $key, $value, int $expire=0): void |
|
| 138 | + public function setValue(string $key, $value, int $expire = 0): void |
|
| 139 | 139 | { |
| 140 | 140 | if (empty($key)) { |
| 141 | 141 | throw new InvalidArgumentException('Empty key not allowed'); |
| 142 | 142 | } |
| 143 | - if (((float) rand() /(float) getrandmax()) < $this->cleanupProbability) { |
|
| 143 | + if (((float) rand() / (float) getrandmax()) < $this->cleanupProbability) { |
|
| 144 | 144 | $this->cleanExpired(); |
| 145 | 145 | } |
| 146 | 146 | // REPLACE INTO is mysql dialect. Supported by sqlite as well. |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | |
| 154 | 154 | // $expire == 0 means never expire |
| 155 | 155 | if ($expire != 0) { |
| 156 | - $expire+=time(); // Store unix timestamp after which the key expires |
|
| 156 | + $expire += time(); // Store unix timestamp after which the key expires |
|
| 157 | 157 | } |
| 158 | 158 | try { |
| 159 | 159 | $sth->execute(array(serialize($value), $expire, $key)); |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | throw new InvalidArgumentException('Empty key not allowed'); |
| 177 | 177 | } |
| 178 | 178 | try { |
| 179 | - $sth = $this->handle->prepare("DELETE FROM " . $this->tablename . " WHERE `key` = ?"); |
|
| 179 | + $sth = $this->handle->prepare("DELETE FROM ".$this->tablename." WHERE `key` = ?"); |
|
| 180 | 180 | $sth->execute(array($key)); |
| 181 | 181 | } |
| 182 | 182 | catch (Exception $e) { |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | try { |
| 209 | - $sth = $this->handle->prepare('SELECT `value` FROM ' . $this->tablename . ' WHERE `key` = ? AND (`expire` >= ? OR `expire` = 0)'); |
|
| 209 | + $sth = $this->handle->prepare('SELECT `value` FROM '.$this->tablename.' WHERE `key` = ? AND (`expire` >= ? OR `expire` = 0)'); |
|
| 210 | 210 | $sth->execute(array($key, time())); |
| 211 | 211 | } |
| 212 | 212 | catch (Exception $e) { |
@@ -220,9 +220,9 @@ discard block |
||
| 220 | 220 | if (false === $result) { |
| 221 | 221 | // Occurs normally |
| 222 | 222 | $this->logger->info(sprintf('getValue: Key "%s" not found in PDO StateStorage', $key)); |
| 223 | - return NULL; // Key not found |
|
| 223 | + return NULL; // Key not found |
|
| 224 | 224 | } |
| 225 | - $result=unserialize($result, array('allowed_classes' => false)); |
|
| 225 | + $result = unserialize($result, array('allowed_classes' => false)); |
|
| 226 | 226 | if (false === $result) { |
| 227 | 227 | throw new RuntimeException(sprintf('getValue: unserialize error for key "%s" in PDO StateStorage', $key)); |
| 228 | 228 | } |
@@ -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)); |
@@ -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 | } |
@@ -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 | } |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | /** |
| 50 | 50 | * @throws Tiqr_Message_Exception_SendFailure |
| 51 | 51 | */ |
| 52 | - private function getGoogleAccessToken($credentialsFile, $cacheTokens, $tokenCacheDir ) |
|
| 52 | + private function getGoogleAccessToken($credentialsFile, $cacheTokens, $tokenCacheDir) |
|
| 53 | 53 | { |
| 54 | 54 | $client = new Google_Client(); |
| 55 | 55 | $client->setLogger($this->logger); |
@@ -61,8 +61,8 @@ discard block |
||
| 61 | 61 | $pool = new FilesystemCachePool($filesystem); |
| 62 | 62 | |
| 63 | 63 | //set up a callback to log token refresh |
| 64 | - $logger=$this->logger; |
|
| 65 | - $tokenCallback = function ($cacheKey, $accessToken) use ($logger) { |
|
| 64 | + $logger = $this->logger; |
|
| 65 | + $tokenCallback = function($cacheKey, $accessToken) use ($logger) { |
|
| 66 | 66 | $logger->info(sprintf('New access token received at cache key %s', $cacheKey)); |
| 67 | 67 | }; |
| 68 | 68 | $client->setTokenCallback($tokenCallback); |
@@ -94,9 +94,9 @@ discard block |
||
| 94 | 94 | * @param $retry boolean is this a 2nd attempt |
| 95 | 95 | * @throws Tiqr_Message_Exception_SendFailure |
| 96 | 96 | */ |
| 97 | - private function _sendFirebase(string $deviceToken, string $alert, string $challenge, string $projectId, string $credentialsFile, bool $cacheTokens, string $tokenCacheDir, bool $retry=false) |
|
| 97 | + private function _sendFirebase(string $deviceToken, string $alert, string $challenge, string $projectId, string $credentialsFile, bool $cacheTokens, string $tokenCacheDir, bool $retry = false) |
|
| 98 | 98 | { |
| 99 | - $apiurl = sprintf('https://fcm.googleapis.com/v1/projects/%s/messages:send',$projectId); |
|
| 99 | + $apiurl = sprintf('https://fcm.googleapis.com/v1/projects/%s/messages:send', $projectId); |
|
| 100 | 100 | |
| 101 | 101 | $fields = [ |
| 102 | 102 | 'message' => [ |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | |
| 114 | 114 | try { |
| 115 | 115 | $headers = array( |
| 116 | - 'Authorization: Bearer ' . $this->getGoogleAccessToken($credentialsFile, $cacheTokens, $tokenCacheDir), |
|
| 116 | + 'Authorization: Bearer '.$this->getGoogleAccessToken($credentialsFile, $cacheTokens, $tokenCacheDir), |
|
| 117 | 117 | 'Content-Type: application/json', |
| 118 | 118 | ); |
| 119 | 119 | } catch (\Google\Exception $e) { |
@@ -137,13 +137,13 @@ discard block |
||
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | if (!empty($errors)) { |
| 140 | - throw new Tiqr_Message_Exception_SendFailure("Http error occurred: ". $errors, true); |
|
| 140 | + throw new Tiqr_Message_Exception_SendFailure("Http error occurred: ".$errors, true); |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | // Wait and retry once in case of a 502 Bad Gateway error |
| 144 | 144 | if ($statusCode === 502 && !($retry)) { |
| 145 | 145 | sleep(2); |
| 146 | - $this->_sendFirebase($deviceToken, $alert, $challenge, $projectId, $credentialsFile, $cacheTokens, $tokenCacheDir, true); |
|
| 146 | + $this->_sendFirebase($deviceToken, $alert, $challenge, $projectId, $credentialsFile, $cacheTokens, $tokenCacheDir, true); |
|
| 147 | 147 | return; |
| 148 | 148 | } |
| 149 | 149 | |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | // handle errors, ignoring registration_id's |
| 155 | 155 | $response = json_decode($result, true); |
| 156 | 156 | foreach ($response as $k => $v) { |
| 157 | - if ($k=="error") { |
|
| 157 | + if ($k == "error") { |
|
| 158 | 158 | throw new Tiqr_Message_Exception_SendFailure(sprintf("Error in FCM response: %s", $result), true); |
| 159 | 159 | } |
| 160 | 160 | } |
@@ -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; |