mirror of
https://github.com/moparisthebest/mail
synced 2024-11-26 02:42:17 -05:00
removed sync private key spaghetti code from cloudstorage dao
This commit is contained in:
parent
39a9a90e26
commit
d7f6c89062
@ -184,66 +184,4 @@ app.dao.CloudStorage = function(window, $) {
|
||||
this.remove(uri, callback);
|
||||
};
|
||||
|
||||
/**
|
||||
* Sync encrypted private key from cloud service
|
||||
*/
|
||||
this.syncPrivateKey = function(emailAddress, storedkey, callback, replaceCallback) {
|
||||
// fetch user's encrypted secret key from keychain/storage
|
||||
var self = this,
|
||||
gottenKey, uri;
|
||||
|
||||
uri = app.config.cloudUrl + '/privatekey/user/' + emailAddress;
|
||||
self.get(uri, function(err, keys) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
if (!keys) {
|
||||
callback({
|
||||
errMsg: 'Key not synced!'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// use first key, if it exists
|
||||
if (keys.length > 0) {
|
||||
gottenKey = keys[0];
|
||||
}
|
||||
|
||||
handleKey(gottenKey, callback);
|
||||
});
|
||||
|
||||
function handleKey(fetchedKey, callback) {
|
||||
if ((!storedkey || !storedkey.encryptedKey) && fetchedKey && fetchedKey.encryptedKey) {
|
||||
// no local key... persist fetched key
|
||||
replaceCallback(fetchedKey);
|
||||
|
||||
} else if (!fetchedKey && storedkey && storedkey.encryptedKey) {
|
||||
// no key in cloud... push local key to cloud
|
||||
self.putPrivateKey(storedkey, callback);
|
||||
|
||||
} else if (storedkey && fetchedKey && (storedkey.encryptedKey !== fetchedKey.encryptedKey || storedkey.iv !== fetchedKey.iv)) {
|
||||
// local and fetched keys are not equal
|
||||
if (window.confirm('Swap local key?')) {
|
||||
// replace local key with fetched key
|
||||
replaceCallback(fetchedKey);
|
||||
} else {
|
||||
if (window.confirm('Swap cloud key?')) {
|
||||
// upload local key to cloud
|
||||
self.putPrivateKey(emailAddress, callback);
|
||||
} else {
|
||||
callback({
|
||||
error: 'err',
|
||||
status: 'Key not synced!'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// local and cloud keys are equal
|
||||
callback();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
};
|
@ -19,17 +19,6 @@ app.dao.EmailDAO = function(_, crypto, devicestorage, cloudstorage, util, keycha
|
||||
}
|
||||
// init crypto
|
||||
initCrypto(storedKeypair);
|
||||
|
||||
}, function(err, keypairReplacement) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
// whipe local storage in case local keypair was replaced with cloud keypair
|
||||
devicestorage.clear(function() {
|
||||
// init crypto and generate new keypair
|
||||
initCrypto(keypairReplacement);
|
||||
});
|
||||
});
|
||||
|
||||
function initCrypto(storedKeypair) {
|
||||
|
@ -73,23 +73,6 @@ asyncTest("Delete Public key from cloud", 1, function() {
|
||||
});
|
||||
});
|
||||
|
||||
// asyncTest("Sync private key from cloud", 1, function() {
|
||||
// cloudstoragedao_test.cloudstorage.syncPrivateKey(cloudstoragedao_test.user, null, function(err) {
|
||||
// ok(!err, 'Get/Sync key from cloud');
|
||||
|
||||
// start();
|
||||
// }, function(fetchedKey) {
|
||||
// // replace local key with cloud key
|
||||
// cloudstoragedao_test.crypto.putEncryptedPrivateKey(fetchedKey);
|
||||
// // whipe local storage
|
||||
// cloudstoragedao_test.storage.clear(function(err) {
|
||||
// ok(!err, 'DB cleared. Error status: ' + err);
|
||||
|
||||
// start();
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
|
||||
asyncTest("Put private key to cloud", 1, function() {
|
||||
cloudstoragedao_test.cloudstorage.putPrivateKey(cloudstoragedao_test.keypair.privateKey, function(err) {
|
||||
ok(!err, 'Persist key to cloud');
|
||||
|
Loading…
Reference in New Issue
Block a user