Skip to content
This repository was archived by the owner on Aug 5, 2021. It is now read-only.

Commit b6c3093

Browse files
SessionCipher: allow caller to provide fillMessageKeys limit
If options.messageKeysLimit is provided by falsey, then we don't apply any limit at all. This can be used to set no limit for communications from your own devices. Why would you want that? People leave their laptops closed for weeks at a time and get this error, since their other devices are sending messages to it constantly: "Too many message keys for chain" And it seems to be really hard to fix once you're in this state. Sync messages no longer show up from the device that got into this state. FREEBIE
1 parent f308236 commit b6c3093

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

dist/libsignal-protocol.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36032,7 +36032,14 @@ libsignal.SessionBuilder = function (storage, remoteAddress) {
3603236032
this.processV3 = builder.processV3.bind(builder);
3603336033
};
3603436034

36035-
function SessionCipher(storage, remoteAddress) {
36035+
function SessionCipher(storage, remoteAddress, options) {
36036+
options = options || {};
36037+
36038+
if (typeof options.messageKeysLimit === 'undefined') {
36039+
options.messageKeysLimit = 1000;
36040+
}
36041+
36042+
this.messageKeysLimit = options.messageKeysLimit;
3603636043
this.remoteAddress = remoteAddress;
3603736044
this.storage = storage;
3603836045
}
@@ -36305,7 +36312,7 @@ SessionCipher.prototype = {
3630536312
});
3630636313
},
3630736314
fillMessageKeys: function(chain, counter) {
36308-
if (Object.keys(chain.messageKeys).length >= 1000) {
36315+
if (this.messageKeysLimit && Object.keys(chain.messageKeys).length >= this.messageKeysLimit) {
3630936316
console.log("Too many message keys for chain");
3631036317
return Promise.resolve(); // Stalker, much?
3631136318
}
@@ -36428,8 +36435,8 @@ SessionCipher.prototype = {
3642836435
}
3642936436
};
3643036437

36431-
libsignal.SessionCipher = function(storage, remoteAddress) {
36432-
var cipher = new SessionCipher(storage, remoteAddress);
36438+
libsignal.SessionCipher = function(storage, remoteAddress, options) {
36439+
var cipher = new SessionCipher(storage, remoteAddress, options);
3643336440

3643436441
// returns a Promise that resolves to a ciphertext object
3643536442
this.encrypt = cipher.encrypt.bind(cipher);

src/SessionCipher.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
function SessionCipher(storage, remoteAddress) {
1+
function SessionCipher(storage, remoteAddress, options) {
2+
options = options || {};
3+
4+
if (typeof options.messageKeysLimit === 'undefined') {
5+
options.messageKeysLimit = 1000;
6+
}
7+
8+
this.messageKeysLimit = options.messageKeysLimit;
29
this.remoteAddress = remoteAddress;
310
this.storage = storage;
411
}
@@ -271,7 +278,7 @@ SessionCipher.prototype = {
271278
});
272279
},
273280
fillMessageKeys: function(chain, counter) {
274-
if (Object.keys(chain.messageKeys).length >= 1000) {
281+
if (this.messageKeysLimit && Object.keys(chain.messageKeys).length >= this.messageKeysLimit) {
275282
console.log("Too many message keys for chain");
276283
return Promise.resolve(); // Stalker, much?
277284
}
@@ -394,8 +401,8 @@ SessionCipher.prototype = {
394401
}
395402
};
396403

397-
libsignal.SessionCipher = function(storage, remoteAddress) {
398-
var cipher = new SessionCipher(storage, remoteAddress);
404+
libsignal.SessionCipher = function(storage, remoteAddress, options) {
405+
var cipher = new SessionCipher(storage, remoteAddress, options);
399406

400407
// returns a Promise that resolves to a ciphertext object
401408
this.encrypt = cipher.encrypt.bind(cipher);

0 commit comments

Comments
 (0)