From bd9680b518ce157babd4947caf54f0ae7a8103e6 Mon Sep 17 00:00:00 2001 From: Petrenko Anton Date: Wed, 13 Feb 2019 00:47:31 +0200 Subject: [PATCH 1/3] Fix UpdateToken class --- passw0rd/Credentials/UpdateToken.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/passw0rd/Credentials/UpdateToken.php b/passw0rd/Credentials/UpdateToken.php index 005abb9..80d8c59 100644 --- a/passw0rd/Credentials/UpdateToken.php +++ b/passw0rd/Credentials/UpdateToken.php @@ -45,7 +45,6 @@ */ class UpdateToken { - private $updateToken; private $version; private $value; @@ -72,7 +71,7 @@ private function validateAndSet(string $updateToken): void $parts = explode(".", $updateToken); if (count($parts) !== 3 || $parts[0] !== self::PREFIX) - throw new UpdateTokenException("Invalid string: $this->updateToken"); + throw new UpdateTokenException("Invalid format: $updateToken"); if ((int)$parts[1] < 1) throw new UpdateTokenException("Invalid version: $parts[1]"); From c2b5f114a9f19bc4e47c030d6311c5c1c6c8b3ca Mon Sep 17 00:00:00 2001 From: Petrenko Anton Date: Tue, 19 Feb 2019 16:56:50 +0200 Subject: [PATCH 2/3] Fix throwable exceptions (var_dump) at ProtocolContext --- passw0rd/Http/HttpVirgilAgent.php | 2 +- passw0rd/Protocol/ProtocolContext.php | 34 +++++++-------------------- 2 files changed, 10 insertions(+), 26 deletions(-) diff --git a/passw0rd/Http/HttpVirgilAgent.php b/passw0rd/Http/HttpVirgilAgent.php index b5ddec4..3d2d88b 100644 --- a/passw0rd/Http/HttpVirgilAgent.php +++ b/passw0rd/Http/HttpVirgilAgent.php @@ -45,7 +45,7 @@ class HttpVirgilAgent { const PRODUCT = 'passw0rd'; const FAMILY = 'php'; - const VERSION = '1.3.0'; // TODO: Add composer.lock parser! + const VERSION = '1.3.1'; // TODO: Add composer.lock parser! private $platform; diff --git a/passw0rd/Protocol/ProtocolContext.php b/passw0rd/Protocol/ProtocolContext.php index 8471531..9b12f92 100644 --- a/passw0rd/Protocol/ProtocolContext.php +++ b/passw0rd/Protocol/ProtocolContext.php @@ -76,12 +76,7 @@ public function create(array $credentials): ProtocolContext { $credentialsChecker = new InputCredentialsChecker($credentials); - try { - $credentialsChecker->check(); - } catch (InputCredentialsCheckerException $e) { - var_dump($e->getMessage()); - die; - } + $credentialsChecker->check(); $this->mainSetter($credentials); @@ -152,46 +147,35 @@ public function getAppToken(): string return $this->appToken; } + /** * @param bool $returnVersion * @return string + * @throws ProtocolContextException */ public function getServicePublicKey(bool $returnVersion = false): string { - try { - return $this->getParsedContext(self::PK_PREFIX, $this->servicePublicKey, $returnVersion); - } catch (ProtocolContextException $e) { - var_dump($e->getMessage()); - die; - } + return $this->getParsedContext(self::PK_PREFIX, $this->servicePublicKey, $returnVersion); } /** * @param bool $returnVersion * @return string + * @throws ProtocolContextException */ public function getAppSecretKey(bool $returnVersion = false): string { - try { - return $this->getParsedContext(self::SK_PREFIX, $this->appSecretKey, $returnVersion); - } catch (ProtocolContextException $e) { - var_dump($e->getMessage()); - die; - } + return $this->getParsedContext(self::SK_PREFIX, $this->appSecretKey, $returnVersion); } /** * @param bool $returnVersion * @return null|string + * @throws ProtocolContextException */ public function getUpdateToken(bool $returnVersion = false):? string { - try { - return $this->getParsedContext(self::UT_PREFIX, $this->updateToken, $returnVersion); - } catch (ProtocolContextException $e) { - var_dump($e->getMessage()); - die; - } + return $this->getParsedContext(self::UT_PREFIX, $this->updateToken, $returnVersion); } /** @@ -231,7 +215,7 @@ public function getVersion(): int } /** - * @return void + * @throws ProtocolContextException */ public function setUpdateTokenVersion(): void { From c7baab13ccc7ccefb8430c5ed5ca259c17e841cf Mon Sep 17 00:00:00 2001 From: Petrenko Anton Date: Tue, 19 Feb 2019 17:22:46 +0200 Subject: [PATCH 3/3] Fix ProtocolContextException --- passw0rd/Protocol/ProtocolContext.php | 29 ++++++++++----------------- 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/passw0rd/Protocol/ProtocolContext.php b/passw0rd/Protocol/ProtocolContext.php index 9b12f92..b5a5d0c 100644 --- a/passw0rd/Protocol/ProtocolContext.php +++ b/passw0rd/Protocol/ProtocolContext.php @@ -39,7 +39,6 @@ use passw0rd\Core\PHEClient; use passw0rd\Credentials\InputCredentialsChecker; -use passw0rd\Exeptions\InputCredentialsCheckerException; use passw0rd\Exeptions\ProtocolContextException; /** @@ -91,28 +90,22 @@ public function mainSetter(array $credentials) { $this->setCredentials($credentials); - try { - if ($this->isKeysVersionsEquals()) - $this->version = (int) $this->getServicePublicKey(true); - - if(!is_null($this->getUpdateToken())) - { - if((int) $this->getUpdateToken(true)!==$this->getVersion()+1) - throw new \Exception("Incorrect token version ".$this->getUpdateToken(true)); + if ($this->isKeysVersionsEquals()) + $this->version = (int) $this->getServicePublicKey(true); - $this->version = (int) $this->getUpdateToken(true); - } + if(!is_null($this->getUpdateToken())) + { + if((int) $this->getUpdateToken(true)!==$this->getVersion()+1) + throw new ProtocolContextException("Incorrect token version ".$this->getUpdateToken(true)); - try { - $this->setPHEClient($this->getAppSecretKey(), $this->getServicePublicKey(), $this->getUpdateToken()); - } catch (\Exception $e) { - throw new ProtocolContextException('Protocol error with PHE client constructor or setKeys method'); - } + $this->version = (int) $this->getUpdateToken(true); + } + try { + $this->setPHEClient($this->getAppSecretKey(), $this->getServicePublicKey(), $this->getUpdateToken()); } catch (\Exception $e) { - throw new \Exception($e->getMessage()); + throw new ProtocolContextException('Protocol error with PHE client constructor or setKeys method'); } - } /**