Getting crypto parameters
This commit is contained in:
@@ -31,6 +31,9 @@ final class Opt
|
|||||||
const APPEND_SALT = "opt.append_salt";
|
const APPEND_SALT = "opt.append_salt";
|
||||||
const CASE_INSENSITIVE_USERNAME = "opt.case_insensitive_username";
|
const CASE_INSENSITIVE_USERNAME = "opt.case_insensitive_username";
|
||||||
const CRYPTO_CLASS = "opt.crypto_class";
|
const CRYPTO_CLASS = "opt.crypto_class";
|
||||||
|
const CRYPTO_PARAM_0 = "opt.crypto_param_0";
|
||||||
|
const CRYPTO_PARAM_1 = "opt.crypto_param_1";
|
||||||
|
const CRYPTO_PARAM_2 = "opt.crypto_param_2";
|
||||||
const EMAIL_SYNC = "opt.email_sync";
|
const EMAIL_SYNC = "opt.email_sync";
|
||||||
const HOME_LOCATION = "opt.home_location";
|
const HOME_LOCATION = "opt.home_location";
|
||||||
const HOME_MODE = "opt.home_mode";
|
const HOME_MODE = "opt.home_mode";
|
||||||
|
|||||||
@@ -28,12 +28,16 @@ use OC\DB\Connection;
|
|||||||
use OC\DB\ConnectionFactory;
|
use OC\DB\ConnectionFactory;
|
||||||
use OCA\UserSQL\Cache;
|
use OCA\UserSQL\Cache;
|
||||||
use OCA\UserSQL\Constant\App;
|
use OCA\UserSQL\Constant\App;
|
||||||
|
use OCA\UserSQL\Constant\Opt;
|
||||||
|
use OCA\UserSQL\Crypto\IPasswordAlgorithm;
|
||||||
use OCA\UserSQL\Platform\PlatformFactory;
|
use OCA\UserSQL\Platform\PlatformFactory;
|
||||||
use OCA\UserSQL\Properties;
|
use OCA\UserSQL\Properties;
|
||||||
use OCP\AppFramework\Controller;
|
use OCP\AppFramework\Controller;
|
||||||
use OCP\IL10N;
|
use OCP\IL10N;
|
||||||
use OCP\ILogger;
|
use OCP\ILogger;
|
||||||
use OCP\IRequest;
|
use OCP\IRequest;
|
||||||
|
use ReflectionClass;
|
||||||
|
use ReflectionException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The settings controller.
|
* The settings controller.
|
||||||
@@ -72,7 +76,8 @@ class SettingsController extends Controller
|
|||||||
public function __construct(
|
public function __construct(
|
||||||
$appName, IRequest $request, ILogger $logger, IL10N $localization,
|
$appName, IRequest $request, ILogger $logger, IL10N $localization,
|
||||||
Properties $properties, Cache $cache
|
Properties $properties, Cache $cache
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
parent::__construct($appName, $request);
|
parent::__construct($appName, $request);
|
||||||
$this->appName = $appName;
|
$this->appName = $appName;
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
@@ -369,34 +374,42 @@ class SettingsController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO
|
* Get parameters for a password algorithm.
|
||||||
*
|
*
|
||||||
* @return array TODO
|
* @return array Password algorithm parameters.
|
||||||
|
* @throws ReflectionException Whenever Opt class cannot be initiated.
|
||||||
*/
|
*/
|
||||||
public function cryptoParams()
|
public function cryptoParams()
|
||||||
{
|
{
|
||||||
sleep(3);
|
$this->logger->debug(
|
||||||
// TODO implement
|
"Entering cryptoParams()", ["app" => $this->appName]
|
||||||
// TODO add current values
|
);
|
||||||
return [
|
|
||||||
"status" => "success",
|
/**
|
||||||
"data" => [
|
* @var $passwordAlgorithm IPasswordAlgorithm
|
||||||
[
|
*/
|
||||||
"name" => "Memory cost (KiB)",
|
$cryptoClass = $this->request->getParam("cryptoClass");
|
||||||
"value" => PASSWORD_ARGON2_DEFAULT_MEMORY_COST,
|
$passwordAlgorithm = new $cryptoClass($this->localization);
|
||||||
"min" => 1, "max" => 1048576
|
$configuration = $passwordAlgorithm->configuration();
|
||||||
],
|
|
||||||
[
|
if ($cryptoClass === $this->properties[Opt::CRYPTO_CLASS]) {
|
||||||
"name" => "Time cost",
|
foreach ($configuration as $key => $value) {
|
||||||
"value" => PASSWORD_ARGON2_DEFAULT_TIME_COST, "min" => 1,
|
$opt = new ReflectionClass("OCA\UserSQL\Constant\Opt");
|
||||||
"max" => 1024
|
$param = $this->properties[$opt->getConstant(
|
||||||
],
|
"CRYPTO_PARAM_" . $key
|
||||||
[
|
)];
|
||||||
"name" => "Threads",
|
|
||||||
"value" => PASSWORD_ARGON2_DEFAULT_THREADS, "min" => 1,
|
if (!empty($param)) {
|
||||||
"max" => 1024
|
$value->value = $param;
|
||||||
]
|
}
|
||||||
]
|
}
|
||||||
];
|
}
|
||||||
|
|
||||||
|
$this->logger->debug(
|
||||||
|
"Returning cryptoParams(): count(" . count($configuration) . ")",
|
||||||
|
["app" => $this->appName]
|
||||||
|
);
|
||||||
|
|
||||||
|
return ["status" => "success", "data" => (array)$configuration];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user