1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-11-27 08:21:03 +02:00

CLI: Added way to decrypt string

This commit is contained in:
Laurent Cozic 2018-06-28 20:48:39 +01:00
parent cf565d1563
commit df4c07d204
3 changed files with 32 additions and 20 deletions

View File

@ -47,30 +47,35 @@ class Command extends BaseCommand {
}
if (args.command === 'decrypt') {
this.stdout(_('Starting decryption... Please wait as it may take several minutes depending on how much there is to decrypt.'));
if (args.path) {
const plainText = await EncryptionService.instance().decryptString(args.path);
this.stdout(plainText);
} else {
this.stdout(_('Starting decryption... Please wait as it may take several minutes depending on how much there is to decrypt.'));
while (true) {
try {
await DecryptionWorker.instance().start();
break;
} 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;
while (true) {
try {
await DecryptionWorker.instance().start();
break;
} 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;
}
Setting.setObjectKey('encryption.passwordCache', masterKeyId, password);
await EncryptionService.instance().loadMasterKeysFromSettings();
continue;
throw error;
}
throw error;
}
}
this.stdout(_('Completed decryption.'));
this.stdout(_('Completed decryption.'));
}
return;
}

View File

@ -2379,6 +2379,11 @@
"resolved": "https://registry.npmjs.org/symbol-tree/-/symbol-tree-3.2.2.tgz",
"integrity": "sha1-rifbOPZgp64uHDt9G8KQgZuFGeY="
},
"syswide-cas": {
"version": "5.2.0",
"resolved": "https://registry.npmjs.org/syswide-cas/-/syswide-cas-5.2.0.tgz",
"integrity": "sha512-I81xC4l8ECPonkPyYPYUw+IO1ebE4W3fMV9KeavvF/5Snlg3T1DLhWFTm9C32YVOHU70VdONPlGCotaBMG2cFA=="
},
"tar": {
"version": "4.4.0",
"resolved": "https://registry.npmjs.org/tar/-/tar-4.4.0.tgz",
@ -2439,6 +2444,7 @@
"requires": {
"chalk": "^2.1.0",
"emphasize": "^1.5.0",
"node-emoji": "git+https://github.com/laurent22/node-emoji.git#9fa01eac463e94dde1316ef8c53089eeef4973b5",
"slice-ansi": "^1.0.0",
"string-width": "^2.1.1",
"terminal-kit": "^1.13.11",
@ -2447,7 +2453,7 @@
"dependencies": {
"node-emoji": {
"version": "git+https://github.com/laurent22/node-emoji.git#9fa01eac463e94dde1316ef8c53089eeef4973b5",
"from": "git+https://github.com/laurent22/node-emoji.git#9fa01eac463e94dde1316ef8c53089eeef4973b5",
"from": "git+https://github.com/laurent22/node-emoji.git",
"requires": {
"lodash.toarray": "^4.4.0"
}

View File

@ -62,6 +62,7 @@
"string-padding": "^1.0.2",
"string-to-stream": "^1.1.0",
"strip-ansi": "^4.0.0",
"syswide-cas": "^5.2.0",
"tar": "^4.4.0",
"tcp-port-used": "^0.1.2",
"tkwidgets": "^0.5.26",