Skip to content

Commit

Permalink
Docblock consistency, fix composer internal server
Browse files Browse the repository at this point in the history
  • Loading branch information
paragonie-security committed Oct 16, 2018
1 parent ca63ffe commit 9c9a6d9
Show file tree
Hide file tree
Showing 16 changed files with 110 additions and 31 deletions.
10 changes: 6 additions & 4 deletions bin/create-client.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<?php
declare(strict_types=1);

use ParagonIE\EasyDB\EasyDB;
use ParagonIE\EasyDB\Factory;
use ParagonIE\Sapient\CryptographyKeys\SigningPublicKey;
use ParagonIE\ConstantTime\Base64UrlSafe;
use Getopt\{
Getopt,
Option
};
use ParagonIE\EasyDB\{
EasyDB,
Factory
};
use ParagonIE\ConstantTime\Base64UrlSafe;
use ParagonIE\Sapient\CryptographyKeys\SigningPublicKey;

$root = \dirname(__DIR__);
/** @psalm-suppress UnresolvableInclude */
Expand Down
10 changes: 6 additions & 4 deletions bin/cross-sign.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
* This script sets up cross-signing to another Chronicle
*/

use ParagonIE\EasyDB\EasyDB;
use ParagonIE\EasyDB\Factory;
use ParagonIE\Sapient\CryptographyKeys\SigningPublicKey;
use ParagonIE\ConstantTime\Base64UrlSafe;
use Getopt\{
Getopt,
Option
};
use ParagonIE\EasyDB\{
EasyDB,
Factory
};
use ParagonIE\ConstantTime\Base64UrlSafe;
use ParagonIE\Sapient\CryptographyKeys\SigningPublicKey;

$root = \dirname(__DIR__);
/** @psalm-suppress UnresolvableInclude */
Expand Down
12 changes: 7 additions & 5 deletions bin/replicate.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
/**
* This script sets up replication of another Chronicle
*/

use ParagonIE\EasyDB\Factory;
use ParagonIE\Sapient\CryptographyKeys\SigningPublicKey;
use ParagonIE\ConstantTime\Base64UrlSafe;
use Getopt\{
Getopt,
Option
};
use ParagonIE\EasyDB\{
EasyDB,
Factory
};
use ParagonIE\ConstantTime\Base64UrlSafe;
use ParagonIE\Sapient\CryptographyKeys\SigningPublicKey;

$root = \dirname(__DIR__);
/** @psalm-suppress UnresolvableInclude */
Expand All @@ -27,7 +29,7 @@
(string) \file_get_contents($root . '/local/settings.json'),
true
);
/** @var \ParagonIE\EasyDB\EasyDB $db */
/** @var EasyDB $db */
$db = Factory::create(
$settings['database']['dsn'],
$settings['database']['username'] ?? '',
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
}
},
"scripts": {
"start": "php -S 0.0.0.0:8080 -t public index.php",
"start": "php -S 0.0.0.0:8080 -t public public/index.php",
"static-analysis": "psalm",
"test": "phpunit"
}
Expand Down
17 changes: 14 additions & 3 deletions src/Chronicle/Chronicle.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
SigningSecretKey
};
use ParagonIE\Sapient\Sapient;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\{
RequestInterface,
ResponseInterface
};

