Skip to content

Commit d73d5a2

Browse files
karaolidisprovokateurin
authored andcommitted
feat: declarative password salt, secret config
Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
1 parent 34c2125 commit d73d5a2

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

core/Command/Maintenance/Install.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ protected function configure(): void {
4848
->addOption('admin-user', null, InputOption::VALUE_REQUIRED, 'Login of the admin account', 'admin')
4949
->addOption('admin-pass', null, InputOption::VALUE_REQUIRED, 'Password of the admin account')
5050
->addOption('admin-email', null, InputOption::VALUE_OPTIONAL, 'E-Mail of the admin account')
51-
->addOption('data-dir', null, InputOption::VALUE_REQUIRED, 'Path to data directory', \OC::$SERVERROOT . '/data');
51+
->addOption('data-dir', null, InputOption::VALUE_REQUIRED, 'Path to data directory', \OC::$SERVERROOT . '/data')
52+
->addOption('password-salt', null, InputOption::VALUE_OPTIONAL, 'Password salt, at least ' . Setup::MIN_PASSWORD_SALT_LENGTH . ' characters (will be randomly generated if not provided)')
53+
->addOption('server-secret', null, InputOption::VALUE_OPTIONAL, 'Server secret, at least ' . Setup::MIN_SECRET_LENGTH . ' characters (will be randomly generated if not provided)');
5254
}
5355

5456
protected function execute(InputInterface $input, OutputInterface $output): int {
@@ -152,6 +154,16 @@ protected function validateInput(InputInterface $input, OutputInterface $output,
152154
throw new InvalidArgumentException('Invalid e-mail-address <' . $adminEmail . '> for <' . $adminLogin . '>.');
153155
}
154156

157+
$passwordSalt = $input->getOption('password-salt');
158+
$secret = $input->getOption('server-secret');
159+
160+
if ($passwordSalt !== null && strlen($passwordSalt) < Setup::MIN_PASSWORD_SALT_LENGTH) {
161+
throw new InvalidArgumentException('Password salt must be at least ' . Setup::MIN_PASSWORD_SALT_LENGTH . ' characters long.');
162+
}
163+
if ($secret !== null && strlen($secret) < Setup::MIN_SECRET_LENGTH) {
164+
throw new InvalidArgumentException('Server secret must be at least ' . Setup::MIN_SECRET_LENGTH . ' characters long.');
165+
}
166+
155167
$options = [
156168
'dbtype' => $db,
157169
'dbuser' => $dbUser,
@@ -162,7 +174,9 @@ protected function validateInput(InputInterface $input, OutputInterface $output,
162174
'adminlogin' => $adminLogin,
163175
'adminpass' => $adminPassword,
164176
'adminemail' => $adminEmail,
165-
'directory' => $dataDir
177+
'directory' => $dataDir,
178+
'passwordsalt' => $passwordSalt,
179+
'secret' => $secret,
166180
];
167181
if ($db === 'oci') {
168182
$options['dbtablespace'] = $input->getParameterOption('--database-table-space', '');

lib/private/Setup.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343
use Psr\Log\LoggerInterface;
4444

4545
class Setup {
46+
public const MIN_PASSWORD_SALT_LENGTH = 30;
47+
public const MIN_SECRET_LENGTH = 48;
48+
4649
protected IL10N $l10n;
4750

4851
public function __construct(
@@ -357,10 +360,8 @@ public function install(array $options, ?IOutput $output = null): array {
357360
$dbType = 'sqlite3';
358361
}
359362

360-
//generate a random salt that is used to salt the local passwords
361-
$salt = $this->random->generate(30);
362-
// generate a secret
363-
$secret = $this->random->generate(48);
363+
$salt = $options['passwordsalt'] ?: $this->random->generate(self::MIN_PASSWORD_SALT_LENGTH);
364+
$secret = $options['secret'] ?: $this->random->generate(self::MIN_SECRET_LENGTH);
364365

365366
//write the config file
366367
$newConfigValues = [

0 commit comments

Comments
 (0)