-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Use OpenSSL instead of Mcrypt in the examples #7934
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
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SHA1 is a Hash algorithm, you cannont use it to encrypt/decrypt purpose
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which algo should we use instead?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would actually recommend to use LibSodium instead of OpenSSL, encryption is a specialty that is hard to get right, LibSodium makes this as easy as possible. Alternatively you can use https://github.com/defuse/php-encryption which provide a developer friendly (and very secure) API on-top of OpenSSL.
https://paragonie.com/blog/2015/05/if-you-re-typing-word-mcrypt-into-your-code-you-re-doing-it-wrong
https://paragonie.com/blog/2015/05/using-encryption-and-authentication-correctly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sstok I'm not sure we can do that, because this should work out-of-the-box in all/mosts PHP versions, so we can't use external libs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you can't use LibSodium I would recommend https://github.com/defuse/php-encryption (uses OpenSSL internally), yes it's PHP 5.4, and Symfony 2.7 still supports PHP 5.3, but from the point of security using an old unmaintained PHP version is already a horrible idea (TM).
It all depends on the level of security you want to provide, 3DES is horrible insecure (for many years). Using OpenSSL without proper padding, authentication (crypto authentication) or IV generating, your data is still encrypted. But it becomes easier to break the encryption and leaking sensitive information, and potentially making it possible change the underlying data https://paragonie.com/blog/2015/05/using-encryption-and-authentication-correctly#title.2.1 and thus compromising the trust level of your security.
As this is only used for session data (server-side) the risk smaller, but still existent.
Not to mention using this example and assuming it's safe 🙀.
For the purpose of an example I think it's best to provide a simple example (using OpenSSL) with a big warning that this is only meant as an example and it should not be used for an actual implementation, and providing links with information on how to do this safely 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sstok Thanks for navigating this with us :). So PHP deprecated mcrypt "in favour of OpenSSL"... but there's really no simple way to actually use OpenSSL? If so, that sucks!
If https://github.com/defuse/php-encryption is "just as good" as LibSodium, I'd rather show it being used. I don't think we need to cover its installation, just show how the end-code would look and link to it (and say it's one encryption example). After all, if you're trying to secure your session data, you obviously care about security and are ok with doing some work to get things setup properly. As long as we show a secure example (even if it takes some setup), we're on solid ground.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we really have a choice to solve this problem using pure PHP code (no libraries)? Let's remember that we're "just" encrypting some "silly" session data, not the nuclear launch codes. Thanks!
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just an example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good enough as an example or session.
But not failure proof for corruption. Because "changing" the iv could produce a garbage/altered result and you would never notice, that's why authenticated encryption is so important, even if the risk is minimal here. You would still want to have a simple MAC to prevent (file-system) corruptions from breaking the application.