MessageReceiver uses SessionCipher to retry conflicts
// FREEBIE
This commit is contained in:
parent
9ecfe6acb0
commit
d5f4665fa4
2 changed files with 58 additions and 46 deletions
|
@ -37038,13 +37038,27 @@ MessageReceiver.prototype.extend({
|
|||
break;
|
||||
case textsecure.protobuf.Envelope.Type.PREKEY_BUNDLE:
|
||||
console.log('prekey whisper message');
|
||||
promise = this.decryptPreKeyWhisperMessage(ciphertext, sessionCipher, address);
|
||||
break;
|
||||
default:
|
||||
promise = Promise.reject(new Error("Unknown message type"));
|
||||
}
|
||||
return promise.catch(function(error) {
|
||||
var ev = new Event('error');
|
||||
ev.error = error;
|
||||
ev.proto = envelope;
|
||||
this.dispatchEvent(ev);
|
||||
return Promise.reject(error);
|
||||
}.bind(this));
|
||||
},
|
||||
decryptPreKeyWhisperMessage: function(ciphertext, sessionCipher, address) {
|
||||
ciphertext.mark();
|
||||
var version = ciphertext.readUint8();
|
||||
if ((version & 0xF) > 3 || (version >> 4) < 3) {
|
||||
// min version > 3 or max version < 3
|
||||
throw new Error("Incompatible version byte");
|
||||
}
|
||||
promise = sessionCipher.decryptPreKeyWhisperMessage(ciphertext).catch(function(e) {
|
||||
return sessionCipher.decryptPreKeyWhisperMessage(ciphertext).catch(function(e) {
|
||||
if (e.message === 'Unknown identity key') {
|
||||
ciphertext.reset(); // restore the version byte.
|
||||
|
||||
|
@ -37058,17 +37072,6 @@ MessageReceiver.prototype.extend({
|
|||
}
|
||||
throw e;
|
||||
});
|
||||
break;
|
||||
default:
|
||||
promise = Promise.reject(new Error("Unknown message type"));
|
||||
}
|
||||
return promise.catch(function(error) {
|
||||
var ev = new Event('error');
|
||||
ev.error = error;
|
||||
ev.proto = envelope;
|
||||
this.dispatchEvent(ev);
|
||||
return Promise.reject(error);
|
||||
}.bind(this));
|
||||
},
|
||||
handleSentMessage: function(destination, timestamp, message) {
|
||||
var p = Promise.resolve();
|
||||
|
@ -37244,15 +37247,18 @@ MessageReceiver.prototype.extend({
|
|||
then(updateAttachment);
|
||||
},
|
||||
tryMessageAgain: function(from, encodedMessage) {
|
||||
var bytes = dcodeIO.ByteBuffer.wrap(encodedMessage);
|
||||
return textsecure.protocol_wrapper.handlePreKeyWhisperMessage(from, bytes).then(function(res) {
|
||||
var ciphertext = dcodeIO.ByteBuffer.wrap(encodedMessage);
|
||||
var address = libsignal.SignalProtocolAddress.fromString(from);
|
||||
var sessionCipher = new libsignal.SessionCipher(textsecure.storage.protocol, address);
|
||||
console.log('retrying prekey whisper message');
|
||||
return this.decryptPreKeyWhisperMessage(ciphertext, sessionCipher, address).then(function(res) {
|
||||
var finalMessage = textsecure.protobuf.DataMessage.decode(res[0]);
|
||||
|
||||
var p = Promise.resolve();
|
||||
if ((finalMessage.flags & textsecure.protobuf.DataMessage.Flags.END_SESSION)
|
||||
== textsecure.protobuf.DataMessage.Flags.END_SESSION &&
|
||||
finalMessage.sync !== null) {
|
||||
var number = textsecure.utils.unencodeNumber(from)[0];
|
||||
var number = address.getName();
|
||||
p = this.handleEndSession(number);
|
||||
}
|
||||
|
||||
|
|
|
@ -118,13 +118,27 @@ MessageReceiver.prototype.extend({
|
|||
break;
|
||||
case textsecure.protobuf.Envelope.Type.PREKEY_BUNDLE:
|
||||
console.log('prekey whisper message');
|
||||
promise = this.decryptPreKeyWhisperMessage(ciphertext, sessionCipher, address);
|
||||
break;
|
||||
default:
|
||||
promise = Promise.reject(new Error("Unknown message type"));
|
||||
}
|
||||
return promise.catch(function(error) {
|
||||
var ev = new Event('error');
|
||||
ev.error = error;
|
||||
ev.proto = envelope;
|
||||
this.dispatchEvent(ev);
|
||||
return Promise.reject(error);
|
||||
}.bind(this));
|
||||
},
|
||||
decryptPreKeyWhisperMessage: function(ciphertext, sessionCipher, address) {
|
||||
ciphertext.mark();
|
||||
var version = ciphertext.readUint8();
|
||||
if ((version & 0xF) > 3 || (version >> 4) < 3) {
|
||||
// min version > 3 or max version < 3
|
||||
throw new Error("Incompatible version byte");
|
||||
}
|
||||
promise = sessionCipher.decryptPreKeyWhisperMessage(ciphertext).catch(function(e) {
|
||||
return sessionCipher.decryptPreKeyWhisperMessage(ciphertext).catch(function(e) {
|
||||
if (e.message === 'Unknown identity key') {
|
||||
ciphertext.reset(); // restore the version byte.
|
||||
|
||||
|
@ -138,17 +152,6 @@ MessageReceiver.prototype.extend({
|
|||
}
|
||||
throw e;
|
||||
});
|
||||
break;
|
||||
default:
|
||||
promise = Promise.reject(new Error("Unknown message type"));
|
||||
}
|
||||
return promise.catch(function(error) {
|
||||
var ev = new Event('error');
|
||||
ev.error = error;
|
||||
ev.proto = envelope;
|
||||
this.dispatchEvent(ev);
|
||||
return Promise.reject(error);
|
||||
}.bind(this));
|
||||
},
|
||||
handleSentMessage: function(destination, timestamp, message) {
|
||||
var p = Promise.resolve();
|
||||
|
@ -324,15 +327,18 @@ MessageReceiver.prototype.extend({
|
|||
then(updateAttachment);
|
||||
},
|
||||
tryMessageAgain: function(from, encodedMessage) {
|
||||
var bytes = dcodeIO.ByteBuffer.wrap(encodedMessage);
|
||||
return textsecure.protocol_wrapper.handlePreKeyWhisperMessage(from, bytes).then(function(res) {
|
||||
var ciphertext = dcodeIO.ByteBuffer.wrap(encodedMessage);
|
||||
var address = libsignal.SignalProtocolAddress.fromString(from);
|
||||
var sessionCipher = new libsignal.SessionCipher(textsecure.storage.protocol, address);
|
||||
console.log('retrying prekey whisper message');
|
||||
return this.decryptPreKeyWhisperMessage(ciphertext, sessionCipher, address).then(function(res) {
|
||||
var finalMessage = textsecure.protobuf.DataMessage.decode(res[0]);
|
||||
|
||||
var p = Promise.resolve();
|
||||
if ((finalMessage.flags & textsecure.protobuf.DataMessage.Flags.END_SESSION)
|
||||
== textsecure.protobuf.DataMessage.Flags.END_SESSION &&
|
||||
finalMessage.sync !== null) {
|
||||
var number = textsecure.utils.unencodeNumber(from)[0];
|
||||
var number = address.getName();
|
||||
p = this.handleEndSession(number);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue