Skip to content

Commit d6150f9

Browse files
committed
Getting crypto parameters
1 parent 04e06bf commit d6150f9

2 files changed

Lines changed: 42 additions & 26 deletions

File tree

lib/Constant/Opt.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ final class Opt
3131
const APPEND_SALT = "opt.append_salt";
3232
const CASE_INSENSITIVE_USERNAME = "opt.case_insensitive_username";
3333
const CRYPTO_CLASS = "opt.crypto_class";
34+
const CRYPTO_PARAM_0 = "opt.crypto_param_0";
35+
const CRYPTO_PARAM_1 = "opt.crypto_param_1";
36+
const CRYPTO_PARAM_2 = "opt.crypto_param_2";
3437
const EMAIL_SYNC = "opt.email_sync";
3538
const HOME_LOCATION = "opt.home_location";
3639
const HOME_MODE = "opt.home_mode";

lib/Controller/SettingsController.php

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,16 @@
2828
use OC\DB\ConnectionFactory;
2929
use OCA\UserSQL\Cache;
3030
use OCA\UserSQL\Constant\App;
31+
use OCA\UserSQL\Constant\Opt;
32+
use OCA\UserSQL\Crypto\IPasswordAlgorithm;
3133
use OCA\UserSQL\Platform\PlatformFactory;
3234
use OCA\UserSQL\Properties;
3335
use OCP\AppFramework\Controller;
3436
use OCP\IL10N;
3537
use OCP\ILogger;
3638
use OCP\IRequest;
39+
use ReflectionClass;
40+
use ReflectionException;
3741

3842
/**
3943
* The settings controller.
@@ -72,7 +76,8 @@ class SettingsController extends Controller
7276
public function __construct(
7377
$appName, IRequest $request, ILogger $logger, IL10N $localization,
7478
Properties $properties, Cache $cache
75-
) {
79+
)
80+
{
7681
parent::__construct($appName, $request);
7782
$this->appName = $appName;
7883
$this->logger = $logger;
@@ -369,34 +374,42 @@ public function groupTableAutocomplete()
369374
}
370375

371376
/**
372-
* TODO
377+
* Get parameters for a password algorithm.
373378
*
374-
* @return array TODO
379+
* @return array Password algorithm parameters.
380+
* @throws ReflectionException Whenever Opt class cannot be initiated.
375381
*/
376382
public function cryptoParams()
377383
{
378-
sleep(3);
379-
// TODO implement
380-
// TODO add current values
381-
return [
382-
"status" => "success",
383-
"data" => [
384-
[
385-
"name" => "Memory cost (KiB)",
386-
"value" => PASSWORD_ARGON2_DEFAULT_MEMORY_COST,
387-
"min" => 1, "max" => 1048576
388-
],
389-
[
390-
"name" => "Time cost",
391-
"value" => PASSWORD_ARGON2_DEFAULT_TIME_COST, "min" => 1,
392-
"max" => 1024
393-
],
394-
[
395-
"name" => "Threads",
396-
"value" => PASSWORD_ARGON2_DEFAULT_THREADS, "min" => 1,
397-
"max" => 1024
398-
]
399-
]
400-
];
384+
$this->logger->debug(
385+
"Entering cryptoParams()", ["app" => $this->appName]
386+
);
387+
388+
/**
389+
* @var $passwordAlgorithm IPasswordAlgorithm
390+
*/
391+
$cryptoClass = $this->request->getParam("cryptoClass");
392+
$passwordAlgorithm = new $cryptoClass($this->localization);
393+
$configuration = $passwordAlgorithm->configuration();
394+
395+
if ($cryptoClass === $this->properties[Opt::CRYPTO_CLASS]) {
396+
foreach ($configuration as $key => $value) {
397+
$opt = new ReflectionClass("OCA\UserSQL\Constant\Opt");
398+
$param = $this->properties[$opt->getConstant(
399+
"CRYPTO_PARAM_" . $key
400+
)];
401+
402+
if (!empty($param)) {
403+
$value->value = $param;
404+
}
405+
}
406+
}
407+
408+
$this->logger->debug(
409+
"Returning cryptoParams(): count(" . count($configuration) . ")",
410+
["app" => $this->appName]
411+
);
412+
413+
return ["status" => "success", "data" => (array)$configuration];
401414
}
402415
}

0 commit comments

Comments
 (0)