mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2026-04-21 00:48:19 +01:00
Move tryMessageAgain to MessageReceiver
`tryMessageAgain` is the routine called when re-trying a message that failed to decrypt due to an IncomingIdentityKeyError. This handling needs to move to MessageReceiver because it depends on `processDecrypted` to handle incoming message protos, which depends on a server instance in order to download attachments. // FREEBIE
This commit is contained in:
@@ -1,28 +1,18 @@
|
||||
/*
|
||||
* vim: ts=4:sw=4:expandtab
|
||||
*/
|
||||
;(function() {
|
||||
'use strict';
|
||||
window.textsecure = window.textsecure || {};
|
||||
window.textsecure.storage = window.textsecure.storage || {};
|
||||
|
||||
textsecure.storage.axolotl = new AxolotlStore();
|
||||
var axolotlInstance = axolotl.protocol(textsecure.storage.axolotl);
|
||||
|
||||
window.textsecure = window.textsecure || {};
|
||||
window.textsecure.protocol_wrapper = {
|
||||
decrypt: function(source, sourceDevice, type, blob) {
|
||||
if (sourceDevice === null) { sourceDevice = 0; }
|
||||
var fromAddress = [source, sourceDevice].join('.');
|
||||
switch(type) {
|
||||
case textsecure.protobuf.Envelope.Type.CIPHERTEXT:
|
||||
return axolotlInstance.decryptWhisperMessage(fromAddress, getString(blob));
|
||||
case textsecure.protobuf.Envelope.Type.PREKEY_BUNDLE:
|
||||
if (blob.readUint8() != ((3 << 4) | 3))
|
||||
throw new Error("Bad version byte");
|
||||
var blob = blob.toArrayBuffer();
|
||||
return axolotlInstance.handlePreKeyWhisperMessage(fromAddress, blob).catch(function(e) {
|
||||
handleIdentityKeyError(fromAddress, blob, e);
|
||||
});
|
||||
default:
|
||||
return new Promise.reject(new Error("Unknown message type"));
|
||||
}
|
||||
decryptWhisperMessage: function(fromAddress, blob) {
|
||||
return axolotlInstance.decryptWhisperMessage(fromAddress, getString(blob));
|
||||
},
|
||||
closeOpenSessionForDevice: function(encodedNumber) {
|
||||
return axolotlInstance.closeOpenSessionForDevice(encodedNumber)
|
||||
@@ -44,33 +34,22 @@
|
||||
},
|
||||
getRegistrationId: function(encodedNumber) {
|
||||
return axolotlInstance.getRegistrationId(encodedNumber);
|
||||
},
|
||||
handlePreKeyWhisperMessage: function(from, blob) {
|
||||
blob.mark();
|
||||
if (blob.readUint8() != ((3 << 4) | 3)) {
|
||||
throw new Error("Bad version byte");
|
||||
}
|
||||
return axolotlInstance.handlePreKeyWhisperMessage(from, blob.toArrayBuffer()).catch(function(e) {
|
||||
if (e.message === 'Unknown identity key') {
|
||||
blob.reset(); // restore the version byte.
|
||||
|
||||
// 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;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
function handleIdentityKeyError(from, blob, e) {
|
||||
if (e.message === 'Unknown identity key') {
|
||||
// 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, e.identityKey);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
|
||||
var tryMessageAgain = function(from, encodedMessage) {
|
||||
return axolotlInstance.handlePreKeyWhisperMessage(from, encodedMessage).then(function(res) {
|
||||
var finalMessage = textsecure.protobuf.DataMessage.decode(res[0]);
|
||||
|
||||
if ((finalMessage.flags & textsecure.protobuf.DataMessage.Flags.END_SESSION)
|
||||
== textsecure.protobuf.DataMessage.Flags.END_SESSION &&
|
||||
finalMessage.sync !== null)
|
||||
res[1]();
|
||||
|
||||
return processDecrypted(finalMessage);
|
||||
}).catch(function(e) {
|
||||
handleIdentityKeyError(from, encodedMessage, e);
|
||||
});
|
||||
};
|
||||
|
||||
textsecure.replay.registerFunction(tryMessageAgain, textsecure.replay.Type.INIT_SESSION);
|
||||
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user