/**
* Class Chronicle
Expand Down Expand Up @@ -52,6 +54,7 @@ class Chronicle
* @param string $signature
* @param SigningPublickey $publicKey
* @return array<string, string>
*
* @throws ChainAppendException
*/
public static function extendBlakechain(
Expand Down Expand Up @@ -127,6 +130,8 @@ public static function extendBlakechain(
* @param string $errorMessage
* @param int $errorCode
* @return ResponseInterface
*
* @throws FilesystemException
*/
public static function errorResponse(
ResponseInterface $response,
Expand Down Expand Up @@ -167,6 +172,7 @@ public static function getDatabaseBoolean(bool $value)
*
* @param string $clientId
* @return SigningPublicKey
*
* @throws ClientNotFound
*/
public static function getClientsPublicKey(string $clientId): SigningPublicKey
Expand Down Expand Up @@ -218,6 +224,7 @@ public static function getSettings(): array
* We should audit all calls to this method.
*
* @return SigningSecretKey
*
* @throws FilesystemException
*/
public static function getSigningKey(): SigningSecretKey
Expand Down Expand Up @@ -287,7 +294,11 @@ public static function validateTimestamps(
if (empty($json[$index])) {
throw new TimestampNotProvided('Parameter "' . $index . '" not provided.', 401);
}
$sent = new \DateTimeImmutable((string) ($json[$index]));
try {
$sent = new \DateTimeImmutable((string)($json[$index]));
} catch (\Exception $ex) {
throw new SecurityViolation('Request timestamp is invalid. Please resend.', 408);
}
$expires = $sent->add(
\DateInterval::createFromDateString(
(string) self::$settings['request-timeout']
Expand Down
7 changes: 6 additions & 1 deletion src/Chronicle/Handlers/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
declare(strict_types=1);
namespace ParagonIE\Chronicle\Handlers;

use ParagonIE\Chronicle\{Chronicle, Exception\FilesystemException, HandlerInterface};
use ParagonIE\Chronicle\{
Chronicle,
Exception\FilesystemException,
HandlerInterface
};
use Psr\Http\Message\{
RequestInterface,
ResponseInterface
Expand All @@ -25,6 +29,7 @@ class Index implements HandlerInterface
* @param ResponseInterface $response
* @param array $args
* @return ResponseInterface
*
* @throws FilesystemException
*/
public function __invoke(
Expand Down
12 changes: 11 additions & 1 deletion src/Chronicle/Handlers/Lookup.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
<?php
namespace ParagonIE\Chronicle\Handlers;

use ParagonIE\Chronicle\{Chronicle, Exception\FilesystemException, Exception\HashNotFound, HandlerInterface};
use ParagonIE\Chronicle\{
Chronicle,
Exception\FilesystemException,
Exception\HashNotFound,
HandlerInterface
};
use Psr\Http\Message\{
RequestInterface,
ResponseInterface
Expand Down Expand Up @@ -33,6 +38,8 @@ public function __construct(string $method = 'index')
* @param ResponseInterface $response
* @param array $args
* @return ResponseInterface
*
* @throws FilesystemException
*/
public function __invoke(
RequestInterface $request,
Expand Down Expand Up @@ -67,6 +74,8 @@ public function __invoke(
* Gets the entire Blakechain.
*
* @return ResponseInterface
*
* @throws FilesystemException
*/
public function exportChain(): ResponseInterface
{
Expand Down Expand Up @@ -131,6 +140,7 @@ public function getByHash(array $args = []): ResponseInterface
* List the latest current hash and summary hash
*
* @return ResponseInterface
*
* @throws FilesystemException
*/
public function getLastHash(): ResponseInterface
Expand Down
8 changes: 7 additions & 1 deletion src/Chronicle/Handlers/Register.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
<?php
namespace ParagonIE\Chronicle\Handlers;

use GuzzleHttp\Exception\GuzzleException;
use ParagonIE\Chronicle\{
Chronicle,
Exception\ChainAppendException,
Exception\FilesystemException,
Exception\SecurityViolation,
Exception\TargetNotFound,
HandlerInterface,
Scheduled
};
use ParagonIE\ConstantTime\Base64UrlSafe;
use ParagonIE\Sapient\CryptographyKeys\SigningPublicKey;
use ParagonIE\Sapient\Exception\InvalidMessageException;
use Psr\Http\Message\{
RequestInterface,
ResponseInterface
Expand All @@ -34,8 +37,10 @@ class Register implements HandlerInterface
*
* @throws ChainAppendException
* @throws FilesystemException
* @throws GuzzleException
* @throws InvalidMessageException
* @throws TargetNotFound
* @throws \SodiumException
* @throws \TypeError
*/
public function __invoke(
RequestInterface $request,
Expand Down Expand Up @@ -154,6 +159,7 @@ public function __invoke(
*
* @param array $post
* @return string
*
* @throws \PDOException
* @throws \Exception
*/
Expand Down
7 changes: 7 additions & 0 deletions src/Chronicle/Handlers/Replica.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public function __construct(string $method = 'index')
* @param ResponseInterface $response
* @param array $args
* @return ResponseInterface
*
* @throws FilesystemException
*/
public function __invoke(
Expand Down Expand Up @@ -95,6 +96,7 @@ public function __invoke(
* Gets the entire Blakechain.
*
* @return ResponseInterface
*
* @throws FilesystemException
*/
public function exportChain(): ResponseInterface
Expand All @@ -117,6 +119,7 @@ public function exportChain(): ResponseInterface
*
* @param array $args
* @return ResponseInterface
*
* @throws HashNotFound
* @throws FilesystemException
*/
Expand Down Expand Up @@ -164,6 +167,7 @@ public function getByHash(array $args = []): ResponseInterface
* List the latest current hash and summary hash for this replica
*
* @return ResponseInterface
*
* @throws FilesystemException
*/
public function getLastHash(): ResponseInterface
Expand Down Expand Up @@ -204,6 +208,7 @@ public function getLastHash(): ResponseInterface
* List all replicated Chronicles and their respective URIs
*
* @return ResponseInterface
*
* @throws FilesystemException
*/
protected function getIndex(): ResponseInterface
Expand Down Expand Up @@ -256,6 +261,7 @@ protected function getIndex(): ResponseInterface
*
* @param array $args
* @return ResponseInterface
*
* @throws FilesystemException
* @throws HashNotFound
*/
Expand Down Expand Up @@ -348,6 +354,7 @@ protected function getFullChain(): array
*
* @param string $uniqueId
* @return self
*
* @throws ReplicationSourceNotFound
*/
protected function selectReplication(string $uniqueId): self
Expand Down
1 change: 1 addition & 0 deletions src/Chronicle/Middleware/CheckAdminSignature.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class CheckAdminSignature extends CheckClientSignature
*
* @param string $clientId
* @return SigningPublicKey
*
* @throws ClientNotFound
*/
public function getPublicKey(string $clientId): SigningPublicKey
Expand Down
15 changes: 10 additions & 5 deletions src/Chronicle/Middleware/CheckClientSignature.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
declare(strict_types=1);
namespace ParagonIE\Chronicle\Middleware;

use ParagonIE\Chronicle\Chronicle;
use ParagonIE\Chronicle\Exception\ClientNotFound;
use ParagonIE\Chronicle\Exception\SecurityViolation;
use ParagonIE\Chronicle\MiddlewareInterface;
use ParagonIE\Chronicle\{
Chronicle,
Exception\ClientNotFound,
Exception\FilesystemException,
Exception\SecurityViolation,
MiddlewareInterface
};
use ParagonIE\Sapient\CryptographyKeys\SigningPublicKey;
use Psr\Http\Message\{
RequestInterface,
Expand All @@ -27,6 +30,7 @@ class CheckClientSignature implements MiddlewareInterface
/**
* @param RequestInterface $request
* @return string
*
* @throws ClientNotFound
* @throws SecurityViolation
*/
Expand All @@ -47,7 +51,8 @@ public function getClientId(RequestInterface $request): string
* @param ResponseInterface $response
* @param callable $next
* @return ResponseInterface
* @throws ClientNotFound
*
* @throws FilesystemException
*/
public function __invoke(
RequestInterface $request,
Expand Down
14 changes: 11 additions & 3 deletions src/Chronicle/Process/Attest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
namespace ParagonIE\Chronicle\Process;

use ParagonIE\Chronicle\Chronicle;
use ParagonIE\Chronicle\Exception\FilesystemException;
use ParagonIE\Chronicle\Exception\{
ChainAppendException,
FilesystemException
};
use ParagonIE\ConstantTime\Base64UrlSafe;

/**
Expand All @@ -29,6 +32,7 @@ public function __construct(array $settings = [])

/**
* @return bool
*
* @throws FilesystemException
*/
public function isScheduled(): bool
Expand Down Expand Up @@ -57,8 +61,11 @@ public function isScheduled(): bool
}

/**
* @throws FilesystemException
* @return void
*
* @throws ChainAppendException
* @throws FilesystemException
* @throws \SodiumException
*/
public function run()
{
Expand All @@ -77,8 +84,9 @@ public function run()

/**
* @return array
*
* @throws ChainAppendException
* @throws FilesystemException
* @throws \ParagonIE\Chronicle\Exception\ChainAppendException
* @throws \SodiumException
* @throws \TypeError
*/
Expand Down
Loading

0 comments on commit 9c9a6d9

Please sign in to comment.