Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/paragonie/chronicle
Browse files Browse the repository at this point in the history
  • Loading branch information
paragonie-security committed Sep 12, 2019
2 parents 22762aa + a145d88 commit edf5f82
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 11 deletions.
2 changes: 1 addition & 1 deletion bin/create-client.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@

$db->beginTransaction();
$db->insert(
Chronicle::getTableName('clients', $isSQLite),
Chronicle::getTableNameUnquoted('clients', $isSQLite),
[
'isAdmin' => !empty($admin),
'publicid' => $newPublicId,
Expand Down
2 changes: 1 addition & 1 deletion bin/replicate.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
}

$db->beginTransaction();
$db->insert(Chronicle::getTableName('replication_sources', true), [
$db->insert(Chronicle::getTableNameUnquoted('replication_sources', true), [
'name' => $name,
'uniqueid' => Base64UrlSafe::encode(random_bytes(33)),
'publickey' => $publicKey,
Expand Down
14 changes: 13 additions & 1 deletion src/Chronicle/Chronicle.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@ public static function getTableName(string $name, bool $dontEscape = false)
);
}

/**
* @param string $name
* @param bool $dontEscape
* @return string
* @throws InvalidInstanceException
*/
public static function getTableNameUnquoted(string $name, bool $dontEscape = false)
{
return trim(self::getTableName($name, $dontEscape), '"');
}

/**
* This extends the Blakechain with an arbitrary message, signature, and
* public key.
Expand All @@ -92,6 +103,7 @@ public static function getTableName(string $name, bool $dontEscape = false)
*
* @throws BaseException
* @throws \SodiumException
* @psalm-suppress MixedTypeCoercion
*/
public static function extendBlakechain(
string $body,
Expand Down Expand Up @@ -150,7 +162,7 @@ public static function extendBlakechain(
self::normalize($db->getDriver(), $fields);

// Insert new row into the database:
$db->insert(self::getTableName('chain', true), $fields);
$db->insert(self::getTableNameUnquoted('chain', true), $fields);
if (!$db->commit()) {
$db->rollBack();
throw new ChainAppendException('Could not commit new hash to database');
Expand Down
6 changes: 4 additions & 2 deletions src/Chronicle/Handlers/Register.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ public function __invoke(
* @throws \Exception
* @throws InvalidInstanceException
* @throws SecurityViolation
*
* @psalm-suppress MixedTypeCoercion
*/
protected function createClient(array $post): string
{
Expand All @@ -185,11 +187,11 @@ protected function createClient(array $post): string

$db->beginTransaction();
$db->insert(
Chronicle::getTableName('clients', true),
Chronicle::getTableNameUnquoted('clients', true),
[
'publicid' => $clientId,
'publickey' => $post['publickey'],
'comment' => $post['comment'] ?? '',
'comment' => (string) ($post['comment'] ?? ''),
'isAdmin' => false,
'created' => $now,
'modified' => $now
Expand Down
13 changes: 8 additions & 5 deletions src/Chronicle/Process/CrossSign.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
use GuzzleHttp\Exception\GuzzleException;
use ParagonIE\Chronicle\Chronicle;
use ParagonIE\Chronicle\Error\ConfigurationError;
use ParagonIE\Chronicle\Exception\{
FilesystemException,
TargetNotFound
};
use ParagonIE\Chronicle\Exception\{FilesystemException, InvalidInstanceException, TargetNotFound};
use ParagonIE\ConstantTime\Base64UrlSafe;
use ParagonIE\EasyDB\EasyDB;
use ParagonIE\Sapient\Adapter\Guzzle;
Expand Down Expand Up @@ -67,6 +64,7 @@ class CrossSign
* @param SigningPublicKey $publicKey
* @param array $policy
* @param array<string, string> $lastRun
* @throws \Exception
*/
public function __construct(
int $id,
Expand Down Expand Up @@ -95,6 +93,7 @@ public function __construct(
* @param int $id
* @return self
*
* @throws InvalidInstanceException
* @throws TargetNotFound
*/
public static function byId(int $id): self
Expand Down Expand Up @@ -127,6 +126,7 @@ public static function byId(int $id): self
* @return bool
*
* @throws ConfigurationError
* @throws InvalidInstanceException
*/
public function needsToCrossSign(): bool
{
Expand Down Expand Up @@ -179,6 +179,7 @@ public function needsToCrossSign(): bool
* @throws InvalidMessageException
* @throws GuzzleException
* @throws FilesystemException
* @throws InvalidInstanceException
*/
public function performCrossSign(): bool
{
Expand Down Expand Up @@ -229,6 +230,7 @@ protected function sendToPeer(array $message): ResponseInterface
*
* @param EasyDB $db
* @return array<string, string>
* @throws InvalidInstanceException
*/
protected function getEndOfChain(EasyDB $db): array
{
Expand All @@ -248,12 +250,13 @@ protected function getEndOfChain(EasyDB $db): array
* @param array $response
* @param array $message
* @return bool
* @throws InvalidInstanceException
*/
protected function updateLastRun(EasyDB $db, array $response, array $message): bool
{
$db->beginTransaction();
$db->update(
Chronicle::getTableName('xsign_targets'),
Chronicle::getTableNameUnquoted('xsign_targets'),
[
'lastrun' => \json_encode([
'id' => $message['id'],
Expand Down
5 changes: 4 additions & 1 deletion src/Chronicle/Process/Replicate.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class Replicate
* @param string $name
* @param string $url
* @param SigningPublicKey $publicKey
* @throws \Exception
*/
public function __construct(
int $id,
Expand All @@ -76,6 +77,7 @@ public function __construct(
* @param int $id
* @return self
*
* @throws InvalidInstanceException
* @throws ReplicationSourceNotFound
*/
public static function byId(int $id): self
Expand Down Expand Up @@ -104,6 +106,7 @@ public static function byId(int $id): self
* @return void
*
* @throws GuzzleException
* @throws InvalidInstanceException
* @throws InvalidMessageException
* @throws SecurityViolation
* @throws \SodiumException
Expand Down Expand Up @@ -196,7 +199,7 @@ protected function appendToChain(array $entry): bool
}

/* Enter the new row to the replication table */
$db->insert(Chronicle::getTableName('replication_chain', true), [
$db->insert(Chronicle::getTableNameUnquoted('replication_chain', true), [
'source' => $this->id,
'data' => $entry['contents'],
'prevhash' => $prevhash,
Expand Down

0 comments on commit edf5f82

Please sign in to comment.