Skip to content

Commit

Permalink
Minor bugfixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
paragonie-security committed Jan 19, 2018
1 parent 39e13d4 commit 49e7908
Show file tree
Hide file tree
Showing 15 changed files with 49 additions and 16 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ matrix:
include:
- php: "7.0"
- php: "7.1"
- php: "7.2"
- php: "nightly"
allow_failures:
- php: "nightly"
Expand Down
1 change: 1 addition & 0 deletions bin/create-client.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
};

$root = \dirname(__DIR__);
/** @psalm-suppress UnresolvableInclude */
require_once $root . '/cli-autoload.php';

if (!\is_readable($root . '/local/settings.json')) {
Expand Down
1 change: 1 addition & 0 deletions bin/cross-sign.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
};

$root = \dirname(__DIR__);
/** @psalm-suppress UnresolvableInclude */
require_once $root . '/cli-autoload.php';

if (!\is_readable($root . '/local/settings.json')) {
Expand Down
1 change: 1 addition & 0 deletions bin/fix-nulls.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use ParagonIE\Chronicle\Chronicle;

$root = \dirname(__DIR__);
/** @psalm-suppress UnresolvableInclude */
require_once $root . '/cli-autoload.php';

if (!\is_readable($root . '/local/settings.json')) {
Expand Down
1 change: 1 addition & 0 deletions bin/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
declare(strict_types=1);

$root = \dirname(__DIR__);
/** @psalm-suppress UnresolvableInclude */
require_once $root . '/cli-autoload.php';

// Generate a signing key.
Expand Down
3 changes: 2 additions & 1 deletion bin/keygen.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
use ParagonIE\Sapient\CryptographyKeys\SigningSecretKey;

$root = \dirname(__DIR__);
/** @psalm-suppress UnresolvableInclude */
require_once $root . '/cli-autoload.php';

/* This generates a new secret key from your kernel's CSPRNG */
$signingSecretKey = SigningSecretKey::generate();

echo json_encode(
echo (string) json_encode(
[
'secret-key' => $signingSecretKey->getString(),
'public-key' => $signingSecretKey->getPublicKey()->getString()
Expand Down
4 changes: 3 additions & 1 deletion bin/make-tables.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
declare(strict_types=1);

$root = \dirname(__DIR__);
/** @psalm-suppress UnresolvableInclude */
require_once $root . '/cli-autoload.php';
/** @psalm-suppress UnresolvableInclude */
require_once $root . '/src/settings.php';

/**
Expand All @@ -29,7 +31,7 @@

if (empty($settings['database'])) {
echo "Please defined a database in local/settings.json. For example:\n\n";
echo \json_encode(
echo (string) \json_encode(
[
'database' => [
'dsn' => 'pgsql:rest-of-dsn-goes-here',
Expand Down
1 change: 1 addition & 0 deletions bin/replicate.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
};

$root = \dirname(__DIR__);
/** @psalm-suppress UnresolvableInclude */
require_once $root . '/cli-autoload.php';

if (!\is_readable($root . '/local/settings.json')) {
Expand Down
1 change: 1 addition & 0 deletions bin/scheduled-tasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use ParagonIE\Chronicle\Chronicle;

$root = \dirname(__DIR__);
/** @psalm-suppress UnresolvableInclude */
require_once $root . '/cli-autoload.php';

if (!\is_readable($root . '/local/settings.json')) {
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"require-dev": {
"phpunit/phpunit": "^6",
"vimeo/psalm": "^0.3"
"vimeo/psalm": "^0"
},
"autoload-dev": {
"psr-4": {
Expand All @@ -37,7 +37,7 @@
}
},
"scripts": {
"start": "php -S 0.0.0.0:8080 -t public public/index.php",
"start": "php -S 0.0.0.0:8080 -t public index.php",
"static-analysis": "psalm",
"test": "phpunit"
}
Expand Down
14 changes: 9 additions & 5 deletions src/Chronicle/Handlers/Register.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

use ParagonIE\Chronicle\{
Chronicle,
Exception\AccessDenied,
Exception\HTTPException,
Exception\ChainAppendException,
Exception\FilesystemException,
Exception\SecurityViolation,
HandlerInterface,
Scheduled
Expand Down Expand Up @@ -32,9 +32,9 @@ class Register implements HandlerInterface
* @param array $args
* @return ResponseInterface
*
* @throws AccessDenied
* @throws HTTPException
* @throws SecurityViolation
* @throws ChainAppendException
* @throws FilesystemException
* @throws \SodiumException
* @throws \TypeError
*/
public function __invoke(
Expand Down Expand Up @@ -105,6 +105,7 @@ public function __invoke(
$settings = Chronicle::getSettings();
if (!empty($settings['publish-new-clients'])) {
$serverKey = Chronicle::getSigningKey();
/** @var string $message */
$message = \json_encode(
[
'server-action' => 'New Client Registration',
Expand All @@ -114,6 +115,9 @@ public function __invoke(
],
JSON_PRETTY_PRINT
);
if (!\is_string($message)) {
throw new \TypeError('Invalid messsage');
}
$signature = Base64UrlSafe::encode(
\ParagonIE_Sodium_Compat::crypto_sign_detached(
$message,
Expand Down
6 changes: 6 additions & 0 deletions src/Chronicle/Handlers/Replica.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use ParagonIE\Chronicle\{
Chronicle,
Exception\FilesystemException,
Exception\ReplicationSourceNotFound,
Exception\HashNotFound,
HandlerInterface
Expand Down Expand Up @@ -93,6 +94,7 @@ public function __invoke(
* Gets the entire Blakechain.
*
* @return ResponseInterface
* @throws FilesystemException
*/
public function exportChain(): ResponseInterface
{
Expand All @@ -115,6 +117,7 @@ public function exportChain(): ResponseInterface
* @param array $args
* @return ResponseInterface
* @throws HashNotFound
* @throws FilesystemException
*/
public function getByHash(array $args = []): ResponseInterface
{
Expand Down Expand Up @@ -159,6 +162,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 @@ -197,6 +201,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 @@ -243,6 +248,7 @@ protected function getIndex(): ResponseInterface
*
* @param array $args
* @return ResponseInterface
* @throws FilesystemException
* @throws HashNotFound
*/
public function getSince(array $args = []): ResponseInterface
Expand Down
16 changes: 10 additions & 6 deletions src/Chronicle/Handlers/Revoke.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
use ParagonIE\Chronicle\{
Chronicle,
Exception\AccessDenied,
Exception\ClientNotFound,
Exception\HTTPException,
Exception\ChainAppendException,
Exception\FilesystemException,
HandlerInterface,
Scheduled
};
Expand All @@ -32,8 +32,9 @@ class Revoke implements HandlerInterface
* @return ResponseInterface
*
* @throws AccessDenied
* @throws ClientNotFound
* @throws HTTPException
* @throws ChainAppendException
* @throws FilesystemException
* @throws \SodiumException
* @throws \TypeError
*/
public function __invoke(
Expand Down Expand Up @@ -115,7 +116,7 @@ public function __invoke(
];

if (!$result['deleted']) {
$result['reason'] = 'Delete operatio nwas unsuccessful due to unknown reasons.';
$result['reason'] = 'Delete operation was unsuccessful due to unknown reasons.';
}
$now = (new \DateTime())->format(\DateTime::ATOM);

Expand All @@ -126,11 +127,14 @@ public function __invoke(
[
'server-action' => 'Client Access Revocation',
'now' => $now,
'clientid' => $result['client-id'],
'clientid' => $post['clientid'],
'publickey' => $post['publickey']
],
JSON_PRETTY_PRINT
);
if (!\is_string($message)) {
throw new \TypeError('Invalid messsage');
}
$signature = Base64UrlSafe::encode(
\ParagonIE_Sodium_Compat::crypto_sign_detached(
$message,
Expand Down
8 changes: 8 additions & 0 deletions src/Chronicle/Process/Attest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ public function run()

/**
* @return array
* @throws FilesystemException
* @throws \ParagonIE\Chronicle\Exception\ChainAppendException
* @throws \SodiumException
* @throws \TypeError
*/
public function attestAll(): array
{
Expand All @@ -91,6 +95,7 @@ public function attestAll(): array
}

// Build the message
/** @var string $message */
$message = \json_encode(
[
'version' => Chronicle::VERSION,
Expand All @@ -99,6 +104,9 @@ public function attestAll(): array
],
JSON_PRETTY_PRINT
);
if (!\is_string($message)) {
throw new \TypeError('Invalid messsage');
}

// Sign the message:
$signature = Base64UrlSafe::encode(
Expand Down
3 changes: 2 additions & 1 deletion src/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
CheckClientSignature
};
use Psr\Http\Message\{
RequestInterface,
ResponseInterface
};

Expand Down Expand Up @@ -58,7 +59,7 @@
$this->get('', Index::class);
});

$app->get('/', function ($request, $response, $args): ResponseInterface {
$app->get('/', function (RequestInterface $request, ResponseInterface $response, array $args = []): ResponseInterface {
/* UX enhancement: Automatically redirect to chronicle URI if client header is present: */
if ($request instanceof \Slim\Http\Request && $response instanceof \Slim\Http\Response) {
if ($request->hasHeader(Chronicle::CLIENT_IDENTIFIER_HEADER)) {
Expand Down

0 comments on commit 49e7908

Please sign in to comment.