Skip to content

Commit 0de3b7f

Browse files
chore: add log to track McFly
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent cd097ff commit 0de3b7f

File tree

5 files changed

+22
-2
lines changed

5 files changed

+22
-2
lines changed

lib/Handler/SignEngine/Pkcs12Handler.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use OCP\IL10N;
2121
use OCP\ITempManager;
2222
use phpseclib3\File\ASN1;
23+
use Psr\Log\LoggerInterface;
2324

2425
class Pkcs12Handler extends SignEngineHandler {
2526
use OrderCertificatesTrait;
@@ -37,8 +38,9 @@ public function __construct(
3738
private IL10N $l10n,
3839
private FooterHandler $footerHandler,
3940
private ITempManager $tempManager,
41+
private LoggerInterface $logger,
4042
) {
41-
parent::__construct($l10n, $folderService);
43+
parent::__construct($l10n, $folderService, $logger);
4244
}
4345

4446
/**

lib/Handler/SignEngine/SignEngineHandler.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use OCP\Files\NotFoundException;
2323
use OCP\Files\NotPermittedException;
2424
use OCP\IL10N;
25+
use Psr\Log\LoggerInterface;
2526

2627
abstract class SignEngineHandler implements ISignEngineHandler {
2728
private File $inputFile;
@@ -35,6 +36,7 @@ abstract class SignEngineHandler implements ISignEngineHandler {
3536
public function __construct(
3637
private IL10N $l10n,
3738
private readonly FolderService $folderService,
39+
private LoggerInterface $logger,
3840
) {
3941
}
4042

@@ -217,7 +219,9 @@ public function getLastSignedDate(): \DateTime {
217219
}
218220

219221
// Prevent accepting certificates with future signing dates (possible clock issues)
220-
if ($last['signingTime'] > new \DateTime()) {
222+
$dateTime = new \DateTime();
223+
if ($last['signingTime'] > $dateTime) {
224+
$this->logger->error('We found Marty McFly', ['last_signature' => $last['signingTime'], 'current_date_time' => $dateTime]);
221225
throw new \UnexpectedValueException('Invalid signingTime in certificate chain. We found Marty McFly');
222226
}
223227

tests/php/Unit/Handler/SignEngine/Pkcs12HandlerTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use OCP\L10N\IFactory as IL10NFactory;
2020
use PHPUnit\Framework\Attributes\DataProvider;
2121
use PHPUnit\Framework\MockObject\MockObject;
22+
use Psr\Log\LoggerInterface;
2223

2324
final class Pkcs12HandlerTest extends \OCA\Libresign\Tests\Unit\TestCase {
2425
protected Pkcs12Handler $pkcs12Handler;
@@ -27,6 +28,7 @@ final class Pkcs12HandlerTest extends \OCA\Libresign\Tests\Unit\TestCase {
2728
private IL10N $l10n;
2829
private FooterHandler&MockObject $footerHandler;
2930
private ITempManager $tempManager;
31+
private LoggerInterface&MockObject $logger;
3032
private CertificateEngineFactory&MockObject $certificateEngineFactory;
3133

3234
public function setUp(): void {
@@ -36,6 +38,7 @@ public function setUp(): void {
3638
$this->l10n = \OCP\Server::get(IL10NFactory::class)->get(Application::APP_ID);
3739
$this->footerHandler = $this->createMock(FooterHandler::class);
3840
$this->tempManager = \OCP\Server::get(ITempManager::class);
41+
$this->logger = $this->createMock(LoggerInterface::class);
3942
}
4043

4144
private function getHandler(array $methods = []): Pkcs12Handler|MockObject {
@@ -48,6 +51,7 @@ private function getHandler(array $methods = []): Pkcs12Handler|MockObject {
4851
$this->l10n,
4952
$this->footerHandler,
5053
$this->tempManager,
54+
$this->logger,
5155
])
5256
->onlyMethods($methods)
5357
->getMock();
@@ -59,6 +63,7 @@ private function getHandler(array $methods = []): Pkcs12Handler|MockObject {
5963
$this->l10n,
6064
$this->footerHandler,
6165
$this->tempManager,
66+
$this->logger,
6267
);
6368
}
6469

tests/php/Unit/Handler/SignEngine/Pkcs7HandlerTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,32 @@
1111
use OCP\IL10N;
1212
use OCP\L10N\IFactory as IL10NFactory;
1313
use PHPUnit\Framework\MockObject\MockObject;
14+
use Psr\Log\LoggerInterface;
1415

1516
final class Pkcs7HandlerTest extends \OCA\Libresign\Tests\Unit\TestCase {
1617
private IL10N $l10n;
1718
private FolderService&MockObject $folderService;
19+
private LoggerInterface&MockObject $logger;
1820
public function setUp(): void {
1921
parent::setUp();
2022
$this->l10n = \OCP\Server::get(IL10NFactory::class)->get(\OCA\Libresign\AppInfo\Application::APP_ID);
2123
$this->folderService = $this->createMock(\OCA\Libresign\Service\FolderService::class);
24+
$this->logger = $this->createMock(LoggerInterface::class);
2225
}
2326

2427
protected function getInstance(array $methods = []): Pkcs7Handler|MockObject {
2528
if (empty($methods)) {
2629
return new Pkcs7Handler(
2730
$this->l10n,
2831
$this->folderService,
32+
$this->logger,
2933
);
3034
}
3135
return $this->getMockBuilder(Pkcs7Handler::class)
3236
->setConstructorArgs([
3337
$this->l10n,
3438
$this->folderService,
39+
$this->logger,
3540
])
3641
->onlyMethods($methods)
3742
->getMock();

tests/php/Unit/Service/IdentifyMethod/PasswordTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use OCP\L10N\IFactory as IL10NFactory;
2424
use PHPUnit\Framework\Attributes\DataProvider;
2525
use PHPUnit\Framework\MockObject\MockObject;
26+
use Psr\Log\LoggerInterface;
2627

2728
final class PasswordTest extends \OCA\Libresign\Tests\Unit\TestCase {
2829
private IdentifyService&MockObject $identifyService;
@@ -34,6 +35,7 @@ final class PasswordTest extends \OCA\Libresign\Tests\Unit\TestCase {
3435
private IL10N $l10n;
3536
private FooterHandler&MockObject $footerHandler;
3637
private ITempManager $tempManager;
38+
private LoggerInterface&MockObject $logger;
3739

3840
public function setUp(): void {
3941
$this->identifyService = $this->createMock(IdentifyService::class);
@@ -44,6 +46,7 @@ public function setUp(): void {
4446
$this->footerHandler = $this->createMock(FooterHandler::class);
4547
$this->tempManager = \OCP\Server::get(ITempManager::class);
4648
$this->userSession = $this->createMock(IUserSession::class);
49+
$this->logger = $this->createMock(LoggerInterface::class);
4750
$this->pkcs12Handler = $this->getPkcs12Instance();
4851
}
4952

@@ -67,6 +70,7 @@ private function getPkcs12Instance(array $methods = []) {
6770
$this->l10n,
6871
$this->footerHandler,
6972
$this->tempManager,
73+
$this->logger,
7074
])
7175
->onlyMethods($methods)
7276
->getMock();

0 commit comments

Comments
 (0)