1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-01-23 18:53:36 +02:00
joplin/CliClient/app/command-encrypt-config.js

45 lines
1.2 KiB
JavaScript
Raw Normal View History

2017-12-12 18:17:30 +00:00
const { BaseCommand } = require('./base-command.js');
const { _ } = require('lib/locale.js');
const { cliUtils } = require('./cli-utils.js');
2017-12-12 21:58:57 +00:00
const EncryptionService = require('lib/services/EncryptionService');
const MasterKey = require('lib/models/MasterKey');
const { Setting } = require('lib/models/setting.js');
2017-12-12 18:17:30 +00:00
class Command extends BaseCommand {
usage() {
return 'encrypt-config <command>';
}
description() {
return _('Manages encryption configuration.');
}
async action(args) {
// init
// change-password
if (args.command === 'init') {
const password = await this.prompt(_('Enter master password:'), { type: 'string', secure: true });
2017-12-12 21:58:57 +00:00
if (!password) {
this.stdout(_('Operation cancelled'));
return;
}
const service = new EncryptionService();
let masterKey = await service.generateMasterKey(password);
masterKey = await MasterKey.save(masterKey);
2017-12-12 21:58:57 +00:00
Setting.setValue('encryption.enabled', true);
Setting.setValue('encryption.activeMasterKeyId', masterKey.id);
let passwordCache = Setting.value('encryption.passwordCache');
passwordCache[masterKey.id] = password;
Setting.setValue('encryption.passwordCache', passwordCache);
2017-12-12 18:17:30 +00:00
}
}
}
module.exports = Command;