@@ -81,7 +81,7 @@ |
||
| 81 | 81 | 'verifyResponse for user "%s" failed', |
| 82 | 82 | $userId |
| 83 | 83 | ), |
| 84 | - array( 'exception' => $e) |
|
| 84 | + array('exception' => $e) |
|
| 85 | 85 | ); |
| 86 | 86 | return false; |
| 87 | 87 | } |
@@ -42,7 +42,7 @@ |
||
| 42 | 42 | public static function randomBytes(int $length): string |
| 43 | 43 | { |
| 44 | 44 | // Get $length cryptographically secure pseudo-random bytes |
| 45 | - $rnd=\random_bytes($length); |
|
| 45 | + $rnd = \random_bytes($length); |
|
| 46 | 46 | |
| 47 | 47 | if (strlen($rnd) !== $length) { |
| 48 | 48 | throw new Exception("random_bytes did not return the requested number of bytes"); |
@@ -22,6 +22,6 @@ |
||
| 22 | 22 | { |
| 23 | 23 | // $code must be int, otherwise this throws with Error("Wrong parameters for ReadWriteException") |
| 24 | 24 | // PDOException::getCode() can return a sting |
| 25 | - return new self($e->getMessage(), (int)$e->getCode(), $e ); |
|
| 25 | + return new self($e->getMessage(), (int) $e->getCode(), $e); |
|
| 26 | 26 | } |
| 27 | 27 | } |
@@ -571,17 +571,17 @@ discard block |
||
| 571 | 571 | } |
| 572 | 572 | |
| 573 | 573 | $metadata = array("service"=> |
| 574 | - array("displayName" => $this->_name, |
|
| 575 | - "identifier" => $this->_identifier, |
|
| 576 | - "logoUrl" => $this->_logoUrl, |
|
| 577 | - "infoUrl" => $this->_infoUrl, |
|
| 578 | - "authenticationUrl" => $authenticationUrl, |
|
| 579 | - "ocraSuite" => $this->_ocraSuite, |
|
| 580 | - "enrollmentUrl" => $enrollmentUrl |
|
| 581 | - ), |
|
| 582 | - "identity"=> |
|
| 583 | - array("identifier" =>$data["userId"], |
|
| 584 | - "displayName"=>$data["displayName"])); |
|
| 574 | + array("displayName" => $this->_name, |
|
| 575 | + "identifier" => $this->_identifier, |
|
| 576 | + "logoUrl" => $this->_logoUrl, |
|
| 577 | + "infoUrl" => $this->_infoUrl, |
|
| 578 | + "authenticationUrl" => $authenticationUrl, |
|
| 579 | + "ocraSuite" => $this->_ocraSuite, |
|
| 580 | + "enrollmentUrl" => $enrollmentUrl |
|
| 581 | + ), |
|
| 582 | + "identity"=> |
|
| 583 | + array("identifier" =>$data["userId"], |
|
| 584 | + "displayName"=>$data["displayName"])); |
|
| 585 | 585 | |
| 586 | 586 | $this->_unsetStateValue(self::PREFIX_ENROLLMENT, $enrollmentKey); |
| 587 | 587 | |
@@ -611,28 +611,28 @@ discard block |
||
| 611 | 611 | */ |
| 612 | 612 | public function getEnrollmentSecret(string $enrollmentKey): string |
| 613 | 613 | { |
| 614 | - $data = $this->_getStateValue(self::PREFIX_ENROLLMENT, $enrollmentKey); |
|
| 615 | - if (!is_array($data)) { |
|
| 616 | - $this->logger->error('getEnrollmentSecret: enrollment key not found'); |
|
| 617 | - throw new RuntimeException('enrollment key not found'); |
|
| 618 | - } |
|
| 619 | - $userId = $data["userId"] ?? NULL; |
|
| 620 | - $sessionId = $data["sessionId"] ?? NULL; |
|
| 621 | - if (!is_string($userId) || !(is_string($sessionId))) { |
|
| 622 | - throw new RuntimeException('getEnrollmentSecret: invalid enrollment data'); |
|
| 623 | - } |
|
| 624 | - $enrollmentData = [ |
|
| 625 | - "userId" => $userId, |
|
| 626 | - "sessionId" => $sessionId |
|
| 627 | - ]; |
|
| 628 | - $enrollmentSecret = $this->_uniqueSessionKey(); |
|
| 629 | - $this->_setStateValue( |
|
| 630 | - self::PREFIX_ENROLLMENT_SECRET, |
|
| 631 | - $enrollmentSecret, |
|
| 632 | - $enrollmentData, |
|
| 633 | - self::ENROLLMENT_EXPIRE |
|
| 634 | - ); |
|
| 635 | - return $enrollmentSecret; |
|
| 614 | + $data = $this->_getStateValue(self::PREFIX_ENROLLMENT, $enrollmentKey); |
|
| 615 | + if (!is_array($data)) { |
|
| 616 | + $this->logger->error('getEnrollmentSecret: enrollment key not found'); |
|
| 617 | + throw new RuntimeException('enrollment key not found'); |
|
| 618 | + } |
|
| 619 | + $userId = $data["userId"] ?? NULL; |
|
| 620 | + $sessionId = $data["sessionId"] ?? NULL; |
|
| 621 | + if (!is_string($userId) || !(is_string($sessionId))) { |
|
| 622 | + throw new RuntimeException('getEnrollmentSecret: invalid enrollment data'); |
|
| 623 | + } |
|
| 624 | + $enrollmentData = [ |
|
| 625 | + "userId" => $userId, |
|
| 626 | + "sessionId" => $sessionId |
|
| 627 | + ]; |
|
| 628 | + $enrollmentSecret = $this->_uniqueSessionKey(); |
|
| 629 | + $this->_setStateValue( |
|
| 630 | + self::PREFIX_ENROLLMENT_SECRET, |
|
| 631 | + $enrollmentSecret, |
|
| 632 | + $enrollmentData, |
|
| 633 | + self::ENROLLMENT_EXPIRE |
|
| 634 | + ); |
|
| 635 | + return $enrollmentSecret; |
|
| 636 | 636 | } |
| 637 | 637 | |
| 638 | 638 | /** |
@@ -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 | |
@@ -287,8 +287,7 @@ discard block |
||
| 287 | 287 | if (isset($options['ocraservice']) && $options['ocraservice']['type'] != 'tiqr') { |
| 288 | 288 | $options['ocraservice']['ocra.suite'] = $this->_ocraSuite; |
| 289 | 289 | $this->_ocraService = Tiqr_OcraService::getOcraService($options['ocraservice']['type'], $options['ocraservice'], $logger); |
| 290 | - } |
|
| 291 | - else { // Create default ocraservice |
|
| 290 | + } else { // Create default ocraservice |
|
| 292 | 291 | $this->_ocraService = Tiqr_OcraService::getOcraService('tiqr', array('ocra.suite' => $this->_ocraSuite), $logger); |
| 293 | 292 | } |
| 294 | 293 | } |
@@ -347,8 +346,9 @@ discard block |
||
| 347 | 346 | case 'APNS': |
| 348 | 347 | case 'APNS_DIRECT': |
| 349 | 348 | $apns_version = $this->_options['apns.version'] ?? 2; |
| 350 | - if ($apns_version !=2) |
|
| 351 | - throw new InvalidArgumentException("Unsupported APNS version '$apns_version'"); |
|
| 349 | + if ($apns_version !=2) { |
|
| 350 | + throw new InvalidArgumentException("Unsupported APNS version '$apns_version'"); |
|
| 351 | + } |
|
| 352 | 352 | $message = new Tiqr_Message_APNS2($this->_options, $this->logger); |
| 353 | 353 | break; |
| 354 | 354 | |
@@ -514,7 +514,9 @@ discard block |
||
| 514 | 514 | $sessionId = session_id(); |
| 515 | 515 | } |
| 516 | 516 | $status = $this->_getStateValue(self::PREFIX_ENROLLMENT_STATUS, $sessionId); |
| 517 | - if (is_null($status)) return self::ENROLLMENT_STATUS_IDLE; |
|
| 517 | + if (is_null($status)) { |
|
| 518 | + return self::ENROLLMENT_STATUS_IDLE; |
|
| 519 | + } |
|
| 518 | 520 | return $status; |
| 519 | 521 | } |
| 520 | 522 | |
@@ -871,8 +873,7 @@ discard block |
||
| 871 | 873 | |
| 872 | 874 | try { |
| 873 | 875 | return $this->_getStateValue("authenticated_", $sessionId); |
| 874 | - } |
|
| 875 | - catch (Exception $e) { |
|
| 876 | + } catch (Exception $e) { |
|
| 876 | 877 | $this->logger->error('getAuthenticatedUser failed', array('exception'=>$e)); |
| 877 | 878 | return NULL; |
| 878 | 879 | } |
@@ -28,8 +28,7 @@ |
||
| 28 | 28 | // Use HTTP/1.1 instead of HTTP/2 |
| 29 | 29 | $curl_options[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_1; |
| 30 | 30 | $this->logger->notice(sprintf('Using HTTP/1.1 CURL Proxy URL: "%s" and port "%s"', $curl_options[CURLOPT_URL], $curl_options[CURLOPT_URL])); |
| 31 | - } |
|
| 32 | - else { |
|
| 31 | + } else { |
|
| 33 | 32 | $version_info = curl_version(); |
| 34 | 33 | if ($version_info['features'] & CURL_VERSION_HTTP2 == 0) { |
| 35 | 34 | throw new RuntimeException('APNS2 requires HTTP/2 support in curl'); |
@@ -20,11 +20,11 @@ discard block |
||
| 20 | 20 | $options = $this->getOptions(); |
| 21 | 21 | if (isset($options['apns.proxy_host_url'])) { |
| 22 | 22 | // Override CURL options to connect to a HTTP/1.1 to HTTP/2 proxy |
| 23 | - $curl_options[CURLOPT_URL] = $options['apns.proxy_host_url'] . '/3/device/' . $this->getAddress(); |
|
| 23 | + $curl_options[CURLOPT_URL] = $options['apns.proxy_host_url'].'/3/device/'.$this->getAddress(); |
|
| 24 | 24 | $curl_options[CURLOPT_PORT] = $options['apns.proxy_host_port'] ?? 443; |
| 25 | 25 | // Use HTTP/1.1 instead of HTTP/2 |
| 26 | 26 | $curl_options[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_1; |
| 27 | - $this->logger->notice(sprintf('Using HTTP/1.1 CURL Proxy URL: "%s" and port "%s"', $curl_options[CURLOPT_URL], $curl_options[CURLOPT_URL])); |
|
| 27 | + $this->logger->notice(sprintf('Using HTTP/1.1 CURL Proxy URL: "%s" and port "%s"', $curl_options[CURLOPT_URL], $curl_options[CURLOPT_URL])); |
|
| 28 | 28 | } |
| 29 | 29 | else { |
| 30 | 30 | $version_info = curl_version(); |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | |
| 36 | 36 | // Get the UID from the client certificate we use for authentication, this |
| 37 | 37 | // is set to the bundle ID. |
| 38 | - $options=$this->getOptions(); |
|
| 38 | + $options = $this->getOptions(); |
|
| 39 | 39 | $cert_filename = $options['apns.certificate']; |
| 40 | 40 | if (strlen($cert_filename) == 0) { |
| 41 | 41 | throw new RuntimeException('apns.certificate option not set'); |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | ); |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - $cert=openssl_x509_parse( $cert_file_contents ); |
|
| 50 | + $cert = openssl_x509_parse($cert_file_contents); |
|
| 51 | 51 | if (false === $cert) { |
| 52 | 52 | throw new RuntimeException('Error parsing APNS client certificate'); |
| 53 | 53 | } |
@@ -72,42 +72,42 @@ discard block |
||
| 72 | 72 | $authProvider = AuthProvider\Certificate::create($authProviderOptions); |
| 73 | 73 | |
| 74 | 74 | // Create the push message |
| 75 | - $alert=Alert::create(); |
|
| 75 | + $alert = Alert::create(); |
|
| 76 | 76 | $alert->setBody($this->getText()); |
| 77 | 77 | // Note: It is possible to specify a title and a subtitle: $alert->setTitle() && $alert->setSubtitle() |
| 78 | 78 | // The tiqr service currently does not implement this. |
| 79 | - $payload=Payload::create()->setAlert($alert); |
|
| 79 | + $payload = Payload::create()->setAlert($alert); |
|
| 80 | 80 | $payload->setSound('default'); |
| 81 | 81 | foreach ($this->getCustomProperties() as $name => $value) { |
| 82 | 82 | $payload->setCustomValue($name, $value); |
| 83 | 83 | } |
| 84 | 84 | $this->logger->debug(sprintf('JSON Payload: %s', $payload->toJson())); |
| 85 | - $notification=new Notification($payload, $this->getAddress()); |
|
| 85 | + $notification = new Notification($payload, $this->getAddress()); |
|
| 86 | 86 | // Set expiration to 30 seconds from now, same as Message_APNS |
| 87 | 87 | $now = new DateTime(); |
| 88 | - $expirationInstant=$now->add(new DateInterval('PT30S')); |
|
| 88 | + $expirationInstant = $now->add(new DateInterval('PT30S')); |
|
| 89 | 89 | $notification->setExpirationAt($expirationInstant); |
| 90 | 90 | |
| 91 | 91 | // Send the push message |
| 92 | 92 | $client = new Client($authProvider, $options['apns.environment'] == 'production', $curl_options); |
| 93 | 93 | $client->addNotification($notification); |
| 94 | - $responses=$client->push(); |
|
| 95 | - if ( sizeof($responses) != 1) { |
|
| 96 | - $this->logger->warning(sprintf('Unexpected number responses. Expected 1, got %d', sizeof($responses)) ); |
|
| 94 | + $responses = $client->push(); |
|
| 95 | + if (sizeof($responses) != 1) { |
|
| 96 | + $this->logger->warning(sprintf('Unexpected number responses. Expected 1, got %d', sizeof($responses))); |
|
| 97 | 97 | if (sizeof($responses) == 0) { |
| 98 | 98 | $this->logger->warning('Could not determine whether the notification was sent'); |
| 99 | 99 | return; |
| 100 | 100 | } |
| 101 | 101 | } |
| 102 | 102 | /** @var \Pushok\Response $response */ |
| 103 | - $response = reset($responses); // Get first response from the array |
|
| 104 | - $deviceToken=$response->getDeviceToken() ?? ''; |
|
| 103 | + $response = reset($responses); // Get first response from the array |
|
| 104 | + $deviceToken = $response->getDeviceToken() ?? ''; |
|
| 105 | 105 | // A canonical UUID that is the unique ID for the notification. E.g. 123e4567-e89b-12d3-a456-4266554400a0 |
| 106 | - $apnsId=$response->getApnsId() ?? ''; |
|
| 106 | + $apnsId = $response->getApnsId() ?? ''; |
|
| 107 | 107 | // Status code. E.g. 200 (Success), 410 (The device token is no longer active for the topic.) |
| 108 | - $statusCode=$response->getStatusCode(); |
|
| 108 | + $statusCode = $response->getStatusCode(); |
|
| 109 | 109 | $this->logger->info(sprintf('Got response with ApnsId "%s", status %s for deviceToken "%s"', $apnsId, $statusCode, $deviceToken)); |
| 110 | - if ( strcasecmp($deviceToken, $this->getAddress()) ) { |
|
| 110 | + if (strcasecmp($deviceToken, $this->getAddress())) { |
|
| 111 | 111 | $this->logger->warning(sprintf('Unexpected deviceToken in response. Expected: "%s"; got: "%s"', $this->getAddress(), $deviceToken)); |
| 112 | 112 | } |
| 113 | 113 | if ($statusCode == 200) { |
@@ -115,9 +115,9 @@ discard block |
||
| 115 | 115 | return; |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | - $reasonPhrase=$response->getReasonPhrase(); // E.g. The device token is no longer active for the topic. |
|
| 119 | - $errorReason=$response->getErrorReason(); // E.g. Unregistered |
|
| 120 | - $errorDescription=$response->getErrorDescription(); // E.g. The device token is inactive for the specified topic. |
|
| 118 | + $reasonPhrase = $response->getReasonPhrase(); // E.g. The device token is no longer active for the topic. |
|
| 119 | + $errorReason = $response->getErrorReason(); // E.g. Unregistered |
|
| 120 | + $errorDescription = $response->getErrorDescription(); // E.g. The device token is inactive for the specified topic. |
|
| 121 | 121 | |
| 122 | 122 | $this->logger->error(sprintf('Error sending APNS2 push notification. APNS ID: "%s"; deviceToken: "%s"; Error: "%s" "%s" "%s"', $apnsId, $deviceToken, $reasonPhrase, $errorReason, $errorDescription)); |
| 123 | 123 | throw new RuntimeException( |
@@ -42,7 +42,6 @@ |
||
| 42 | 42 | userid varchar(30) NOT NULL UNIQUE, |
| 43 | 43 | secret varchar(128), |
| 44 | 44 | ); |
| 45 | - |
|
| 46 | 45 | * @see Tiqr_UserSecretStorage::getSecretStorage() |
| 47 | 46 | * @see Tiqr_UserSecretStorage_Interface |
| 48 | 47 | * |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | public function userExists(string $userId): bool |
| 88 | 88 | { |
| 89 | 89 | try { |
| 90 | - $sth = $this->handle->prepare('SELECT userid FROM ' . $this->tableName . ' WHERE userid = ?'); |
|
| 90 | + $sth = $this->handle->prepare('SELECT userid FROM '.$this->tableName.' WHERE userid = ?'); |
|
| 91 | 91 | $sth->execute(array($userId)); |
| 92 | 92 | return (false !== $sth->fetchColumn()); |
| 93 | 93 | } |
@@ -107,9 +107,9 @@ discard block |
||
| 107 | 107 | protected function getUserSecret(string $userId): string |
| 108 | 108 | { |
| 109 | 109 | try { |
| 110 | - $sth = $this->handle->prepare('SELECT secret FROM ' . $this->tableName . ' WHERE userid = ?'); |
|
| 110 | + $sth = $this->handle->prepare('SELECT secret FROM '.$this->tableName.' WHERE userid = ?'); |
|
| 111 | 111 | $sth->execute(array($userId)); |
| 112 | - $res=$sth->fetchColumn(); |
|
| 112 | + $res = $sth->fetchColumn(); |
|
| 113 | 113 | if ($res === false) { |
| 114 | 114 | // No result |
| 115 | 115 | $this->logger->error(sprintf('No result getting secret for user "%s"', $userId)); |
@@ -145,9 +145,9 @@ discard block |
||
| 145 | 145 | // - The INSERT will fail when displayname has a NOT NULL constraint |
| 146 | 146 | try { |
| 147 | 147 | if ($this->userExists($userId)) { |
| 148 | - $sth = $this->handle->prepare('UPDATE ' . $this->tableName . ' SET secret = ? WHERE userid = ?'); |
|
| 148 | + $sth = $this->handle->prepare('UPDATE '.$this->tableName.' SET secret = ? WHERE userid = ?'); |
|
| 149 | 149 | } else { |
| 150 | - $sth = $this->handle->prepare('INSERT INTO ' . $this->tableName . ' (secret,userid) VALUES (?,?)'); |
|
| 150 | + $sth = $this->handle->prepare('INSERT INTO '.$this->tableName.' (secret,userid) VALUES (?,?)'); |
|
| 151 | 151 | } |
| 152 | 152 | $sth->execute(array($secret, $userId)); |
| 153 | 153 | } |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | $sth->execute(); |
| 172 | 172 | } |
| 173 | 173 | catch (Exception $e) { |
| 174 | - $statusMessage = "UserSecretStorage_PDO error: " . $e->getMessage(); |
|
| 174 | + $statusMessage = "UserSecretStorage_PDO error: ".$e->getMessage(); |
|
| 175 | 175 | return false; |
| 176 | 176 | } |
| 177 | 177 | |
@@ -90,8 +90,7 @@ discard block |
||
| 90 | 90 | $sth = $this->handle->prepare('SELECT userid FROM ' . $this->tableName . ' WHERE userid = ?'); |
| 91 | 91 | $sth->execute(array($userId)); |
| 92 | 92 | return (false !== $sth->fetchColumn()); |
| 93 | - } |
|
| 94 | - catch (Exception $e) { |
|
| 93 | + } catch (Exception $e) { |
|
| 95 | 94 | $this->logger->error('PDO error checking user exists', array('exception'=>$e, 'userId'=>$userId)); |
| 96 | 95 | throw ReadWriteException::fromOriginalException($e); |
| 97 | 96 | } |
@@ -115,8 +114,7 @@ discard block |
||
| 115 | 114 | $this->logger->error(sprintf('No result getting secret for user "%s"', $userId)); |
| 116 | 115 | throw new RuntimeException('User not found'); |
| 117 | 116 | } |
| 118 | - } |
|
| 119 | - catch (Exception $e) { |
|
| 117 | + } catch (Exception $e) { |
|
| 120 | 118 | $this->logger->error('PDO error getting user', array('exception' => $e, 'userId' => $userId)); |
| 121 | 119 | throw ReadWriteException::fromOriginalException($e); |
| 122 | 120 | } |
@@ -150,8 +148,7 @@ discard block |
||
| 150 | 148 | $sth = $this->handle->prepare('INSERT INTO ' . $this->tableName . ' (secret,userid) VALUES (?,?)'); |
| 151 | 149 | } |
| 152 | 150 | $sth->execute(array($secret, $userId)); |
| 153 | - } |
|
| 154 | - catch (Exception $e) { |
|
| 151 | + } catch (Exception $e) { |
|
| 155 | 152 | $this->logger->error( |
| 156 | 153 | sprintf('Unable to persist user secret for user "%s" in user secret storage (PDO)', $userId), |
| 157 | 154 | array('exception'=>$e) |
@@ -169,8 +166,7 @@ discard block |
||
| 169 | 166 | try { |
| 170 | 167 | $sth = $this->handle->prepare('SELECT secret FROM '.$this->tableName.' LIMIT 1'); |
| 171 | 168 | $sth->execute(); |
| 172 | - } |
|
| 173 | - catch (Exception $e) { |
|
| 169 | + } catch (Exception $e) { |
|
| 174 | 170 | $statusMessage = "UserSecretStorage_PDO error: " . $e->getMessage(); |
| 175 | 171 | return false; |
| 176 | 172 | } |
@@ -59,7 +59,6 @@ |
||
| 59 | 59 | ); |
| 60 | 60 | |
| 61 | 61 | CREATE INDEX IF NOT EXISTS index_tiqrstate_expire ON tiqrstate (expire); |
| 62 | - |
|
| 63 | 62 | * @see Tiqr_StateStorage::getStorage() |
| 64 | 63 | * @see Tiqr_StateStorage_StateStorageInterface |
| 65 | 64 | * |
@@ -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 | } |
@@ -237,7 +237,7 @@ discard block |
||
| 237 | 237 | { |
| 238 | 238 | try { |
| 239 | 239 | // Retrieve a random row from the table, this checks that the table exists and is readable |
| 240 | - $sth = $this->handle->prepare('SELECT `value`, `key`, `expire` FROM ' . $this->tablename . ' LIMIT 1'); |
|
| 240 | + $sth = $this->handle->prepare('SELECT `value`, `key`, `expire` FROM '.$this->tablename.' LIMIT 1'); |
|
| 241 | 241 | $sth->execute(); |
| 242 | 242 | } |
| 243 | 243 | catch (Exception $e) { |
@@ -123,8 +123,7 @@ discard block |
||
| 123 | 123 | $this->logger->notice( |
| 124 | 124 | sprintf("Deleted %d expired keys", $deletedRows) |
| 125 | 125 | ); |
| 126 | - } |
|
| 127 | - catch (Exception $e) { |
|
| 126 | + } catch (Exception $e) { |
|
| 128 | 127 | $this->logger->error( |
| 129 | 128 | sprintf("Deleting expired keys failed: %s", $e->getMessage()), |
| 130 | 129 | array('exception', $e) |
@@ -157,8 +156,7 @@ discard block |
||
| 157 | 156 | } |
| 158 | 157 | try { |
| 159 | 158 | $sth->execute(array(serialize($value), $expire, $key)); |
| 160 | - } |
|
| 161 | - catch (Exception $e) { |
|
| 159 | + } catch (Exception $e) { |
|
| 162 | 160 | $this->logger->error( |
| 163 | 161 | sprintf('Unable to store key "%s" in PDO StateStorage', $key), |
| 164 | 162 | array('exception' => $e) |
@@ -178,8 +176,7 @@ discard block |
||
| 178 | 176 | try { |
| 179 | 177 | $sth = $this->handle->prepare("DELETE FROM " . $this->tablename . " WHERE `key` = ?"); |
| 180 | 178 | $sth->execute(array($key)); |
| 181 | - } |
|
| 182 | - catch (Exception $e) { |
|
| 179 | + } catch (Exception $e) { |
|
| 183 | 180 | $this->logger->error( |
| 184 | 181 | sprintf('Error deleting key "%s" from PDO StateStorage', $key), |
| 185 | 182 | array('exception' => $e) |
@@ -208,8 +205,7 @@ discard block |
||
| 208 | 205 | try { |
| 209 | 206 | $sth = $this->handle->prepare('SELECT `value` FROM ' . $this->tablename . ' WHERE `key` = ? AND (`expire` >= ? OR `expire` = 0)'); |
| 210 | 207 | $sth->execute(array($key, time())); |
| 211 | - } |
|
| 212 | - catch (Exception $e) { |
|
| 208 | + } catch (Exception $e) { |
|
| 213 | 209 | $this->logger->error( |
| 214 | 210 | sprintf('Error getting value for key "%s" from PDO StateStorage', $key), |
| 215 | 211 | array('exception' => $e) |
@@ -239,8 +235,7 @@ discard block |
||
| 239 | 235 | // Retrieve a random row from the table, this checks that the table exists and is readable |
| 240 | 236 | $sth = $this->handle->prepare('SELECT `value`, `key`, `expire` FROM ' . $this->tablename . ' LIMIT 1'); |
| 241 | 237 | $sth->execute(); |
| 242 | - } |
|
| 243 | - catch (Exception $e) { |
|
| 238 | + } catch (Exception $e) { |
|
| 244 | 239 | $statusMessage = sprintf('Error performing health check on PDO StateStorage: %s', $e->getMessage()); |
| 245 | 240 | return false; |
| 246 | 241 | } |
@@ -74,7 +74,7 @@ |
||
| 74 | 74 | $password = $options['password']; |
| 75 | 75 | |
| 76 | 76 | try { |
| 77 | - $handle = new PDO($dsn, $userName, $password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION) ); |
|
| 77 | + $handle = new PDO($dsn, $userName, $password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)); |
|
| 78 | 78 | } catch (PDOException $e) { |
| 79 | 79 | $logger->error( |
| 80 | 80 | sprintf('Unable to establish a PDO connection. Error message from PDO: %s', $e->getMessage()) |
@@ -97,7 +97,7 @@ |
||
| 97 | 97 | * ), |
| 98 | 98 | * ) |
| 99 | 99 | * ); |
| 100 | - * |
|
| 100 | + * |
|
| 101 | 101 | * |
| 102 | 102 | * @return Tiqr_UserSecretStorage_Interface |
| 103 | 103 | * @throws RuntimeException If an unknown type is requested. |
@@ -39,10 +39,10 @@ |
||
| 39 | 39 | * @return Tiqr_OcraService_Interface |
| 40 | 40 | * @throws Exception An exception if an unknown orca service type is requested. |
| 41 | 41 | */ |
| 42 | - public static function getOcraService(string $type="tiqr", array $options=array(), LoggerInterface $logger=null) |
|
| 42 | + public static function getOcraService(string $type = "tiqr", array $options = array(), LoggerInterface $logger = null) |
|
| 43 | 43 | { |
| 44 | 44 | if (!$logger) |
| 45 | - $logger=new \Psr\Log\NullLogger(); |
|
| 45 | + $logger = new \Psr\Log\NullLogger(); |
|
| 46 | 46 | |
| 47 | 47 | switch ($type) { |
| 48 | 48 | case "tiqr": |
@@ -41,8 +41,9 @@ |
||
| 41 | 41 | */ |
| 42 | 42 | public static function getOcraService(string $type="tiqr", array $options=array(), LoggerInterface $logger=null) |
| 43 | 43 | { |
| 44 | - if (!$logger) |
|
| 45 | - $logger=new \Psr\Log\NullLogger(); |
|
| 44 | + if (!$logger) { |
|
| 45 | + $logger=new \Psr\Log\NullLogger(); |
|
| 46 | + } |
|
| 46 | 47 | |
| 47 | 48 | switch ($type) { |
| 48 | 49 | case "tiqr": |