|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | +/** |
| 5 | + * SPDX-FileCopyrightText: 2026 LibreCode coop and contributors |
| 6 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 7 | + */ |
| 8 | + |
| 9 | +namespace OCA\Libresign\SetupCheck; |
| 10 | + |
| 11 | +use OCA\Libresign\Service\Install\SignSetupService; |
| 12 | +use OCP\IURLGenerator; |
| 13 | +use OCP\App\IAppManager; |
| 14 | +use Psr\Log\LoggerInterface; |
| 15 | +use OCP\IL10N; |
| 16 | + |
| 17 | +trait SetupCheckUtils |
| 18 | +{ |
| 19 | + private SignSetupService $signSetupService; |
| 20 | + private IURLGenerator $urlGenerator; |
| 21 | + private IAppManager $appManager; |
| 22 | + private LoggerInterface $logger; |
| 23 | + |
| 24 | + private function verifyResourceIntegrity(string $resource, bool $debugEnabled): array |
| 25 | + { |
| 26 | + $this->signSetupService->willUseLocalCert($debugEnabled); |
| 27 | + $result = $this->signSetupService->verify(php_uname('m'), $resource); |
| 28 | + if (count($result) === 1 && $debugEnabled) { |
| 29 | + if (isset($result['SIGNATURE_DATA_NOT_FOUND']) || isset($result['EMPTY_SIGNATURE_DATA'])) { |
| 30 | + return []; |
| 31 | + } |
| 32 | + } |
| 33 | + return $result; |
| 34 | + } |
| 35 | + |
| 36 | + private function getErrorAndTipFromVerify(array $result, string $resource, bool $debugEnabled, IL10N $l10n): array |
| 37 | + { |
| 38 | + if (count($result) === 1 && !$debugEnabled) { |
| 39 | + if (isset($result['SIGNATURE_DATA_NOT_FOUND'])) { |
| 40 | + return [ |
| 41 | + $l10n->t('Signature data not found.'), |
| 42 | + $l10n->t("Sounds that you are running from source code of LibreSign.\nEnable debug mode by: occ config:system:set debug --value true --type boolean"), |
| 43 | + ]; |
| 44 | + } |
| 45 | + if (isset($result['EMPTY_SIGNATURE_DATA'])) { |
| 46 | + return [ |
| 47 | + $l10n->t('Your signature data is empty.'), |
| 48 | + $l10n->t("Sounds that you are running from source code of LibreSign.\nEnable debug mode by: occ config:system:set debug --value true --type boolean"), |
| 49 | + ]; |
| 50 | + } |
| 51 | + } |
| 52 | + if (isset($result['HASH_FILE_ERROR'])) { |
| 53 | + if ($debugEnabled) { |
| 54 | + return [ |
| 55 | + $l10n->t('Invalid hash of binaries files.'), |
| 56 | + $l10n->t('Debug mode is enabled at your config.php and your LibreSign app was signed using a production signature. If you are not working at development of LibreSign, disable your debug mode or run the command: occ libresign install --%s --use-local-cert', [$resource]), |
| 57 | + ]; |
| 58 | + } |
| 59 | + } |
| 60 | + $this->logger->error('Invalid hash of binaries files', ['result' => $result]); |
| 61 | + if ($this->appManager->isEnabledForUser('logreader')) { |
| 62 | + return [ |
| 63 | + $l10n->t('Invalid hash of binaries files.'), |
| 64 | + $l10n->t('Check your nextcloud.log file on %s and run occ libresign:install --all', [ |
| 65 | + $this->urlGenerator->linkToRouteAbsolute('settings.adminsettings.form', ['section' => 'logging']) |
| 66 | + ]), |
| 67 | + ]; |
| 68 | + } |
| 69 | + return [ |
| 70 | + $l10n->t('Invalid hash of binaries files.'), |
| 71 | + $l10n->t('Check your nextcloud.log file and run occ libresign:install --all'), |
| 72 | + ]; |
| 73 | + } |
| 74 | +} |
0 commit comments