Merge pull request #1766 from matiu/fix/import
Fix import wallets and profile from 0.7.2
This commit is contained in:
commit
3e073403f5
7 changed files with 77 additions and 30 deletions
|
|
@ -30,7 +30,7 @@ angular.module('copayApp.controllers').controller('ImportController',
|
|||
$rootScope.iden.importEncryptedWallet(encryptedObj, password, skipFields, opts, function(err, w) {
|
||||
if (!w) {
|
||||
$scope.loading = false;
|
||||
notification.error('Error', err || 'Wrong password');
|
||||
$scope.error = 'Wrong password';
|
||||
$rootScope.$digest();
|
||||
return;
|
||||
}
|
||||
|
|
@ -47,7 +47,7 @@ angular.module('copayApp.controllers').controller('ImportController',
|
|||
updateStatus('Importing wallet - We are almost there...');
|
||||
if (err) {
|
||||
$scope.loading = false;
|
||||
notification.error('Error', 'Error updating indexes: ' + err);
|
||||
$scope.error = 'Error updating indexes: ' + err;
|
||||
}
|
||||
controllerUtils.installWalletHandlers($scope, w);
|
||||
controllerUtils.setFocusedWallet(w);
|
||||
|
|
@ -72,7 +72,7 @@ angular.module('copayApp.controllers').controller('ImportController',
|
|||
function(err, wallet) {
|
||||
if (err) {
|
||||
$scope.loading = false;
|
||||
notification.error('Error', 'Could not read wallet. Please check your password');
|
||||
$scope.error = 'Could not read wallet. Please check your password';
|
||||
} else {
|
||||
controllerUtils.installWalletHandlers($scope, wallet);
|
||||
controllerUtils.setFocusedWallet(wallet);
|
||||
|
|
@ -89,7 +89,7 @@ angular.module('copayApp.controllers').controller('ImportController',
|
|||
|
||||
if (form.$invalid) {
|
||||
$scope.loading = false;
|
||||
notification.error('Error', 'There is an error in the form.');
|
||||
$scope.error = 'There is an error in the form';
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -104,8 +104,7 @@ angular.module('copayApp.controllers').controller('ImportController',
|
|||
|
||||
if (!backupFile && !backupText) {
|
||||
$scope.loading = false;
|
||||
notification.error('Error', 'Please, select your backup file');
|
||||
$scope.loading = false;
|
||||
$scope.error = 'Please, select your backup file';
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -115,7 +114,7 @@ angular.module('copayApp.controllers').controller('ImportController',
|
|||
copay.Compatibility.importEncryptedWallet($rootScope.iden, backupText, $scope.password, {},
|
||||
function(err, wallet) {
|
||||
if (err) {
|
||||
notification.error('Error', 'Could not read wallet. Please check your password');
|
||||
$scope.error = 'Could not read wallet. Please check your password';
|
||||
} else {
|
||||
copay.Compatibility.deleteOldWallet(backupOldWallet);
|
||||
controllerUtils.installWalletHandlers($scope, wallet);
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@ angular.module('copayApp.controllers').controller('ImportProfileController',
|
|||
passphraseConfig: config.passphraseConfig,
|
||||
}, function(err, iden) {
|
||||
if (err && !iden) {
|
||||
controllerUtils.onErrorDigest(
|
||||
$scope, (err.toString() || '').match('BADSTR') ? 'Bad password or corrupt profile file' : 'Unknown error');
|
||||
$scope.error = (err.toString() || '').match('BADSTR') ? 'Bad password or corrupt profile file' : 'Unknown error';
|
||||
} else {
|
||||
notification.info('Success', 'Profile imported successfully');
|
||||
$location.path('/');
|
||||
|
|
@ -59,7 +58,7 @@ angular.module('copayApp.controllers').controller('ImportProfileController',
|
|||
|
||||
if (form.$invalid) {
|
||||
$scope.loading = false;
|
||||
notification.error('Error', 'There is an error in the form.');
|
||||
$scope.error = 'Please enter the required fields';
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -69,8 +68,7 @@ angular.module('copayApp.controllers').controller('ImportProfileController',
|
|||
|
||||
if (!backupFile && !backupText) {
|
||||
$scope.loading = false;
|
||||
notification.error('Error', 'Please, select your backup file');
|
||||
$scope.loading = false;
|
||||
$scope.error = 'Please, select your backup file';
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -285,18 +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);
|
||||
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);
|
||||
|
|
@ -338,13 +355,21 @@ Identity.prototype.closeWallet = function(wallet, cb) {
|
|||
});
|
||||
};
|
||||
|
||||
Identity.importFromEncryptedFullJson = function(str, password, opts, cb) {
|
||||
Identity.importFromEncryptedFullJson = function(ejson, password, opts, cb) {
|
||||
var crypto = opts.cryptoUtil || cryptoUtil;
|
||||
|
||||
var str = crypto.decrypt(password, str);
|
||||
var str = crypto.decrypt(password, ejson);
|
||||
|
||||
if (!str) {
|
||||
return cb('BADSTR');
|
||||
// 0.7.3 broken KDF
|
||||
log.debug('Trying legacy encryption...');
|
||||
var passphrase = crypto.kdf(password, 'mjuBtGybi/4=', 100);
|
||||
str = crypto.decrypt(passphrase, ejson);
|
||||
}
|
||||
|
||||
if (!str)
|
||||
return cb('BADSTR');
|
||||
|
||||
return Identity.importFromFullJson(str, password, opts, cb);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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"}');
|
||||
|
|
|
|||
|
|
@ -10,6 +10,13 @@
|
|||
<div class="large-12 columns">
|
||||
<div class="panel">
|
||||
<form name="importForm" ng-submit="import(importForm)" novalidate>
|
||||
<div class="text-warning size-12 m20b"
|
||||
ng-show="error">
|
||||
<i class="fi-x"></i>
|
||||
{{error|translate}}
|
||||
</div>
|
||||
|
||||
|
||||
<div ng-show="!is_iOS && !backupOldWallet">
|
||||
<legend for="backupFile" class="m10b">
|
||||
<span translate>Choose backup file from your computer</span> <i class="fi-laptop"></i>
|
||||
|
|
|
|||
|
|
@ -10,6 +10,13 @@
|
|||
<h1><span translate>Import Profile<span></h1>
|
||||
|
||||
<form name="importProfileForm" ng-submit="import(importProfileForm)" novalidate>
|
||||
<p class="text-warning size-12"
|
||||
ng-show="error">
|
||||
<i class="fi-x"></i>
|
||||
{{error|translate}}
|
||||
</p>
|
||||
|
||||
|
||||
<div ng-show="!is_iOS">
|
||||
<legend for="backupFile" class="m10b">
|
||||
<span translate>Choose backup file from your computer</span> <i class="fi-laptop"></i>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue