Move local identitykey and registrationid to indexeddb

This commit is contained in:
lilia 2015-05-11 15:40:21 -07:00
parent fe1d78b5fa
commit d230df5622
6 changed files with 410 additions and 391 deletions

View file

@ -82,23 +82,27 @@
});
var IdentityKey = Model.extend({ storeName: 'identityKeys' });
var Group = Model.extend({ storeName: 'groups' });
var Item = Model.extend({ storeName: 'items' });
function AxolotlStore() {}
AxolotlStore.prototype = {
constructor: AxolotlStore,
getMyIdentityKey: function() {
var res = textsecure.storage.get('identityKey');
if (res === undefined)
return undefined;
return {
pubKey: convertToArrayBuffer(res.pubKey),
privKey: convertToArrayBuffer(res.privKey)
};
var item = new Item({id: 'identityKey'});
return new Promise(function(resolve) {
item.fetch().then(function() {
resolve(item.get('value'));
});
});
},
getMyRegistrationId: function() {
return textsecure.storage.get('registrationId');
var item = new Item({id: 'registrationId'});
return new Promise(function(resolve) {
item.fetch().then(function() {
resolve(item.get('value'));
});
});
},
/* Returns a prekeypair object or undefined */

View file

@ -42,6 +42,7 @@
var preKeys = transaction.db.createObjectStore("preKeys");
var signedPreKeys = transaction.db.createObjectStore("signedPreKeys");
var items = transaction.db.createObjectStore("items");
next();
}
}

View file

