Ejemplo n.º 1
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');
     }
 }
Ejemplo n.º 2
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.º 3
0
 /**
  * Load a key pair from disk
  * @param string $name
  * @param string $passPhrase
  * @return void
  */
 protected function loadKey($name, $passPhrase = NULL)
 {
     $list = $this->getKeyList();
     $hash = $list[$name]['file'];
     $base = $this->options->getBasePath() . DIRECTORY_SEPARATOR;
     $private = $base . $hash;
     $public = $private . '.pub';
     $options = array('private_key' => $private, 'public_key' => $public, 'pass_phrase' => $passPhrase, 'binary_output' => $list[$name]['binaryOutput'], 'hashAlgorithm' => $list[$name]['hashAlgorithm']);
     if ($this->requiresPassPhrase($name) && empty($passPhrase)) {
         /**
          * Do not load the private key so we can still perform encryption
          * with the public key
          */
         unset($options['private_key'], $options['pass_phrase']);
     }
     try {
         $rsa = Rsa::factory($options);
     } catch (ZendException $e) {
         throw new Exception\RuntimeException('Failed to load key pair', $e);
     }
     $this->keys[$name] = $rsa;
 }