Skip to content

Commit

Permalink
Merge pull request #12 from VirgilSecurity/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
PetrenkoAnton authored Feb 27, 2019
2 parents 2b4ffb3 + 4b34410 commit 92824ed
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 46 deletions.
3 changes: 1 addition & 2 deletions passw0rd/Credentials/UpdateToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
*/
class UpdateToken
{
private $updateToken;
private $version;
private $value;

Expand All @@ -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]");
Expand Down
2 changes: 1 addition & 1 deletion passw0rd/Http/HttpVirgilAgent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
63 changes: 20 additions & 43 deletions passw0rd/Protocol/ProtocolContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@

use passw0rd\Core\PHEClient;
use passw0rd\Credentials\InputCredentialsChecker;
use passw0rd\Exeptions\InputCredentialsCheckerException;
use passw0rd\Exeptions\ProtocolContextException;

/**
Expand Down Expand Up @@ -76,12 +75,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);

Expand All @@ -96,28 +90,22 @@ public function mainSetter(array $credentials)
{
$this->setCredentials($credentials);

try {
if ($this->isKeysVersionsEquals())
$this->version = (int) $this->getServicePublicKey(true);
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(!is_null($this->getUpdateToken()))
{
if((int) $this->getUpdateToken(true)!==$this->getVersion()+1)
throw new ProtocolContextException("Incorrect token version ".$this->getUpdateToken(true));

$this->version = (int) $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');
}

}

/**
Expand Down Expand Up @@ -152,46 +140,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);
}

/**
Expand Down Expand Up @@ -231,7 +208,7 @@ public function getVersion(): int
}

/**
* @return void
* @throws ProtocolContextException
*/
public function setUpdateTokenVersion(): void
{
Expand Down

0 comments on commit 92824ed

Please sign in to comment.