libresign/lib/Handler/Pkcs7Handler.php
Vitor Mattos 45cd3c374d
chore: Add SPDX header
Signed-off-by: Vitor Mattos <vitor@php.rio>
2024-05-14 12:32:04 -03:00

46 lines
1,009 B
PHP

<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2020-2024 LibreCode coop and contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Libresign\Handler;
use OCP\Files\File;
use OCP\Files\Node;
/**
* @codeCoverageIgnore
*/
class Pkcs7Handler extends SignEngineHandler {
/**
* @psalm-suppress MixedReturnStatement
*
* @param Node $fileToSign
* @param Node $certificate
* @param string $passphrase
*/
public function sign(): File {
$p7sFile = $this->getP7sFile();
openssl_pkcs12_read($this->getCertificate(), $certificateData, $this->getPassword());
openssl_pkcs7_sign(
$this->getInputFile()->getInternalPath(),
$p7sFile->getInternalPath(),
$certificateData['cert'],
$certificateData['pkey'],
[],
PKCS7_DETACHED
);
return $p7sFile;
}
public function getP7sFile(): File {
$newName = $this->getInputFile()->getName() . '.p7s';
$p7sFile = $this->getInputFile()
->getParent()
->newFile($newName);
return $p7sFile;
}
}