-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -394,9 +394,10 @@ private function addEncodersSection(ArrayNodeDefinition $rootNode) | |
->children() | ||
->arrayNode('encoders') | ||
->example([ | ||
'App\Entity\User1' => 'bcrypt', | ||
'App\Entity\User1' => 'auto', | ||
'App\Entity\User2' => [ | ||
'algorithm' => 'bcrypt', | ||
'algorithm' => 'auto', | ||
'time_cost' => 8, | ||
'cost' => 13, | ||
], | ||
]) | ||
|
@@ -416,11 +417,14 @@ private function addEncodersSection(ArrayNodeDefinit 10000 ion $rootNode) | |
->integerNode('cost') | ||
->min(4) | ||
->max(31) | ||
->defaultValue(13) | ||
->defaultNull() | ||
->end() | ||
->scalarNode('memory_cost')->defaultNull()->end() | ||
->scalarNode('time_cost')->defaultNull()->end() | ||
->scalarNode('threads')->defaultNull()->end() | ||
->scalarNode('threads') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. libsodium hardcodes threads to 1, and this makes sense in PHP too. |
||
->defaultNull() | ||
->setDeprecated('The "%path%.%node%" configuration key has no effect since Symfony 4.3 and will be removed in 5.0.') | ||
->end() | ||
->scalarNode('id')->end() | ||
->end() | ||
->end() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ | |
use Symfony\Component\HttpKernel\DependencyInjection\Extension; | ||
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface; | ||
use Symfony\Component\Security\Core\Encoder\Argon2iPasswordEncoder; | ||
use Symfony\Component\Security\Core\Encoder\NativePasswordEncoder; | ||
use Symfony\Component\Security\Core\Encoder\SodiumPasswordEncoder; | ||
use Symfony\Component\Security\Core\User\UserProviderInterface; | ||
use Symfony\Component\Security\Http\Controller\UserValueResolver; | ||
|
@@ -559,20 +560,20 @@ private function createEncoder($config, ContainerBuilder $container) | |
if ('bcrypt' === $config['algorithm']) { | ||
return [ | ||
'class' => 'Symfony\Component\Security\Core\Encoder\BCryptPasswordEncoder', | ||
'arguments' => [$config['cost']], | ||
'arguments' => [$config['cost'] ?? 13], | ||
]; | ||
} | ||
|
||
// Argon2i encoder | ||
if ('argon2i' === $config['algorithm']) { | ||
@trigger_error('Configuring an encoder with "argon2i" as algorithm is deprecated since Symfony 4.3, use "sodium" instead.', E_USER_DEPRECATED); | ||
@trigger_error('Configuring an encoder with "argon2i" as algorithm is deprecated since Symfony 4.3, use "auto" instead.', E_USER_DEPRECATED); | ||
nicolas-grekas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if (!Argon2iPasswordEncoder::isSupported()) { | ||
if (\extension_loaded('sodium') && !\defined('SODIUM_CRYPTO_PWHASH_SALTBYTES')) { | ||
throw new InvalidConfigurationException('The installed libsodium version does not have support for Argon2i. Use Bcrypt instead.'); | ||
throw new InvalidConfigurationException('The installed libsodium version does not have support for Argon2i. Use "auto" instead.'); | ||
} | ||
|
||
throw new InvalidConfigurationException('Argon2i algorithm is not supported. Install the libsodium extension or use BCrypt instead.'); | ||
throw new InvalidConfigurationException('Argon2i algorithm is not supported. Install the libsodium extension or use "auto" instead.'); | ||
} | ||
|
||
return [ | ||
|
@@ -585,14 +586,28 @@ private function createEncoder($config, ContainerBuilder $container) | |
]; | ||
} | ||
|
||
if ('native' === $config['algorithm']) { | ||
return [ | ||
'class' => NativePasswordEncoder::class, | ||
'arguments' => [ | ||
$config['time_cost'], | ||
(($config['memory_cost'] ?? 0) << 10) ?: null, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. memory_cost (from password_hash) is in |
||
$config['cost'], | ||
], | ||
]; | ||
} | ||
|
||
if ('sodium' === $config['algorithm']) { | ||
if (!SodiumPasswordEncoder::isSupported()) { | ||
throw new InvalidConfigurationException('Libsodium is not available. Install the sodium extension or use BCrypt instead.'); | ||
throw new InvalidConfigurationException('Libsodium is not available. Install the sodium extension or use "auto" instead.'); | ||
} | ||
|
||
return [ | ||
'class' => SodiumPasswordEncoder::class, | ||
'arguments' => [], | ||
'arguments' => [ | ||
$config['time_cost'], | ||
(($config['memory_cost'] ?? 0) << 10) ?: null, | ||
], | ||
]; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,5 @@ security: | |
encoders: | ||
JMS\FooBundle\Entity\User7: | ||
algorithm: sodium | ||
time_cost: 8 | ||
memory_cost: 131072 |
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.
The defaults belong to the implementation now, not to the configuration.