2015-09-25 17:25:25 -07:00
|
|
|
/*
|
|
|
|
* vim: ts=4:sw=4:expandtab
|
|
|
|
*/
|
2015-01-14 13:42:01 -10:00
|
|
|
;(function() {
|
2015-04-01 13:08:09 -07:00
|
|
|
'use strict';
|
|
|
|
window.textsecure = window.textsecure || {};
|
|
|
|
window.textsecure.storage = window.textsecure.storage || {};
|
2015-09-25 17:25:25 -07:00
|
|
|
|
2015-04-01 13:08:09 -07:00
|
|
|
textsecure.storage.axolotl = new AxolotlStore();
|
|
|
|
var axolotlInstance = axolotl.protocol(textsecure.storage.axolotl);
|
2015-01-15 10:42:32 -10:00
|
|
|
|
|
|
|
window.textsecure = window.textsecure || {};
|
|
|
|
window.textsecure.protocol_wrapper = {
|
2015-09-25 17:25:25 -07:00
|
|
|
decryptWhisperMessage: function(fromAddress, blob) {
|
|
|
|
return axolotlInstance.decryptWhisperMessage(fromAddress, getString(blob));
|
2015-03-17 14:31:33 -07:00
|
|
|
},
|
|
|
|
closeOpenSessionForDevice: function(encodedNumber) {
|
|
|
|
return axolotlInstance.closeOpenSessionForDevice(encodedNumber)
|
|
|
|
},
|
|
|
|
encryptMessageFor: function(deviceObject, pushMessageContent) {
|
|
|
|
return axolotlInstance.encryptMessageFor(deviceObject, pushMessageContent);
|
|
|
|
},
|
2015-05-04 11:55:47 -07:00
|
|
|
startWorker: function() {
|
|
|
|
axolotlInstance.startWorker('/js/libaxolotl-worker.js');
|
|
|
|
},
|
|
|
|
stopWorker: function() {
|
|
|
|
axolotlInstance.stopWorker();
|
2015-03-17 14:31:33 -07:00
|
|
|
},
|
|
|
|
createIdentityKeyRecvSocket: function() {
|
|
|
|
return axolotlInstance.createIdentityKeyRecvSocket();
|
2015-04-01 13:08:09 -07:00
|
|
|
},
|
|
|
|
hasOpenSession: function(encodedNumber) {
|
|
|
|
return axolotlInstance.hasOpenSession(encodedNumber);
|
|
|
|
},
|
|
|
|
getRegistrationId: function(encodedNumber) {
|
|
|
|
return axolotlInstance.getRegistrationId(encodedNumber);
|
2015-09-25 17:25:25 -07:00
|
|
|
},
|
|
|
|
handlePreKeyWhisperMessage: function(from, blob) {
|
|
|
|
blob.mark();
|
2015-11-09 16:48:14 -08:00
|
|
|
var version = blob.readUint8();
|
|
|
|
if ((version & 0xF) > 3 || (version >> 4) < 3) {
|
|
|
|
// min version > 3 or max version < 3
|
|
|
|
throw new Error("Incompatible version byte");
|
2015-09-25 17:25:25 -07:00
|
|
|
}
|
2015-10-02 00:03:22 -07:00
|
|
|
return axolotlInstance.handlePreKeyWhisperMessage(from, blob).catch(function(e) {
|
2015-09-25 17:25:25 -07:00
|
|
|
if (e.message === 'Unknown identity key') {
|
|
|
|
blob.reset(); // restore the version byte.
|
2015-01-15 14:30:55 -10:00
|
|
|
|
2015-09-25 17:25:25 -07:00
|
|
|
// create an error that the UI will pick up and ask the
|
|
|
|
// user if they want to re-negotiate
|
|
|
|
throw new textsecure.IncomingIdentityKeyError(from, blob.toArrayBuffer(), e.identityKey);
|
|
|
|
}
|
|
|
|
throw e;
|
|
|
|
});
|
2015-07-31 12:11:17 -07:00
|
|
|
}
|
2015-06-01 14:08:21 -07:00
|
|
|
};
|
2015-01-14 13:42:01 -10:00
|
|
|
})();
|