-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Security] Add configuration for Argon2i encryption #26175
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
[Security] Add configuration for Argon2i encryption #26175
Conversation
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.
thanks for working on this
would you mind adding some tests please?
/** | ||
* Argon2iPasswordEncoder constructor. | ||
* | ||
* @param int $memoryCost |
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.
since this is for PHP 7.1, you can move the types to the constructor's signature, and remove the docblock altogether.
{ | ||
if (\defined('PASSWORD_ARGON2I')) { | ||
$this->config = array( | ||
'memory_cost' => $memoryCost ?: PASSWORD_ARGON2_DEFAULT_MEMORY_COST, |
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.
?? instead of ?: (same below)
@nicolas-grekas Ready for next review. |
SecurityBundle also needs an update, so that you can configure these settings using yaml. |
$this->config = array( | ||
'memory_cost' => $memoryCost ?? PASSWORD_ARGON2_DEFAULT_MEMORY_COST, | ||
'time_cost' => $timeCost ?? PASSWORD_ARGON2_DEFAULT_TIME_COST, | ||
'threads' => $threads ?? PASSWORD_ARGON2_DEFAULT_THREADS, |
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.
we could fully-qualify these constants though (as we do in encodePasswordNative
)
is it possible to support this config when using ext-sodium on older versions too ? |
@stof There are I can't say how these 2 parameters are related to |
@@ -385,6 +385,9 @@ private function addEncodersSection(ArrayNodeDefinition $rootNode) | |||
->max(31) | |||
->defaultValue(13) | |||
->end() | |||
->integerNode('memory_cost')->setDefaultValue(1024)->end() |
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.
defaultNull instead?
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.
You are right. Fixed it.
|
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.
Should it throw when configuring these options while they aren't supported?
|
||
public function __construct(int $memoryCost = null, int $timeCost = null, int $threads = null) | ||
{ | ||
if (\defined('PASSWORD_ARGON2I')) { |
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.
these options are used in encodePasswordNative only which is restricted to php 7.2+, we should probably have the same check here
*/ | ||
class Argon2iPasswordEncoder extends BasePasswordEncoder implements SelfSaltingEncoderInterface | ||
{ | ||
private $config; |
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 default value should be array()
, otherwise password_hash($raw, \PASSWORD_ARGON2I, $this->config);
will throw a warning
this should cover @chalasr's comment below
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.
Thanks. Done.
almost there, tests should be updated (see failures) |
@nicolas-grekas The tests should now run successfully. But the runners fail on installing the libsodium extension. Do you know why? |
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.
failures related to pecl.php.net being down today
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.
oups sorry I voted too fast: the test suite should still pass when the libsodium is not installed, by skipping the cases that require the extension
I suppose you'll need to split the new functional tests in dedicated test methods, and add them the |
Thank you @CoalaJoe. |
…oalaJoe) This PR was merged into the 4.1-dev branch. Discussion ---------- [Security] Add configuration for Argon2i encryption | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #26174 | License | MIT | Doc PR | [#9300](symfony/symfony-docs#9300) Feedback? Current situation: Configuration only applies if argon2i is natively supported. Commits ------- 1300fec [Security] Add configuration for Argon2i encryption
This PR was merged into the master branch. Discussion ---------- Update configuration for argon2i encoder From: symfony/symfony#26175 Commits ------- a3e9bf2 Update configuration for argon2i encoder
Feedback?
Current situation: Configuration only applies if argon2i is natively supported.