setName('integrity:check-app')
->setDescription('Check integrity of an app using a signature.')
->addArgument('appid', InputArgument::OPTIONAL, 'Application to check')
->addOption('path', null, InputOption::VALUE_OPTIONAL, 'Path to application. If none is given it will be guessed.')
->addOption('all', null, InputOption::VALUE_NONE, 'Check integrity of all apps.');
}
/**
* {@inheritdoc }
*/
protected function execute(InputInterface $input, OutputInterface $output): int {
if ($input->getOption('all') && $input->getArgument('appid')) {
$output->writeln('Option "--all" cannot be combined with an appid');
return 1;
}
if (!$input->getArgument('appid') && !$input->getOption('all')) {
$output->writeln('Please specify an appid, or "--all" to verify all apps');
return 1;
}
if ($input->getArgument('appid')) {
$appIds = [$input->getArgument('appid')];
} else {
$appIds = $this->appManager->getAllAppsInAppsFolders();
}
$errorsFound = false;
foreach ($appIds as $appId) {
$path = (string)$input->getOption('path');
if ($path === '') {
$path = $this->appLocator->getAppPath($appId);
}
if ($this->appManager->isShipped($appId) || $this->fileAccessHelper->file_exists($path . '/appinfo/signature.json')) {
// Only verify if the application explicitly ships a signature.json file
$result = $this->checker->verifyAppSignature($appId, $path, true);
if (count($result) > 0) {
$output->writeln('' . $appId . ': ' . count($result) . ' errors found:');
$this->writeArrayInOutputFormat($input, $output, $result);
$errorsFound = true;
}
} else {
$output->writeln('' . $appId . ': ' . 'App signature not found, skipping app integrity check');
}
}
if (!$errorsFound) {
$output->writeln('No errors found', OutputInterface::VERBOSITY_VERBOSE);
return 0;
}
return 1;
}
}