Description
Symfony version(s) affected
6.1
Description
I tried to encrypt a email via smime, my code looks like this:
$email = (new Email())
->from('test@test.de')
->to('test@test.de')
->subject('Subject')
->text('TEST123');
$encrypter = new SMimeEncrypter('/tmp/test.pem');
$encryptedEmail = $encrypter->encrypt($email);
I will get this error from symfony/openssl.
Failed to encrypt S/Mime message. Error: "error:0909006C:PEM routines:get_name:no start line".
Now i figured out that the passed cert file path will be "normalized" (https://github.com/symfony/mime/blob/6.1/Crypto/SMimeEncrypter.php#L36-L38 & https://github.com/symfony/mime/blob/6.1/Crypto/SMime.php#L24-L31) from
/tmp/test.pem
to
file:///tmp/test.pem
Which will be passed as third parameter to the openssl_pkcs7_encrypt method.
Which seems not accepting that format and only accepts certificates as string(array).
Either a lone X.509 certificate, or an array of X.509 certificates.
How to reproduce
The Descriptions has all important information to reproduce the issue.
Just an E-Mail Object which will be passt to the encrypt
method of the SMimeEncrypter
class.
Possible Solution
I tested it with a raw php file which look the following and it it works fine.
<?php
if (openssl_pkcs7_encrypt("message.txt", "encrypted.txt", file_get_contents("/tmp/test.pem"), [], 0, OPENSSL_CIPHER_AES_256_CBC)) {
echo 'encrypted';
}
So instead of passing file://PATH
it works with file_get_contents('PATH')
in my raw php file.
As quick fix i replaced the normalizeFilePath
call with file_get_contents
(https://github.com/symfony/mime/blob/6.1/Crypto/SMimeEncrypter.php#L36-L38).
Additional Context
@sstok implemented that 4 years ago, so maybe he has an idea what happens.