[Mime] add check for openssl when using SMime
This commit is contained in:
parent
09e3cef7a0
commit
f33c67bfc1
@ -36,7 +36,7 @@ class FlattenException
|
||||
private $file;
|
||||
private $line;
|
||||
|
||||
public static function createFromThrowable(\Throwable $exception, ?int $statusCode = null, array $headers = []): self
|
||||
public static function createFromThrowable(\Throwable $exception, int $statusCode = null, array $headers = []): self
|
||||
{
|
||||
$e = new static();
|
||||
$e->setMessage($exception->getMessage());
|
||||
|
@ -24,17 +24,21 @@ final class SMimeEncrypter extends SMime
|
||||
|
||||
/**
|
||||
* @param string|string[] $certificate The path (or array of paths) of the file(s) containing the X.509 certificate(s)
|
||||
* @param int $cipher A set of algorithms used to encrypt the message. Must be one of these PHP constants: https://www.php.net/manual/en/openssl.ciphers.php
|
||||
* @param int|null $cipher A set of algorithms used to encrypt the message. Must be one of these PHP constants: https://www.php.net/manual/en/openssl.ciphers.php
|
||||
*/
|
||||
public function __construct($certificate, int $cipher = OPENSSL_CIPHER_AES_256_CBC)
|
||||
public function __construct($certificate, int $cipher = null)
|
||||
{
|
||||
if (!\extension_loaded('openssl')) {
|
||||
throw new \LogicException('PHP extension "openssl" is required to use SMime.');
|
||||
}
|
||||
|
||||
if (\is_array($certificate)) {
|
||||
$this->certs = array_map([$this, 'normalizeFilePath'], $certificate);
|
||||
} else {
|
||||
$this->certs = $this->normalizeFilePath($certificate);
|
||||
}
|
||||
|
||||
$this->cipher = $cipher;
|
||||
$this->cipher = $cipher ?? OPENSSL_CIPHER_AES_256_CBC;
|
||||
}
|
||||
|
||||
public function encrypt(Message $message): Message
|
||||
|
@ -34,10 +34,14 @@ final class SMimeSigner extends SMime
|
||||
* @param string $privateKey The path of the file containing the private key (in PEM format)
|
||||
* @param string|null $privateKeyPassphrase A passphrase of the private key (if any)
|
||||
* @param string|null $extraCerts The path of the file containing intermediate certificates (in PEM format) needed by the signing certificate
|
||||
* @param int $signOptions Bitwise operator options for openssl_pkcs7_sign() (@see https://secure.php.net/manual/en/openssl.pkcs7.flags.php)
|
||||
* @param int|null $signOptions Bitwise operator options for openssl_pkcs7_sign() (@see https://secure.php.net/manual/en/openssl.pkcs7.flags.php)
|
||||
*/
|
||||
public function __construct(string $certificate, string $privateKey, ?string $privateKeyPassphrase = null, ?string $extraCerts = null, int $signOptions = PKCS7_DETACHED)
|
||||
public function __construct(string $certificate, string $privateKey, string $privateKeyPassphrase = null, string $extraCerts = null, int $signOptions = null)
|
||||
{
|
||||
if (!\extension_loaded('openssl')) {
|
||||
throw new \LogicException('PHP extension "openssl" is required to use SMime.');
|
||||
}
|
||||
|
||||
$this->signCertificate = $this->normalizeFilePath($certificate);
|
||||
|
||||
if (null !== $privateKeyPassphrase) {
|
||||
@ -46,7 +50,7 @@ final class SMimeSigner extends SMime
|
||||
$this->signPrivateKey = $this->normalizeFilePath($privateKey);
|
||||
}
|
||||
|
||||
$this->signOptions = $signOptions;
|
||||
$this->signOptions = $signOptions ?? PKCS7_DETACHED;
|
||||
$this->extraCerts = $extraCerts ? realpath($extraCerts) : null;
|
||||
$this->privateKeyPassphrase = $privateKeyPassphrase;
|
||||
}
|
||||
|
@ -16,6 +16,9 @@ use Symfony\Component\Mime\Crypto\SMimeSigner;
|
||||
use Symfony\Component\Mime\Email;
|
||||
use Symfony\Component\Mime\Message;
|
||||
|
||||
/**
|
||||
* @requires extension openssl
|
||||
*/
|
||||
class SMimeEncryptorTest extends SMimeTestCase
|
||||
{
|
||||
public function testEncryptMessage()
|
||||
|
@ -18,6 +18,9 @@ use Symfony\Component\Mime\Header\Headers;
|
||||
use Symfony\Component\Mime\Message;
|
||||
use Symfony\Component\Mime\Part\TextPart;
|
||||
|
||||
/**
|
||||
* @requires extension openssl
|
||||
*/
|
||||
class SMimeSignerTest extends SMimeTestCase
|
||||
{
|
||||
public function testSignedMessage()
|
||||
|
Reference in New Issue
Block a user