Ejemplo n.º 1
0
 /**
  * Generate new private/public key pair
  * @see RsaOptions::generateKeys()
  *
  * @param  array $opensslConfig
  * @return Rsa
  * @throws Rsa\Exception\RuntimeException
  */
 public function generateKeys(array $opensslConfig = array())
 {
     $this->options->generateKeys($opensslConfig);
     return $this;
 }
 /**
  * Controller Action for generation of a new key pair
  * @return ViewModel
  */
 public function generateAction()
 {
     $view = new ViewModel();
     $view->form = $this->getGenerateForm();
     $view->error = false;
     $redirectUrl = $this->url()->fromRoute(static::ROUTE_GEN_KEYS);
     $prg = $this->prg($redirectUrl, true);
     if ($prg instanceof Response) {
         return $prg;
     }
     if ($prg === false) {
         return $view;
     }
     $view->form->setData($prg);
     if (!$view->form->isValid()) {
         $view->error = true;
         return $view;
     }
     $post = $view->form->getData();
     $keys = $this->getKeyStorage();
     try {
         $rsaOptions = array();
         if (!empty($post['keyPassPhrase'])) {
             $rsaOptions['passPhrase'] = $post['keyPassPhrase'];
         }
         $rsaOptions['binaryOutput'] = $post['outputType'] === 'binary';
         $rsaOptions['hashAlgorithm'] = $post['digestAlgo'];
         $rsaOptions = new RsaOptions($rsaOptions);
         $rsaOptions->generateKeys(array('private_key_bits' => $post['keySize']));
         $rsa = new Rsa($rsaOptions);
         $keys->set($rsa, $post['keyName']);
     } catch (Exception $e) {
         $view->error = true;
         $message = 'Failed to Create Key Pair: ' . $e->getMessage();
         $form->setMessages(array('keyName' => $message));
         return $view;
     }
     $this->flashMessenger()->addSuccessMessage('New RSA Key Pair Created Successfully');
     return $this->redirect()->toRoute(static::ROUTE_HOME);
 }
Ejemplo n.º 3
0
 public function testRsaLoadsPassphrasedKeys()
 {
     $rsaOptions = new RsaOptions(array('pass_phrase' => '0987654321'));
     $rsaOptions->generateKeys(array('config' => $this->userOpenSslConf, 'private_key_bits' => 512));
     Rsa::factory(array('pass_phrase' => '0987654321', 'private_key' => $rsaOptions->getPrivateKey()->toString()));
 }
Ejemplo n.º 4
0
 public function testRsaLoadsPassphrasedKeys()
 {
     $rsaOptions = new RsaOptions(array('pass_phrase' => '0987654321'));
     $rsaOptions->generateKeys(array('config' => $this->userOpenSslConf, 'private_key_bits' => 512));
     try {
         $rsa = Rsa::factory(array('pass_phrase' => '0987654321', 'private_key' => $rsaOptions->getPrivateKey()->toString()));
     } catch (Exception\RuntimeException $e) {
         $this->fail('Passphrase loading of a private key failed');
     }
 }