[8.x] Use lowercase OpenSSL cipher names #38594
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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, butaes-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.phpThe 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 andstrtolower()
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 atconfig('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.