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

View file

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

View file

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

View file

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

View file

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