Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichaIng <micha@dietpi.com>2020-04-28 22:04:34 +0300
committerRoeland Jago Douma <roeland@famdouma.nl>2020-04-30 11:18:46 +0300
commitad606196554dadea49e5ddfa44fb54b89ba24d3e (patch)
tree8069559c81a3d7b7236485faa512c04318d9a37e
parenta1c1b354fcb79153a78a658b758acd514089c9e1 (diff)
Fix Argon2 options checks
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 <micha@dietpi.com> Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
-rw-r--r--lib/private/Security/Hasher.php15
-rw-r--r--tests/lib/Security/HasherTest.php5
2 files changed, 10 insertions, 10 deletions
diff --git a/lib/private/Security/Hasher.php b/lib/private/Security/Hasher.php
index 7a6c66d8f87..2ed21e7e427 100644
--- a/lib/private/Security/Hasher.php
+++ b/lib/private/Security/Hasher.php
@@ -67,16 +67,11 @@ class Hasher implements IHasher {
if (\defined('PASSWORD_ARGON2I')) {
// password_hash fails, when the minimum values are undershot.
- // In this case, ignore and revert to default
- if ($this->config->getSystemValueInt('hashingMemoryCost', PASSWORD_ARGON2_DEFAULT_MEMORY_COST) >= 8) {
- $this->options['memory_cost'] = $this->config->getSystemValueInt('hashingMemoryCost', PASSWORD_ARGON2_DEFAULT_MEMORY_COST);
- }
- if ($this->config->getSystemValueInt('hashingTimeCost', PASSWORD_ARGON2_DEFAULT_MEMORY_COST) >= 1) {
- $this->options['time_cost'] = $this->config->getSystemValueInt('hashingTimeCost', PASSWORD_ARGON2_DEFAULT_TIME_COST);
- }
- if ($this->config->getSystemValueInt('hashingThreads', PASSWORD_ARGON2_DEFAULT_MEMORY_COST) >= 1) {
- $this->options['threads'] = $this->config->getSystemValueInt('hashingThreads', PASSWORD_ARGON2_DEFAULT_THREADS);
- }
+ // In this case, apply minimum.
+ $this->options['threads'] = max($this->config->getSystemValueInt('hashingThreads', PASSWORD_ARGON2_DEFAULT_THREADS), 1);
+ // The minimum memory cost is 8 KiB per thread.
+ $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);
}
$hashingCost = $this->config->getSystemValue('hashingCost', null);
diff --git a/tests/lib/Security/HasherTest.php b/tests/lib/Security/HasherTest.php
index cc5cb786088..e1faef2f69b 100644
--- a/tests/lib/Security/HasherTest.php
+++ b/tests/lib/Security/HasherTest.php
@@ -113,6 +113,11 @@ class HasherTest extends \Test\TestCase {
$this->config = $this->createMock(IConfig::class);
+ $this->config->method('getSystemValueInt')
+ ->willReturnCallback(function ($name, $default) {
+ return $default;
+ });
+
$this->hasher = new Hasher($this->config);
}