From 3ef22258e5f2674a4259b60e2eb0377ccd145d26 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sun, 17 Jan 2016 14:49:58 +0000 Subject: [PATCH] Add key fingerprints for easier comparison and debugging via diagnose --- src/Composer/Command/DiagnoseCommand.php | 33 ++++++++++++++++++++++ src/Composer/Command/SelfUpdateCommand.php | 7 +++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/Composer/Command/DiagnoseCommand.php b/src/Composer/Command/DiagnoseCommand.php index faf537a10..b3ecb08bb 100644 --- a/src/Composer/Command/DiagnoseCommand.php +++ b/src/Composer/Command/DiagnoseCommand.php @@ -22,6 +22,7 @@ use Composer\Util\ConfigValidator; use Composer\Util\ProcessExecutor; use Composer\Util\RemoteFilesystem; use Composer\Util\StreamContextFactory; +use Composer\Util\Keys; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -133,6 +134,9 @@ EOT $io->write('Checking disk free space: ', false); $this->outputResult($this->checkDiskSpace($config)); + $io->write('Checking pubkeys: ', false); + $this->outputResult($this->checkPubKeys($config)); + $io->write('Checking composer version: ', false); $this->outputResult($this->checkVersion()); @@ -327,6 +331,35 @@ EOT return true; } + private function checkPubKeys($config) + { + $home = $config->get('home'); + $errors = []; + $io = $this->getIO(); + + if (file_exists($home.'/keys.tags.pub') && file_exists($home.'/keys.dev.pub')) { + $io->write(''); + } + + if (file_exists($home.'/keys.tags.pub')) { + $io->write('Tags Public Key Fingerprint: ' . Keys::fingerprint($home.'/keys.tags.pub')); + } else { + $errors[] = 'Missing pubkey for tags verification'; + } + + if (file_exists($home.'/keys.dev.pub')) { + $io->write('Dev Public Key Fingerprint: ' . Keys::fingerprint($home.'/keys.dev.pub')); + } else { + $errors[] = 'Missing pubkey for dev verification'; + } + + if ($errors) { + $errors[] = 'Run composer self-update --update-keys to set them up'; + } + + return $errors ?: true; + } + private function checkVersion() { $protocol = extension_loaded('openssl') ? 'https' : 'http'; diff --git a/src/Composer/Command/SelfUpdateCommand.php b/src/Composer/Command/SelfUpdateCommand.php index f227b22dc..3f456862c 100644 --- a/src/Composer/Command/SelfUpdateCommand.php +++ b/src/Composer/Command/SelfUpdateCommand.php @@ -16,6 +16,7 @@ use Composer\Composer; use Composer\Factory; use Composer\Config; use Composer\Util\Filesystem; +use Composer\Util\Keys; use Composer\IO\IOInterface; use Composer\Util\RemoteFilesystem; use Composer\Downloader\FilesystemException; @@ -220,7 +221,8 @@ EOT } } } - file_put_contents($config->get('home').'/keys.dev.pub', $match[0]); + file_put_contents($keyPath = $config->get('home').'/keys.dev.pub', $match[0]); + $io->write('Stored key with fingerprint: ' . Keys::fingerprint($keyPath)); $tagsKey = ''; while (!preg_match('{(-----BEGIN PUBLIC KEY-----.+?-----END PUBLIC KEY-----)}s', $tagsKey, $match)) { @@ -232,7 +234,8 @@ EOT } } } - file_put_contents($config->get('home').'/keys.tags.pub', $match[0]); + file_put_contents($keyPath = $config->get('home').'/keys.tags.pub', $match[0]); + $io->write('Stored key with fingerprint: ' . Keys::fingerprint($keyPath)); $io->write('Public keys stored in '.$config->get('home')); }