@@ -74,12 +74,12 @@ discard block |
||
| 74 | 74 | /** |
| 75 | 75 | * Enrollment status codes |
| 76 | 76 | */ |
| 77 | - const ENROLLMENT_STATUS_IDLE = 1; // Nothing happens |
|
| 77 | + const ENROLLMENT_STATUS_IDLE = 1; // Nothing happens |
|
| 78 | 78 | const ENROLLMENT_STATUS_INITIALIZED = 2; // An enrollment session has begun |
| 79 | - const ENROLLMENT_STATUS_RETRIEVED = 3; // The device has retrieved the metadata |
|
| 80 | - const ENROLLMENT_STATUS_PROCESSED = 4; // The device has snet back a secret |
|
| 81 | - const ENROLLMENT_STATUS_FINALIZED = 5; // The application has stored the secret |
|
| 82 | - const ENROLLMENT_STATUS_VALIDATED = 6; // A first succesful authentication was performed |
|
| 79 | + const ENROLLMENT_STATUS_RETRIEVED = 3; // The device has retrieved the metadata |
|
| 80 | + const ENROLLMENT_STATUS_PROCESSED = 4; // The device has snet back a secret |
|
| 81 | + const ENROLLMENT_STATUS_FINALIZED = 5; // The application has stored the secret |
|
| 82 | + const ENROLLMENT_STATUS_VALIDATED = 6; // A first succesful authentication was performed |
|
| 83 | 83 | |
| 84 | 84 | const PREFIX_ENROLLMENT_SECRET = 'enrollsecret'; |
| 85 | 85 | const PREFIX_ENROLLMENT = 'enroll'; |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | * @param array $options |
| 159 | 159 | * @param int $version The protocol version to use (defaults to the latest) |
| 160 | 160 | */ |
| 161 | - public function __construct(LoggerInterface $logger, $options=array(), $version = 2) |
|
| 161 | + public function __construct(LoggerInterface $logger, $options = array(), $version = 2) |
|
| 162 | 162 | { |
| 163 | 163 | $this->_options = $options; |
| 164 | 164 | $this->logger = $logger; |
@@ -311,7 +311,7 @@ discard block |
||
| 311 | 311 | |
| 312 | 312 | $this->logger->info(sprintf('Creating and sending a %s push notification', $notificationType)); |
| 313 | 313 | $message->setId(time()); |
| 314 | - $message->setText("Please authenticate for " . $this->_name); |
|
| 314 | + $message->setText("Please authenticate for ".$this->_name); |
|
| 315 | 315 | $message->setAddress($notificationAddress); |
| 316 | 316 | $message->setCustomProperty('challenge', $this->_getChallengeUrl($sessionKey)); |
| 317 | 317 | $message->send(); |
@@ -380,13 +380,13 @@ discard block |
||
| 380 | 380 | * @param String $spIdentifier If SP and IDP are 2 different things, pass the url/identifier of the SP the user is logging into. |
| 381 | 381 | * For setups where IDP==SP, just leave this blank. |
| 382 | 382 | */ |
| 383 | - public function startAuthenticationSession($userId="", $sessionId="", $spIdentifier="") |
|
| 383 | + public function startAuthenticationSession($userId = "", $sessionId = "", $spIdentifier = "") |
|
| 384 | 384 | { |
| 385 | - if ($sessionId=="") { |
|
| 385 | + if ($sessionId == "") { |
|
| 386 | 386 | $sessionId = session_id(); |
| 387 | 387 | } |
| 388 | 388 | |
| 389 | - if ($spIdentifier=="") { |
|
| 389 | + if ($spIdentifier == "") { |
|
| 390 | 390 | $spIdentifier = $this->_identifier; |
| 391 | 391 | } |
| 392 | 392 | |
@@ -396,11 +396,11 @@ discard block |
||
| 396 | 396 | |
| 397 | 397 | $data = array("sessionId"=>$sessionId, "challenge"=>$challenge, "spIdentifier" => $spIdentifier); |
| 398 | 398 | |
| 399 | - if ($userId!="") { |
|
| 399 | + if ($userId != "") { |
|
| 400 | 400 | $data["userId"] = $userId; |
| 401 | 401 | } |
| 402 | 402 | |
| 403 | - $this->_stateStorage->setValue(self::PREFIX_CHALLENGE . $sessionKey, $data, self::CHALLENGE_EXPIRE); |
|
| 403 | + $this->_stateStorage->setValue(self::PREFIX_CHALLENGE.$sessionKey, $data, self::CHALLENGE_EXPIRE); |
|
| 404 | 404 | |
| 405 | 405 | return $sessionKey; |
| 406 | 406 | } |
@@ -420,9 +420,9 @@ discard block |
||
| 420 | 420 | * to php session) |
| 421 | 421 | * @return String The enrollment key |
| 422 | 422 | */ |
| 423 | - public function startEnrollmentSession($userId, $displayName, $sessionId="") |
|
| 423 | + public function startEnrollmentSession($userId, $displayName, $sessionId = "") |
|
| 424 | 424 | { |
| 425 | - if ($sessionId=="") { |
|
| 425 | + if ($sessionId == "") { |
|
| 426 | 426 | $sessionId = session_id(); |
| 427 | 427 | } |
| 428 | 428 | $enrollmentKey = $this->_uniqueSessionKey(self::PREFIX_ENROLLMENT); |
@@ -431,7 +431,7 @@ discard block |
||
| 431 | 431 | "displayName" => $displayName, |
| 432 | 432 | "sessionId" => $sessionId |
| 433 | 433 | ]; |
| 434 | - $this->_stateStorage->setValue(self::PREFIX_ENROLLMENT . $enrollmentKey, $data, self::ENROLLMENT_EXPIRE); |
|
| 434 | + $this->_stateStorage->setValue(self::PREFIX_ENROLLMENT.$enrollmentKey, $data, self::ENROLLMENT_EXPIRE); |
|
| 435 | 435 | $this->_setEnrollmentStatus($sessionId, self::ENROLLMENT_STATUS_INITIALIZED); |
| 436 | 436 | |
| 437 | 437 | return $enrollmentKey; |
@@ -442,9 +442,9 @@ discard block |
||
| 442 | 442 | * @param $sessionId The application's session identifier (defaults |
| 443 | 443 | * to php session) |
| 444 | 444 | */ |
| 445 | - public function resetEnrollmentSession($sessionId="") |
|
| 445 | + public function resetEnrollmentSession($sessionId = "") |
|
| 446 | 446 | { |
| 447 | - if ($sessionId=="") { |
|
| 447 | + if ($sessionId == "") { |
|
| 448 | 448 | $sessionId = session_id(); |
| 449 | 449 | } |
| 450 | 450 | |
@@ -489,9 +489,9 @@ discard block |
||
| 489 | 489 | * A first successful authentication was performed |
| 490 | 490 | * (todo: currently not used) |
| 491 | 491 | */ |
| 492 | - public function getEnrollmentStatus($sessionId="") |
|
| 492 | + public function getEnrollmentStatus($sessionId = "") |
|
| 493 | 493 | { |
| 494 | - if ($sessionId=="") { |
|
| 494 | + if ($sessionId == "") { |
|
| 495 | 495 | $sessionId = session_id(); |
| 496 | 496 | } |
| 497 | 497 | $status = $this->_stateStorage->getValue("enrollstatus".$sessionId); |
@@ -550,7 +550,7 @@ discard block |
||
| 550 | 550 | */ |
| 551 | 551 | public function getEnrollmentMetadata($enrollmentKey, $authenticationUrl, $enrollmentUrl) |
| 552 | 552 | { |
| 553 | - $data = $this->_stateStorage->getValue(self::PREFIX_ENROLLMENT . $enrollmentKey); |
|
| 553 | + $data = $this->_stateStorage->getValue(self::PREFIX_ENROLLMENT.$enrollmentKey); |
|
| 554 | 554 | if (!is_array($data)) { |
| 555 | 555 | $this->logger->error('Unable to find enrollment metadata in state storage'); |
| 556 | 556 | return false; |
@@ -569,7 +569,7 @@ discard block |
||
| 569 | 569 | array("identifier" =>$data["userId"], |
| 570 | 570 | "displayName"=>$data["displayName"])); |
| 571 | 571 | |
| 572 | - $this->_stateStorage->unsetValue(self::PREFIX_ENROLLMENT . $enrollmentKey); |
|
| 572 | + $this->_stateStorage->unsetValue(self::PREFIX_ENROLLMENT.$enrollmentKey); |
|
| 573 | 573 | |
| 574 | 574 | $this->_setEnrollmentStatus($data["sessionId"], self::ENROLLMENT_STATUS_RETRIEVED); |
| 575 | 575 | return $metadata; |
@@ -590,14 +590,14 @@ discard block |
||
| 590 | 590 | */ |
| 591 | 591 | public function getEnrollmentSecret($enrollmentKey) |
| 592 | 592 | { |
| 593 | - $data = $this->_stateStorage->getValue(self::PREFIX_ENROLLMENT . $enrollmentKey); |
|
| 593 | + $data = $this->_stateStorage->getValue(self::PREFIX_ENROLLMENT.$enrollmentKey); |
|
| 594 | 594 | $secret = $this->_uniqueSessionKey(self::PREFIX_ENROLLMENT_SECRET); |
| 595 | 595 | $enrollmentData = [ |
| 596 | 596 | "userId" => $data["userId"], |
| 597 | 597 | "sessionId" => $data["sessionId"] |
| 598 | 598 | ]; |
| 599 | 599 | $this->_stateStorage->setValue( |
| 600 | - self::PREFIX_ENROLLMENT_SECRET . $secret, |
|
| 600 | + self::PREFIX_ENROLLMENT_SECRET.$secret, |
|
| 601 | 601 | $enrollmentData, |
| 602 | 602 | self::ENROLLMENT_EXPIRE |
| 603 | 603 | ); |
@@ -647,7 +647,7 @@ discard block |
||
| 647 | 647 | $this->_stateStorage->unsetValue(self::PREFIX_ENROLLMENT_SECRET.$enrollmentSecret); |
| 648 | 648 | } else { |
| 649 | 649 | $this->logger->error( |
| 650 | - 'Enrollment status is not finalized, enrollmentsecret was not found in state storage. ' . |
|
| 650 | + 'Enrollment status is not finalized, enrollmentsecret was not found in state storage. '. |
|
| 651 | 651 | 'Warning! the method will still return "true" as a result.' |
| 652 | 652 | ); |
| 653 | 653 | } |
@@ -677,7 +677,7 @@ discard block |
||
| 677 | 677 | */ |
| 678 | 678 | public function authenticate($userId, $userSecret, $sessionKey, $response) |
| 679 | 679 | { |
| 680 | - $state = $this->_stateStorage->getValue(self::PREFIX_CHALLENGE . $sessionKey); |
|
| 680 | + $state = $this->_stateStorage->getValue(self::PREFIX_CHALLENGE.$sessionKey); |
|
| 681 | 681 | if (is_null($state)) { |
| 682 | 682 | $this->logger->info('The auth challenge could not be found in the state storage'); |
| 683 | 683 | return self::AUTH_RESULT_INVALID_CHALLENGE; |
@@ -691,7 +691,7 @@ discard block |
||
| 691 | 691 | $challengeUserId = $state["userId"]; |
| 692 | 692 | } |
| 693 | 693 | // Check if we're dealing with a second factor |
| 694 | - if ($challengeUserId!=NULL && ($userId != $challengeUserId)) { |
|
| 694 | + if ($challengeUserId != NULL && ($userId != $challengeUserId)) { |
|
| 695 | 695 | $this->logger->error( |
| 696 | 696 | 'Authentication failed: the first factor user id does not match with that of the second factor' |
| 697 | 697 | ); |
@@ -709,7 +709,7 @@ discard block |
||
| 709 | 709 | $this->_stateStorage->setValue("authenticated_".$sessionId, $userId, self::LOGIN_EXPIRE); |
| 710 | 710 | |
| 711 | 711 | // Clean up the challenge. |
| 712 | - $this->_stateStorage->unsetValue(self::PREFIX_CHALLENGE . $sessionKey); |
|
| 712 | + $this->_stateStorage->unsetValue(self::PREFIX_CHALLENGE.$sessionKey); |
|
| 713 | 713 | $this->logger->info('Authentication succeeded'); |
| 714 | 714 | return self::AUTH_RESULT_AUTHENTICATED; |
| 715 | 715 | } |
@@ -722,9 +722,9 @@ discard block |
||
| 722 | 722 | * @param String $sessionId The application's session identifier (defaults |
| 723 | 723 | * to the php session). |
| 724 | 724 | */ |
| 725 | - public function logout($sessionId="") |
|
| 725 | + public function logout($sessionId = "") |
|
| 726 | 726 | { |
| 727 | - if ($sessionId=="") { |
|
| 727 | + if ($sessionId == "") { |
|
| 728 | 728 | $sessionId = session_id(); |
| 729 | 729 | } |
| 730 | 730 | |
@@ -759,9 +759,9 @@ discard block |
||
| 759 | 759 | * @return mixed An array with user data if a user was logged in or NULL if |
| 760 | 760 | * no user is logged in. |
| 761 | 761 | */ |
| 762 | - public function getAuthenticatedUser($sessionId="") |
|
| 762 | + public function getAuthenticatedUser($sessionId = "") |
|
| 763 | 763 | { |
| 764 | - if ($sessionId=="") { |
|
| 764 | + if ($sessionId == "") { |
|
| 765 | 765 | $this->logger->debug('Using the PHP session id, as no session id was provided'); |
| 766 | 766 | $sessionId = session_id(); |
| 767 | 767 | } |
@@ -780,7 +780,7 @@ discard block |
||
| 780 | 780 | */ |
| 781 | 781 | protected function _getChallengeUrl($sessionKey) |
| 782 | 782 | { |
| 783 | - $state = $this->_stateStorage->getValue(self::PREFIX_CHALLENGE . $sessionKey); |
|
| 783 | + $state = $this->_stateStorage->getValue(self::PREFIX_CHALLENGE.$sessionKey); |
|
| 784 | 784 | if (is_null($state)) { |
| 785 | 785 | $this->logger->error( |
| 786 | 786 | 'Unable find an existing challenge url in the state storage based on the existing session key' |
@@ -788,7 +788,7 @@ discard block |
||
| 788 | 788 | return false; |
| 789 | 789 | } |
| 790 | 790 | |
| 791 | - $userId = NULL; |
|
| 791 | + $userId = NULL; |
|
| 792 | 792 | $challenge = $state["challenge"]; |
| 793 | 793 | if (isset($state["userId"])) { |
| 794 | 794 | $userId = $state["userId"]; |
@@ -796,7 +796,7 @@ discard block |
||
| 796 | 796 | $spIdentifier = $state["spIdentifier"]; |
| 797 | 797 | |
| 798 | 798 | // Last bit is the spIdentifier |
| 799 | - return $this->_protocolAuth."://".(!is_null($userId)?urlencode($userId).'@':'').$this->getIdentifier()."/".$sessionKey."/".$challenge."/".urlencode($spIdentifier)."/".$this->_protocolVersion; |
|
| 799 | + return $this->_protocolAuth."://".(!is_null($userId) ?urlencode($userId).'@' : '').$this->getIdentifier()."/".$sessionKey."/".$challenge."/".urlencode($spIdentifier)."/".$this->_protocolVersion; |
|
| 800 | 800 | } |
| 801 | 801 | |
| 802 | 802 | /** |
@@ -820,7 +820,7 @@ discard block |
||
| 820 | 820 | protected function _uniqueSessionKey($prefix) |
| 821 | 821 | { |
| 822 | 822 | $value = 1; |
| 823 | - while ($value!=NULL) { |
|
| 823 | + while ($value != NULL) { |
|
| 824 | 824 | $sessionKey = $this->_ocraWrapper->generateSessionKey(); |
| 825 | 825 | $value = $this->_stateStorage->getValue($prefix.$sessionKey); |
| 826 | 826 | } |
@@ -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 | } |
@@ -122,72 +122,72 @@ discard block |
||
| 122 | 122 | $cryptoFunction = $components[1]; |
| 123 | 123 | $dataInput = strtolower($components[2]); // lower here so we can do case insensitive comparisons |
| 124 | 124 | |
| 125 | - if(stripos($cryptoFunction, "sha1")!==false) |
|
| 125 | + if (stripos($cryptoFunction, "sha1") !== false) |
|
| 126 | 126 | $crypto = "sha1"; |
| 127 | - if(stripos($cryptoFunction, "sha256")!==false) |
|
| 127 | + if (stripos($cryptoFunction, "sha256") !== false) |
|
| 128 | 128 | $crypto = "sha256"; |
| 129 | - if(stripos($cryptoFunction, "sha512")!==false) |
|
| 129 | + if (stripos($cryptoFunction, "sha512") !== false) |
|
| 130 | 130 | $crypto = "sha512"; |
| 131 | 131 | |
| 132 | - $codeDigits = substr($cryptoFunction, strrpos($cryptoFunction, "-")+1); |
|
| 132 | + $codeDigits = substr($cryptoFunction, strrpos($cryptoFunction, "-") + 1); |
|
| 133 | 133 | |
| 134 | 134 | // The size of the byte array message to be encrypted |
| 135 | 135 | // Counter |
| 136 | - if($dataInput[0] == "c" ) { |
|
| 136 | + if ($dataInput[0] == "c") { |
|
| 137 | 137 | // Fix the length of the HEX string |
| 138 | - while(strlen($counter) < 16) |
|
| 139 | - $counter = "0" . $counter; |
|
| 140 | - $counterLength=8; |
|
| 138 | + while (strlen($counter) < 16) |
|
| 139 | + $counter = "0".$counter; |
|
| 140 | + $counterLength = 8; |
|
| 141 | 141 | } |
| 142 | 142 | // Question |
| 143 | - if($dataInput[0] == "q" || |
|
| 144 | - stripos($dataInput, "-q")!==false) { |
|
| 145 | - while(strlen($question) < 256) |
|
| 146 | - $question = $question . "0"; |
|
| 147 | - $questionLength=128; |
|
| 143 | + if ($dataInput[0] == "q" || |
|
| 144 | + stripos($dataInput, "-q") !== false) { |
|
| 145 | + while (strlen($question) < 256) |
|
| 146 | + $question = $question."0"; |
|
| 147 | + $questionLength = 128; |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | // Password |
| 151 | - if(stripos($dataInput, "psha1")!==false) { |
|
| 152 | - while(strlen($password) < 40) |
|
| 153 | - $password = "0" . $password; |
|
| 154 | - $passwordLength=20; |
|
| 151 | + if (stripos($dataInput, "psha1") !== false) { |
|
| 152 | + while (strlen($password) < 40) |
|
| 153 | + $password = "0".$password; |
|
| 154 | + $passwordLength = 20; |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | - if(stripos($dataInput, "psha256")!==false) { |
|
| 158 | - while(strlen($password) < 64) |
|
| 159 | - $password = "0" . $password; |
|
| 160 | - $passwordLength=32; |
|
| 157 | + if (stripos($dataInput, "psha256") !== false) { |
|
| 158 | + while (strlen($password) < 64) |
|
| 159 | + $password = "0".$password; |
|
| 160 | + $passwordLength = 32; |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | - if(stripos($dataInput, "psha512")!==false) { |
|
| 164 | - while(strlen($password) < 128) |
|
| 165 | - $password = "0" . $password; |
|
| 166 | - $passwordLength=64; |
|
| 163 | + if (stripos($dataInput, "psha512") !== false) { |
|
| 164 | + while (strlen($password) < 128) |
|
| 165 | + $password = "0".$password; |
|
| 166 | + $passwordLength = 64; |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | // sessionInformation |
| 170 | - if(stripos($dataInput, "s064") !==false) { |
|
| 171 | - while(strlen($sessionInformation) < 128) |
|
| 172 | - $sessionInformation = "0" . $sessionInformation; |
|
| 170 | + if (stripos($dataInput, "s064") !== false) { |
|
| 171 | + while (strlen($sessionInformation) < 128) |
|
| 172 | + $sessionInformation = "0".$sessionInformation; |
|
| 173 | 173 | |
| 174 | - $sessionInformationLength=64; |
|
| 175 | - } else if(stripos($dataInput, "s128") !==false) { |
|
| 176 | - while(strlen($sessionInformation) < 256) |
|
| 177 | - $sessionInformation = "0" . $sessionInformation; |
|
| 174 | + $sessionInformationLength = 64; |
|
| 175 | + } else if (stripos($dataInput, "s128") !== false) { |
|
| 176 | + while (strlen($sessionInformation) < 256) |
|
| 177 | + $sessionInformation = "0".$sessionInformation; |
|
| 178 | 178 | |
| 179 | - $sessionInformationLength=128; |
|
| 180 | - } else if(stripos($dataInput, "s256") !==false) { |
|
| 181 | - while(strlen($sessionInformation) < 512) |
|
| 182 | - $sessionInformation = "0" . $sessionInformation; |
|
| 179 | + $sessionInformationLength = 128; |
|
| 180 | + } else if (stripos($dataInput, "s256") !== false) { |
|
| 181 | + while (strlen($sessionInformation) < 512) |
|
| 182 | + $sessionInformation = "0".$sessionInformation; |
|
| 183 | 183 | |
| 184 | - $sessionInformationLength=256; |
|
| 185 | - } else if(stripos($dataInput, "s512") !==false) { |
|
| 186 | - while(strlen($sessionInformation) < 128) |
|
| 187 | - $sessionInformation = "0" . $sessionInformation; |
|
| 184 | + $sessionInformationLength = 256; |
|
| 185 | + } else if (stripos($dataInput, "s512") !== false) { |
|
| 186 | + while (strlen($sessionInformation) < 128) |
|
| 187 | + $sessionInformation = "0".$sessionInformation; |
|
| 188 | 188 | |
| 189 | - $sessionInformationLength=64; |
|
| 190 | - } else if (stripos($dataInput, "-s") !== false ) { |
|
| 189 | + $sessionInformationLength = 64; |
|
| 190 | + } else if (stripos($dataInput, "-s") !== false) { |
|
| 191 | 191 | // deviation from spec. Officially 's' without a length indicator is not in the reference implementation. |
| 192 | 192 | // RFC is ambigious. However we have supported this in Tiqr since day 1, so we continue to support it. |
| 193 | 193 | |
@@ -196,27 +196,27 @@ discard block |
||
| 196 | 196 | // to prevent matching the "s" in the password input e.g. "psha1". |
| 197 | 197 | // [C] | QFxx | [PH | Snnn | TG] : Challenge-Response computation |
| 198 | 198 | // [C] | QFxx | [PH | TG] : Plain Signature computation |
| 199 | - while(strlen($sessionInformation) < 128) |
|
| 200 | - $sessionInformation = "0" . $sessionInformation; |
|
| 199 | + while (strlen($sessionInformation) < 128) |
|
| 200 | + $sessionInformation = "0".$sessionInformation; |
|
| 201 | 201 | |
| 202 | - $sessionInformationLength=64; |
|
| 202 | + $sessionInformationLength = 64; |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | |
| 206 | 206 | |
| 207 | 207 | // TimeStamp |
| 208 | - if($dataInput[0] == "t" || |
|
| 208 | + if ($dataInput[0] == "t" || |
|
| 209 | 209 | stripos($dataInput, "-t") !== false) { |
| 210 | - while(strlen($timeStamp) < 16) |
|
| 211 | - $timeStamp = "0" . $timeStamp; |
|
| 212 | - $timeStampLength=8; |
|
| 210 | + while (strlen($timeStamp) < 16) |
|
| 211 | + $timeStamp = "0".$timeStamp; |
|
| 212 | + $timeStampLength = 8; |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | // Put the bytes of "ocraSuite" parameters into the message |
| 216 | 216 | |
| 217 | - $msg = array_fill(0,$ocraSuiteLength+$counterLength+$questionLength+$passwordLength+$sessionInformationLength+$timeStampLength+1, 0); |
|
| 217 | + $msg = array_fill(0, $ocraSuiteLength + $counterLength + $questionLength + $passwordLength + $sessionInformationLength + $timeStampLength + 1, 0); |
|
| 218 | 218 | |
| 219 | - for($i=0;$i<strlen($ocraSuite);$i++) { |
|
| 219 | + for ($i = 0; $i < strlen($ocraSuite); $i++) { |
|
| 220 | 220 | $msg[$i] = $ocraSuite[$i]; |
| 221 | 221 | } |
| 222 | 222 | |
@@ -225,9 +225,9 @@ discard block |
||
| 225 | 225 | |
| 226 | 226 | // Put the bytes of "Counter" to the message |
| 227 | 227 | // Input is HEX encoded |
| 228 | - if($counterLength > 0 ) { |
|
| 228 | + if ($counterLength > 0) { |
|
| 229 | 229 | $bArray = self::_hexStr2Bytes($counter, $counterLength, 'counter'); |
| 230 | - for ($i=0;$i<strlen($bArray);$i++) { |
|
| 230 | + for ($i = 0; $i < strlen($bArray); $i++) { |
|
| 231 | 231 | $msg [$i + $ocraSuiteLength + 1] = $bArray[$i]; |
| 232 | 232 | } |
| 233 | 233 | } |
@@ -235,41 +235,41 @@ discard block |
||
| 235 | 235 | |
| 236 | 236 | // Put the bytes of "question" to the message |
| 237 | 237 | // Input is text encoded |
| 238 | - if($questionLength > 0 ) { |
|
| 238 | + if ($questionLength > 0) { |
|
| 239 | 239 | $bArray = self::_hexStr2Bytes($question, $questionLength, 'question'); |
| 240 | - for ($i=0;$i<strlen($bArray);$i++) { |
|
| 240 | + for ($i = 0; $i < strlen($bArray); $i++) { |
|
| 241 | 241 | $msg [$i + $ocraSuiteLength + 1 + $counterLength] = $bArray[$i]; |
| 242 | 242 | } |
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | // Put the bytes of "password" to the message |
| 246 | 246 | // Input is HEX encoded |
| 247 | - if($passwordLength > 0){ |
|
| 247 | + if ($passwordLength > 0) { |
|
| 248 | 248 | $bArray = self::_hexStr2Bytes($password, $passwordLength, 'password'); |
| 249 | - for ($i=0;$i<strlen($bArray);$i++) { |
|
| 249 | + for ($i = 0; $i < strlen($bArray); $i++) { |
|
| 250 | 250 | $msg [$i + $ocraSuiteLength + 1 + $counterLength + $questionLength] = $bArray[$i]; |
| 251 | 251 | } |
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | // Put the bytes of "sessionInformation" to the message |
| 255 | 255 | // Input is HEX encoded |
| 256 | - if($sessionInformationLength > 0 ){ |
|
| 256 | + if ($sessionInformationLength > 0) { |
|
| 257 | 257 | $bArray = self::_hexStr2Bytes($sessionInformation, $sessionInformationLength, 'sessionInformation'); |
| 258 | - for ($i=0;$i<strlen($bArray);$i++) { |
|
| 258 | + for ($i = 0; $i < strlen($bArray); $i++) { |
|
| 259 | 259 | $msg [$i + $ocraSuiteLength + 1 + $counterLength + $questionLength + $passwordLength] = $bArray[$i]; |
| 260 | 260 | } |
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | // Put the bytes of "time" to the message |
| 264 | 264 | // Input is HEX encoded value of minutes |
| 265 | - if($timeStampLength > 0){ |
|
| 265 | + if ($timeStampLength > 0) { |
|
| 266 | 266 | $bArray = self::_hexStr2Bytes($timeStamp, $timeStampLength, 'timeStamp'); |
| 267 | - for ($i=0;$i<strlen($bArray);$i++) { |
|
| 267 | + for ($i = 0; $i < strlen($bArray); $i++) { |
|
| 268 | 268 | $msg [$i + $ocraSuiteLength + 1 + $counterLength + $questionLength + $passwordLength + $sessionInformationLength] = $bArray[$i]; |
| 269 | 269 | } |
| 270 | 270 | } |
| 271 | 271 | |
| 272 | - $byteKey = self::_hexStr2Bytes($key, strlen($key)/2, 'key'); |
|
| 272 | + $byteKey = self::_hexStr2Bytes($key, strlen($key) / 2, 'key'); |
|
| 273 | 273 | |
| 274 | 274 | $msg = implode("", $msg); |
| 275 | 275 | |
@@ -291,23 +291,23 @@ discard block |
||
| 291 | 291 | static function _oath_truncate(string $hash, int $length = 6) : string |
| 292 | 292 | { |
| 293 | 293 | // Convert to dec |
| 294 | - foreach(str_split($hash,2) as $hex) |
|
| 294 | + foreach (str_split($hash, 2) as $hex) |
|
| 295 | 295 | { |
| 296 | - $hmac_result[]=hexdec($hex); |
|
| 296 | + $hmac_result[] = hexdec($hex); |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | // Find offset |
| 300 | 300 | $offset = $hmac_result[count($hmac_result) - 1] & 0xf; |
| 301 | 301 | |
| 302 | 302 | $v = strval( |
| 303 | - (($hmac_result[$offset+0] & 0x7f) << 24 ) | |
|
| 304 | - (($hmac_result[$offset+1] & 0xff) << 16 ) | |
|
| 305 | - (($hmac_result[$offset+2] & 0xff) << 8 ) | |
|
| 306 | - ($hmac_result[$offset+3] & 0xff) |
|
| 303 | + (($hmac_result[$offset + 0] & 0x7f) << 24) | |
|
| 304 | + (($hmac_result[$offset + 1] & 0xff) << 16) | |
|
| 305 | + (($hmac_result[$offset + 2] & 0xff) << 8) | |
|
| 306 | + ($hmac_result[$offset + 3] & 0xff) |
|
| 307 | 307 | ); |
| 308 | 308 | |
| 309 | 309 | // Prefix truncated string with 0's to ensure it always has the required length |
| 310 | - $v=str_pad($v, $length, "0", STR_PAD_LEFT); |
|
| 310 | + $v = str_pad($v, $length, "0", STR_PAD_LEFT); |
|
| 311 | 311 | |
| 312 | 312 | $v = substr($v, strlen($v) - $length); |
| 313 | 313 | return $v; |
@@ -122,12 +122,15 @@ discard block |
||
| 122 | 122 | $cryptoFunction = $components[1]; |
| 123 | 123 | $dataInput = strtolower($components[2]); // lower here so we can do case insensitive comparisons |
| 124 | 124 | |
| 125 | - if(stripos($cryptoFunction, "sha1")!==false) |
|
| 126 | - $crypto = "sha1"; |
|
| 127 | - if(stripos($cryptoFunction, "sha256")!==false) |
|
| 128 | - $crypto = "sha256"; |
|
| 129 | - if(stripos($cryptoFunction, "sha512")!==false) |
|
| 130 | - $crypto = "sha512"; |
|
| 125 | + if(stripos($cryptoFunction, "sha1")!==false) { |
|
| 126 | + $crypto = "sha1"; |
|
| 127 | + } |
|
| 128 | + if(stripos($cryptoFunction, "sha256")!==false) { |
|
| 129 | + $crypto = "sha256"; |
|
| 130 | + } |
|
| 131 | + if(stripos($cryptoFunction, "sha512")!==false) { |
|
| 132 | + $crypto = "sha512"; |
|
| 133 | + } |
|
| 131 | 134 | |
| 132 | 135 | $codeDigits = substr($cryptoFunction, strrpos($cryptoFunction, "-")+1); |
| 133 | 136 | |
@@ -135,56 +138,65 @@ discard block |
||
| 135 | 138 | // Counter |
| 136 | 139 | if($dataInput[0] == "c" ) { |
| 137 | 140 | // Fix the length of the HEX string |
| 138 | - while(strlen($counter) < 16) |
|
| 139 | - $counter = "0" . $counter; |
|
| 141 | + while(strlen($counter) < 16) { |
|
| 142 | + $counter = "0" . $counter; |
|
| 143 | + } |
|
| 140 | 144 | $counterLength=8; |
| 141 | 145 | } |
| 142 | 146 | // Question |
| 143 | 147 | if($dataInput[0] == "q" || |
| 144 | 148 | stripos($dataInput, "-q")!==false) { |
| 145 | - while(strlen($question) < 256) |
|
| 146 | - $question = $question . "0"; |
|
| 149 | + while(strlen($question) < 256) { |
|
| 150 | + $question = $question . "0"; |
|
| 151 | + } |
|
| 147 | 152 | $questionLength=128; |
| 148 | 153 | } |
| 149 | 154 | |
| 150 | 155 | // Password |
| 151 | 156 | if(stripos($dataInput, "psha1")!==false) { |
| 152 | - while(strlen($password) < 40) |
|
| 153 | - $password = "0" . $password; |
|
| 157 | + while(strlen($password) < 40) { |
|
| 158 | + $password = "0" . $password; |
|
| 159 | + } |
|
| 154 | 160 | $passwordLength=20; |
| 155 | 161 | } |
| 156 | 162 | |
| 157 | 163 | if(stripos($dataInput, "psha256")!==false) { |
| 158 | - while(strlen($password) < 64) |
|
| 159 | - $password = "0" . $password; |
|
| 164 | + while(strlen($password) < 64) { |
|
| 165 | + $password = "0" . $password; |
|
| 166 | + } |
|
| 160 | 167 | $passwordLength=32; |
| 161 | 168 | } |
| 162 | 169 | |
| 163 | 170 | if(stripos($dataInput, "psha512")!==false) { |
| 164 | - while(strlen($password) < 128) |
|
| 165 | - $password = "0" . $password; |
|
| 171 | + while(strlen($password) < 128) { |
|
| 172 | + $password = "0" . $password; |
|
| 173 | + } |
|
| 166 | 174 | $passwordLength=64; |
| 167 | 175 | } |
| 168 | 176 | |
| 169 | 177 | // sessionInformation |
| 170 | 178 | if(stripos($dataInput, "s064") !==false) { |
| 171 | - while(strlen($sessionInformation) < 128) |
|
| 172 | - $sessionInformation = "0" . $sessionInformation; |
|
| 179 | + while(strlen($sessionInformation) < 128) { |
|
| 180 | + $sessionInformation = "0" . $sessionInformation; |
|
| 181 | + } |
|
| 173 | 182 | |
| 174 | 183 | $sessionInformationLength=64; |
| 175 | 184 | } else if(stripos($dataInput, "s128") !==false) { |
| 176 | - while(strlen($sessionInformation) < 256) |
|
| 177 | - $sessionInformation = "0" . $sessionInformation; |
|
| 185 | + while(strlen($sessionInformation) < 256) { |
|
| 186 | + $sessionInformation = "0" . $sessionInformation; |
|
| 187 | + } |
|
| 178 | 188 | |
| 179 | 189 | $sessionInformationLength=128; |
| 180 | 190 | } else if(stripos($dataInput, "s256") !==false) { |
| 181 | - while(strlen($sessionInformation) < 512) |
|
| 182 | - $sessionInformation = "0" . $sessionInformation; |
|
| 191 | + while(strlen($sessionInformation) < 512) { |
|
| 192 | + $sessionInformation = "0" . $sessionInformation; |
|
| 193 | + } |
|
| 183 | 194 | |
| 184 | 195 | $sessionInformationLength=256; |
| 185 | 196 | } else if(stripos($dataInput, "s512") !==false) { |
| 186 | - while(strlen($sessionInformation) < 128) |
|
| 187 | - $sessionInformation = "0" . $sessionInformation; |
|
| 197 | + while(strlen($sessionInformation) < 128) { |
|
| 198 | + $sessionInformation = "0" . $sessionInformation; |
|
| 199 | + } |
|
| 188 | 200 | |
| 189 | 201 | $sessionInformationLength=64; |
| 190 | 202 | } else if (stripos($dataInput, "-s") !== false ) { |
@@ -196,8 +208,9 @@ discard block |
||
| 196 | 208 | // to prevent matching the "s" in the password input e.g. "psha1". |
| 197 | 209 | // [C] | QFxx | [PH | Snnn | TG] : Challenge-Response computation |
| 198 | 210 | // [C] | QFxx | [PH | TG] : Plain Signature computation |
| 199 | - while(strlen($sessionInformation) < 128) |
|
| 200 | - $sessionInformation = "0" . $sessionInformation; |
|
| 211 | + while(strlen($sessionInformation) < 128) { |
|
| 212 | + $sessionInformation = "0" . $sessionInformation; |
|
| 213 | + } |
|
| 201 | 214 | |
| 202 | 215 | $sessionInformationLength=64; |
| 203 | 216 | } |
@@ -207,8 +220,9 @@ discard block |
||
| 207 | 220 | // TimeStamp |
| 208 | 221 | if($dataInput[0] == "t" || |
| 209 | 222 | stripos($dataInput, "-t") !== false) { |
| 210 | - while(strlen($timeStamp) < 16) |
|
| 211 | - $timeStamp = "0" . $timeStamp; |
|
| 223 | + while(strlen($timeStamp) < 16) { |
|
| 224 | + $timeStamp = "0" . $timeStamp; |
|
| 225 | + } |
|
| 212 | 226 | $timeStampLength=8; |
| 213 | 227 | } |
| 214 | 228 | |