Update libsignal-protocol 1.1.8

// FREEBIE
This commit is contained in:
lilia 2017-02-08 22:25:17 -08:00
parent 819ba8ee74
commit f0f6bbb8c0
2 changed files with 56 additions and 40 deletions

View file

@ -35639,6 +35639,7 @@ Internal.ChainType = {
Internal.SessionRecord = function() {
'use strict';
var ARCHIVED_STATES_MAX_LENGTH = 40;
var OLD_RATCHETS_MAX_LENGTH = 10;
var SESSION_RECORD_VERSION = 'v1';
var StaticByteBufferProto = new dcodeIO.ByteBuffer().__proto__;
@ -35724,7 +35725,7 @@ Internal.SessionRecord = function() {
}
var SessionRecord = function() {
this._sessions = {};
this.sessions = {};
this.version = SESSION_RECORD_VERSION;
};
@ -35733,8 +35734,8 @@ Internal.SessionRecord = function() {
if (data.version !== SESSION_RECORD_VERSION) { migrate(data); }
var record = new SessionRecord();
record._sessions = data.sessions;
if (record._sessions === undefined || record._sessions === null || typeof record._sessions !== "object" || Array.isArray(record._sessions)) {
record.sessions = data.sessions;
if (record.sessions === undefined || record.sessions === null || typeof record.sessions !== "object" || Array.isArray(record.sessions)) {
throw new Error("Error deserializing SessionRecord");
}
return record;
@ -35743,7 +35744,7 @@ Internal.SessionRecord = function() {
SessionRecord.prototype = {
serialize: function() {
return jsonThing({
sessions : this._sessions,
sessions : this.sessions,
version : this.version
});
},
@ -35753,7 +35754,7 @@ Internal.SessionRecord = function() {
},
getSessionByBaseKey: function(baseKey) {
var session = this._sessions[util.toString(baseKey)];
var session = this.sessions[util.toString(baseKey)];
if (session && session.indexInfo.baseKeyType === Internal.BaseKeyType.OURS) {
console.log("Tried to lookup a session using our basekey");
return undefined;
@ -35762,7 +35763,7 @@ Internal.SessionRecord = function() {
},
getSessionByRemoteEphemeralKey: function(remoteEphemeralKey) {
this.detectDuplicateOpenSessions();
var sessions = this._sessions;
var sessions = this.sessions;
var searchKey = util.toString(remoteEphemeralKey);
@ -35782,7 +35783,7 @@ Internal.SessionRecord = function() {
return undefined;
},
getOpenSession: function() {
var sessions = this._sessions;
var sessions = this.sessions;
if (sessions === undefined) {
return undefined;
}
@ -35798,7 +35799,7 @@ Internal.SessionRecord = function() {
},
detectDuplicateOpenSessions: function() {
var openSession;
var sessions = this._sessions;
var sessions = this.sessions;
for (var key in sessions) {
if (sessions[key].indexInfo.closed == -1) {
if (openSession !== undefined) {
@ -35809,7 +35810,7 @@ Internal.SessionRecord = function() {
}
},
updateSessionState: function(session) {
var sessions = this._sessions;
var sessions = this.sessions;
this.removeOldChains(session);
@ -35823,11 +35824,11 @@ Internal.SessionRecord = function() {
// followed by the open session
var list = [];
var openSession;
for (var k in this._sessions) {
if (this._sessions[k].indexInfo.closed === -1) {
openSession = this._sessions[k];
for (var k in this.sessions) {
if (this.sessions[k].indexInfo.closed === -1) {
openSession = this.sessions[k];
} else {
list.push(this._sessions[k]);
list.push(this.sessions[k]);
}
}
list = list.sort(function(s1, s2) {
@ -35871,8 +35872,8 @@ Internal.SessionRecord = function() {
removeOldChains: function(session) {
// Sending ratchets are always removed when we step because we never need them again
// Receiving ratchets are added to the oldRatchetList, which we parse
// here and remove all but the last five.
while (session.oldRatchetList.length > 5) {
// here and remove all but the last ten.
while (session.oldRatchetList.length > OLD_RATCHETS_MAX_LENGTH) {
var index = 0;
var oldest = session.oldRatchetList[0];
for (var i = 0; i < session.oldRatchetList.length; i++) {
@ -35888,7 +35889,7 @@ Internal.SessionRecord = function() {
},
removeOldSessions: function() {
// Retain only the last 20 sessions
var sessions = this._sessions;
var sessions = this.sessions;
var oldestBaseKey, oldestSession;
while (Object.keys(sessions).length > ARCHIVED_STATES_MAX_LENGTH) {
for (var key in sessions) {
@ -35968,15 +35969,20 @@ SessionBuilder.prototype = {
}).then(function() {
return Internal.crypto.createKeyPair();
}).then(function(baseKey) {
var devicePreKey = (device.preKey.publicKey);
var devicePreKey;
if (device.preKey) {
devicePreKey = device.preKey.publicKey;
}
return this.initSession(true, baseKey, undefined, device.identityKey,
devicePreKey, device.signedPreKey.publicKey, device.registrationId
).then(function(session) {
session.pendingPreKey = {
preKeyId : device.preKey.keyId,
signedKeyId : device.signedPreKey.keyId,
baseKey : baseKey.pubKey
};
if (device.preKey) {
session.pendingPreKey.preKeyId = device.preKey.keyId;
}
return session;
});
}.bind(this)).then(function(session) {
@ -36259,7 +36265,9 @@ SessionCipher.prototype = {
preKeyMsg.registrationId = myRegistrationId;
preKeyMsg.baseKey = util.toArrayBuffer(session.pendingPreKey.baseKey);
preKeyMsg.preKeyId = session.pendingPreKey.preKeyId;
if (session.pendingPreKey.preKeyId) {
preKeyMsg.preKeyId = session.pendingPreKey.preKeyId;
}
preKeyMsg.signedPreKeyId = session.pendingPreKey.signedKeyId;
preKeyMsg.message = message;
@ -36342,7 +36350,7 @@ SessionCipher.prototype = {
).then(function(plaintext) {
record.updateSessionState(session);
return this.storage.storeSession(address, record.serialize()).then(function() {
if (preKeyId !== undefined) {
if (preKeyId !== undefined && preKeyId !== null) {
return this.storage.removePreKey(preKeyId);
}
}.bind(this)).then(function() {

View file

@ -35515,6 +35515,7 @@ Internal.ChainType = {
Internal.SessionRecord = function() {
'use strict';
var ARCHIVED_STATES_MAX_LENGTH = 40;
var OLD_RATCHETS_MAX_LENGTH = 10;
var SESSION_RECORD_VERSION = 'v1';
var StaticByteBufferProto = new dcodeIO.ByteBuffer().__proto__;
@ -35600,7 +35601,7 @@ Internal.SessionRecord = function() {
}
var SessionRecord = function() {
this._sessions = {};
this.sessions = {};
this.version = SESSION_RECORD_VERSION;
};
@ -35609,8 +35610,8 @@ Internal.SessionRecord = function() {
if (data.version !== SESSION_RECORD_VERSION) { migrate(data); }
var record = new SessionRecord();
record._sessions = data.sessions;
if (record._sessions === undefined || record._sessions === null || typeof record._sessions !== "object" || Array.isArray(record._sessions)) {
record.sessions = data.sessions;
if (record.sessions === undefined || record.sessions === null || typeof record.sessions !== "object" || Array.isArray(record.sessions)) {
throw new Error("Error deserializing SessionRecord");
}
return record;
@ -35619,7 +35620,7 @@ Internal.SessionRecord = function() {
SessionRecord.prototype = {
serialize: function() {
return jsonThing({
sessions : this._sessions,
sessions : this.sessions,
version : this.version
});
},
@ -35629,7 +35630,7 @@ Internal.SessionRecord = function() {
},
getSessionByBaseKey: function(baseKey) {
var session = this._sessions[util.toString(baseKey)];
var session = this.sessions[util.toString(baseKey)];
if (session && session.indexInfo.baseKeyType === Internal.BaseKeyType.OURS) {
console.log("Tried to lookup a session using our basekey");
return undefined;
@ -35638,7 +35639,7 @@ Internal.SessionRecord = function() {
},
getSessionByRemoteEphemeralKey: function(remoteEphemeralKey) {
this.detectDuplicateOpenSessions();
var sessions = this._sessions;
var sessions = this.sessions;
var searchKey = util.toString(remoteEphemeralKey);
@ -35658,7 +35659,7 @@ Internal.SessionRecord = function() {
return undefined;
},
getOpenSession: function() {
var sessions = this._sessions;
var sessions = this.sessions;
if (sessions === undefined) {
return undefined;
}
@ -35674,7 +35675,7 @@ Internal.SessionRecord = function() {
},
detectDuplicateOpenSessions: function() {
var openSession;
var sessions = this._sessions;
var sessions = this.sessions;
for (var key in sessions) {
if (sessions[key].indexInfo.closed == -1) {
if (openSession !== undefined) {
@ -35685,7 +35686,7 @@ Internal.SessionRecord = function() {
}
},
updateSessionState: function(session) {
var sessions = this._sessions;
var sessions = this.sessions;
this.removeOldChains(session);
@ -35699,11 +35700,11 @@ Internal.SessionRecord = function() {
// followed by the open session
var list = [];
var openSession;
for (var k in this._sessions) {
if (this._sessions[k].indexInfo.closed === -1) {
openSession = this._sessions[k];
for (var k in this.sessions) {
if (this.sessions[k].indexInfo.closed === -1) {
openSession = this.sessions[k];
} else {
list.push(this._sessions[k]);
list.push(this.sessions[k]);
}
}
list = list.sort(function(s1, s2) {
@ -35747,8 +35748,8 @@ Internal.SessionRecord = function() {
removeOldChains: function(session) {
// Sending ratchets are always removed when we step because we never need them again
// Receiving ratchets are added to the oldRatchetList, which we parse
// here and remove all but the last five.
while (session.oldRatchetList.length > 5) {
// here and remove all but the last ten.
while (session.oldRatchetList.length > OLD_RATCHETS_MAX_LENGTH) {
var index = 0;
var oldest = session.oldRatchetList[0];
for (var i = 0; i < session.oldRatchetList.length; i++) {
@ -35764,7 +35765,7 @@ Internal.SessionRecord = function() {
},
removeOldSessions: function() {
// Retain only the last 20 sessions
var sessions = this._sessions;
var sessions = this.sessions;
var oldestBaseKey, oldestSession;
while (Object.keys(sessions).length > ARCHIVED_STATES_MAX_LENGTH) {
for (var key in sessions) {
@ -35844,15 +35845,20 @@ SessionBuilder.prototype = {
}).then(function() {
return Internal.crypto.createKeyPair();
}).then(function(baseKey) {
var devicePreKey = (device.preKey.publicKey);
var devicePreKey;
if (device.preKey) {
devicePreKey = device.preKey.publicKey;
}
return this.initSession(true, baseKey, undefined, device.identityKey,
devicePreKey, device.signedPreKey.publicKey, device.registrationId
).then(function(session) {
session.pendingPreKey = {
preKeyId : device.preKey.keyId,
signedKeyId : device.signedPreKey.keyId,
baseKey : baseKey.pubKey
};
if (device.preKey) {
session.pendingPreKey.preKeyId = device.preKey.keyId;
}
return session;
});
}.bind(this)).then(function(session) {
@ -36135,7 +36141,9 @@ SessionCipher.prototype = {
preKeyMsg.registrationId = myRegistrationId;
preKeyMsg.baseKey = util.toArrayBuffer(session.pendingPreKey.baseKey);
preKeyMsg.preKeyId = session.pendingPreKey.preKeyId;
if (session.pendingPreKey.preKeyId) {
preKeyMsg.preKeyId = session.pendingPreKey.preKeyId;
}
preKeyMsg.signedPreKeyId = session.pendingPreKey.signedKeyId;
preKeyMsg.message = message;
@ -36218,7 +36226,7 @@ SessionCipher.prototype = {
).then(function(plaintext) {
record.updateSessionState(session);
return this.storage.storeSession(address, record.serialize()).then(function() {
if (preKeyId !== undefined) {
if (preKeyId !== undefined && preKeyId !== null) {
return this.storage.removePreKey(preKeyId);
}
}.bind(this)).then(function() {