mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-26 19:47:20 +00:00
Rejigged encrypted import so that the current password isn't changed
We still try the currently stored password. If that doesn’t work then we prompt for a password, but we no longer store the password in the store.
This commit is contained in:
parent
f31369035b
commit
2fc6451bf7
19
boot/boot.js
19
boot/boot.js
@ -545,8 +545,9 @@ the password, and to encrypt/decrypt a block of text
|
|||||||
*/
|
*/
|
||||||
$tw.utils.Crypto = function() {
|
$tw.utils.Crypto = function() {
|
||||||
var sjcl = $tw.browser ? window.sjcl : require("./sjcl.js"),
|
var sjcl = $tw.browser ? window.sjcl : require("./sjcl.js"),
|
||||||
password = null,
|
currentPassword = null,
|
||||||
callSjcl = function(method,inputText) {
|
callSjcl = function(method,inputText,password) {
|
||||||
|
password = password || currentPassword;
|
||||||
var outputText;
|
var outputText;
|
||||||
try {
|
try {
|
||||||
if(password) {
|
if(password) {
|
||||||
@ -559,22 +560,22 @@ $tw.utils.Crypto = function() {
|
|||||||
return outputText;
|
return outputText;
|
||||||
};
|
};
|
||||||
this.setPassword = function(newPassword) {
|
this.setPassword = function(newPassword) {
|
||||||
password = newPassword;
|
currentPassword = newPassword;
|
||||||
this.updateCryptoStateTiddler();
|
this.updateCryptoStateTiddler();
|
||||||
};
|
};
|
||||||
this.updateCryptoStateTiddler = function() {
|
this.updateCryptoStateTiddler = function() {
|
||||||
if($tw.wiki && $tw.wiki.addTiddler) {
|
if($tw.wiki && $tw.wiki.addTiddler) {
|
||||||
$tw.wiki.addTiddler(new $tw.Tiddler({title: "$:/isEncrypted", text: password ? "yes" : "no"}));
|
$tw.wiki.addTiddler(new $tw.Tiddler({title: "$:/isEncrypted", text: currentPassword ? "yes" : "no"}));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
this.hasPassword = function() {
|
this.hasPassword = function() {
|
||||||
return !!password;
|
return !!currentPassword;
|
||||||
}
|
}
|
||||||
this.encrypt = function(text) {
|
this.encrypt = function(text,password) {
|
||||||
return callSjcl("encrypt",text);
|
return callSjcl("encrypt",text,password);
|
||||||
};
|
};
|
||||||
this.decrypt = function(text) {
|
this.decrypt = function(text,password) {
|
||||||
return callSjcl("decrypt",text);
|
return callSjcl("decrypt",text,password);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -28,16 +28,18 @@ exports.extractEncryptedStoreArea = function(text) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Attempt to extract the tiddlers from an encrypted store area using the current password
|
Attempt to extract the tiddlers from an encrypted store area using the current password. If the password is not provided then the password in the password store will be used
|
||||||
*/
|
*/
|
||||||
exports.decryptStoreArea = function(encryptedStoreArea) {
|
exports.decryptStoreArea = function(encryptedStoreArea,password) {
|
||||||
var decryptedText = $tw.crypto.decrypt(encryptedStoreArea);
|
var decryptedText = $tw.crypto.decrypt(encryptedStoreArea,password);
|
||||||
if(decryptedText) {
|
if(decryptedText) {
|
||||||
var json = JSON.parse(decryptedText),
|
var json = JSON.parse(decryptedText),
|
||||||
tiddlers = [];
|
tiddlers = [];
|
||||||
for(var title in json) {
|
for(var title in json) {
|
||||||
|
if(title !== "$:/isEncrypted") {
|
||||||
tiddlers.push(json[title]);
|
tiddlers.push(json[title]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return tiddlers;
|
return tiddlers;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
@ -62,8 +64,7 @@ exports.decryptStoreAreaInteractive = function(encryptedStoreArea,callback) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Attempt to decrypt the tiddlers
|
// Attempt to decrypt the tiddlers
|
||||||
$tw.crypto.setPassword(data.password);
|
var tiddlers = $tw.utils.decryptStoreArea(encryptedStoreArea,data.password);
|
||||||
var tiddlers = $tw.utils.decryptStoreArea(encryptedStoreArea);
|
|
||||||
if(tiddlers) {
|
if(tiddlers) {
|
||||||
callback(tiddlers);
|
callback(tiddlers);
|
||||||
// Exit and remove the password prompt
|
// Exit and remove the password prompt
|
||||||
|
Loading…
Reference in New Issue
Block a user