1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-01-11 18:24:43 +02:00

Revert "CLI: improve e2ee decrypt command"

This reverts commit 6e235605ed.
Fixed #1144: e2ee decrypt cannot be used inside cron. If we need
manually decrypting a file, we'll need to move this command
somewhere else.
This commit is contained in:
Laurent Cozic 2019-02-10 16:43:55 +00:00
parent 29e7ec4cc9
commit 2ef77dcf1f

View File

@ -47,63 +47,34 @@ class Command extends BaseCommand {
} }
if (args.command === 'decrypt') { if (args.command === 'decrypt') {
while (true) { if (args.path) {
try { const plainText = await EncryptionService.instance().decryptString(args.path);
if (args.path) { this.stdout(plainText);
const plainText = await EncryptionService.instance().decryptString(args.path); } else {
this.stdout(plainText); this.stdout(_('Starting decryption... Please wait as it may take several minutes depending on how much there is to decrypt.'));
return;
} else {
if (process.stdin.isTTY) {
this.stdout(_('Starting decryption... Please wait as it may take several minutes depending on how much there is to decrypt.'));
await DecryptionWorker.instance().start();
this.stdout(_('Completed decryption.'));
return;
} else {
// var repl = require("repl");
// var r = repl.start("node> ");
const text = await new Promise((accept, reject) => { while (true) {
var buffer = ''; try {
process.stdin.setEncoding('utf8'); await DecryptionWorker.instance().start();
process.stdin.on('data', function(chunk) { break;
buffer += chunk; } catch (error) {
// process.stdout.write(chunk); if (error.code === 'masterKeyNotLoaded') {
}); const masterKeyId = error.masterKeyId;
process.stdin.on('end', function() { const password = await this.prompt(_('Enter master password:'), { type: 'string', secure: true });
accept(buffer.trim()); if (!password) {
}); this.stdout(_('Operation cancelled'));
}); return;
if (text.length > 0) {
var cipherText = text;
try {
var item = await BaseItem.unserialize(text);
cipherText = item.encryption_cipher_text;
} catch (error) {
// we already got the pure cipher text
}
const plainText = await EncryptionService.instance().decryptString(cipherText);
this.stdout(plainText);
} }
return; Setting.setObjectKey('encryption.passwordCache', masterKeyId, password);
await EncryptionService.instance().loadMasterKeysFromSettings();
continue;
} }
}
} catch (error) {
if (error.code === 'masterKeyNotLoaded') {
const masterKeyId = error.masterKeyId;
const password = await this.prompt(_('Enter master password:'), { type: 'string', secure: true });
if (!password) {
this.stdout(_('Operation cancelled'));
return;
}
Setting.setObjectKey('encryption.passwordCache', masterKeyId, password);
await EncryptionService.instance().loadMasterKeysFromSettings();
continue;
}
throw error; throw error;
}
} }
this.stdout(_('Completed decryption.'));
} }
return; return;