Removing encryption key if it already exists from a previous installation.

This commit is contained in:
Brendon Duncan 2018-06-28 21:38:14 +12:00
commit 074e691cf9
4 changed files with 52 additions and 3 deletions

View file

@ -10,7 +10,8 @@
var service = {
decrypt: decrypt,
encrypt: encrypt
encrypt: encrypt,
removeKeyIfExists: removeKeyIfExists
};
return service;
@ -141,5 +142,15 @@
});
};
function removeKeyIfExists() {
secureStorageService.remove(storageKey, function onKeyRemoved(err){
if (err) {
$log.Error('Error removing key.', err);
return;
}
$log.debug('Key removed.');
});
}
});
})();

View file

@ -57,6 +57,32 @@ angular.module('copayApp.services').factory('mobileSecureStorageService', functi
key);
};
root.remove = function(key, cb) {
if (!platformInfo.isMobile) {
cb(new Error('mobileSecureStorageService is only available on mobile.'));
}
if (!isReady) {
if (initialisationFailed) {
cb(new Error('mobileSecureStorageService initialisation failed.'));
} else {
pending.push(function(){ root.remove(key, cb); });
}
return;
}
storage.remove(
function (value) {
cb();
},
function (error) {
cb(new Error(error));
},
key);
};
root.set = function(key, value, cb) {
if (!platformInfo.isMobile) {

View file

@ -16,7 +16,17 @@ angular.module('copayApp.services').factory('secureStorageService', function(des
} else { // Browser
localStorageService.get(alteredKeyIndicatingDesireForSecureStorage(k), cb);
}
}
};
root.remove = function(k, cb) {
if (platformInfo.isMobile) {
mobileSecureStorageService.remove(k, cb);
} else if (platformInfo.isNW) {
desktopSecureStorageService.remove(k, cb);
} else { // Browser
localStorageService.remove(alteredKeyIndicatingDesireForSecureStorage(k), cb);
}
};
root.set = function(k, v, cb) {
if (platformInfo.isMobile) {
@ -26,7 +36,7 @@ angular.module('copayApp.services').factory('secureStorageService', function(des
} else { // Browser
localStorageService.set(alteredKeyIndicatingDesireForSecureStorage(k), v, cb);
}
}
};
return root;
});

View file

@ -269,6 +269,8 @@ angular.module('copayApp.services')
if (!profileStr) {
$log.debug('No string loaded, returning nothing.');
// Don't want to use the same key as a previous installation
encryptionService.removeKeyIfExists();
return cb(null, null);
}