From b15679c08c3511b56ccb224982035746647693ad Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Tue, 11 Nov 2014 15:14:54 -0300 Subject: [PATCH] fix import wallets and profile form 0.7.2 --- js/models/Compatibility.js | 16 ++++++++++--- js/models/Identity.js | 48 +++++++++++++++++++++----------------- test/Identity.js | 3 ++- views/import.html | 4 ++-- 4 files changed, 44 insertions(+), 27 deletions(-) diff --git a/js/models/Compatibility.js b/js/models/Compatibility.js index 32254f768..d42eb9be0 100644 --- a/js/models/Compatibility.js +++ b/js/models/Compatibility.js @@ -198,13 +198,23 @@ Compatibility.importEncryptedWallet = function(identity, cypherText, password, o var crypto = (opts && opts.cryptoUtil) || cryptoUtils; var obj = crypto.decrypt(password, cypherText); + if (!obj) { + // 0.7.3 broken KDF + log.debug('Trying legacy encryption 0.7.2...'); + var passphrase = crypto.kdf(password, 'mjuBtGybi/4=', 100); + obj = crypto.decrypt(passphrase, cypherText); + } + if (!obj) { log.info("Could not decrypt, trying legacy.."); obj = Compatibility.importLegacy(cypherText, password); - if (!obj) { - return cb('Could not decrypt', null); - } }; + + if (!obj) { + return cb('Could not decrypt', null); + } + + try { obj = JSON.parse(obj); } catch (e) { diff --git a/js/models/Identity.js b/js/models/Identity.js index 046aaf6b0..e04797575 100644 --- a/js/models/Identity.js +++ b/js/models/Identity.js @@ -285,29 +285,35 @@ Identity.prototype.close = function(cb) { * @param {string[]} opts.importFunction - for stubbing * @return {Wallet} */ -Identity.prototype.importEncryptedWallet = function(cypherText, password, opts, cb) { - var crypto = opts.cryptoUtil || cryptoUtil; - var obj = crypto.decrypt(password, cypherText); -console.log('[Identity.js.290:obj:]',obj); //TODO - if (!obj) { - // 0.7.3 broken KDF - log.debug('Trying legacy encryption...'); - var passphrase = crypto.kdf(password, 'mjuBtGybi/4=', 100); - obj = crypto.decrypt(passphrase, ejson); - } -console.log('[Identity.js.300:obj:]',obj); //TOD - - if (!obj) - return cb(new Error('Could not decrypt')); - try { - obj = JSON.parse(obj); - } catch (e) { - return cb(new Error('Could not decrypt')); - } - return this.importWalletFromObj(obj, opts, cb) -}; +// This is not used in favor of Compatibility. importEncryptedWallet +// Identity.prototype.importEncryptedWallet = function(cypherText, password, opts, cb) { +// var crypto = opts.cryptoUtil || cryptoUtil; +// var obj = crypto.decrypt(password, cypherText); +// console.log('[Identity.js.290:obj:]',obj); //TODO +// +// if (!obj) { +// // 0.7.3 broken KDF +// log.debug('Trying legacy encryption...'); +// console.log('[Identity.js.296:password:]',password); //TODO +// var passphrase = crypto.kdf(password, 'mjuBtGybi/4=', 100); +// console.log('[Identity.js.296:passphrase:]',passphrase); //TODO +// obj = crypto.decrypt(passphrase, ejson); +// console.log('[Identity.js.297:obj:]',obj); //TODO +// } +// console.log('[Identity.js.300:obj:]',obj); //TOD +// +// if (!obj) +// return cb(new Error('Could not decrypt')); +// try { +// obj = JSON.parse(obj); +// } catch (e) { +// return cb(new Error('Could not decrypt')); +// } +// return this.importWalletFromObj(obj, opts, cb) +// }; +// Identity.prototype.importWalletFromObj = function(obj, opts, cb) { var self = this; preconditions.checkArgument(cb); diff --git a/test/Identity.js b/test/Identity.js index 0fc31d795..804680ca7 100644 --- a/test/Identity.js +++ b/test/Identity.js @@ -238,7 +238,8 @@ describe('Identity model', function() { }); }); - describe('#importWallet', function() { + // This is implemented in Compatibility + describe.skip('#importWallet', function() { it('should import a wallet, call the right encryption functions', function(done) { var args = createIdentity(); args.storage.getItem.onFirstCall().callsArgWith(1, null, '{"wallet": "fakeData"}'); diff --git a/views/import.html b/views/import.html index 19e8d5068..516ec00f0 100644 --- a/views/import.html +++ b/views/import.html @@ -10,11 +10,11 @@
-

{{error|translate}} -

+