Add replayable error for signed key failure

Disable message sending if signed key updates fail too many times, but
allow the user to retry sending.

// FREEBIE
This commit is contained in:
lilia 2017-02-15 18:27:06 -08:00
parent e0fd188d42
commit cd0fe7037b
5 changed files with 77 additions and 7 deletions

View file

@ -183,6 +183,11 @@ MessageSender.prototype = {
}.bind(this));
},
sendMessageProto: function(timestamp, numbers, message, callback) {
var rejections = textsecure.storage.get('signedKeyRotationRejected', 0);
if (rejections > 5) {
throw new textsecure.SignedPreKeyRotationError(numbers, message.toArrayBuffer(), timestamp);
}
var outgoing = new OutgoingMessage(this.server, timestamp, numbers, message, callback);
numbers.forEach(function(number) {
@ -192,6 +197,18 @@ MessageSender.prototype = {
}.bind(this));
},
retrySendMessageProto: function(numbers, encodedMessage, timestamp) {
var proto = textsecure.protobuf.DataMessage.decode(encodedMessage);
return new Promise(function(resolve, reject) {
this.sendMessageProto(timestamp, numbers, proto, function(res) {
if (res.errors.length > 0)
reject(res);
else
resolve(res);
});
}.bind(this));
},
sendIndividualProto: function(number, proto, timestamp) {
return new Promise(function(resolve, reject) {
this.sendMessageProto(timestamp, [number], proto, function(res) {
@ -499,6 +516,7 @@ textsecure.MessageSender = function(url, ports, username, password, attachment_s
textsecure.replay.registerFunction(sender.tryMessageAgain.bind(sender), textsecure.replay.Type.ENCRYPT_MESSAGE);
textsecure.replay.registerFunction(sender.retransmitMessage.bind(sender), textsecure.replay.Type.TRANSMIT_MESSAGE);
textsecure.replay.registerFunction(sender.sendMessage.bind(sender), textsecure.replay.Type.REBUILD_MESSAGE);
textsecure.replay.registerFunction(sender.retrySendMessageProto.bind(sender), textsecure.replay.Type.RETRY_SEND_MESSAGE_PROTO);
this.sendExpirationTimerUpdateToNumber = sender.sendExpirationTimerUpdateToNumber.bind(sender);
this.sendExpirationTimerUpdateToGroup = sender.sendExpirationTimerUpdateToGroup .bind(sender);