From 4c4086172845ebb1631d9a5bef32fd99d4494d06 Mon Sep 17 00:00:00 2001 From: lilia Date: Tue, 23 Jun 2015 14:24:13 -0700 Subject: [PATCH] Fix reinstalls Delay saving of new account info until we confirm with the server. Explicitly delete old account info beforehand. // FREEBIE --- js/libtextsecure.js | 21 +++++++++++++-------- libtextsecure/account_manager.js | 21 +++++++++++++-------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/js/libtextsecure.js b/js/libtextsecure.js index 8609f6832..5cc5c1422 100644 --- a/js/libtextsecure.js +++ b/js/libtextsecure.js @@ -39409,23 +39409,28 @@ TextSecureServer = function () { } }; function createAccount(number, verificationCode, identityKeyPair, deviceName) { - textsecure.storage.put('identityKey', identityKeyPair); - var signalingKey = textsecure.crypto.getRandomBytes(32 + 20); - textsecure.storage.put('signaling_key', signalingKey); - var password = btoa(getString(textsecure.crypto.getRandomBytes(16))); password = password.substring(0, password.length - 2); - textsecure.storage.put("password", password); - var registrationId = axolotl.util.generateRegistrationId(); - textsecure.storage.put("registrationId", registrationId); return TextSecureServer.confirmCode( number, verificationCode, password, signalingKey, registrationId, deviceName ).then(function(response) { + textsecure.storage.remove('identityKey'); + textsecure.storage.remove('signaling_key'); + textsecure.storage.remove('password'); + textsecure.storage.remove('registrationId'); + textsecure.storage.remove('number_id'); + textsecure.storage.remove('regionCode'); + + textsecure.storage.put('identityKey', identityKeyPair); + textsecure.storage.put('signaling_key', signalingKey); + textsecure.storage.put('password', password); + textsecure.storage.put('registrationId', registrationId); + textsecure.storage.user.setNumberAndDeviceId(number, response.deviceId || 1, deviceName); - textsecure.storage.put("regionCode", libphonenumber.util.getRegionCodeForNumber(number)); + textsecure.storage.put('regionCode', libphonenumber.util.getRegionCodeForNumber(number)); }); } diff --git a/libtextsecure/account_manager.js b/libtextsecure/account_manager.js index 35c97a4ee..0c8821c66 100644 --- a/libtextsecure/account_manager.js +++ b/libtextsecure/account_manager.js @@ -89,23 +89,28 @@ } }; function createAccount(number, verificationCode, identityKeyPair, deviceName) { - textsecure.storage.put('identityKey', identityKeyPair); - var signalingKey = textsecure.crypto.getRandomBytes(32 + 20); - textsecure.storage.put('signaling_key', signalingKey); - var password = btoa(getString(textsecure.crypto.getRandomBytes(16))); password = password.substring(0, password.length - 2); - textsecure.storage.put("password", password); - var registrationId = axolotl.util.generateRegistrationId(); - textsecure.storage.put("registrationId", registrationId); return TextSecureServer.confirmCode( number, verificationCode, password, signalingKey, registrationId, deviceName ).then(function(response) { + textsecure.storage.remove('identityKey'); + textsecure.storage.remove('signaling_key'); + textsecure.storage.remove('password'); + textsecure.storage.remove('registrationId'); + textsecure.storage.remove('number_id'); + textsecure.storage.remove('regionCode'); + + textsecure.storage.put('identityKey', identityKeyPair); + textsecure.storage.put('signaling_key', signalingKey); + textsecure.storage.put('password', password); + textsecure.storage.put('registrationId', registrationId); + textsecure.storage.user.setNumberAndDeviceId(number, response.deviceId || 1, deviceName); - textsecure.storage.put("regionCode", libphonenumber.util.getRegionCodeForNumber(number)); + textsecure.storage.put('regionCode', libphonenumber.util.getRegionCodeForNumber(number)); }); }