Skip to content

Commit 694f3e0

Browse files
authored
Merge pull request #20765 from nextcloud/backport/20710/stable16
[stable16] Fix Argon2 options checks
2 parents 4cc06f1 + b7f2f93 commit 694f3e0

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

lib/private/Security/Hasher.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,11 @@ public function __construct(IConfig $config) {
6363

6464
if (\defined('PASSWORD_ARGON2I')) {
6565
// password_hash fails, when the minimum values are undershot.
66-
// In this case, ignore and revert to default
67-
if ($this->config->getSystemValueInt('hashingMemoryCost', PASSWORD_ARGON2_DEFAULT_MEMORY_COST) >= 8) {
68-
$this->options['memory_cost'] = $this->config->getSystemValueInt('hashingMemoryCost', PASSWORD_ARGON2_DEFAULT_MEMORY_COST);
69-
}
70-
if ($this->config->getSystemValueInt('hashingTimeCost', PASSWORD_ARGON2_DEFAULT_MEMORY_COST) >= 1) {
71-
$this->options['time_cost'] = $this->config->getSystemValueInt('hashingTimeCost', PASSWORD_ARGON2_DEFAULT_TIME_COST);
72-
}
73-
if ($this->config->getSystemValueInt('hashingThreads', PASSWORD_ARGON2_DEFAULT_MEMORY_COST) >= 1) {
74-
$this->options['threads'] = $this->config->getSystemValueInt('hashingThreads', PASSWORD_ARGON2_DEFAULT_THREADS);
75-
}
66+
// In this case, apply minimum.
67+
$this->options['threads'] = max($this->config->getSystemValueInt('hashingThreads', PASSWORD_ARGON2_DEFAULT_THREADS), 1);
68+
// The minimum memory cost is 8 KiB per thread.
69+
$this->options['memory_cost'] = max($this->config->getSystemValueInt('hashingMemoryCost', PASSWORD_ARGON2_DEFAULT_MEMORY_COST), $this->options['threads'] * 8);
70+
$this->options['time_cost'] = max($this->config->getSystemValueInt('hashingTimeCost', PASSWORD_ARGON2_DEFAULT_TIME_COST), 1);
7671
}
7772

7873
$hashingCost = $this->config->getSystemValue('hashingCost', null);

tests/lib/Security/HasherTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ protected function setUp() {
102102

103103
$this->config = $this->createMock(IConfig::class);
104104

105+
$this->config->method('getSystemValueInt')
106+
->willReturnCallback(function ($name, $default) {
107+
return $default;
108+
});
109+
105110
$this->hasher = new Hasher($this->config);
106111
}
107112

0 commit comments

Comments
 (0)