Commit 29bbbeb0 authored by Guillaume Perréal's avatar Guillaume Perréal
Browse files

Laisse GPG localiser et charger automatiquement les clefs.

No related merge requests found
Showing with 34 additions and 19 deletions
+34 -19
...@@ -5,7 +5,7 @@ package: ...@@ -5,7 +5,7 @@ package:
phar: phar:
archive_url: https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/%version%/php-cs-fixer.phar archive_url: https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/%version%/php-cs-fixer.phar
signature_url: https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/%version%/php-cs-fixer.phar.asc signature_url: https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/%version%/php-cs-fixer.phar.asc
keys: BBAB5DF0A0D6672989CF1869E82B2FB314E9906E keys: E82B2FB314E9906E
target: target:
name: irstea/php-cs-fixer-shim name: irstea/php-cs-fixer-shim
......
...@@ -5,7 +5,7 @@ package: ...@@ -5,7 +5,7 @@ package:
phar: phar:
archive_url: https://phar.phpunit.de/phpunit-%version%.phar archive_url: https://phar.phpunit.de/phpunit-%version%.phar
signature_url: https://phar.phpunit.de/phpunit-%version%.phar.asc signature_url: https://phar.phpunit.de/phpunit-%version%.phar.asc
keys: D8406D0D82947747293778314AA394086372C20A keys: 4AA394086372C20A
target: target:
name: irstea/phpunit-shim name: irstea/phpunit-shim
......
...@@ -31,6 +31,11 @@ class Verifier implements VerifierInterface, LoggerAwareInterface ...@@ -31,6 +31,11 @@ class Verifier implements VerifierInterface, LoggerAwareInterface
*/ */
private $gpgBinary; private $gpgBinary;
/**
* @var string[]
*/
private $trustedKeys = [];
/** /**
* Verifier constructor. * Verifier constructor.
* *
...@@ -48,22 +53,7 @@ class Verifier implements VerifierInterface, LoggerAwareInterface ...@@ -48,22 +53,7 @@ class Verifier implements VerifierInterface, LoggerAwareInterface
*/ */
public function loadKeys(array $ids): void public function loadKeys(array $ids): void
{ {
if (!$ids) { $this->trustedKeys = array_merge($this->trustedKeys, $ids);
return;
}
try {
Assertion::allString($ids);
$cmd = array_merge([$this->getGpgBinaryPath(), '--receive-keys'], $ids);
$process = new Process($cmd);
$process->mustRun();
$this->logger->debug('Loaded keys: ' . implode(', ', $ids));
} catch (ExceptionInterface $exception) {
throw new VerifierException('could not receive keys: ' . implode(', ', $ids), 0, $exception);
}
} }
/** /**
...@@ -75,7 +65,13 @@ class Verifier implements VerifierInterface, LoggerAwareInterface ...@@ -75,7 +65,13 @@ class Verifier implements VerifierInterface, LoggerAwareInterface
Assertion::file($signaturePath); Assertion::file($signaturePath);
Assertion::file($dataPath); Assertion::file($dataPath);
$process = new Process([$this->getGpgBinaryPath(), '--verify', $signaturePath, $dataPath]); $cmd = array_merge(
[$this->getGpgBinaryPath()],
$this->getGpgOptions(),
['--verify', $signaturePath, $dataPath]
);
$process = new Process($cmd);
$process->mustRun(); $process->mustRun();
$this->logger->info("$dataPath signature verified."); $this->logger->info("$dataPath signature verified.");
} catch (ExceptionInterface $exception) { } catch (ExceptionInterface $exception) {
...@@ -83,6 +79,25 @@ class Verifier implements VerifierInterface, LoggerAwareInterface ...@@ -83,6 +79,25 @@ class Verifier implements VerifierInterface, LoggerAwareInterface
} }
} }
/**
* @return array
*/
private function getGpgOptions(): array
{
$options = [
'--batch',
'--auto-key-locate=wkd',
'--auto-key-retrieve',
];
foreach ($this->trustedKeys as $keyId) {
$options[] = '--trusted-key';
$options[] = $keyId;
}
return $options;
}
/** /**
* @return string * @return string
*/ */
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment