2015-09-26 02:25:25 +02:00
|
|
|
/*
|
|
|
|
* vim: ts=4:sw=4:expandtab
|
|
|
|
*/
|
2015-01-15 00:42:01 +01:00
|
|
|
;(function() {
|
2015-04-01 22:08:09 +02:00
|
|
|
'use strict';
|
|
|
|
window.textsecure = window.textsecure || {};
|
|
|
|
window.textsecure.storage = window.textsecure.storage || {};
|
2015-09-26 02:25:25 +02:00
|
|
|
|
2015-04-01 22:08:09 +02:00
|
|
|
textsecure.storage.axolotl = new AxolotlStore();
|
|
|
|
var axolotlInstance = axolotl.protocol(textsecure.storage.axolotl);
|
2015-01-15 21:42:32 +01:00
|
|
|
|
|
|
|
window.textsecure = window.textsecure || {};
|
|
|
|
window.textsecure.protocol_wrapper = {
|
2015-09-26 02:25:25 +02:00
|
|
|
decryptWhisperMessage: function(fromAddress, blob) {
|
|
|
|
return axolotlInstance.decryptWhisperMessage(fromAddress, getString(blob));
|
2015-03-17 22:31:33 +01:00
|
|
|
},
|
|
|
|
closeOpenSessionForDevice: function(encodedNumber) {
|
|
|
|
return axolotlInstance.closeOpenSessionForDevice(encodedNumber)
|
|
|
|
},
|
|
|
|
encryptMessageFor: function(deviceObject, pushMessageContent) {
|
|
|
|
return axolotlInstance.encryptMessageFor(deviceObject, pushMessageContent);
|
|
|
|
},
|
2015-05-04 20:55:47 +02:00
|
|
|
startWorker: function() {
|
|
|
|
axolotlInstance.startWorker('/js/libaxolotl-worker.js');
|
|
|
|
},
|
|
|
|
stopWorker: function() {
|
|
|
|
axolotlInstance.stopWorker();
|
2015-03-17 22:31:33 +01:00
|
|
|
},
|
|
|
|
createIdentityKeyRecvSocket: function() {
|
|
|
|
return axolotlInstance.createIdentityKeyRecvSocket();
|
2015-04-01 22:08:09 +02:00
|
|
|
},
|
|
|
|
hasOpenSession: function(encodedNumber) {
|
|
|
|
return axolotlInstance.hasOpenSession(encodedNumber);
|
|
|
|
},
|
|
|
|
getRegistrationId: function(encodedNumber) {
|
|
|
|
return axolotlInstance.getRegistrationId(encodedNumber);
|
2015-09-26 02:25:25 +02:00
|
|
|
},
|
|
|
|
handlePreKeyWhisperMessage: function(from, blob) {
|
|
|
|
blob.mark();
|
|
|
|
if (blob.readUint8() != ((3 << 4) | 3)) {
|
|
|
|
throw new Error("Bad version byte");
|
|
|
|
}
|
2015-10-02 09:03:22 +02:00
|
|
|
return axolotlInstance.handlePreKeyWhisperMessage(from, blob).catch(function(e) {
|
2015-09-26 02:25:25 +02:00
|
|
|
if (e.message === 'Unknown identity key') {
|
|
|
|
blob.reset(); // restore the version byte.
|
2015-01-16 01:30:55 +01:00
|
|
|
|
2015-09-26 02:25:25 +02: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 21:11:17 +02:00
|
|
|
}
|
2015-06-01 23:08:21 +02:00
|
|
|
};
|
2015-01-15 00:42:01 +01:00
|
|
|
})();
|