Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Security] Add NativePasswordEncoder#31140

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
chalasr merged 1 commit intosymfony:masterfromnicolas-grekas:sec-encoder-native
Apr 18, 2019

Conversation

@nicolas-grekas
Copy link
Member

QA
Branch?master
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets-
LicenseMIT
Doc PR-

This PR adds a newNativePasswordEncoder that defaults to the best available hashing algo topassword_hash(). Best is determined by "us" or "php", the goal being that this will change in the future as new algos are published.

This provides a native encoder that we should recommend using by default.

dmaicher, hhamon, and chalasr reacted with thumbs up emoji
@nicolas-grekas
Copy link
MemberAuthor

nicolas-grekas commentedApr 17, 2019
edited
Loading

Todo:

  • fix tests
  • update SecurityExtension
  • find a default cost for Argon2 that is at least as good as13 for Bcrypt's (any idea?)

@ro0NL
Copy link
Contributor

is there any reason to keepBCryptPasswordEncoder?

@nicolas-grekas
Copy link
MemberAuthor

is there any reason to keep BCryptPasswordEncoder?

I don't think so, we should deprecate it in 4.4

ro0NL reacted with thumbs up emoji

@nicolas-grekasnicolas-grekasforce-pushed thesec-encoder-native branch 3 times, most recently fromadcef7e to40f1dafCompareApril 17, 2019 14:12
Copy link
MemberAuthor

@nicolas-grekasnicolas-grekas left a comment

Choose a reason for hiding this comment

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

PR ready

->min(4)
->max(31)
->defaultValue(13)
->defaultNull()
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

The defaults belong to the implementation now, not to the configuration.

->scalarNode('memory_cost')->defaultNull()->end()
->scalarNode('time_cost')->defaultNull()->end()
->scalarNode('threads')->defaultNull()->end()
->scalarNode('threads')
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

libsodium hardcodes threads to 1, and this makes sense in PHP too.

returnnewReference($config['id']);
}

