Skip to content

Conversation

@MichaIng
Copy link
Member

@MichaIng MichaIng commented Apr 28, 2020

As of: #19023 (comment)

The minimum for memory cost is 8 KiB per thread. Threads must be checked and set first to allow checking against the correct memory cost mimimum.
Options are now applied the following way:

  • If config.php contains the setting with an integer higher or equal to the minimum, it is applied.
  • If config.php contains the setting with an integer lower than the minimum, the minimum is applied.
  • If config.php does not contain the setting or with no integer value, the PHP default is applied.

@MichaIng MichaIng added bug 2. developing Work in progress labels Apr 28, 2020
@MichaIng MichaIng added this to the Nextcloud 19 milestone Apr 28, 2020
@MichaIng MichaIng requested review from blizzz and kesselb April 28, 2020 19:14
@MichaIng MichaIng marked this pull request as draft April 28, 2020 19:16
@kesselb
Copy link
Contributor

kesselb commented Apr 28, 2020

Probably we should explicitly set the default (if PASSWORD_ARGON2_DEFAULT_THREADS is assured to be always set valid?) or the minimum 1 then, so options['threads'] is assure to be set and can be used in the memory cost arithmetic check?

I think so.

$this->options['threads'] = max($this->config->getSystemValueInt('hashingThreads', PASSWORD_ARGON2_DEFAULT_THREADS), 1);
$this->options['memory_cost'] = max($this->config->getSystemValueInt('hashingMemoryCost', PASSWORD_ARGON2_DEFAULT_MEMORY_COST), $this->options['threads'] * 8);
$this->options['time_cost'] = max($this->config->getSystemValueInt('hashingTimeCost', PASSWORD_ARGON2_DEFAULT_TIME_COST), 1);

Probably something like that. As long as we use the PASSWORD_ARGON2_DEFAULT* constants as fallback values we are good. But I don't know much about ARGON2 ;)

@rullzer rullzer mentioned this pull request Apr 29, 2020
11 tasks
@MichaIng
Copy link
Member Author

@kesselb
That looks actually like a great clean solution. I am no PHP code/syntax specialist but would just take it exactly like this. If the PASSWORD_ARGON2_DEFAULT* would not be present or invalid, the minimum values are the second fallback. The max() function takes the largest integer and does not fail in case one argument is empty or no integer, doesn't it?

@kesselb
Copy link
Contributor

kesselb commented Apr 29, 2020

The max() function takes the largest integer and does not fail in case one argument is empty or no integer, doesn't it?

I'm not sure but getSystemValueInt should always return an integer.

@MichaIng
Copy link
Member Author

MichaIng commented Apr 29, 2020

@kesselb
Makes sense to expect/enforce a valid integer as default value. I'll go through the code and PHP docs, just to be sure 😉.

EDIT:

Okay so all this is pretty failsafe.

@MichaIng MichaIng force-pushed the fix/argon2-options-checks branch 2 times, most recently from c908fd7 to 6123e68 Compare April 29, 2020 14:42
@MichaIng
Copy link
Member Author

MichaIng commented Apr 29, 2020

@kesselb
I added the PASSWORD_ARGON2_DEFAULT_* variables separatly to max() arguments as well. This way, if the config.php setting is set, but contains an invalid value or too low integer, the PASSWORD_ARGON2_DEFAULT_* (if set and valid) will be applied. Only if PASSWORD_ARGON2_DEFAULT_* is not set or invalid, the minimum will be applied.

@MichaIng MichaIng marked this pull request as ready for review April 29, 2020 14:47
@MichaIng MichaIng added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Apr 29, 2020
@kesselb
Copy link
Contributor

kesselb commented Apr 29, 2020

@kesselb
I added the PASSWORD_ARGON2_DEFAULT_* variables separatly to max() arguments as well. This way, if the config.php setting is set, but contains an invalid value or too low integer, the PASSWORD_ARGON2_DEFAULT_* (if set and valid) will be applied. Only if PASSWORD_ARGON2_DEFAULT_* is not set or invalid, the minimum will be applied.

That makes it impossible to pick a lower value than PASSWORD_ARGON2_DEFAULT_* 🤔

@kesselb
Copy link
Contributor

kesselb commented Apr 29, 2020

  1. getSystemValueInt will always return a integer. PASSWORD_ARGON2_DEFAULT_* as default or the value set in config.php.
  2. Make sure to use at least X as value.

That should cover most cases. Lets keep it simple ;)

@MichaIng
Copy link
Member Author

@kesselb

That makes it impossible to pick a lower value than PASSWORD_ARGON2_DEFAULT_* 🤔

Ah damn you're right. Also: https://www.php.net/manual/en/password.constants.php

The constants below are always available as part of the PHP core.

So no chance those are not set or invalid.

@MichaIng MichaIng force-pushed the fix/argon2-options-checks branch from 6123e68 to dd17608 Compare April 29, 2020 20:57
Copy link
Member

@rullzer rullzer left a comment

Choose a reason for hiding this comment

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

Makes sense.

@rullzer
Copy link
Member

rullzer commented Apr 30, 2020

CI says no...
I'll have a look

The minimum for memory cost is 8 KiB per thread. Threads must be checked and set first to allow checking against the correct memory cost mimimum.
Options are now applied the following way:
- If config.php contains the setting with an integer higher or equal to the minimum, it is applied.
- If config.php contains the setting with an integer lower than the minimum, the minimum is applied.
- If config.php does not contain the setting or with no integer value, the PHP default is applied.

Signed-off-by: MichaIng <[email protected]>
Signed-off-by: Roeland Jago Douma <[email protected]>
@rullzer rullzer force-pushed the fix/argon2-options-checks branch from dd17608 to ad60619 Compare April 30, 2020 08:19
@rullzer
Copy link
Member

rullzer commented Apr 30, 2020

Fixed the tests

@MorrisJobke MorrisJobke added 4. to release Ready to be released and/or waiting for tests to finish and removed 3. to review Waiting for reviews labels Apr 30, 2020
@rullzer rullzer merged commit 8d5404b into master Apr 30, 2020
@rullzer rullzer deleted the fix/argon2-options-checks branch April 30, 2020 12:42
@MichaIng
Copy link
Member Author

MichaIng commented May 1, 2020

/backport to stable18

@MichaIng
Copy link
Member Author

MichaIng commented May 1, 2020

/backport to stable17

@MichaIng
Copy link
Member Author

MichaIng commented May 1, 2020

/backport to stable16

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4. to release Ready to be released and/or waiting for tests to finish bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants