Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions REUSE.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ path = [
"src/types/openapi/openapi.ts",
"tests/php/Unit/Handler/mock/cert.json",
"tests/php/fixtures/cfssl/newcert-with-success.json",
"tests/php/fixtures/real_jsignpdf_level1.pdf",
"tests/php/fixtures/small_valid-signed.pdf",
"tests/php/fixtures/small_valid.pdf",
"tests/php/fixtures/pdfs/real_jsignpdf_level1.pdf",
"tests/php/fixtures/pdfs/small_valid-signed.pdf",
"tests/php/fixtures/pdfs/small_valid.pdf",
"tests/integration/composer.json",
"tests/integration/composer.lock",
"tests/integration/features/**/*.feature",
Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@
},
"autoload-dev": {
"psr-4": {
"OCP\\": "vendor/nextcloud/ocp/OCP"
"OCP\\": "vendor/nextcloud/ocp/OCP",
"OCA\\Libresign\\Tests\\Unit\\": "tests/php/Unit/",
"OCA\\Libresign\\Tests\\Fixtures\\": "tests/php/fixtures/"
}
},
"require": {
Expand Down
2 changes: 1 addition & 1 deletion lib/Controller/DevelopController.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function pdf(): FileDisplayResponse|Response {
if (!$this->isDebugMode()) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
$file = new InMemoryFile('file.pdf', file_get_contents(__DIR__ . '/../../tests/php/fixtures/small_valid.pdf'));
$file = new InMemoryFile('file.pdf', file_get_contents(__DIR__ . '/../../tests/php/fixtures/pdfs/small_valid.pdf'));
$response = new FileDisplayResponse($file);
$response->setHeaders([
'Content-Disposition' => 'inline; filename="file.pdf"',
Expand Down
41 changes: 21 additions & 20 deletions lib/Handler/SignEngine/Pkcs12Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,32 +52,23 @@ public function __construct(
private function getSignatures($resource): iterable {
rewind($resource);
$content = stream_get_contents($resource);
preg_match_all(
'/ByteRange\s*\[\s*(?<offset1>\d+)\s+(?<length1>\d+)\s+(?<offset2>\d+)\s+(?<length2>\d+)\s*\]/',
$content,
$bytes
);
if (empty($bytes['offset1']) || empty($bytes['length1']) || empty($bytes['offset2']) || empty($bytes['length2'])) {
throw new LibresignException($this->l10n->t('Unsigned file.'));
}

for ($i = 0; $i < count($bytes['offset1']); $i++) {
$offset1 = (int)$bytes['offset1'][$i];
$length1 = (int)$bytes['length1'][$i];
$offset2 = (int)$bytes['offset2'][$i];
preg_match_all('/\/Contents\s*<([0-9a-fA-F]+)>/', $content, $contents, PREG_OFFSET_CAPTURE);

$signatureStart = $offset1 + $length1 + 1;
$signatureLength = $offset2 - $signatureStart - 1;
if (empty($contents[1])) {
throw new LibresignException($this->l10n->t('Unsigned file.'));
}

rewind($resource);
$seenHexSignatures = [];
foreach ($contents[1] as $match) {
$signatureHex = $match[0];

$signature = stream_get_contents($resource, $signatureLength, $signatureStart);
if ($signature === false) {
yield null;
if (isset($seenHexSignatures[$signatureHex])) {
continue;
}
$seenHexSignatures[$signatureHex] = true;

$decodedSignature = @hex2bin($signature);
$decodedSignature = @hex2bin($signatureHex);
if ($decodedSignature === false) {
yield null;
continue;
Expand All @@ -101,7 +92,17 @@ public function getCertificateChain($resource): array {
$certificates = [];

foreach ($this->getSignatures($resource) as $signature) {
$certificates[] = $this->processSignature($resource, $signature);
if (!$signature) {
continue;
}

$result = $this->processSignature($resource, $signature);

if (empty($result['chain'])) {
continue;
}

$certificates[] = $result;
}
return $certificates;
}
Expand Down
6 changes: 3 additions & 3 deletions tests/php/Api/Controller/FileControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function testValidateWithSuccessUsingUnloggedUser():void {

$user->setEMailAddress('person@test.coop');
$file = $this->requestSignFile([
'file' => ['base64' => base64_encode(file_get_contents(__DIR__ . '/../../fixtures/small_valid.pdf'))],
'file' => ['base64' => base64_encode(file_get_contents(__DIR__ . '/../../fixtures/pdfs/small_valid.pdf'))],
'name' => 'test',
'users' => [
[
Expand Down Expand Up @@ -93,7 +93,7 @@ public function testValidateWithSuccessUsingSigner():void {

$user->setEMailAddress('person@test.coop');
$file = $this->requestSignFile([
'file' => ['base64' => base64_encode(file_get_contents(__DIR__ . '/../../fixtures/small_valid.pdf'))],
'file' => ['base64' => base64_encode(file_get_contents(__DIR__ . '/../../fixtures/pdfs/small_valid.pdf'))],
'name' => 'test',
'users' => [
[
Expand Down Expand Up @@ -149,7 +149,7 @@ public function testSendNewFile():void {
->withMethod('POST')
->withRequestBody([
'name' => 'test',
'file' => ['base64' => base64_encode(file_get_contents(__DIR__ . '/../../fixtures/small_valid.pdf'))],
'file' => ['base64' => base64_encode(file_get_contents(__DIR__ . '/../../fixtures/pdfs/small_valid.pdf'))],
]);

$this->assertRequest();
Expand Down
2 changes: 1 addition & 1 deletion tests/php/Api/Controller/FileElementControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function testPostSuccess():array {
$user = $this->createAccount('username', 'password');
$user->setEMailAddress('person@test.coop');
$file = $this->requestSignFile([
'file' => ['base64' => base64_encode(file_get_contents(__DIR__ . '/../../fixtures/small_valid.pdf'))],
'file' => ['base64' => base64_encode(file_get_contents(__DIR__ . '/../../fixtures/pdfs/small_valid.pdf'))],
'name' => 'test',
'users' => [
[
Expand Down
2 changes: 1 addition & 1 deletion tests/php/Api/Controller/IdDocsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function testPostIdDocsWithSuccess():void {
[
'type' => 'IDENTIFICATION',
'file' => [
'base64' => base64_encode(file_get_contents(__DIR__ . '/../../fixtures/small_valid.pdf'))
'base64' => base64_encode(file_get_contents(__DIR__ . '/../../fixtures/pdfs/small_valid.pdf'))
]
]
]
Expand Down
2 changes: 1 addition & 1 deletion tests/php/Api/Controller/NotifyControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function testNotifySignersWithSuccess():void {
$appConfig->setValueArray(Application::APP_ID, 'groups_request_sign', ['admin','testGroup']);
$appConfig->setValueBool(Application::APP_ID, 'notifyUnsignedUser', true);
$file = $this->requestSignFile([
'file' => ['base64' => base64_encode(file_get_contents(__DIR__ . '/../../fixtures/small_valid.pdf'))],
'file' => ['base64' => base64_encode(file_get_contents(__DIR__ . '/../../fixtures/pdfs/small_valid.pdf'))],
'name' => 'test',
'users' => [
[
Expand Down
4 changes: 2 additions & 2 deletions tests/php/Api/Controller/RequestSignatureControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function testPostRegisterWithSuccess():void {
->withRequestBody([
'name' => 'filename',
'file' => [
'base64' => base64_encode(file_get_contents(__DIR__ . '/../../fixtures/small_valid.pdf'))
'base64' => base64_encode(file_get_contents(__DIR__ . '/../../fixtures/pdfs/small_valid.pdf'))
],
'users' => [
[
Expand Down Expand Up @@ -114,7 +114,7 @@ public function testPatchRegisterWithSuccess():void {

$user->setEMailAddress('person@test.coop');
$file = $this->requestSignFile([
'file' => ['base64' => base64_encode(file_get_contents(__DIR__ . '/../../fixtures/small_valid.pdf'))],
'file' => ['base64' => base64_encode(file_get_contents(__DIR__ . '/../../fixtures/pdfs/small_valid.pdf'))],
'name' => 'test',
'users' => [
[
Expand Down
12 changes: 6 additions & 6 deletions tests/php/Api/Controller/SignFileControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function testSignUsingFileIdWithAlreadySignedFile():void {

$user->setEMailAddress('person@test.coop');
$file = $this->requestSignFile([
'file' => ['base64' => base64_encode(file_get_contents(__DIR__ . '/../../fixtures/small_valid.pdf'))],
'file' => ['base64' => base64_encode(file_get_contents(__DIR__ . '/../../fixtures/pdfs/small_valid.pdf'))],
'name' => 'test',
'users' => [
[
Expand Down Expand Up @@ -122,7 +122,7 @@ public function testSignUsingFileIdWithNotFoundFile():void {

$user->setEMailAddress('person@test.coop');
$file = $this->requestSignFile([
'file' => ['base64' => base64_encode(file_get_contents(__DIR__ . '/../../fixtures/small_valid.pdf'))],
'file' => ['base64' => base64_encode(file_get_contents(__DIR__ . '/../../fixtures/pdfs/small_valid.pdf'))],
'name' => 'test',
'users' => [
[
Expand Down Expand Up @@ -166,7 +166,7 @@ public function testSignUsingUuidWithEmptyToken():void {

$user->setEMailAddress('person@test.coop');
$file = $this->requestSignFile([
'file' => ['base64' => base64_encode(file_get_contents(__DIR__ . '/../../fixtures/small_valid.pdf'))],
'file' => ['base64' => base64_encode(file_get_contents(__DIR__ . '/../../fixtures/pdfs/small_valid.pdf'))],
'name' => 'test',
'users' => [
[
Expand Down Expand Up @@ -203,7 +203,7 @@ public function testSignWithCertificateButEmptyPassword():void {

$user->setEMailAddress('person@test.coop');
$file = $this->requestSignFile([
'file' => ['base64' => base64_encode(file_get_contents(__DIR__ . '/../../fixtures/small_valid.pdf'))],
'file' => ['base64' => base64_encode(file_get_contents(__DIR__ . '/../../fixtures/pdfs/small_valid.pdf'))],
'name' => 'test',
'users' => [
[
Expand Down Expand Up @@ -259,7 +259,7 @@ public function testAccountSignatureEndpointWithFailure():void {
public function testDeleteSignFileIdSignRequestIdWithSuccess():void {
$user = $this->createAccount('allowrequestsign', 'password', 'testGroup');
$file = $this->requestSignFile([
'file' => ['base64' => base64_encode(file_get_contents(__DIR__ . '/../../fixtures/small_valid.pdf'))],
'file' => ['base64' => base64_encode(file_get_contents(__DIR__ . '/../../fixtures/pdfs/small_valid.pdf'))],
'name' => 'test',
'users' => [
[
Expand Down Expand Up @@ -307,7 +307,7 @@ public function testDeleteSignFileIdSignRequestIdWithError():void {
public function testDeleteUsingSignFileIdWithSuccess():void {
$user = $this->createAccount('allowrequestsign', 'password', 'testGroup');
$file = $this->requestSignFile([
'file' => ['base64' => base64_encode(file_get_contents(__DIR__ . '/../../fixtures/small_valid.pdf'))],
'file' => ['base64' => base64_encode(file_get_contents(__DIR__ . '/../../fixtures/pdfs/small_valid.pdf'))],
'name' => 'test',
'users' => [
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function testLoadFileUuidWhenFileNotFound(): void {
$user = $this->createAccount('username', 'password');
$user->setEMailAddress('person@test.coop');
$file = $this->requestSignFile([
'file' => ['base64' => base64_encode(file_get_contents(__DIR__ . '/../../fixtures/small_valid.pdf'))],
'file' => ['base64' => base64_encode(file_get_contents(__DIR__ . '/../../fixtures/pdfs/small_valid.pdf'))],
'name' => 'test',
'users' => [
[
Expand Down
Loading
Loading