8000 [Mime] Line endings not correct when using S/MIME and Linux · Issue #36398 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
8000

[Mime] Line endings not correct when using S/MIME and Linux #36398

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
TokkCorp opened this issue Apr 9, 2020 · 4 comments · Fixed by #36463
Closed

[Mime] Line endings not correct when using S/MIME and Linux #36398

TokkCorp opened this issue Apr 9, 2020 · 4 comments · Fixed by #36463

Comments

@TokkCorp
Copy link
TokkCorp commented Apr 9, 2020

Symfony version(s) affected: 5.0+

Description
When sending mails using the symfony mailer the line endings in the message to the mailserver are missing the carriage return if S/MIME encryption is used on a linux server.

I've prepared four examples of what gets send to the mailserver:

Because of the wrong endings sending huge files leads to the following error:
PHP Fatal error: Uncaught Symfony\Component\Mailer\Exception\TransportException: Expected response code "250" but got code "501", with message "501 Syntax error - line too long". in /example/vendor/symfony/mailer/Transport/Smtp/SmtpTransport.php:298

How to reproduce
The Problem will occur always when sending an S/MIME encrypted Mail like this:

$email = (new Email())
    ->from('sender@example.com')
    ->to('recipient@example.com')
    ->subject('Encrypted mail with attachment')
    ->attachFromPath('./attachments/LoremIpsum.pdf')
    ->text(fopen('./attachments/content.txt', 'r'))
    ->html(fopen('./attachments/content.html', 'r'));

$encrypter = new SMimeEncrypter('./cert/smime.cer');
$encryptedEmail = $encrypter->encrypt($email);

The wrong line endings are also present without an attachment but the server error will occure only if the message is long enough to exceed the maximal line length.

Possible Solution
Fix the line endings in S/MIME encrypted messages.

Additional Information
It is working using Swiftmailer on the same systems so I would conclude the error is in the mailer component and not in openssl or any other system.

@nicolas-grekas
Copy link
8000
Member

/cc @sstok maybe?

@sstok
Copy link
Contributor
sstok commented Apr 16, 2020

https://github.com/openssl/openssl/blob/6d9b4d7f4bf1ea9bc1d1b1bd8b7e83c6fbeed395/crypto/asn1/asn_mime.c#L244

if (flags & SMIME_CRLFEOL)
        mime_eol = "\r\n";
    else
        mime_eol = "\n";

But there is no way to use this constant directly in PHP (gotta love the OpenSSL extension).
I'm working on a pull request to normalize the line-ending to their correct format 👍

@sstok
Copy link
Contributor
sstok commented Apr 16, 2020

@TokkCorp can you try if #36463 fixes the problem?

@TokkCorp
Copy link
Author

Just tried and can confirm that it is working with the change from this commit.

fabpot added a commit that referenced this issue Apr 17, 2020
This PR was merged into the 5.0 branch.

Discussion
----------

[Mime] Ensure proper line-ending for SMIME

| Q             | A
| ------------- | ---
| Branch?       | 5.0
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #36398
| License       | MIT
| Doc PR        |

Commits
-------

5e3ccc2 [Mime] Ensure proper line-ending for SMIME
@fabpot fabpot closed this as completed Apr 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants
0