From d7f6c890625ac40aeedebdbdae1471fdf3cabad6 Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Fri, 31 May 2013 23:30:30 +0200 Subject: [PATCH] removed sync private key spaghetti code from cloudstorage dao --- src/js/dao/cloudstorage-dao.js | 62 ----------------------- src/js/dao/email-dao.js | 11 ---- test/integration/cloudstorage-dao-test.js | 17 ------- 3 files changed, 90 deletions(-) diff --git a/src/js/dao/cloudstorage-dao.js b/src/js/dao/cloudstorage-dao.js index b46e0d1..9cd5c8f 100644 --- a/src/js/dao/cloudstorage-dao.js +++ b/src/js/dao/cloudstorage-dao.js @@ -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(); - } - } - }; - }; \ No newline at end of file diff --git a/src/js/dao/email-dao.js b/src/js/dao/email-dao.js index d5c260f..b1c4f98 100644 --- a/src/js/dao/email-dao.js +++ b/src/js/dao/email-dao.js @@ -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) { diff --git a/test/integration/cloudstorage-dao-test.js b/test/integration/cloudstorage-dao-test.js index c350b57..df4a3d2 100644 --- a/test/integration/cloudstorage-dao-test.js +++ b/test/integration/cloudstorage-dao-test.js @@ -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');