@ -37122,8 +37122,7 @@ window.axolotl.protocol = function(storage_interface) {
}
var initSession = function(isInitiator, ourEphemeralKey, ourSignedKey, encodedNumber, theirIdentityPubKey, theirEphemeralPubKey, theirSignedPubKey) {
var ourIdentityKey = storage_interface.getMyIdentityKey();
return storage_interface.getMyIdentityKey().then(function(ourIdentityKey) {
if (isInitiator) {
if (ourSignedKey !== undefined)
throw new Error("Invalid call to initSession");
@ -37195,6 +37194,7 @@ window.axolotl.protocol = function(storage_interface) {
}).then(finishInit);
});
});
});
}
var removeOldChains = function(session) {
@ -37386,12 +37386,13 @@ window.axolotl.protocol = function(storage_interface) {
return fillMessageKeys(chain, message.counter).then(function() {
return HKDF(axolotlInternal.utils.convertToArrayBuffer(chain.messageKeys[message.counter]), '', "WhisperMessageKeys").then(function(keys) {
return storage_interface.getMyIdentityKey().then(function(ourIdentityKey) {
delete chain.messageKeys[message.counter];
var messageProtoArray = axolotlInternal.utils.convertToArrayBuffer(messageProto);
var macInput = new Uint8Array(messageProtoArray.byteLength + 33*2 + 1);
macInput.set(new Uint8Array(axolotlInternal.utils.convertToArrayBuffer(session.indexInfo.remoteIdentityKey)));
macInput.set(new Uint8Array(axolotlInternal.utils.convertToArrayBuffer(storage_interface.getMyIdentityKey().pubKey)), 33);
macInput.set(new Uint8Array(axolotlInternal.utils.convertToArrayBuffer(ourIdentityKey.pubKey)), 33);
macInput[33*2] = (3 << 4) | 3;
macInput.set(new Uint8Array(messageProtoArray), 33*2 + 1);
@ -37426,6 +37427,7 @@ window.axolotl.protocol = function(storage_interface) {
});
});
});
});
}
/*************************
@ -37452,6 +37454,8 @@ window.axolotl.protocol = function(storage_interface) {
// return Promise(encoded [PreKey]WhisperMessage)
self.encryptMessageFor = function(deviceObject, pushMessageContent) {
return storage_interface.getMyIdentityKey().then(function(ourIdentityKey) {
return storage_interface.getMyRegistrationId().then(function(myRegistrationId) {
return crypto_storage.getOpenSession(deviceObject.encodedNumber).then(function(session) {
var hadSession = session !== undefined;
@ -37477,7 +37481,7 @@ window.axolotl.protocol = function(storage_interface) {
var encodedMsg = axolotlInternal.utils.convertToArrayBuffer(msg.encode());
var macInput = new Uint8Array(encodedMsg.byteLength + 33*2 + 1);
macInput.set(new Uint8Array(axolotlInternal.utils.convertToArrayBuffer(storage_interface.getMyIdentityKey().pubKey)));
macInput.set(new Uint8Array(axolotlInternal.utils.convertToArrayBuffer(ourIdentityKey.pubKey)));
macInput.set(new Uint8Array(axolotlInternal.utils.convertToArrayBuffer(session.indexInfo.remoteIdentityKey)), 33);
macInput[33*2] = (3 << 4) | 3;
macInput.set(new Uint8Array(encodedMsg), 33*2 + 1);
@ -37500,8 +37504,8 @@ window.axolotl.protocol = function(storage_interface) {
}
var preKeyMsg = new axolotlInternal.protobuf.PreKeyWhisperMessage();
preKeyMsg.identityKey = axolotlInternal.utils.convertToArrayBuffer(storage_interface.getMyIdentityKey().pubKey);
preKeyMsg.registrationId = storage_interface.getMyRegistrationId();
preKeyMsg.identityKey = axolotlInternal.utils.convertToArrayBuffer(ourIdentityKey.pubKey);
preKeyMsg.registrationId = myRegistrationId;
if (session === undefined) {
var deviceIdentityKey = axolotlInternal.utils.convertToArrayBuffer(deviceObject.identityKey);
@ -37539,6 +37543,8 @@ window.axolotl.protocol = function(storage_interface) {
return {type: 1, body: axolotlInternal.utils.convertToString(message)};
});
});
});
});
}
self.createIdentityKeyRecvSocket = function() {
@ -37987,7 +37993,7 @@ axolotlInternal.RecipientRecord = function() {
window.textsecure.storage = window.textsecure.storage || {};
// Overrideable storage implementation
window.textsecure.storage.impl = {
window.textsecure.storage.impl = window.textsecure.storage.impl || {
/*****************************
*** Base Storage Routines ***
*****************************/
@ -39408,7 +39414,7 @@ function generateKeys(count, progressCallback) {
textsecure.protocol_wrapper.startWorker();
var store = textsecure.storage.axolotl;
var identityKey = store.getMyIdentityKey();
return store.getMyIdentityKey().then(function(identityKey) {
var result = { preKeys: [], identityKey: identityKey.pubKey };
var promises = [];
@ -39443,6 +39449,7 @@ function generateKeys(count, progressCallback) {
textsecure.protocol_wrapper.stopWorker();
return result;
});
});
}
/* vim: ts=4:sw=4:expandtab

View file

@ -123,7 +123,7 @@ function generateKeys(count, progressCallback) {
textsecure.protocol_wrapper.startWorker();
var store = textsecure.storage.axolotl;
var identityKey = store.getMyIdentityKey();
return store.getMyIdentityKey().then(function(identityKey) {
var result = { preKeys: [], identityKey: identityKey.pubKey };
var promises = [];
@ -158,4 +158,5 @@ function generateKeys(count, progressCallback) {
textsecure.protocol_wrapper.stopWorker();
return result;
});
});
}

View file

@ -37045,8 +37045,7 @@ window.axolotl.protocol = function(storage_interface) {
}
var initSession = function(isInitiator, ourEphemeralKey, ourSignedKey, encodedNumber, theirIdentityPubKey, theirEphemeralPubKey, theirSignedPubKey) {
var ourIdentityKey = storage_interface.getMyIdentityKey();
return storage_interface.getMyIdentityKey().then(function(ourIdentityKey) {
if (isInitiator) {
if (ourSignedKey !== undefined)
throw new Error("Invalid call to initSession");
@ -37118,6 +37117,7 @@ window.axolotl.protocol = function(storage_interface) {
}).then(finishInit);
});
});
});
}
var removeOldChains = function(session) {
@ -37309,12 +37309,13 @@ window.axolotl.protocol = function(storage_interface) {
return fillMessageKeys(chain, message.counter).then(function() {
return HKDF(axolotlInternal.utils.convertToArrayBuffer(chain.messageKeys[message.counter]), '', "WhisperMessageKeys").then(function(keys) {
return storage_interface.getMyIdentityKey().then(function(ourIdentityKey) {
delete chain.messageKeys[message.counter];
var messageProtoArray = axolotlInternal.utils.convertToArrayBuffer(messageProto);
var macInput = new Uint8Array(messageProtoArray.byteLength + 33*2 + 1);
macInput.set(new Uint8Array(axolotlInternal.utils.convertToArrayBuffer(session.indexInfo.remoteIdentityKey)));
macInput.set(new Uint8Array(axolotlInternal.utils.convertToArrayBuffer(storage_interface.getMyIdentityKey().pubKey)), 33);
macInput.set(new Uint8Array(axolotlInternal.utils.convertToArrayBuffer(ourIdentityKey.pubKey)), 33);
macInput[33*2] = (3 << 4) | 3;
macInput.set(new Uint8Array(messageProtoArray), 33*2 + 1);
@ -37349,6 +37350,7 @@ window.axolotl.protocol = function(storage_interface) {
});
});
});
});
}
/*************************
@ -37375,6 +37377,8 @@ window.axolotl.protocol = function(storage_interface) {
// return Promise(encoded [PreKey]WhisperMessage)
self.encryptMessageFor = function(deviceObject, pushMessageContent) {
return storage_interface.getMyIdentityKey().then(function(ourIdentityKey) {
return storage_interface.getMyRegistrationId().then(function(myRegistrationId) {
return crypto_storage.getOpenSession(deviceObject.encodedNumber).then(function(session) {
var hadSession = session !== undefined;
@ -37400,7 +37404,7 @@ window.axolotl.protocol = function(storage_interface) {
var encodedMsg = axolotlInternal.utils.convertToArrayBuffer(msg.encode());
var macInput = new Uint8Array(encodedMsg.byteLength + 33*2 + 1);
macInput.set(new Uint8Array(axolotlInternal.utils.convertToArrayBuffer(storage_interface.getMyIdentityKey().pubKey)));
macInput.set(new Uint8Array(axolotlInternal.utils.convertToArrayBuffer(ourIdentityKey.pubKey)));
macInput.set(new Uint8Array(axolotlInternal.utils.convertToArrayBuffer(session.indexInfo.remoteIdentityKey)), 33);
macInput[33*2] = (3 << 4) | 3;
macInput.set(new Uint8Array(encodedMsg), 33*2 + 1);
@ -37423,8 +37427,8 @@ window.axolotl.protocol = function(storage_interface) {
}
var preKeyMsg = new axolotlInternal.protobuf.PreKeyWhisperMessage();
preKeyMsg.identityKey = axolotlInternal.utils.convertToArrayBuffer(storage_interface.getMyIdentityKey().pubKey);
preKeyMsg.registrationId = storage_interface.getMyRegistrationId();
preKeyMsg.identityKey = axolotlInternal.utils.convertToArrayBuffer(ourIdentityKey.pubKey);
preKeyMsg.registrationId = myRegistrationId;
if (session === undefined) {
var deviceIdentityKey = axolotlInternal.utils.convertToArrayBuffer(deviceObject.identityKey);
@ -37462,6 +37466,8 @@ window.axolotl.protocol = function(storage_interface) {
return {type: 1, body: axolotlInternal.utils.convertToString(message)};
});
});
});
});
}
self.createIdentityKeyRecvSocket = function() {

View file

@ -25,7 +25,7 @@
window.textsecure.storage = window.textsecure.storage || {};
// Overrideable storage implementation
window.textsecure.storage.impl = {
window.textsecure.storage.impl = window.textsecure.storage.impl || {
/*****************************
*** Base Storage Routines ***
*****************************/