Check END_SESSION messages in processDecrypted

This commit is contained in:
Matt Corallo 2015-02-25 17:42:47 -08:00 committed by lilia
parent 29192edcb8
commit 5abf3073d5
3 changed files with 31 additions and 7 deletions

View file

@ -138,12 +138,12 @@
// identity key change.
var source = message.get('source');
var timestamp = message.get('sent_at');
var type = 'incoming';
if (source === textsecure.storage.getUnencrypted("number_id").split('.')[0] && pushMessageContent.sync) {
type = 'outgoing';
timestamp = pushMessageContent.sync.timestamp;
}
return textsecure.processDecrypted(pushMessageContent, source).then(function(pushMessageContent) {
var type = 'incoming';
if (pushMessageContent.sync) {
type = 'outgoing';
timestamp = pushMessageContent.sync.timestamp;
}
var now = new Date().getTime();
var conversationId = getConversationId(pushMessageContent) || source;

View file

@ -16277,9 +16277,21 @@ textsecure.processDecrypted = function(decrypted, source) {
if (decrypted.flags == null)
decrypted.flags = 0;
if (decrypted.sync !== null && textsecure.utils.unencodeNumber(textsecure.storage.getUnencrypted("number_id"))[0] != source)
throw new Error("Got sync context on a message not from a peer device");
if ((decrypted.flags & textsecure.protobuf.PushMessageContent.Flags.END_SESSION)
== textsecure.protobuf.PushMessageContent.Flags.END_SESSION)
== textsecure.protobuf.PushMessageContent.Flags.END_SESSION) {
decrypted.body = null;
decrypted.attachments = [];
decrypted.group = null;
if (decrypted.sync !== null) {
// We didn't actually close the session - see axolotl_wrapper
// so just throw an error since this message makes no sense
throw new Error("Got a sync END_SESSION message");
}
return Promise.resolve(decrypted);
}
if (decrypted.flags != 0) {
throw new Error("Unknown flags in message");
}

View file

@ -161,9 +161,21 @@ textsecure.processDecrypted = function(decrypted, source) {
if (decrypted.flags == null)
decrypted.flags = 0;
if (decrypted.sync !== null && textsecure.utils.unencodeNumber(textsecure.storage.getUnencrypted("number_id"))[0] != source)
throw new Error("Got sync context on a message not from a peer device");
if ((decrypted.flags & textsecure.protobuf.PushMessageContent.Flags.END_SESSION)
== textsecure.protobuf.PushMessageContent.Flags.END_SESSION)
== textsecure.protobuf.PushMessageContent.Flags.END_SESSION) {
decrypted.body = null;
decrypted.attachments = [];
decrypted.group = null;
if (decrypted.sync !== null) {
// We didn't actually close the session - see axolotl_wrapper
// so just throw an error since this message makes no sense
throw new Error("Got a sync END_SESSION message");
}
return Promise.resolve(decrypted);
}
if (decrypted.flags != 0) {
throw new Error("Unknown flags in message");
}