Skip to content

Commit d773528

Browse files
committed
Hash HMAC algo
1 parent 7e9af00 commit d773528

18 files changed

Lines changed: 330 additions & 48 deletions

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1212
- Allow email login option
1313
- UID user table column
1414
- GID user table column
15+
- HMAC hash implementation
1516

1617
## [4.4.1] - 2020-02-02
1718
### Fixed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ Argon2i (Crypt) | Requires PHP >= 7.2. See [password_hash](http://php.net/manual
199199
Argon2id (Crypt) | Requires PHP >= 7.2. See [password_hash](http://php.net/manual/en/function.password-hash.php). | $argon2id$v=19$m=65536,t=4,p=1$eWhTd3huemlhNGFkWTVSSQ$BjSh9PINc9df9WU1zppBsYJKvkwUEYHYNUUMTj+QGPw
200200
Blowfish (Crypt) | See [password_hash](http://php.net/manual/en/function.password-hash.php). | $2y$10$5rsN1fmoSkaRy9bqhozAXOr0mn0QiVIfd2L04Bbk1Go9MjdvotwBq
201201
Extended DES (Crypt) | | cDRpdxPmHpzS.
202+
Hash HMAC | See [hash_hmac](https://www.php.net/manual/en/function.hash-hmac.php). | ba4f8624f0a4d1f2a3991f4d88cd9afb604dac20
202203
MD5 (Crypt) | | $1$RzaFbNcU$u9adfTY/Q6za6nu0Ogrl1/
203204
SHA256 (Crypt) | | $5$rounds=5000$VIYD0iHkg7uY9SRc$v2XLS/9dvfFN84mzGvW9wxnVt9Xd/urXaaTkpW8EwD1
204205
SHA512 (Crypt) | | $6$rounds=5000$yH.Q0OL4qbCOUJ3q$Xry5EVFva3wKnfo8/ktrugmBd8tcl34NK6rXInv1HhmdSUNLEm0La9JnA57rqwQ.9/Bz513MD4tvmmISLUIHs/

js/settings.js

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,41 @@ user_sql.adminSettingsUI = function () {
7676
var param = $("<div></div>");
7777
var label = $("<label></label>").attr({for: "opt-crypto_param_" + index});
7878
var title = $("<span></span>").text(data.data[index]["name"]);
79-
var input = $("<input/>").attr({
80-
type: "number",
81-
id: "opt-crypto_param_" + index,
82-
name: "opt-crypto_param_" + index,
83-
step: 1,
84-
min: data.data[index]["min"],
85-
max: data.data[index]["max"],
86-
value: data.data[index]["value"]
87-
});
79+
80+
var input = null;
81+
switch (data.data[index]["type"]) {
82+
case "choice":
83+
input = $("<select/>").attr({
84+
id: "opt-crypto_param_" + index,
85+
name: "opt-crypto_param_" + index,
86+
});
87+
data.data[index]["choices"].forEach(
88+
function (item) {
89+
if (data.data[index]["value"] === item) {
90+
input.append($("<option/>").attr({
91+
value: item,
92+
selected: "selected"
93+
}).text(item));
94+
} else {
95+
input.append($("<option/>").attr({value: item}).text(item));
96+
}
97+
}
98+
);
99+
break;
100+
case "int":
101+
input = $("<input/>").attr({
102+
type: "number",
103+
id: "opt-crypto_param_" + index,
104+
name: "opt-crypto_param_" + index,
105+
step: 1,
106+
min: data.data[index]["min"],
107+
max: data.data[index]["max"],
108+
value: data.data[index]["value"]
109+
});
110+
break;
111+
default:
112+
break;
113+
}
88114

89115
label.append(title);
90116
param.append(label);

lib/Controller/SettingsController.php

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
use OCA\UserSQL\Constant\DB;
3232
use OCA\UserSQL\Constant\Opt;
3333
use OCA\UserSQL\Crypto\IPasswordAlgorithm;
34+
use OCA\UserSQL\Crypto\Param\ChoiceParam;
35+
use OCA\UserSQL\Crypto\Param\IntParam;
3436
use OCA\UserSQL\Platform\PlatformFactory;
3537
use OCA\UserSQL\Properties;
3638
use OCP\AppFramework\Controller;
@@ -77,8 +79,7 @@ class SettingsController extends Controller
7779
public function __construct(
7880
$appName, IRequest $request, ILogger $logger, IL10N $localization,
7981
Properties $properties, Cache $cache
80-
)
81-
{
82+
) {
8283
parent::__construct($appName, $request);
8384
$this->appName = $appName;
8485
$this->logger = $logger;
@@ -267,13 +268,23 @@ private function validateCryptoParams()
267268
$reqParam = $this->request->getParam(
268269
"opt-crypto_param_" . $i, null
269270
);
270-
$cryptoParam = $configuration[$i];
271-
272-
if (is_null($reqParam) || $reqParam < $cryptoParam->min
273-
|| $reqParam > $cryptoParam->max
274-
) {
271+
if (is_null($reqParam)) {
275272
return false;
276273
}
274+
275+
$cryptoParam = $configuration[$i];
276+
switch ($cryptoParam->type) {
277+
case ChoiceParam::TYPE:
278+
if (!in_array($reqParam, $cryptoParam->choices)) {
279+
return false;
280+
}
281+
break;
282+
case IntParam::TYPE:
283+
if ($reqParam < $cryptoParam->min || $reqParam > $cryptoParam->max) {
284+
return false;
285+
}
286+
break;
287+
}
277288
}
278289

279290
return true;

lib/Crypto/CryptArgon2.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
namespace OCA\UserSQL\Crypto;
2323

24+
use OCA\UserSQL\Crypto\Param\IntParam;
2425
use OCP\IL10N;
2526

2627
/**
@@ -106,14 +107,14 @@ public function getPasswordHash($password, $salt = null)
106107
public function configuration()
107108
{
108109
return [
109-
new CryptoParam(
110+
new IntParam(
110111
"Memory cost (KiB)", PASSWORD_ARGON2_DEFAULT_MEMORY_COST, 1,
111112
1048576
112113
),
113-
new CryptoParam(
114+
new IntParam(
114115
"Time cost", PASSWORD_ARGON2_DEFAULT_TIME_COST, 1, 1024
115116
),
116-
new CryptoParam("Threads", PASSWORD_ARGON2_DEFAULT_THREADS, 1, 1024)
117+
new IntParam("Threads", PASSWORD_ARGON2_DEFAULT_THREADS, 1, 1024)
117118
];
118119
}
119120

lib/Crypto/CryptArgon2id.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
namespace OCA\UserSQL\Crypto;
2323

24+
use OCA\UserSQL\Crypto\Param\IntParam;
2425
use OCP\IL10N;
2526

2627
/**
@@ -92,7 +93,7 @@ public function checkPassword($password, $dbHash, $salt = null)
9293
public function getPasswordHash($password, $salt = null)
9394
{
9495
return password_hash(
95-
$password, PASSWORD_ARGON2ID, [
96+
$password, PASSWORD_ARGON2ID, [
9697
"memory_cost" => $this->memoryCost,
9798
"time_cost" => $this->timeCost,
9899
"threads" => $this->threads
@@ -106,14 +107,14 @@ public function getPasswordHash($password, $salt = null)
106107
public function configuration()
107108
{
108109
return [
109-
new CryptoParam(
110+
new IntParam(
110111
"Memory cost (KiB)", PASSWORD_ARGON2_DEFAULT_MEMORY_COST, 1,
111112
1048576
112113
),
113-
new CryptoParam(
114+
new IntParam(
114115
"Time cost", PASSWORD_ARGON2_DEFAULT_TIME_COST, 1, 1024
115116
),
116-
new CryptoParam("Threads", PASSWORD_ARGON2_DEFAULT_THREADS, 1, 1024)
117+
new IntParam("Threads", PASSWORD_ARGON2_DEFAULT_THREADS, 1, 1024)
117118
];
118119
}
119120

lib/Crypto/CryptBlowfish.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
namespace OCA\UserSQL\Crypto;
2323

24+
use OCA\UserSQL\Crypto\Param\IntParam;
2425
use OCP\IL10N;
2526

2627
/**
@@ -72,7 +73,7 @@ public function getPasswordHash($password, $salt = null)
7273
*/
7374
public function configuration()
7475
{
75-
return [new CryptoParam("Cost", 10, 4, 31)];
76+
return [new IntParam("Cost", 10, 4, 31)];
7677
}
7778

7879
/**

lib/Crypto/CryptExtendedDES.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
namespace OCA\UserSQL\Crypto;
2323

24+
use OCA\UserSQL\Crypto\Param\IntParam;
2425
use OCP\IL10N;
2526

2627
/**
@@ -53,7 +54,7 @@ public function __construct(IL10N $localization, $iterationCount = 1000)
5354
*/
5455
public function configuration()
5556
{
56-
return [new CryptoParam("Iterations", 1000, 0, 16777215)];
57+
return [new IntParam("Iterations", 1000, 0, 16777215)];
5758
}
5859

5960
/**

lib/Crypto/CryptSHA256.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
namespace OCA\UserSQL\Crypto;
2323

24+
use OCA\UserSQL\Crypto\Param\IntParam;
2425
use OCP\IL10N;
2526

2627
/**
@@ -40,7 +41,7 @@ class CryptSHA256 extends AbstractCrypt
4041
* The class constructor.
4142
*
4243
* @param IL10N $localization The localization service.
43-
* @param int $rounds The number of rounds.
44+
* @param int $rounds The number of rounds.
4445
* This value must be between 1000 and 999999999.
4546
*/
4647
public function __construct(IL10N $localization, $rounds = 5000)
@@ -54,7 +55,7 @@ public function __construct(IL10N $localization, $rounds = 5000)
5455
*/
5556
public function configuration()
5657
{
57-
return [new CryptoParam("Rounds", 5000, 1000, 999999999)];
58+
return [new IntParam("Rounds", 5000, 1000, 999999999)];
5859
}
5960

6061
/**

lib/Crypto/CryptSHA512.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
namespace OCA\UserSQL\Crypto;
2323

24+
use OCA\UserSQL\Crypto\Param\IntParam;
2425
use OCP\IL10N;
2526

2627
/**
@@ -40,7 +41,7 @@ class CryptSHA512 extends AbstractCrypt
4041
* The class constructor.
4142
*
4243
* @param IL10N $localization The localization service.
43-
* @param int $rounds The number of rounds.
44+
* @param int $rounds The number of rounds.
4445
* This value must be between 1000 and 999999999.
4546
*/
4647
public function __construct(IL10N $localization, $rounds = 5000)
@@ -54,7 +55,7 @@ public function __construct(IL10N $localization, $rounds = 5000)
5455
*/
5556
public function configuration()
5657
{
57-
return [new CryptoParam("Rounds", 5000, 1000, 999999999)];
58+
return [new IntParam("Rounds", 5000, 1000, 999999999)];
5859
}
5960

6061
/**

0 commit comments

Comments
 (0)