Merge (un)encrypted storage layers

This commit is contained in:
Matt Corallo 2015-03-24 16:20:36 -07:00 committed by lilia
parent 454b4726bd
commit 00cb420d37
12 changed files with 102 additions and 143 deletions

View file

@ -255,19 +255,19 @@ textsecure.processDecrypted = function(decrypted, source) {
window.textsecure.registerSingleDevice = function(number, verificationCode, stepDone) {
var signalingKey = textsecure.crypto.getRandomBytes(32 + 20);
textsecure.storage.putEncrypted('signaling_key', signalingKey);
textsecure.storage.put('signaling_key', signalingKey);
var password = btoa(getString(textsecure.crypto.getRandomBytes(16)));
password = password.substring(0, password.length - 2);
textsecure.storage.putEncrypted("password", password);
textsecure.storage.put("password", password);
var registrationId = new Uint16Array(textsecure.crypto.getRandomBytes(2))[0];
registrationId = registrationId & 0x3fff;
textsecure.storage.putUnencrypted("registrationId", registrationId);
textsecure.storage.put("registrationId", registrationId);
return textsecure.api.confirmCode(number, verificationCode, password, signalingKey, registrationId, true).then(function() {
textsecure.storage.user.setNumberAndDeviceId(number, 1);
textsecure.storage.putUnencrypted("regionCode", libphonenumber.util.getRegionCodeForNumber(number));
textsecure.storage.put("regionCode", libphonenumber.util.getRegionCodeForNumber(number));
stepDone(1);
return textsecure.protocol_wrapper.generateKeys().then(function(keys) {
@ -285,19 +285,19 @@ window.textsecure.registerSecondDevice = function(encodedProvisionEnvelope, cryp
stepDone(1);
var signalingKey = textsecure.crypto.getRandomBytes(32 + 20);
textsecure.storage.putEncrypted('signaling_key', signalingKey);
textsecure.storage.put('signaling_key', signalingKey);
var password = btoa(getString(textsecure.crypto.getRandomBytes(16)));
password = password.substring(0, password.length - 2);
textsecure.storage.putEncrypted("password", password);
textsecure.storage.put("password", password);
var registrationId = new Uint16Array(textsecure.crypto.getRandomBytes(2))[0];
registrationId = registrationId & 0x3fff;
textsecure.storage.putUnencrypted("registrationId", registrationId);
textsecure.storage.put("registrationId", registrationId);
return textsecure.api.confirmCode(identityKey.number, identityKey.provisioningCode, password, signalingKey, registrationId, false).then(function(result) {
textsecure.storage.user.setNumberAndDeviceId(identityKey.number, result.deviceId);
textsecure.storage.putUnencrypted("regionCode", libphonenumber.util.getRegionCodeForNumber(identityKey.number));
textsecure.storage.put("regionCode", libphonenumber.util.getRegionCodeForNumber(identityKey.number));
stepDone(2);
return textsecure.protocol_wrapper.generateKeys().then(function(keys) {