Removing encryption key if it already exists from a previous installation.
This commit is contained in:
parent
a388e6deac
commit
074e691cf9
4 changed files with 52 additions and 3 deletions
|
|
@ -10,7 +10,8 @@
|
||||||
|
|
||||||
var service = {
|
var service = {
|
||||||
decrypt: decrypt,
|
decrypt: decrypt,
|
||||||
encrypt: encrypt
|
encrypt: encrypt,
|
||||||
|
removeKeyIfExists: removeKeyIfExists
|
||||||
};
|
};
|
||||||
return service;
|
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.');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
|
@ -57,6 +57,32 @@ angular.module('copayApp.services').factory('mobileSecureStorageService', functi
|
||||||
key);
|
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) {
|
root.set = function(key, value, cb) {
|
||||||
|
|
||||||
if (!platformInfo.isMobile) {
|
if (!platformInfo.isMobile) {
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,17 @@ angular.module('copayApp.services').factory('secureStorageService', function(des
|
||||||
} else { // Browser
|
} else { // Browser
|
||||||
localStorageService.get(alteredKeyIndicatingDesireForSecureStorage(k), cb);
|
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) {
|
root.set = function(k, v, cb) {
|
||||||
if (platformInfo.isMobile) {
|
if (platformInfo.isMobile) {
|
||||||
|
|
@ -26,7 +36,7 @@ angular.module('copayApp.services').factory('secureStorageService', function(des
|
||||||
} else { // Browser
|
} else { // Browser
|
||||||
localStorageService.set(alteredKeyIndicatingDesireForSecureStorage(k), v, cb);
|
localStorageService.set(alteredKeyIndicatingDesireForSecureStorage(k), v, cb);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
return root;
|
return root;
|
||||||
});
|
});
|
||||||
|
|
@ -269,6 +269,8 @@ angular.module('copayApp.services')
|
||||||
|
|
||||||
if (!profileStr) {
|
if (!profileStr) {
|
||||||
$log.debug('No string loaded, returning nothing.');
|
$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);
|
return cb(null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue