1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-07-16 00:14:34 +02:00

Cli: Ask for master password when encryption or decryption fails

This commit is contained in:
Laurent Cozic
2021-11-22 12:46:57 +00:00
parent 0e11273c45
commit c19e59f5da
5 changed files with 52 additions and 23 deletions

View File

@ -6,8 +6,8 @@ import BaseItem from '@joplin/lib/models/BaseItem';
import Setting from '@joplin/lib/models/Setting';
import shim from '@joplin/lib/shim';
import * as pathUtils from '@joplin/lib/path-utils';
import { getEncryptionEnabled } from '@joplin/lib/services/synchronizer/syncInfoUtils';
import { generateMasterKeyAndEnableEncryption, loadMasterKeysFromSettings, setupAndDisableEncryption } from '@joplin/lib/services/e2ee/utils';
import { getEncryptionEnabled, localSyncInfo } from '@joplin/lib/services/synchronizer/syncInfoUtils';
import { generateMasterKeyAndEnableEncryption, loadMasterKeysFromSettings, masterPasswordIsValid, setupAndDisableEncryption } from '@joplin/lib/services/e2ee/utils';
const imageType = require('image-type');
const readChunk = require('read-chunk');
@ -40,6 +40,13 @@ class Command extends BaseCommand {
this.stdout(_('Operation cancelled'));
return false;
}
const masterKey = localSyncInfo().masterKeys.find(mk => mk.id === masterKeyId);
if (!(await masterPasswordIsValid(password, masterKey))) {
this.stdout(_('Invalid password'));
return false;
}
Setting.setObjectValue('encryption.passwordCache', masterKeyId, password);
await loadMasterKeysFromSettings(EncryptionService.instance());
return true;