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'));
}