Skip to content
Draft
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
11 changes: 7 additions & 4 deletions lib/Controller/AccountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
* @psalm-import-type LibresignConfigValueResponse from \OCA\Libresign\ResponseDefinitions
* @psalm-import-type LibresignUserConfigValue from \OCA\Libresign\ResponseDefinitions
* @psalm-import-type LibresignCreateToSignResponse from \OCA\Libresign\ResponseDefinitions
* @psalm-import-type LibresignFile from \OCA\Libresign\ResponseDefinitions
* @psalm-import-type LibresignIdDocFile from \OCA\Libresign\ResponseDefinitions
* @psalm-import-type LibresignMessageResponse from \OCA\Libresign\ResponseDefinitions
* @psalm-import-type LibresignPagination from \OCA\Libresign\ResponseDefinitions
*/
Expand Down Expand Up @@ -142,10 +142,11 @@ public function createToSign(string $uuid, string $email, string $password, ?str
*
* @param string $signPassword The password that will be used to encrypt the certificate file
*
* @return DataResponse<Http::STATUS_OK, array{}, array{}>|DataResponse<Http::STATUS_UNAUTHORIZED, LibresignMessageResponse, array{}>
* @return DataResponse<Http::STATUS_OK, array{}, array{}>|DataResponse<Http::STATUS_UNPROCESSABLE_ENTITY|Http::STATUS_INTERNAL_SERVER_ERROR, LibresignMessageResponse, array{}>
*
* 200: Settings saved
* 401: Failure to create PFX file
* 422: Invalid data to create the PFX file
* 500: Failure to create PFX file
*/
#[NoAdminRequired]
#[NoCSRFRequired]
Expand Down Expand Up @@ -185,7 +186,9 @@ public function signatureGenerate(
[
'message' => $exception->getMessage()
],
Http::STATUS_UNAUTHORIZED
$exception instanceof LibresignException || $exception instanceof InvalidArgumentException
? Http::STATUS_UNPROCESSABLE_ENTITY
: Http::STATUS_INTERNAL_SERVER_ERROR,
);
}
}
Expand Down
33 changes: 22 additions & 11 deletions lib/Controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@

namespace OCA\Libresign\Controller;

