Merge pull request #5348 from LibreSign/chore/added-log-to-track-mcfly

chore: add log to track McFly
This commit is contained in:
Vitor Mattos 2025-08-22 21:02:58 -03:00 committed by GitHub
commit 31da4499ea
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 22 additions and 2 deletions

View file

@ -20,6 +20,7 @@ use OCP\IAppConfig;
use OCP\IL10N;
use OCP\ITempManager;
use phpseclib3\File\ASN1;
use Psr\Log\LoggerInterface;
class Pkcs12Handler extends SignEngineHandler {
use OrderCertificatesTrait;
@ -37,8 +38,9 @@ class Pkcs12Handler extends SignEngineHandler {
private IL10N $l10n,
private FooterHandler $footerHandler,
private ITempManager $tempManager,
private LoggerInterface $logger,
) {
parent::__construct($l10n, $folderService);
parent::__construct($l10n, $folderService, $logger);
}
/**

View file

@ -22,6 +22,7 @@ use OCP\Files\InvalidPathException;
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
use OCP\IL10N;
use Psr\Log\LoggerInterface;
abstract class SignEngineHandler implements ISignEngineHandler {
private File $inputFile;
@ -35,6 +36,7 @@ abstract class SignEngineHandler implements ISignEngineHandler {
public function __construct(
private IL10N $l10n,
private readonly FolderService $folderService,
private LoggerInterface $logger,
) {
}
@ -217,7 +219,9 @@ abstract class SignEngineHandler implements ISignEngineHandler {
}
// Prevent accepting certificates with future signing dates (possible clock issues)
if ($last['signingTime'] > new \DateTime()) {
$dateTime = new \DateTime();
if ($last['signingTime'] > $dateTime) {
$this->logger->error('We found Marty McFly', ['last_signature' => $last['signingTime'], 'current_date_time' => $dateTime]);
throw new \UnexpectedValueException('Invalid signingTime in certificate chain. We found Marty McFly');
}

View file

@ -19,6 +19,7 @@ use OCP\ITempManager;
use OCP\L10N\IFactory as IL10NFactory;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
final class Pkcs12HandlerTest extends \OCA\Libresign\Tests\Unit\TestCase {
protected Pkcs12Handler $pkcs12Handler;
@ -27,6 +28,7 @@ final class Pkcs12HandlerTest extends \OCA\Libresign\Tests\Unit\TestCase {
private IL10N $l10n;
private FooterHandler&MockObject $footerHandler;
private ITempManager $tempManager;
private LoggerInterface&MockObject $logger;
private CertificateEngineFactory&MockObject $certificateEngineFactory;
public function setUp(): void {
@ -36,6 +38,7 @@ final class Pkcs12HandlerTest extends \OCA\Libresign\Tests\Unit\TestCase {
$this->l10n = \OCP\Server::get(IL10NFactory::class)->get(Application::APP_ID);
$this->footerHandler = $this->createMock(FooterHandler::class);
$this->tempManager = \OCP\Server::get(ITempManager::class);
$this->logger = $this->createMock(LoggerInterface::class);
}
private function getHandler(array $methods = []): Pkcs12Handler|MockObject {
@ -48,6 +51,7 @@ final class Pkcs12HandlerTest extends \OCA\Libresign\Tests\Unit\TestCase {
$this->l10n,
$this->footerHandler,
$this->tempManager,
$this->logger,
])
->onlyMethods($methods)
->getMock();
@ -59,6 +63,7 @@ final class Pkcs12HandlerTest extends \OCA\Libresign\Tests\Unit\TestCase {
$this->l10n,
$this->footerHandler,
$this->tempManager,
$this->logger,
);
}

View file

@ -11,14 +11,17 @@ use OCA\Libresign\Service\FolderService;
use OCP\IL10N;
use OCP\L10N\IFactory as IL10NFactory;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
final class Pkcs7HandlerTest extends \OCA\Libresign\Tests\Unit\TestCase {
private IL10N $l10n;
private FolderService&MockObject $folderService;
private LoggerInterface&MockObject $logger;
public function setUp(): void {
parent::setUp();
$this->l10n = \OCP\Server::get(IL10NFactory::class)->get(\OCA\Libresign\AppInfo\Application::APP_ID);
$this->folderService = $this->createMock(\OCA\Libresign\Service\FolderService::class);
$this->logger = $this->createMock(LoggerInterface::class);
}
protected function getInstance(array $methods = []): Pkcs7Handler|MockObject {
@ -26,12 +29,14 @@ final class Pkcs7HandlerTest extends \OCA\Libresign\Tests\Unit\TestCase {
return new Pkcs7Handler(
$this->l10n,
$this->folderService,
$this->logger,
);
}
return $this->getMockBuilder(Pkcs7Handler::class)
->setConstructorArgs([
$this->l10n,
$this->folderService,
$this->logger,
])
->onlyMethods($methods)
->getMock();

View file

@ -23,6 +23,7 @@ use OCP\IUserSession;
use OCP\L10N\IFactory as IL10NFactory;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
final class PasswordTest extends \OCA\Libresign\Tests\Unit\TestCase {
private IdentifyService&MockObject $identifyService;
@ -34,6 +35,7 @@ final class PasswordTest extends \OCA\Libresign\Tests\Unit\TestCase {
private IL10N $l10n;
private FooterHandler&MockObject $footerHandler;
private ITempManager $tempManager;
private LoggerInterface&MockObject $logger;
public function setUp(): void {
$this->identifyService = $this->createMock(IdentifyService::class);
@ -44,6 +46,7 @@ final class PasswordTest extends \OCA\Libresign\Tests\Unit\TestCase {
$this->footerHandler = $this->createMock(FooterHandler::class);
$this->tempManager = \OCP\Server::get(ITempManager::class);
$this->userSession = $this->createMock(IUserSession::class);
$this->logger = $this->createMock(LoggerInterface::class);
$this->pkcs12Handler = $this->getPkcs12Instance();
}
@ -67,6 +70,7 @@ final class PasswordTest extends \OCA\Libresign\Tests\Unit\TestCase {
$this->l10n,
$this->footerHandler,
$this->tempManager,
$this->logger,
])
->onlyMethods($methods)
->getMock();