Update libsignal-protocol 1.1.8
// FREEBIE
This commit is contained in:
parent
819ba8ee74
commit
f0f6bbb8c0
2 changed files with 56 additions and 40 deletions
|
@ -35639,6 +35639,7 @@ Internal.ChainType = {
|
||||||
Internal.SessionRecord = function() {
|
Internal.SessionRecord = function() {
|
||||||
'use strict';
|
'use strict';
|
||||||
var ARCHIVED_STATES_MAX_LENGTH = 40;
|
var ARCHIVED_STATES_MAX_LENGTH = 40;
|
||||||
|
var OLD_RATCHETS_MAX_LENGTH = 10;
|
||||||
var SESSION_RECORD_VERSION = 'v1';
|
var SESSION_RECORD_VERSION = 'v1';
|
||||||
|
|
||||||
var StaticByteBufferProto = new dcodeIO.ByteBuffer().__proto__;
|
var StaticByteBufferProto = new dcodeIO.ByteBuffer().__proto__;
|
||||||
|
@ -35724,7 +35725,7 @@ Internal.SessionRecord = function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
var SessionRecord = function() {
|
var SessionRecord = function() {
|
||||||
this._sessions = {};
|
this.sessions = {};
|
||||||
this.version = SESSION_RECORD_VERSION;
|
this.version = SESSION_RECORD_VERSION;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -35733,8 +35734,8 @@ Internal.SessionRecord = function() {
|
||||||
if (data.version !== SESSION_RECORD_VERSION) { migrate(data); }
|
if (data.version !== SESSION_RECORD_VERSION) { migrate(data); }
|
||||||
|
|
||||||
var record = new SessionRecord();
|
var record = new SessionRecord();
|
||||||
record._sessions = data.sessions;
|
record.sessions = data.sessions;
|
||||||
if (record._sessions === undefined || record._sessions === null || typeof record._sessions !== "object" || Array.isArray(record._sessions)) {
|
if (record.sessions === undefined || record.sessions === null || typeof record.sessions !== "object" || Array.isArray(record.sessions)) {
|
||||||
throw new Error("Error deserializing SessionRecord");
|
throw new Error("Error deserializing SessionRecord");
|
||||||
}
|
}
|
||||||
return record;
|
return record;
|
||||||
|
@ -35743,7 +35744,7 @@ Internal.SessionRecord = function() {
|
||||||
SessionRecord.prototype = {
|
SessionRecord.prototype = {
|
||||||
serialize: function() {
|
serialize: function() {
|
||||||
return jsonThing({
|
return jsonThing({
|
||||||
sessions : this._sessions,
|
sessions : this.sessions,
|
||||||
version : this.version
|
version : this.version
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -35753,7 +35754,7 @@ Internal.SessionRecord = function() {
|
||||||
},
|
},
|
||||||
|
|
||||||
getSessionByBaseKey: function(baseKey) {
|
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) {
|
if (session && session.indexInfo.baseKeyType === Internal.BaseKeyType.OURS) {
|
||||||
console.log("Tried to lookup a session using our basekey");
|
console.log("Tried to lookup a session using our basekey");
|
||||||
return undefined;
|
return undefined;
|
||||||
|
@ -35762,7 +35763,7 @@ Internal.SessionRecord = function() {
|
||||||
},
|
},
|
||||||
getSessionByRemoteEphemeralKey: function(remoteEphemeralKey) {
|
getSessionByRemoteEphemeralKey: function(remoteEphemeralKey) {
|
||||||
this.detectDuplicateOpenSessions();
|
this.detectDuplicateOpenSessions();
|
||||||
var sessions = this._sessions;
|
var sessions = this.sessions;
|
||||||
|
|
||||||
var searchKey = util.toString(remoteEphemeralKey);
|
var searchKey = util.toString(remoteEphemeralKey);
|
||||||
|
|
||||||
|
@ -35782,7 +35783,7 @@ Internal.SessionRecord = function() {
|
||||||
return undefined;
|
return undefined;
|
||||||
},
|
},
|
||||||
getOpenSession: function() {
|
getOpenSession: function() {
|
||||||
var sessions = this._sessions;
|
var sessions = this.sessions;
|
||||||
if (sessions === undefined) {
|
if (sessions === undefined) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
@ -35798,7 +35799,7 @@ Internal.SessionRecord = function() {
|
||||||
},
|
},
|
||||||
detectDuplicateOpenSessions: function() {
|
detectDuplicateOpenSessions: function() {
|
||||||
var openSession;
|
var openSession;
|
||||||
var sessions = this._sessions;
|
var sessions = this.sessions;
|
||||||
for (var key in sessions) {
|
for (var key in sessions) {
|
||||||
if (sessions[key].indexInfo.closed == -1) {
|
if (sessions[key].indexInfo.closed == -1) {
|
||||||
if (openSession !== undefined) {
|
if (openSession !== undefined) {
|
||||||
|
@ -35809,7 +35810,7 @@ Internal.SessionRecord = function() {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
updateSessionState: function(session) {
|
updateSessionState: function(session) {
|
||||||
var sessions = this._sessions;
|
var sessions = this.sessions;
|
||||||
|
|
||||||
this.removeOldChains(session);
|
this.removeOldChains(session);
|
||||||
|
|
||||||
|
@ -35823,11 +35824,11 @@ Internal.SessionRecord = function() {
|
||||||
// followed by the open session
|
// followed by the open session
|
||||||
var list = [];
|
var list = [];
|
||||||
var openSession;
|
var openSession;
|
||||||
for (var k in this._sessions) {
|
for (var k in this.sessions) {
|
||||||
if (this._sessions[k].indexInfo.closed === -1) {
|
if (this.sessions[k].indexInfo.closed === -1) {
|
||||||
openSession = this._sessions[k];
|
openSession = this.sessions[k];
|
||||||
} else {
|
} else {
|
||||||
list.push(this._sessions[k]);
|
list.push(this.sessions[k]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
list = list.sort(function(s1, s2) {
|
list = list.sort(function(s1, s2) {
|
||||||
|
@ -35871,8 +35872,8 @@ Internal.SessionRecord = function() {
|
||||||
removeOldChains: function(session) {
|
removeOldChains: function(session) {
|
||||||
// Sending ratchets are always removed when we step because we never need them again
|
// Sending ratchets are always removed when we step because we never need them again
|
||||||
// Receiving ratchets are added to the oldRatchetList, which we parse
|
// Receiving ratchets are added to the oldRatchetList, which we parse
|
||||||
// here and remove all but the last five.
|
// here and remove all but the last ten.
|
||||||
while (session.oldRatchetList.length > 5) {
|
while (session.oldRatchetList.length > OLD_RATCHETS_MAX_LENGTH) {
|
||||||
var index = 0;
|
var index = 0;
|
||||||
var oldest = session.oldRatchetList[0];
|
var oldest = session.oldRatchetList[0];
|
||||||
for (var i = 0; i < session.oldRatchetList.length; i++) {
|
for (var i = 0; i < session.oldRatchetList.length; i++) {
|
||||||
|
@ -35888,7 +35889,7 @@ Internal.SessionRecord = function() {
|
||||||
},
|
},
|
||||||
removeOldSessions: function() {
|
removeOldSessions: function() {
|
||||||
// Retain only the last 20 sessions
|
// Retain only the last 20 sessions
|
||||||
var sessions = this._sessions;
|
var sessions = this.sessions;
|
||||||
var oldestBaseKey, oldestSession;
|
var oldestBaseKey, oldestSession;
|
||||||
while (Object.keys(sessions).length > ARCHIVED_STATES_MAX_LENGTH) {
|
while (Object.keys(sessions).length > ARCHIVED_STATES_MAX_LENGTH) {
|
||||||
for (var key in sessions) {
|
for (var key in sessions) {
|
||||||
|
@ -35968,15 +35969,20 @@ SessionBuilder.prototype = {
|
||||||
}).then(function() {
|
}).then(function() {
|
||||||
return Internal.crypto.createKeyPair();
|
return Internal.crypto.createKeyPair();
|
||||||
}).then(function(baseKey) {
|
}).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,
|
return this.initSession(true, baseKey, undefined, device.identityKey,
|
||||||
devicePreKey, device.signedPreKey.publicKey, device.registrationId
|
devicePreKey, device.signedPreKey.publicKey, device.registrationId
|
||||||
).then(function(session) {
|
).then(function(session) {
|
||||||
session.pendingPreKey = {
|
session.pendingPreKey = {
|
||||||
preKeyId : device.preKey.keyId,
|
|
||||||
signedKeyId : device.signedPreKey.keyId,
|
signedKeyId : device.signedPreKey.keyId,
|
||||||
baseKey : baseKey.pubKey
|
baseKey : baseKey.pubKey
|
||||||
};
|
};
|
||||||
|
if (device.preKey) {
|
||||||
|
session.pendingPreKey.preKeyId = device.preKey.keyId;
|
||||||
|
}
|
||||||
return session;
|
return session;
|
||||||
});
|
});
|
||||||
}.bind(this)).then(function(session) {
|
}.bind(this)).then(function(session) {
|
||||||
|
@ -36259,7 +36265,9 @@ SessionCipher.prototype = {
|
||||||
preKeyMsg.registrationId = myRegistrationId;
|
preKeyMsg.registrationId = myRegistrationId;
|
||||||
|
|
||||||
preKeyMsg.baseKey = util.toArrayBuffer(session.pendingPreKey.baseKey);
|
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.signedPreKeyId = session.pendingPreKey.signedKeyId;
|
||||||
|
|
||||||
preKeyMsg.message = message;
|
preKeyMsg.message = message;
|
||||||
|
@ -36342,7 +36350,7 @@ SessionCipher.prototype = {
|
||||||
).then(function(plaintext) {
|
).then(function(plaintext) {
|
||||||
record.updateSessionState(session);
|
record.updateSessionState(session);
|
||||||
return this.storage.storeSession(address, record.serialize()).then(function() {
|
return this.storage.storeSession(address, record.serialize()).then(function() {
|
||||||
if (preKeyId !== undefined) {
|
if (preKeyId !== undefined && preKeyId !== null) {
|
||||||
return this.storage.removePreKey(preKeyId);
|
return this.storage.removePreKey(preKeyId);
|
||||||
}
|
}
|
||||||
}.bind(this)).then(function() {
|
}.bind(this)).then(function() {
|
||||||
|
|
|
@ -35515,6 +35515,7 @@ Internal.ChainType = {
|
||||||
Internal.SessionRecord = function() {
|
Internal.SessionRecord = function() {
|
||||||
'use strict';
|
'use strict';
|
||||||
var ARCHIVED_STATES_MAX_LENGTH = 40;
|
var ARCHIVED_STATES_MAX_LENGTH = 40;
|
||||||
|
var OLD_RATCHETS_MAX_LENGTH = 10;
|
||||||
var SESSION_RECORD_VERSION = 'v1';
|
var SESSION_RECORD_VERSION = 'v1';
|
||||||
|
|
||||||
var StaticByteBufferProto = new dcodeIO.ByteBuffer().__proto__;
|
var StaticByteBufferProto = new dcodeIO.ByteBuffer().__proto__;
|
||||||
|
@ -35600,7 +35601,7 @@ Internal.SessionRecord = function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
var SessionRecord = function() {
|
var SessionRecord = function() {
|
||||||
this._sessions = {};
|
this.sessions = {};
|
||||||
this.version = SESSION_RECORD_VERSION;
|
this.version = SESSION_RECORD_VERSION;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -35609,8 +35610,8 @@ Internal.SessionRecord = function() {
|
||||||
if (data.version !== SESSION_RECORD_VERSION) { migrate(data); }
|
if (data.version !== SESSION_RECORD_VERSION) { migrate(data); }
|
||||||
|
|
||||||
var record = new SessionRecord();
|
var record = new SessionRecord();
|
||||||
record._sessions = data.sessions;
|
record.sessions = data.sessions;
|
||||||
if (record._sessions === undefined || record._sessions === null || typeof record._sessions !== "object" || Array.isArray(record._sessions)) {
|
if (record.sessions === undefined || record.sessions === null || typeof record.sessions !== "object" || Array.isArray(record.sessions)) {
|
||||||
throw new Error("Error deserializing SessionRecord");
|
throw new Error("Error deserializing SessionRecord");
|
||||||
}
|
}
|
||||||
return record;
|
return record;
|
||||||
|
@ -35619,7 +35620,7 @@ Internal.SessionRecord = function() {
|
||||||
SessionRecord.prototype = {
|
SessionRecord.prototype = {
|
||||||
serialize: function() {
|
serialize: function() {
|
||||||
return jsonThing({
|
return jsonThing({
|
||||||
sessions : this._sessions,
|
sessions : this.sessions,
|
||||||
version : this.version
|
version : this.version
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -35629,7 +35630,7 @@ Internal.SessionRecord = function() {
|
||||||
},
|
},
|
||||||
|
|
||||||
getSessionByBaseKey: function(baseKey) {
|
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) {
|
if (session && session.indexInfo.baseKeyType === Internal.BaseKeyType.OURS) {
|
||||||
console.log("Tried to lookup a session using our basekey");
|
console.log("Tried to lookup a session using our basekey");
|
||||||
return undefined;
|
return undefined;
|
||||||
|
@ -35638,7 +35639,7 @@ Internal.SessionRecord = function() {
|
||||||
},
|
},
|
||||||
getSessionByRemoteEphemeralKey: function(remoteEphemeralKey) {
|
getSessionByRemoteEphemeralKey: function(remoteEphemeralKey) {
|
||||||
this.detectDuplicateOpenSessions();
|
this.detectDuplicateOpenSessions();
|
||||||
var sessions = this._sessions;
|
var sessions = this.sessions;
|
||||||
|
|
||||||
var searchKey = util.toString(remoteEphemeralKey);
|
var searchKey = util.toString(remoteEphemeralKey);
|
||||||
|
|
||||||
|
@ -35658,7 +35659,7 @@ Internal.SessionRecord = function() {
|
||||||
return undefined;
|
return undefined;
|
||||||
},
|
},
|
||||||
getOpenSession: function() {
|
getOpenSession: function() {
|
||||||
var sessions = this._sessions;
|
var sessions = this.sessions;
|
||||||
if (sessions === undefined) {
|
if (sessions === undefined) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
@ -35674,7 +35675,7 @@ Internal.SessionRecord = function() {
|
||||||
},
|
},
|
||||||
detectDuplicateOpenSessions: function() {
|
detectDuplicateOpenSessions: function() {
|
||||||
var openSession;
|
var openSession;
|
||||||
var sessions = this._sessions;
|
var sessions = this.sessions;
|
||||||
for (var key in sessions) {
|
for (var key in sessions) {
|
||||||
if (sessions[key].indexInfo.closed == -1) {
|
if (sessions[key].indexInfo.closed == -1) {
|
||||||
if (openSession !== undefined) {
|
if (openSession !== undefined) {
|
||||||
|
@ -35685,7 +35686,7 @@ Internal.SessionRecord = function() {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
updateSessionState: function(session) {
|
updateSessionState: function(session) {
|
||||||
var sessions = this._sessions;
|
var sessions = this.sessions;
|
||||||
|
|
||||||
this.removeOldChains(session);
|
this.removeOldChains(session);
|
||||||
|
|
||||||
|
@ -35699,11 +35700,11 @@ Internal.SessionRecord = function() {
|
||||||
// followed by the open session
|
// followed by the open session
|
||||||
var list = [];
|
var list = [];
|
||||||
var openSession;
|
var openSession;
|
||||||
for (var k in this._sessions) {
|
for (var k in this.sessions) {
|
||||||
if (this._sessions[k].indexInfo.closed === -1) {
|
if (this.sessions[k].indexInfo.closed === -1) {
|
||||||
openSession = this._sessions[k];
|
openSession = this.sessions[k];
|
||||||
} else {
|
} else {
|
||||||
list.push(this._sessions[k]);
|
list.push(this.sessions[k]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
list = list.sort(function(s1, s2) {
|
list = list.sort(function(s1, s2) {
|
||||||
|
@ -35747,8 +35748,8 @@ Internal.SessionRecord = function() {
|
||||||
removeOldChains: function(session) {
|
removeOldChains: function(session) {
|
||||||
// Sending ratchets are always removed when we step because we never need them again
|
// Sending ratchets are always removed when we step because we never need them again
|
||||||
// Receiving ratchets are added to the oldRatchetList, which we parse
|
// Receiving ratchets are added to the oldRatchetList, which we parse
|
||||||
// here and remove all but the last five.
|
// here and remove all but the last ten.
|
||||||
while (session.oldRatchetList.length > 5) {
|
while (session.oldRatchetList.length > OLD_RATCHETS_MAX_LENGTH) {
|
||||||
var index = 0;
|
var index = 0;
|
||||||
var oldest = session.oldRatchetList[0];
|
var oldest = session.oldRatchetList[0];
|
||||||
for (var i = 0; i < session.oldRatchetList.length; i++) {
|
for (var i = 0; i < session.oldRatchetList.length; i++) {
|
||||||
|
@ -35764,7 +35765,7 @@ Internal.SessionRecord = function() {
|
||||||
},
|
},
|
||||||
removeOldSessions: function() {
|
removeOldSessions: function() {
|
||||||
// Retain only the last 20 sessions
|
// Retain only the last 20 sessions
|
||||||
var sessions = this._sessions;
|
var sessions = this.sessions;
|
||||||
var oldestBaseKey, oldestSession;
|
var oldestBaseKey, oldestSession;
|
||||||
while (Object.keys(sessions).length > ARCHIVED_STATES_MAX_LENGTH) {
|
while (Object.keys(sessions).length > ARCHIVED_STATES_MAX_LENGTH) {
|
||||||
for (var key in sessions) {
|
for (var key in sessions) {
|
||||||
|
@ -35844,15 +35845,20 @@ SessionBuilder.prototype = {
|
||||||
}).then(function() {
|
}).then(function() {
|
||||||
return Internal.crypto.createKeyPair();
|
return Internal.crypto.createKeyPair();
|
||||||
}).then(function(baseKey) {
|
}).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,
|
return this.initSession(true, baseKey, undefined, device.identityKey,
|
||||||
devicePreKey, device.signedPreKey.publicKey, device.registrationId
|
devicePreKey, device.signedPreKey.publicKey, device.registrationId
|
||||||
).then(function(session) {
|
).then(function(session) {
|
||||||
session.pendingPreKey = {
|
session.pendingPreKey = {
|
||||||
preKeyId : device.preKey.keyId,
|
|
||||||
signedKeyId : device.signedPreKey.keyId,
|
signedKeyId : device.signedPreKey.keyId,
|
||||||
baseKey : baseKey.pubKey
|
baseKey : baseKey.pubKey
|
||||||
};
|
};
|
||||||
|
if (device.preKey) {
|
||||||
|
session.pendingPreKey.preKeyId = device.preKey.keyId;
|
||||||
|
}
|
||||||
return session;
|
return session;
|
||||||
});
|
});
|
||||||
}.bind(this)).then(function(session) {
|
}.bind(this)).then(function(session) {
|
||||||
|
@ -36135,7 +36141,9 @@ SessionCipher.prototype = {
|
||||||
preKeyMsg.registrationId = myRegistrationId;
|
preKeyMsg.registrationId = myRegistrationId;
|
||||||
|
|
||||||
preKeyMsg.baseKey = util.toArrayBuffer(session.pendingPreKey.baseKey);
|
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.signedPreKeyId = session.pendingPreKey.signedKeyId;
|
||||||
|
|
||||||
preKeyMsg.message = message;
|
preKeyMsg.message = message;
|
||||||
|
@ -36218,7 +36226,7 @@ SessionCipher.prototype = {
|
||||||
).then(function(plaintext) {
|
).then(function(plaintext) {
|
||||||
record.updateSessionState(session);
|
record.updateSessionState(session);
|
||||||
return this.storage.storeSession(address, record.serialize()).then(function() {
|
return this.storage.storeSession(address, record.serialize()).then(function() {
|
||||||
if (preKeyId !== undefined) {
|
if (preKeyId !== undefined && preKeyId !== null) {
|
||||||
return this.storage.removePreKey(preKeyId);
|
return this.storage.removePreKey(preKeyId);
|
||||||
}
|
}
|
||||||
}.bind(this)).then(function() {
|
}.bind(this)).then(function() {
|
||||||
|
|
Loading…
Reference in a new issue