if ('auto' ===$config['algorithm']) {
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

"auto" should be the recommended default - I'm going to submit it as a recipe

weaverryan and hhamon reacted with thumbs up emojiro0NL reacted with heart emoji
'class' => NativePasswordEncoder::class,
'arguments' => [
$config['time_cost'],
(($config['memory_cost'] ??0) <<10) ?:null,
Copy link
MemberAuthor

@nicolas-grekasnicolas-grekasApr 17, 2019
edited
Loading

Choose a reason for hiding this comment

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

memory_cost (from password_hash) is inkib but SodiumPasswordEncoder and NativePasswordEncoder accept bytes - this makes the conversion

{
$cost =$cost ??13;
$opsLimit =$opsLimit ??max(6,\defined('SODIUM_CRYPTO_PWHASH_OPSLIMIT_MODERATE') ? \SODIUM_CRYPTO_PWHASH_OPSLIMIT_MODERATE :6);
$memLimit =$memLimit ??max(64 *1024 *1024,\defined('SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE') ? \SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE :64 *1024 *1024);
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Argon2 with opslimit = 6 & memlimit=64MiB roughly operate in the same amount of time as BCrypt's cost=13
Also, in PHP7.4 SODIUM_CRYPTO_PWHASH_OPSLIMIT_MODERATE=6 and SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE=32MiB
So our defaults are a bit more strict than PHP 7.4, which matches the fact that a cost=13 for BCrypt is stricter than PHP's default.

ro0NL reacted with heart emoji

Choose a reason for hiding this comment

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

Just wondering about using SODIUM Constants in the Native Encoder, as what happens if PHP >7.2 but Sodium is NOT installed. Native should work?

Copy link
Member

@chalasrchalasrMay 31, 2019
edited
Loading

Choose a reason for hiding this comment

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

The code above checks thatSODUM_* constants are defined before using them, and fallback to sensible defaults (equivalent hardcoded values) otherwise

thrownew \InvalidArgumentException('$cost must be in the range of 4-31.');
}

$this->algo =\defined('PASSWORD_ARGON2I') ?max(PASSWORD_DEFAULT,\defined('PASSWORD_ARGON2ID') ?PASSWORD_ARGON2ID :PASSWORD_ARGON2I) :PASSWORD_DEFAULT;
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

PASSWORD_ARGON2ID > PASSWORD_ARGON2I > PASSWORD_BCRYPT, unless PASSWORD_DEFAULT is set to an even higher algo in the future

Copy link
Contributor

Choose a reason for hiding this comment

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

So if the argon algo is available the native encoder and the sodium encoder basically do the same thing?

I am wondering if it would be better for DX to use only PASSWORD_DEFAULT in the native encoder.

Then the config would become:
auto => use best supported / recommended encoder
native => use php default algo
sodium => use best supported / available sodium algo

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I think always using the best available algo is required for best security. I don't understand how that relates to DX.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think always using the best available algo is required for best security.

Agreed.

I don't understand how that relates to DX.

I just think it might be confusing that there are 2 encoders that can do the same thing (encode with the argon algo).

}

if ('auto' ===$config['algorithm']) {
$config['algorithm'] = SodiumPasswordEncoder::isSupported() ?'sodium' :'native';
Copy link
Member

Choose a reason for hiding this comment

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

is the sodium encoder superior to our native encoder? Is that why it's preferred?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

yes, in two aspects: it is faster for the same cost parameters, and it can be more up to date than the native one, as an extension can move faster to new algos.

Copy link
Member

Choose a reason for hiding this comment

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

being faster for the same cost may not actually be superior. The whole point of a password hashing algorithm is that it should not be too fast.

ro0NL reacted with thumbs up emoji
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

being faster for the same cost may not actually be superior. The whole point of a password hashing algorithm is that it should not be too fast.

this answer is wrong ;)
what matters is thatattackers must spend significant resources to compute password hashes when they leaked. Being faster for the same cost is just improving UX and reducing greenhouse emissions. So yes, it matters a lot.

@nicolas-grekasnicolas-grekasforce-pushed thesec-encoder-native branch 2 times, most recently from4fcca31 to6aa50d1CompareApril 17, 2019 19:19
@chalasr
Copy link
Member

Thank you@nicolas-grekas.

@chalasrchalasr merged commit28f7961 intosymfony:masterApr 18, 2019
chalasr pushed a commit that referenced this pull requestApr 18, 2019
This PR was merged into the 4.3-dev branch.Discussion----------[Security] Add NativePasswordEncoder| Q             | A| ------------- | ---| Branch?       | master| Bug fix?      | no| New feature?  | yes| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets | -| License       | MIT| Doc PR        | -This PR adds a new `NativePasswordEncoder` that defaults to the best available hashing algo to `password_hash()`. Best is determined by "us" or "php", the goal being that this will change in the future as new algos are published.This provides a native encoder that we should recommend using by default.Commits-------28f7961 [Security] Add NativePasswordEncoder
@nicolas-grekasnicolas-grekas deleted the sec-encoder-native branchApril 18, 2019 14:01
chalasr pushed a commit that referenced this pull requestApr 19, 2019
… NativePasswordEncoder (nicolas-grekas)This PR was merged into the 4.3-dev branch.Discussion----------[Security] deprecate BCryptPasswordEncoder in favor of NativePasswordEncoder| Q             | A| ------------- | ---| Branch?       | master| Bug fix?      | no| New feature?  | no| BC breaks?    | no| Deprecations? | yes| Tests pass?   | yes| Fixed tickets | -| License       | MIT| Doc PR        | -Follow up of#31140Commits-------e197398 [Security] deprecate BCryptPasswordEncoder in favor of NativePasswordEncoder
@nicolas-grekasnicolas-grekas modified the milestones:next,4.3Apr 30, 2019
@fabpotfabpot mentioned this pull requestMay 9, 2019
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@stofstofstof left review comments

@chalasrchalasrchalasr approved these changes

@weaverryanweaverryanweaverryan approved these changes

+3 more reviewers

@rosierrosierrosier left review comments

@craynercraynercrayner left review comments

@ro0NLro0NLro0NL approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

4.3

Development

Successfully merging this pull request may close these issues.

8 participants

@nicolas-grekas@ro0NL@chalasr@rosier@weaverryan@stof@crayner@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp