Skip to content

Commit

Permalink
Merge pull request #454 from sachaaaaa/short_ttl
Browse files Browse the repository at this point in the history
[multi-device] Shorter TTL for pairing requests
  • Loading branch information
sachaaaaa committed Sep 2, 2019
2 parents 1d4c98a + 7b9e578 commit fbe0cbd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
4 changes: 3 additions & 1 deletion js/views/standalone_registration_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@

this.onValidatePassword();

this.onSecondaryDeviceRegistered = this.onSecondaryDeviceRegistered.bind(this);
this.onSecondaryDeviceRegistered = this.onSecondaryDeviceRegistered.bind(
this
);
},
events: {
'validation input.number': 'onValidation',
Expand Down
2 changes: 1 addition & 1 deletion libloki/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
const content = new textsecure.protobuf.Content({
pairingAuthorisation,
});
const options = {};
const options = { messageType: 'pairing-request' };
const p = new Promise((resolve, reject) => {
const outgoingMessage = new textsecure.OutgoingMessage(
null, // server
Expand Down
26 changes: 15 additions & 11 deletions libtextsecure/outgoing_message.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,17 +370,21 @@ OutgoingMessage.prototype = {
dcodeIO.ByteBuffer.wrap(ciphertext.body, 'binary').toArrayBuffer()
);
}
let ttl;
if (this.messageType === 'friend-request') {
ttl = 4 * 24 * 60 * 60 * 1000; // 4 days for friend request message
} else if (this.messageType === 'onlineBroadcast') {
ttl = 60 * 1000; // 1 minute for online broadcast message
} else if (this.messageType === 'typing') {
ttl = 60 * 1000; // 1 minute for typing indicators
} else {
const hours = window.getMessageTTL() || 24; // 1 day default for any other message
ttl = hours * 60 * 60 * 1000;
}
const getTTL = type => {
switch (type) {
case 'friend-request':
return 4 * 24 * 60 * 60 * 1000; // 4 days for friend request message
case 'onlineBroadcast':
return 60 * 1000; // 1 minute for online broadcast message
case 'typing':
return 60 * 1000; // 1 minute for typing indicators
case 'pairing-request':
return 2 * 60 * 1000; // 2 minutes for pairing requests
default:
return (window.getMessageTTL() || 24) * 60 * 60 * 1000; // 1 day default for any other message
}
};
const ttl = getTTL(this.messageType);

return {
type: ciphertext.type, // FallBackSessionCipher sets this to FRIEND_REQUEST
Expand Down

0 comments on commit fbe0cbd

Please sign in to comment.