Ejemplo n.º 1
0
 protected function fetchKeys(IOInterface $io, Config $config)
 {
     if (!$io->isInteractive()) {
         throw new \RuntimeException('Public keys can not be fetched in non-interactive mode, please run Composer interactively');
     }
     $io->write('Open <info>https://composer.github.io/pubkeys.html</info> to find the latest keys');
     $validator = function ($value) {
         if (!preg_match('{^-----BEGIN PUBLIC KEY-----$}', trim($value))) {
             throw new \UnexpectedValueException('Invalid input');
         }
         return trim($value) . "\n";
     };
     $devKey = '';
     while (!preg_match('{(-----BEGIN PUBLIC KEY-----.+?-----END PUBLIC KEY-----)}s', $devKey, $match)) {
         $devKey = $io->askAndValidate('Enter Dev / Snapshot Public Key (including lines with -----): ', $validator);
         while ($line = $io->ask('')) {
             $devKey .= trim($line) . "\n";
             if (trim($line) === '-----END PUBLIC KEY-----') {
                 break;
             }
         }
     }
     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)) {
         $tagsKey = $io->askAndValidate('Enter Tags Public Key (including lines with -----): ', $validator);
         while ($line = $io->ask('')) {
             $tagsKey .= trim($line) . "\n";
             if (trim($line) === '-----END PUBLIC KEY-----') {
                 break;
             }
         }
     }
     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'));
 }
Ejemplo n.º 2
0
 private function checkPubKeys($config)
 {
     $home = $config->get('home');
     $errors = array();
     $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[] = '<error>Missing pubkey for tags verification</error>';
     }
     if (file_exists($home . '/keys.dev.pub')) {
         $io->write('Dev Public Key Fingerprint: ' . Keys::fingerprint($home . '/keys.dev.pub'));
     } else {
         $errors[] = '<error>Missing pubkey for dev verification</error>';
     }
     if ($errors) {
         $errors[] = '<error>Run composer self-update --update-keys to set them up</error>';
     }
     return $errors ?: true;
 }