1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Cli: Allow setting up E2EE without having to confirm the password

This commit is contained in:
Laurent Cozic 2021-06-15 17:15:00 +01:00
parent ba322b1f9b
commit c5b0529968

View File

@ -71,20 +71,28 @@ class Command extends BaseCommand {
};
if (args.command === 'enable') {
const password = options.password ? options.password.toString() : await this.prompt(_('Enter master password:'), { type: 'string', secure: true });
const argPassword = options.password ? options.password.toString() : '';
const password = argPassword ? argPassword : await this.prompt(_('Enter master password:'), { type: 'string', secure: true });
if (!password) {
this.stdout(_('Operation cancelled'));
return;
}
const password2 = await this.prompt(_('Confirm password:'), { type: 'string', secure: true });
if (!password2) {
this.stdout(_('Operation cancelled'));
return;
}
if (password !== password2) {
this.stdout(_('Passwords do not match!'));
return;
// If the password was passed via command line, we don't ask for
// confirmation. This is to allow setting up E2EE entirely from the
// command line.
if (!argPassword) {
const password2 = await this.prompt(_('Confirm password:'), { type: 'string', secure: true });
if (!password2) {
this.stdout(_('Operation cancelled'));
return;
}
if (password !== password2) {
this.stdout(_('Passwords do not match!'));
return;
}
}
await EncryptionService.instance().generateMasterKeyAndEnableEncryption(password);
return;
}