feat: store hash of signed file at database

Signed-off-by: Vitor Mattos <vitor@php.rio>
This commit is contained in:
Vitor Mattos 2025-01-02 23:21:59 -03:00
parent 11f16b1443
commit f900fa8305
No known key found for this signature in database
GPG key ID: B7AB4B76A7CA7318
5 changed files with 62 additions and 1 deletions

View file

@ -25,7 +25,7 @@ Developed with ❤️ by [LibreCode](https://librecode.coop). Help us transform
* [Donate with GitHub Sponsor: ![Donate using GitHub Sponsor](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86)](https://github.com/sponsors/libresign)
]]></description>
<version>11.0.0-dev</version>
<version>11.0.0-dev.2</version>
<licence>agpl</licence>
<author mail="contact@librecode.coop" homepage="https://librecode.coop">LibreCode</author>
<documentation>

View file

@ -18,6 +18,8 @@ use OCP\DB\Types;
* @method int getNodeId()
* @method void setSignedNodeId(int $nodeId)
* @method int getSignedNodeId()
* @method void setSignedHash(string $hash)
* @method string getSignedHash()
* @method void setUserId(string $userId)
* @method void setUuid(string $uuid)
* @method string getUuid()
@ -42,6 +44,9 @@ class File extends Entity {
/** @var integer */
protected $signedNodeId;
/** @var string */
protected $signedHash;
/** @var string */
protected $userId;
@ -73,6 +78,7 @@ class File extends Entity {
$this->addType('id', 'integer');
$this->addType('nodeId', 'integer');
$this->addType('signedNodeId', 'integer');
$this->addType('signedHash', 'string');
$this->addType('userId', 'string');
$this->addType('uuid', 'string');
$this->addType('createdAt', 'integer');

View file

@ -24,6 +24,8 @@ use OCP\DB\Types;
* @method int getCreatedAt()
* @method void setSigned(int $signed)
* @method int getSigned()
* @method void setSignedHash(string $hash)
* @method string getSignedHash()
* @method void setDisplayName(string $displayName)
* @method string getDisplayName()
* @method void setMetadata(array $metadata)
@ -55,6 +57,9 @@ class SignRequest extends Entity {
/** @var int */
protected $signed;
/** @var string */
protected $signedHash;
/** @var string */
protected $metadata;
@ -66,6 +71,7 @@ class SignRequest extends Entity {
$this->addType('description', 'string');
$this->addType('createdAt', 'integer');
$this->addType('signed', 'integer');
$this->addType('signedHash', 'string');
$this->addType('metadata', Types::JSON);
}
}

View file

@ -0,0 +1,46 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2025 LibreCode coop and contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Libresign\Migration;
use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\DB\Types;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;
class Version11000Date20250103005204 extends SimpleMigrationStep {
/**
* @param IOutput $output
* @param Closure(): ISchemaWrapper $schemaClosure
* @param array $options
* @return null|ISchemaWrapper
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
/** @var ISchemaWrapper */
$schema = $schemaClosure();
$tableFile = $schema->getTable('libresign_file');
if (!$tableFile->hasColumn('signed_hash')) {
$tableFile->addColumn('signed_hash', Types::STRING, [
'notnull' => false,
'length' => 64,
]);
}
$tableSignRequest = $schema->getTable('libresign_sign_request');
if (!$tableSignRequest->hasColumn('signed_hash')) {
$tableSignRequest->addColumn('signed_hash', Types::STRING, [
'notnull' => false,
'length' => 64,
]);
}
return $schema;
}
}

View file

@ -274,8 +274,10 @@ class SignFileService {
->setPassword($this->password)
->sign();
}
$hash = hash('sha256', $signedFile->getContent());
$this->signRequest->setSigned(time());
$this->signRequest->setSignedHash($hash);
if ($this->signRequest->getId()) {
$this->signRequestMapper->update($this->signRequest);
} else {
@ -283,6 +285,7 @@ class SignFileService {
}
$this->libreSignFile->setSignedNodeId($signedFile->getId());
$this->libreSignFile->setSignedHash($hash);
$allSigned = $this->updateStatus();
$this->fileMapper->update($this->libreSignFile);