Esempio n. 1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $name = $input->getArgument('name');
     if (empty($name)) {
         $helper = $this->getHelper('question');
         $question = new Question('<question>Please enter the name of the safe to create:</question> ');
         $name = $helper->ask($input, $output, $question);
     }
     if (empty($name)) {
         throw new \Exception("Invalid safe name");
     }
     $output->writeln('');
     $output->write(sprintf("Creating safe '%s'... ", $name));
     $SafeController = new SafeController();
     try {
         $PrivateKey = $SafeController->create($name);
     } 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('<comment>PLEASE STORE PRIVATE KEY (CANNOT BE RECOVERED)</comment>');
     $output->writeln($PrivateKey->getKey());
     $output->writeln('');
 }
Esempio n. 2
0
 /**
  * @param $keyName
  * @return bool|string
  * @throws \Exception
  */
 public function getKey($keyName)
 {
     if (!is_callable($this->privateKeyCallback)) {
         throw new \Exception("Missing private key callback");
     }
     $SafeController = new SafeController();
     $SafeController->setContainer($this->getContainer());
     $SecretController = new SecretController();
     $SecretController->setContainer($this->getContainer());
     $safe = $this->getSafe();
     if (is_string($safe)) {
         $safe = $SafeController->view($this->getSafe());
         if (!$safe) {
             throw new \Exception("Invalid Portunus safe");
         }
     }
     $secret = $SecretController->view($safe, $keyName);
     $callback = $this->privateKeyCallback;
     $privateKeyString = $callback($safe->getName());
     if (empty($privateKeyString)) {
         throw new \Exception("Invalid private key");
     }
     $PrivateKey = new PrivateKey();
     $PrivateKey->setKey($privateKeyString);
     try {
         $result = $secret->getValue($PrivateKey);
     } catch (\Exception $e) {
         $result = false;
     }
     return $result;
 }
Esempio n. 3
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln('');
     $SafeController = new SafeController();
     try {
         $safes = $SafeController->listSafes();
     } catch (\Exception $e) {
         $output->writeln('<error>FAILED</error>');
         $output->writeln('');
         $output->writeln('<error>' . $e->getMessage() . '</error>');
         return;
     }
     $SecretController = new SecretController();
     $rows = array();
     foreach ($safes as $key => $safe) {
         if ($input->getOption('signature')) {
             $rows[] = array($safe->getName(), $safe->getPublicKey()->getKeySignature(), count($SecretController->listSecrets($safe)), $safe->getCreated()->format('Y-m-d H:i:s'), $safe->getUpdated()->format('Y-m-d H:i:s'));
         } else {
             $rows[] = array($safe->getName(), count($SecretController->listSecrets($safe)), $safe->getCreated()->format('Y-m-d H:i:s'), $safe->getUpdated()->format('Y-m-d H:i:s'));
         }
     }
     $table = $this->getHelper('table');
     if ($input->getOption('signature')) {
         $table->setHeaders(array('Safe Name', 'Signature', '# Secrets', 'Created', 'Updated'))->setRows($rows);
     } else {
         $table->setHeaders(array('Safe Name', '# Secrets', 'Created', 'Updated'))->setRows($rows);
     }
     $table->render($output);
     $output->writeln('');
 }
Esempio n. 4
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $SafeController = new SafeController();
     $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('');
     $output->writeln(sprintf("<info>Using safe '%s'... </info>", $safeName));
     $keyName = $input->getArgument('key');
     if (empty($keyName)) {
         $helper = $this->getHelper('question');
         $question = new Question('<question>Please enter the key name for this secret :</question> ');
         $keyName = $helper->ask($input, $output, $question);
     }
     if (empty($keyName)) {
         throw new \Exception("Invalid key name");
     }
     $value = $input->getArgument('value');
     if (empty($value)) {
         $helper = $this->getHelper('question');
         $question = new Question('<question>Please enter the value for this secret (output hidden):</question> ');
         $question->setHidden(true);
         $question->setHiddenFallback(false);
         $value = $helper->ask($input, $output, $question);
     }
     if (empty($value) && !file_exists($value)) {
         throw new \Exception("Invalid value");
     }
     if (file_exists($value)) {
         $value = file_get_contents($value);
     }
     $output->writeln('');
     $output->write(sprintf("Creating secret '%s'... ", $keyName));
     $SecretController = new SecretController();
     try {
         $safe = $SafeController->view($safeName);
         $SecretController->create($safe, $keyName, $value);
     } catch (\Exception $e) {
         $output->writeln('<error>FAILED</error>');
         $output->writeln('');
         $output->writeln('<error>' . $e->getMessage() . '</error>');
         return;
     }
     $output->writeln('<info>DONE</info>');
     $output->writeln('');
 }
Esempio n. 5
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('');
 }
Esempio n. 6
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('');
 }
Esempio n. 7
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $SafeController = new SafeController();
     $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('');
     $SafeController = new SafeController();
     $safe = $SafeController->view($safeName);
     $SecretController = new SecretController();
     try {
         $secrets = $SecretController->listSecrets($safe);
     } catch (\Exception $e) {
         $output->writeln('<error>FAILED</error>');
         $output->writeln('');
         $output->writeln('<error>' . $e->getMessage() . '</error>');
         return;
     }
     $rows = array();
     foreach ($secrets as $key => $secret) {
         if ($input->getOption('signature')) {
             $rows[] = array($secret->getKey(), hash('sha256', $secret->getValue()), strlen($secret->getValue()), $secret->getCreated()->format('Y-m-d H:i:s'), $secret->getUpdated()->format('Y-m-d H:i:s'));
         } else {
             $rows[] = array($secret->getKey(), strlen($secret->getValue()), $secret->getCreated()->format('Y-m-d H:i:s'), $secret->getUpdated()->format('Y-m-d H:i:s'));
         }
     }
     $table = $this->getHelper('table');
     if ($input->getOption('signature')) {
         $table->setHeaders(array('Key Name', 'Signature', 'Length', 'Created', 'Updated'))->setRows($rows);
     } else {
         $table->setHeaders(array('Key Name', 'Length', 'Created', 'Updated'))->setRows($rows);
     }
     $table->render($output);
     $output->writeln('');
 }
Esempio n. 8
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $SafeController = new SafeController();
     $helper = $this->getHelper('question');
     $output->writeln('');
     $safeName = $input->getArgument('name');
     if (empty($safeName)) {
         $safeNames = $SafeController->getSafeNames();
         $question = new ChoiceQuestion('<question>Please select the safe to delete:</question> ', $safeNames);
         $safeName = $helper->ask($input, $output, $question);
     }
     if (empty($safeName)) {
         throw new \Exception("Invalid safe name");
     }
     $question = "<question>Are you sure you want to remove this safe?</question>\n";
     $question .= '<info>(This action will remove all secrets stored for this safe): </info>';
     $removeSafe = new ConfirmationQuestion($question, false);
     if (!$helper->ask($input, $output, $removeSafe)) {
         return;
     }
     if (!$removeSafe) {
         return;
     }
     $output->writeln('');
     $output->write(sprintf("Removing safe '%s'... ", $safeName));
     $SafeController = new SafeController();
     $removed = $SafeController->remove($safeName);
     if (!$removed) {
         $output->writeln('<error>FAILED</error>');
         $output->writeln('<error>Error removing safe</error>');
         $output->writeln('');
         return;
     }
     $output->writeln('<info>DONE</info>');
     $output->writeln('');
 }