Skip to content
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

[8.x] Use lowercase OpenSSL cipher names #38594

Merged
merged 1 commit into from
Aug 30, 2021

Conversation

Krisell
Copy link
Contributor

@Krisell Krisell commented Aug 30, 2021

See #38558 for the issue discussion leading up to this PR.

Problem
OpenSSL < 1.1.0 doesn't recognize AES-128-GCM as a cipher name, but aes-128-gcm (i.e. lowercase) is valid. This is caused by the fact that OpenSSL previously maintained upper- and lowercase names for ciphers as aliases, and for GCM a different alias was used instead (id-aes128-GCM). More recent versions of OpenSSL perform case-insensitive matching.

Prior to this PR, all cipher names are referenced in uppercase in Laravel, causing AES-128/256-GCM to not work on php versions using OpenSSL < 1.1.0. Assuming the following information is updated, this problem remains in PHP 8 (the requirement is OpenSSL ≥ 1.0.1): https://www.php.net/manual/en/openssl.requirements.php

The effect is that AES-128/256-GCM can't be used as the new default cipher in Laravel, which is unfortunate since it does provide some performance and theoretical security advantages over the CBC+MAC mode.

Solution
This PR instead passes lowercase strings to OpenSSL.

Backwards compatibility
The internal cipher name in Encrypter.php is untouched and strtolower() is only applied when being passed to OpenSSL. Also, uppercase strings are still supported in the config file and can be left unchanged. This keeps BC with any packages or extending code peeking at config('app.cipher') or $encrypter->cipher.

The other supported ciphers (only AES-128/256-CBC) has always used the lower- and uppercase names as aliases in OpenSSL, so there is no risk of lowercase CBC not working on older systems.


new Encrypter(str_repeat('a', 16), 'AES-256-CFB8');
new Encrypter(str_repeat('a', 16), 'AES-256-GCM');
Copy link
Contributor Author

@Krisell Krisell Aug 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unrelated to this PR but must have been a typo previously. It did not test what the test name says and was a clone of the neighbor test. Now it tests that a valid cipher but invalid key length throws as expected.

@taylorotwell taylorotwell merged commit d2de6f8 into laravel:8.x Aug 30, 2021
@driesvints
Copy link
Member

Thanks for the PR @Krisell. Appreciate your help with this 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants