Example #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $SafeController = new SafeController();
     $SecretController = new SecretController();
     $safeName = $input->getArgument('safe');
     if (empty($safeName)) {
         $safeNames = $SafeController->getSafeNames();
         $helper = $this->getHelper('question');
         $question = new ChoiceQuestion('<question>Please select the safe for this secret:</question> ', $safeNames);
         $safeName = $helper->ask($input, $output, $question);
     }
     if (empty($safeName)) {
         throw new \Exception("Invalid safe name");
     }
     $output->writeln(sprintf("<info>Using safe '%s'... </info>", $safeName));
     $safe = $SafeController->view($safeName);
     $keyName = $input->getArgument('key');
     if (empty($keyName)) {
         $keyNames = $SecretController->getKeys($safe);
         $helper = $this->getHelper('question');
         $question = new ChoiceQuestion('<question>Please select the key to decrypt:</question> ', $keyNames);
         $keyName = $helper->ask($input, $output, $question);
     }
     if (empty($keyName)) {
         throw new \Exception("Invalid key name");
     }
     $privateKey = $input->getArgument('privatekey');
     if (empty($privateKey) || !file_exists($privateKey)) {
         throw new \Exception("Invalid private key");
     }
     $output->writeln('');
     $output->write(sprintf("Decrypting secret '%s'... ", $keyName));
     $PrivateKey = new PrivateKey();
     $PrivateKey->setKey(file_get_contents($privateKey));
     try {
         $secret = $SecretController->view($safe, $keyName);
         $plainText = $secret->getValue($PrivateKey);
     } catch (\Exception $e) {
         $output->writeln('<error>FAILED</error>');
         $output->writeln('');
         $output->writeln('<error>' . $e->getMessage() . '</error>');
         return;
     }
     $output->writeln('<info>DONE</info>');
     $output->writeln('');
     $output->writeln(sprintf("<comment>'%s'</comment> = '%s'", $keyName, $plainText));
     $output->writeln('');
 }
Example #2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $SafeController = new SafeController();
     $SecretController = new SecretController();
     $helper = $this->getHelper('question');
     $safeName = $input->getArgument('safe');
     if (empty($safeName)) {
         $safeNames = $SafeController->getSafeNames();
         $question = new ChoiceQuestion('<question>Please select the safe for this secret:</question> ', $safeNames);
         $safeName = $helper->ask($input, $output, $question);
     }
     if (empty($safeName)) {
         throw new \Exception("Invalid safe name");
     }
     $output->writeln('');
     $output->writeln(sprintf("<info>Using safe '%s'... </info>", $safeName));
     $safe = $SafeController->view($safeName);
     $keyName = $input->getArgument('key');
     if (empty($keyName)) {
         $keys = $SecretController->getKeys($safe);
         $question = new ChoiceQuestion('<question>Please select the secret key to remove:</question> ', $keys);
         $keyName = $helper->ask($input, $output, $question);
     }
     if (empty($keyName)) {
         throw new \Exception("Invalid secret ket");
     }
     $question = "<question>Are you sure you want to delete this secret?</question>\n";
     $removeSecret = new ConfirmationQuestion($question, false);
     if (!$helper->ask($input, $output, $removeSecret)) {
         return;
     }
     if (!$removeSecret) {
         return;
     }
     $output->writeln('');
     $output->write(sprintf("Removing secret '%s'... ", $keyName));
     $removed = $SecretController->remove($safe, $keyName);
     if (!$removed) {
         $output->writeln('<error>FAILED</error>');
         $output->writeln('<error>Error removing secret</error>');
         $output->writeln('');
         return;
     }
     $output->writeln('<info>DONE</info>');
     $output->writeln('');
 }