use InvalidArgumentException;
use OCA\Libresign\AppInfo\Application;
use OCA\Libresign\Controller\Traits\UploadValidator;
use OCA\Libresign\Exception\LibresignException;
use OCA\Libresign\Handler\CertificateEngine\CertificateEngineFactory;
use OCA\Libresign\Handler\CertificateEngine\IEngineHandler;
use OCA\Libresign\Service\ActiveSigningsService;
Expand Down Expand Up @@ -83,10 +85,11 @@ public function __construct(
* @param array{commonName: string, names: array<string, array{value:string|list<string>}>} $rootCert fields of root certificate
* @param string $cfsslUri URI of CFSSL API
* @param string $configPath Path of config files of CFSSL
* @return DataResponse<Http::STATUS_OK, LibresignEngineHandlerResponse, array{}>|DataResponse<Http::STATUS_UNAUTHORIZED, LibresignMessageResponse, array{}>
* @return DataResponse<Http::STATUS_OK, LibresignEngineHandlerResponse, array{}>|DataResponse<Http::STATUS_UNPROCESSABLE_ENTITY|Http::STATUS_INTERNAL_SERVER_ERROR, LibresignMessageResponse, array{}>
*
* 200: OK
* 401: Account not found
* 422: Invalid certificate data
* 500: Failure to generate the certificate
*/
#[NoCSRFRequired]
#[OpenAPI(tags: ['certificates'])]
Expand All @@ -110,7 +113,9 @@ public function generateCertificateCfssl(
[
'message' => $exception->getMessage()
],
Http::STATUS_UNAUTHORIZED
$exception instanceof LibresignException || $exception instanceof InvalidArgumentException
? Http::STATUS_UNPROCESSABLE_ENTITY
: Http::STATUS_INTERNAL_SERVER_ERROR,
);
}
}
Expand All @@ -120,10 +125,11 @@ public function generateCertificateCfssl(
*
* @param array{commonName: string, names: array<string, array{value:string|list<string>}>} $rootCert fields of root certificate
* @param string $configPath Path of config files of CFSSL
* @return DataResponse<Http::STATUS_OK, LibresignEngineHandlerResponse, array{}>|DataResponse<Http::STATUS_UNAUTHORIZED, LibresignMessageResponse, array{}>
* @return DataResponse<Http::STATUS_OK, LibresignEngineHandlerResponse, array{}>|DataResponse<Http::STATUS_UNPROCESSABLE_ENTITY|Http::STATUS_INTERNAL_SERVER_ERROR, LibresignMessageResponse, array{}>
*
* 200: OK
* 401: Account not found
* 422: Invalid certificate data
* 500: Failure to generate the certificate
*/
#[NoCSRFRequired]
#[OpenAPI(tags: ['certificates'])]
Expand All @@ -145,7 +151,9 @@ public function generateCertificateOpenSsl(
[
'message' => $exception->getMessage()
],
Http::STATUS_UNAUTHORIZED
$exception instanceof LibresignException || $exception instanceof InvalidArgumentException
? Http::STATUS_UNPROCESSABLE_ENTITY
: Http::STATUS_INTERNAL_SERVER_ERROR,
);
}
}
Expand Down Expand Up @@ -336,7 +344,7 @@ public function signatureBackgroundSave(): DataResponse {
/**
* Get custom background image
*
* @return FileDisplayResponse<Http::STATUS_OK, array{}>
* @return FileDisplayResponse<Http::STATUS_OK, array{Content-Disposition: 'attachment; filename="background.png"', Content-Type: 'image/png'}>
*
* 200: Image returned
*/
Expand All @@ -346,14 +354,17 @@ public function signatureBackgroundSave(): DataResponse {
public function signatureBackgroundGet(): FileDisplayResponse {
$file = $this->signatureBackgroundService->getImage();

$response = new FileDisplayResponse($file);
$response = new FileDisplayResponse($file, Http::STATUS_OK, [
'Content-Disposition' => 'attachment; filename="background.png"',
'Content-Type' => 'image/png',
]);
// The constructor always sets Content-Disposition to "inline" using the
// file name, so the attachment disposition must be set again afterwards.
$response->addHeader('Content-Disposition', 'attachment; filename="background.png"');
$csp = new ContentSecurityPolicy();
$csp->allowInlineStyle();
$response->setContentSecurityPolicy($csp);
$response->cacheFor(3600);
$response->addHeader('Content-Type', 'image/png');
$response->addHeader('Content-Disposition', 'attachment; filename="background.png"');
$response->addHeader('Content-Type', 'image/png');
return $response;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Controller/CrlController.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __construct(
* @param string $instanceId Instance identifier
* @param int $generation Generation identifier
* @param string $engineType Engine type identifier
* @return DataDownloadResponse<Http::STATUS_OK, string, array{}>|DataResponse<Http::STATUS_INTERNAL_SERVER_ERROR, LibresignCrlErrorResponse, array{}>
* @return DataDownloadResponse<Http::STATUS_OK, 'application/pkix-crl', array{}>|DataResponse<Http::STATUS_INTERNAL_SERVER_ERROR, LibresignCrlErrorResponse, array{}>
*
* 200: CRL retrieved successfully in DER format
* 500: Failed to generate CRL
Expand Down
14 changes: 8 additions & 6 deletions lib/Controller/FileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
use Psr\Log\LoggerInterface;

/**
* @psalm-import-type LibresignFile from \OCA\Libresign\ResponseDefinitions
* @psalm-import-type LibresignIdDocFile from \OCA\Libresign\ResponseDefinitions
* @psalm-import-type LibresignDetailedFile from \OCA\Libresign\ResponseDefinitions
* @psalm-import-type LibresignDetailedFileResponse from \OCA\Libresign\ResponseDefinitions
* @psalm-import-type LibresignActionErrorResponse from \OCA\Libresign\ResponseDefinitions
Expand Down Expand Up @@ -585,7 +585,7 @@ private function getMimeFallbackResponse(string $mimeType): ?\OCP\AppFramework\H
* @param string $name The name of file to sign
* @param LibresignFolderSettings $settings Settings to define how and where the file should be stored
* @param list<LibresignNewFile> $files Multiple files to create an envelope (optional, use either file or files)
* @return DataResponse<Http::STATUS_OK, LibresignDetailedFileResponse, array{}>|DataResponse<Http::STATUS_UNPROCESSABLE_ENTITY, LibresignMessageResponse, array{}>
* @return DataResponse<Http::STATUS_OK, LibresignDetailedFileResponse, array{}>|DataResponse<Http::STATUS_UNPROCESSABLE_ENTITY, LibresignMessageResponse|LibresignActionErrorResponse, array{}>
*
* 200: OK
* 422: Failed to save data
Expand Down Expand Up @@ -630,7 +630,7 @@ public function save(
* Multipart clients can send optional expectedFilesCount to reject incomplete batches.
*
* @param string $uuid The UUID of the envelope
* @return DataResponse<Http::STATUS_OK, LibresignDetailedFileResponse, array{}>|DataResponse<Http::STATUS_BAD_REQUEST|Http::STATUS_NOT_FOUND|Http::STATUS_UNPROCESSABLE_ENTITY, LibresignMessageResponse, array{}>
* @return DataResponse<Http::STATUS_OK, LibresignDetailedFileResponse, array{}>|DataResponse<Http::STATUS_BAD_REQUEST|Http::STATUS_NOT_FOUND, LibresignMessageResponse, array{}>|DataResponse<Http::STATUS_UNPROCESSABLE_ENTITY, LibresignMessageResponse|LibresignActionErrorResponse, array{}>
*
* 200: Files added successfully
* 400: Invalid request
Expand Down Expand Up @@ -887,11 +887,11 @@ private function extractFileName(array $fileData): string {
*
* @param integer $fileId LibreSign file ID
* @param boolean $deleteFile Whether to delete the physical file from Nextcloud (default: true)
* @return DataResponse<Http::STATUS_OK, LibresignMessageResponse, array{}>|DataResponse<Http::STATUS_UNAUTHORIZED, LibresignMessageResponse, array{}>|DataResponse<Http::STATUS_UNPROCESSABLE_ENTITY, LibresignActionErrorResponse, array{}>
* @return DataResponse<Http::STATUS_OK, LibresignMessageResponse, array{}>|DataResponse<Http::STATUS_UNPROCESSABLE_ENTITY, LibresignMessageResponse|LibresignActionErrorResponse, array{}>|DataResponse<Http::STATUS_INTERNAL_SERVER_ERROR, LibresignMessageResponse, array{}>
*
* 200: OK
* 401: Failed
* 422: Failed
* 500: Unexpected failure
*/
#[NoAdminRequired]
#[NoCSRFRequired]
Expand All @@ -913,7 +913,9 @@ public function deleteFile(int $fileId, bool $deleteFile = true): DataResponse {
[
'message' => $th->getMessage(),
],
Http::STATUS_UNAUTHORIZED
$th instanceof LibresignException
? Http::STATUS_UNPROCESSABLE_ENTITY
: Http::STATUS_INTERNAL_SERVER_ERROR,
);
}
return new DataResponse(
Expand Down
2 changes: 1 addition & 1 deletion lib/Controller/IdDocsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
use Psr\Log\LoggerInterface;

/**
* @psalm-import-type LibresignFile from \OCA\Libresign\ResponseDefinitions
* @psalm-import-type LibresignIdDocFile from \OCA\Libresign\ResponseDefinitions
* @psalm-import-type LibresignIdDocs from \OCA\Libresign\ResponseDefinitions
* @psalm-import-type LibresignIdDocsApprovalListResponse from \OCA\Libresign\ResponseDefinitions
* @psalm-import-type LibresignIdDocsListResponse from \OCA\Libresign\ResponseDefinitions
Expand Down
4 changes: 3 additions & 1 deletion lib/Controller/IdentifyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use OCP\IRequest;

/**
* @psalm-import-type LibresignActionErrorResponse from \OCA\Libresign\ResponseDefinitions
* @psalm-import-type LibresignIdentifyAccount from \OCA\Libresign\ResponseDefinitions
* @psalm-import-type LibresignIdentifyAccountsResponse from \OCA\Libresign\ResponseDefinitions
*/
Expand Down Expand Up @@ -59,9 +60,10 @@ public function __construct(
* @param string $method filter by method (email, account, sms, signal, telegram, whatsapp, whatsappbusiness, xmpp)
* @param int $page the number of page to return. Default: 1
* @param int $limit Total of elements to return. Default: 25
* @return DataResponse<Http::STATUS_OK, LibresignIdentifyAccountsResponse, array{}>
* @return DataResponse<Http::STATUS_OK, LibresignIdentifyAccountsResponse, array{}>|DataResponse<Http::STATUS_UNPROCESSABLE_ENTITY, LibresignActionErrorResponse, array{}>
*
* 200: Certificate saved with success
* 422: User is not allowed to request signatures
*/
#[NoAdminRequired]
#[RequireManager]
Expand Down
15 changes: 7 additions & 8 deletions lib/Controller/RequestSignatureController.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,9 @@ public function updateSignatureRequest(
*
* @param integer $fileId LibreSign file ID
* @param integer $signRequestId The sign request id
* @return DataResponse<Http::STATUS_OK, LibresignMessageResponse, array{}>|DataResponse<Http::STATUS_UNAUTHORIZED, LibresignMessageResponse, array{}>|DataResponse<Http::STATUS_UNPROCESSABLE_ENTITY, LibresignActionErrorResponse, array{}>
* @return DataResponse<Http::STATUS_OK, LibresignMessageResponse, array{}>|DataResponse<Http::STATUS_UNPROCESSABLE_ENTITY, LibresignMessageResponse|LibresignActionErrorResponse, array{}>
*
* 200: OK
* 401: Failed
* 422: Failed
*/
#[NoAdminRequired]
Expand All @@ -238,9 +237,7 @@ public function removeSigner(int $fileId, int $signRequestId): DataResponse {
} catch (LibresignException $e) {
return new DataResponse(
['message' => $e->getMessage()],
$e->getCode() === Http::STATUS_UNPROCESSABLE_ENTITY
? Http::STATUS_UNPROCESSABLE_ENTITY
: Http::STATUS_UNAUTHORIZED,
Http::STATUS_UNPROCESSABLE_ENTITY,
);
}
return new DataResponse(
Expand All @@ -258,11 +255,11 @@ public function removeSigner(int $fileId, int $signRequestId): DataResponse {
* You can only request exclusion as any sign
*
* @param integer $fileId LibreSign file ID
* @return DataResponse<Http::STATUS_OK, LibresignMessageResponse, array{}>|DataResponse<Http::STATUS_UNAUTHORIZED, LibresignMessageResponse, array{}>|DataResponse<Http::STATUS_UNPROCESSABLE_ENTITY, LibresignActionErrorResponse, array{}>
* @return DataResponse<Http::STATUS_OK, LibresignMessageResponse, array{}>|DataResponse<Http::STATUS_UNPROCESSABLE_ENTITY, LibresignMessageResponse|LibresignActionErrorResponse, array{}>|DataResponse<Http::STATUS_INTERNAL_SERVER_ERROR, LibresignMessageResponse, array{}>
*
* 200: OK
* 401: Failed
* 422: Failed
* 500: Unexpected failure
*/
#[NoAdminRequired]
#[NoCSRFRequired]
Expand All @@ -284,7 +281,9 @@ public function deleteSignatureRequest(int $fileId): DataResponse {
[
'message' => $th->getMessage(),
],
Http::STATUS_UNAUTHORIZED
$th instanceof LibresignException
? Http::STATUS_UNPROCESSABLE_ENTITY
: Http::STATUS_INTERNAL_SERVER_ERROR,
);
}
return new DataResponse(
Expand Down
12 changes: 6 additions & 6 deletions lib/ResponseDefinitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@
* name: string,
* status: int,
* statusText: string,
* nodeId: int,
* nodeId: ?int,
* totalPages?: non-negative-int,
* size: non-negative-int,
* pdfVersion?: string,
Expand All @@ -671,7 +671,7 @@
* name: string,
* status: 0|1|2|3|4|6,
* statusText: string,
* nodeId: non-negative-int,
* nodeId: non-negative-int|null,
* nodeType: 'file'|'envelope',
* signatureFlow: 'none'|'parallel'|'ordered_numeric',
* policySnapshotFrozen?: bool,
Expand Down Expand Up @@ -778,7 +778,7 @@
* files: list<LibresignFileListItem>,
* filesCount: int<0, max>,
* id: int,
* nodeId: int,
* nodeId: ?int,
* uuid: string,
* name: non-falsy-string,
* status: int,
Expand All @@ -805,7 +805,7 @@
*
* Account, elements, and ID document contracts
*
* @psalm-type LibresignFile = array{
* @psalm-type LibresignIdDocFile = array{
* account: array{
* userId: string,
* displayName: string,
Expand Down Expand Up @@ -882,11 +882,11 @@
* }
* @psalm-type LibresignIdDocsListResponse = array{
* pagination: LibresignPagination,
* data: list<LibresignFile>,
* data: list<LibresignIdDocFile>,
* }
* @psalm-type LibresignIdDocsApprovalListResponse = array{
* pagination: LibresignPagination,
* data: list<LibresignFile>,
* data: list<LibresignIdDocFile>,
* }
* @psalm-type LibresignCreateToSignPdfReference = array{
* url: string,
Expand Down
Loading
Loading