]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix Argon2 options checks 20765/head
authorMichaIng <micha@dietpi.com>
Tue, 28 Apr 2020 19:04:34 +0000 (21:04 +0200)
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>
Fri, 1 May 2020 09:39:28 +0000 (09:39 +0000)
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>
lib/private/Security/Hasher.php
tests/lib/Security/HasherTest.php

index a65ecabb6204bd15cc55dd6af67693506ecd8ed8..a331a7eeddefc9c782166c128831950fc674af46 100644 (file)
@@ -63,16 +63,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);
index c994b68f781310c2ddb7fa25192cfa13d76b09fd..58d36ff54f7eebff38377b798c0b44c325f58af7 100644 (file)
@@ -102,6 +102,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);
        }