Skip to content

[2.2][Security] Outsource all the BCrypt heavy lifting to a library #7247

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
wants to merge 1 commit into from

Conversation

elnur
Copy link
Contributor

@elnur elnur commented Mar 3, 2013

Q A
Bug fix? [no]
New feature? [no]
BC breaks? [no]
Deprecations? [no]
Tests pass? [yes]
License MIT

The BCrypt bundle is already using the library.

@lsmith77
Copy link
Contributor

lsmith77 commented Mar 4, 2013

seems like a good idea.

/cc @ircmaxell

@gerryvdm
Copy link

gerryvdm commented Mar 4, 2013

-1, (out of principle) I'm not in favor of adding a dependency to the standard framework that defines functions in the global namespace, even if it is purely for BC. password-compat is at it's core a compatibility plugger, not a Bcrypt "heavy-lifter", and it's mostly made redundant by the core SecureRandom classes.

@fabpot
Copy link
Member

fabpot commented Mar 26, 2013

I agree with @gerryvdm. We spent quite some time on the SecureRandom class, with many eyes on it.

@fabpot fabpot closed this Mar 26, 2013
@elnur
Copy link
Contributor Author

elnur commented Mar 26, 2013

@fabpot, the library uses the PHP 5.5 simple password hashing API when available and falls back to mcrypt_create_iv() and openssl_random_pseudo_bytes() the way we do.

Are you sure we need to keep dealing with all that base64 stuff ourselves? Also we have to decide which bcrypt algorithm to use based on the PHP version. It feels like a hack. Why not rely on a de facto library for that?

Also, my bundle uses the library and I hoped I could tell its users they can abandon the bundle in favor of the built-in encoder, but without this commit I don't feel like it.

@ircmaxell
Copy link
Contributor

@fabpot I just took a look at the "SecureRandom" class, and it leaves a bit to be desired.

Check out these two blog posts for some reasons why:

http://blog.astrumfutura.com/2013/03/predicting-random-numbers-in-php-its-easier-than-you-think/

http://phpsecurity.readthedocs.org/en/latest/Insufficient-Entropy-For-Random-Values.html

I'll open a new ticket for that which details specific issues and recommendations.

However, I disagree with @gerryvdm on two points. First off, that reply is basically the definition of NIH syndrome. Second, this is not a "whatever you want to call it". It's a polyfill. If you use it, the encoder can simply not care what version of PHP you're on, and simply call the API. As it is now, your encoder has two unique execution paths (<=5.4 and >=5.5). Leveraging the polyfill will allow you to only maintain one path, and let the other fall to the 3pd maintainer.

It's not like you're doing something different from password_compat. In fact, you're calling the same API if it's available...

My $0.02 at least...

@elnur
Copy link
Contributor Author

elnur commented Apr 5, 2013

@fabpot, please reconsider.

@fabpot fabpot reopened this Apr 12, 2013
@asm89
Copy link
Contributor

asm89 commented Apr 12, 2013

What is the benefit of the lib? Crypt works fine? And the comments on SecureRandom, shouldn't we fix that class instead?

@elnur
Copy link
Contributor Author

elnur commented Apr 12, 2013

The benefit is to get a higher abstraction of working with BCrypt. The lower level we go, the higher chance there is of doing something wrong.

I thought the PHP community got cured of the NIH syndrome. 😉

@bendavies
Copy link
Contributor

has @ircmaxell expanded anywhere on his "leaves a bit to be desired" comment?

@@ -19,7 +19,8 @@
"php": ">=5.3.3",
"doctrine/common": "~2.2",
"twig/twig": "~1.11",
"psr/log": "~1.0"
"psr/log": "~1.0",
"ircmaxell/password-compat": "1.0.*"
Copy link
Member

Choose a reason for hiding this comment

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

it's not a requirement, only for testing, so it should be moved to the require-dev section.

@fabpot
Copy link
Member

fabpot commented Apr 25, 2013

@ircmaxell I've decided to actually used your library in Symfony (see #7853). You mentioned some problems with our SecureRandom class, can you open a ticket for this? Thanks.

Closing in favor of #7853

@fabpot fabpot closed this Apr 25, 2013
fabpot added a commit that referenced this pull request Apr 25, 2013
This PR was merged into the master branch.

Discussion
----------

[Security] Outsource all the BCrypt heavy lifting to a library

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | yes
| Deprecations? | no
| Tests pass?   | yes
| License       | MIT

The [BCrypt bundle](https://github.com/elnur/ElnurBlowfishPasswordEncoderBundle) is already using the library.

This is a working implementation of #7247

Commits
-------

c83546d [Security] tweaked previous commit
b2e553a Outsource all the BCrypt heavy lifting to a library
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.

7 participants