Ejemplo n.º 1
0
 /**
  * Speichert den Schlüssel als PEM.
  *
  * @param string $filename
  * @param string $password
  * @param array $config
  */
 public function exportToFile(string $filename, string $password = NULL, array $config = [])
 {
     $status = openssl_pkey_export_to_file($this->getHandle(), $filename, $password, $config);
     if (!$status) {
         throw new RuntimeException(OpenSSL::getLastError());
     }
 }
Ejemplo n.º 2
0
 /**
  * @param mixed $publicKey
  */
 public function load($publicKey)
 {
     parent::load($publicKey);
     if ($publicKey instanceof File) {
         $publicKey = $publicKey->getContent();
     }
     if ($publicKey instanceof SplFileInfo) {
         $publicKey = file_get_contents($publicKey);
     }
     if (is_string($publicKey)) {
         $handle = openssl_pkey_get_public($publicKey);
         if (!$handle) {
             throw new RuntimeException(OpenSSL::getLastError());
         }
         $this->setHandle($handle);
     }
 }
Ejemplo n.º 3
0
 /**
  * @param string $mime
  * @param $chain
  *
  * @return bool
  */
 public function verify(string $mime, $chain) : bool
 {
     $inputFileName = new TempFile('smime_signed_');
     $inputFileName->setContent($mime);
     $status = openssl_pkcs7_verify($inputFileName, $this->getFlags(), '/dev/null', [], $chain);
     if (!is_bool($status)) {
         throw new RuntimeException(OpenSSL::getLastError());
     }
     return $status;
 }
Ejemplo n.º 4
0
 public function testGetCertificateLocations()
 {
     $certificateLocations = OpenSSL::getCertificateLocations();
     $this->assertTrue(is_array($certificateLocations));
 }
Ejemplo n.º 5
0
 /**
  * @param string $fileName
  * @param string $password
  *
  * @throws RuntimeException
  */
 public function exportToFile(string $fileName, string $password = NULL)
 {
     $options = [];
     if ($this->hasChain()) {
         $options['extracerts'] = $this->getChain();
     }
     $status = openssl_pkcs12_export_to_file($this->getCertificate(), $fileName, $this->getPrivateKey(), $password, $options);
     if (!$status) {
         throw new RuntimeException(OpenSSL::getLastError());
     }
 }
Ejemplo n.º 6
0
 /**
  * @param string $algorithm
  *
  * @return Hash
  */
 public function getFingerprint(string $algorithm = 'SHA1') : Hash
 {
     $value = openssl_x509_fingerprint($this->getHandle(), $algorithm, TRUE);
     if (!$value) {
         throw new RuntimeException(OpenSSL::getLastError());
     }
     $hash = new Hash($algorithm);
     $hash->setValue($value);
     return $hash;
 }