From be38e767b49c57c28267331104b9afde5070b40a Mon Sep 17 00:00:00 2001 From: Ricardo Boss Date: Wed, 19 Jan 2022 16:14:19 +0100 Subject: [PATCH] Added option to skip signature verification --- phive | 0 src/commands/install/InstallCommand.php | 2 +- src/commands/install/InstallCommandConfig.php | 4 ++++ src/commands/install/InstallContext.php | 17 ++++++++++------- src/services/phar/InstallService.php | 4 ++-- src/services/phar/PharDownloader.php | 4 ++-- src/services/phar/PharService.php | 4 ++-- 7 files changed, 21 insertions(+), 14 deletions(-) mode change 100755 => 100644 phive diff --git a/phive b/phive old mode 100755 new mode 100644 diff --git a/src/commands/install/InstallCommand.php b/src/commands/install/InstallCommand.php index 1832a712..bb811162 100644 --- a/src/commands/install/InstallCommand.php +++ b/src/commands/install/InstallCommand.php @@ -51,7 +51,7 @@ protected function installRequestedPhar(RequestedPhar $requestedPhar, Directory $release = $this->resolveToRelease($requestedPhar); $destination = $this->getDestination($release->getUrl()->getPharName(), $requestedPhar, $targetDirectory); - $this->installService->execute($release, $requestedPhar, $destination, !$this->getConfig()->doNotAddToPhiveXml()); + $this->installService->execute($release, $requestedPhar, $destination, !$this->getConfig()->doNotAddToPhiveXml(), $this->getConfig()->skipSignatureVerification()); } protected function getConfig(): InstallCommandConfig { diff --git a/src/commands/install/InstallCommandConfig.php b/src/commands/install/InstallCommandConfig.php index b8077d56..ee4b25a8 100644 --- a/src/commands/install/InstallCommandConfig.php +++ b/src/commands/install/InstallCommandConfig.php @@ -83,6 +83,10 @@ public function forceAcceptUnsignedPhars(): bool { return $this->cliOptions->hasOption('force-accept-unsigned'); } + public function skipSignatureVerification(): bool { + return $this->cliOptions->hasOption('skip-signature-verification'); + } + /** * @throws ConfiguredPharException * diff --git a/src/commands/install/InstallContext.php b/src/commands/install/InstallContext.php index 359d77bf..316816d1 100644 --- a/src/commands/install/InstallContext.php +++ b/src/commands/install/InstallContext.php @@ -20,19 +20,22 @@ public function requiresValue(string $option): bool { protected function getKnownOptions(): array { return [ - 'target' => 't', - 'copy' => 'c', - 'global' => 'g', - 'temporary' => false, - 'trust-gpg-keys' => false, - 'force-accept-unsigned' => false + 'target' => 't', + 'copy' => 'c', + 'global' => 'g', + 'temporary' => false, + 'trust-gpg-keys' => false, + 'force-accept-unsigned' => false, + 'skip-signature-verification' => false, ]; } protected function getConflictingOptions(): array { return [ ['global' => 'temporary'], - ['global' => 'target'] + ['global' => 'target'], + ['skip-signature-verification' => 'trust-gpg-keys'], + ['skip-signature-verification' => 'force-accept-unsigned'], ]; } } diff --git a/src/services/phar/InstallService.php b/src/services/phar/InstallService.php index ada89971..2f31f161 100644 --- a/src/services/phar/InstallService.php +++ b/src/services/phar/InstallService.php @@ -49,10 +49,10 @@ public function __construct( $this->compatibilityService = $compatibilityChecker; } - public function execute(SupportedRelease $release, RequestedPhar $requestedPhar, Filename $destination, bool $updatePhiveXml): void { + public function execute(SupportedRelease $release, RequestedPhar $requestedPhar, Filename $destination, bool $updatePhiveXml, bool $skipSignatureVerification = false): void { $versionConstraint = $requestedPhar->getVersionConstraint(); $makeCopy = $requestedPhar->makeCopy(); - $phar = $this->pharService->getPharFromRelease($release); + $phar = $this->pharService->getPharFromRelease($release, $skipSignatureVerification); if (!$this->compatibilityService->canRun($phar)) { return; diff --git a/src/services/phar/PharDownloader.php b/src/services/phar/PharDownloader.php index 757d02b7..fb35d60b 100644 --- a/src/services/phar/PharDownloader.php +++ b/src/services/phar/PharDownloader.php @@ -42,12 +42,12 @@ public function __construct( * @throws DownloadFailedException * @throws InvalidHashException */ - public function download(SupportedRelease $release): Phar { + public function download(SupportedRelease $release, bool $skipSignatureVerification = false): Phar { $pharFile = $this->downloadFile($release->getUrl()); $fingerprint = null; - if ($release->hasSignatureUrl()) { + if (!$skipSignatureVerification && $release->hasSignatureUrl()) { $fingerprint = $this->verifySignature( $release, $pharFile, diff --git a/src/services/phar/PharService.php b/src/services/phar/PharService.php index dccc9ce5..9a996492 100644 --- a/src/services/phar/PharService.php +++ b/src/services/phar/PharService.php @@ -22,13 +22,13 @@ public function __construct(PharRegistry $registry, PharDownloader $downloader) $this->downloader = $downloader; } - public function getPharFromRelease(SupportedRelease $release): Phar { + public function getPharFromRelease(SupportedRelease $release, bool $skipSignatureVerification = false): Phar { if ($this->registry->hasPhar($release->getName(), $release->getVersion())) { return $this->registry->getPhar($release->getName(), $release->getVersion()); } return $this->registry->addPhar( - $this->downloader->download($release) + $this->downloader->download($release, $skipSignatureVerification) ); } }