vendor/lexik/jwt-authentication-bundle/Services/KeyLoader/OpenSSLKeyLoader.php line 5

Open in your IDE?
  1. <?php
  2. namespace Lexik\Bundle\JWTAuthenticationBundle\Services\KeyLoader;
  3. @trigger_error(sprintf('The "%s\OpenSSLKeyLoader" class is deprecated since version 2.5 and will be removed in 3.0. Use "%s" instead.'__NAMESPACE__RawKeyLoader::class), E_USER_DEPRECATED);
  4. /**
  5.  * Load crypto keys for the OpenSSL crypto engine.
  6.  *
  7.  * @author Robin Chalas <robin.chalas@gmail.com>
  8.  *
  9.  * @deprecated since version 2.5, to be removed in 3.0. Use RawKeyLoader instead
  10.  */
  11. class OpenSSLKeyLoader extends AbstractKeyLoader implements KeyDumperInterface
  12. {
  13.     /**
  14.      * {@inheritdoc}
  15.      *
  16.      * @throws \RuntimeException If the key cannot be read
  17.      * @throws \RuntimeException Either the key or the passphrase is not valid
  18.      */
  19.     public function loadKey($type)
  20.     {
  21.         if (!in_array($type, [self::TYPE_PUBLICself::TYPE_PRIVATE])) {
  22.             throw new \InvalidArgumentException(sprintf('The key type must be "public" or "private", "%s" given.'$type));
  23.         }
  24.         $rawKey file_get_contents($this->getKeyPath($type));
  25.         $key    call_user_func_array("openssl_pkey_get_$type"self::TYPE_PRIVATE == $type ? [$rawKey$this->getPassphrase()] : [$rawKey]);
  26.         if (!$key) {
  27.             $sslError '';
  28.             while ($msg trim(openssl_error_string(), " \n\r\t\0\x0B\"")) {
  29.                 if ('error:' === substr($msg06)) {
  30.                     $msg substr($msg6);
  31.                 }
  32.                 $sslError .= "\n $msg";
  33.             }
  34.             throw new \RuntimeException(
  35.                 sprintf('Failed to load %s key: %s'$type$sslError)
  36.             );
  37.         }
  38.         return $key;
  39.     }
  40.     /**
  41.      * {@inheritdoc}
  42.      */
  43.     public function dumpKey()
  44.     {
  45.         $key openssl_pkey_get_details($this->loadKey('public'));
  46.         if (!isset($key['key'])) {
  47.             return;
  48.         }
  49.         return $key['key'];
  50.     }
  51. }