SessionRecord: Once again serialize/deserialize within libsignal

This commit is contained in:
Scott Nonnenberg 2019-10-30 12:04:39 -07:00
parent b659ddc68c
commit fd5af8bb62
3 changed files with 20 additions and 14 deletions

View file

@ -329,7 +329,7 @@
const session = this.sessions[encodedNumber]; const session = this.sessions[encodedNumber];
if (session) { if (session) {
return libsignal.SessionRecord.deserialize(session.record); return session.record;
} }
return undefined; return undefined;
@ -346,7 +346,7 @@
id: encodedNumber, id: encodedNumber,
number, number,
deviceId, deviceId,
record: record.serialize(), record,
}; };
this.sessions[encodedNumber] = data; this.sessions[encodedNumber] = data;

View file

@ -35766,8 +35766,6 @@ Internal.SessionRecord = function() {
return SessionRecord; return SessionRecord;
}(); }();
libsignal.SessionRecord = Internal.SessionRecord;
function SignalProtocolAddress(name, deviceId) { function SignalProtocolAddress(name, deviceId) {
this.name = name; this.name = name;
this.deviceId = deviceId; this.deviceId = deviceId;
@ -35846,15 +35844,18 @@ SessionBuilder.prototype = {
}); });
}.bind(this)).then(function(session) { }.bind(this)).then(function(session) {
var address = this.remoteAddress.toString(); var address = this.remoteAddress.toString();
return this.storage.loadSession(address).then(function(record) { return this.storage.loadSession(address).then(function(serialized) {
if (record === undefined) { var record;
if (serialized !== undefined) {
record = Internal.SessionRecord.deserialize(serialized);
} else {
record = new Internal.SessionRecord(); record = new Internal.SessionRecord();
} }
record.archiveCurrentState(); record.archiveCurrentState();
record.updateSessionState(session); record.updateSessionState(session);
return Promise.all([ return Promise.all([
this.storage.storeSession(address, record), this.storage.storeSession(address, record.serialize()),
this.storage.saveIdentity(this.remoteAddress.toString(), device.identityKey) this.storage.saveIdentity(this.remoteAddress.toString(), device.identityKey)
]); ]);
}.bind(this)); }.bind(this));
@ -36038,7 +36039,12 @@ function SessionCipher(storage, remoteAddress) {
SessionCipher.prototype = { SessionCipher.prototype = {
getRecord: function(encodedNumber) { getRecord: function(encodedNumber) {
return this.storage.loadSession(encodedNumber); return this.storage.loadSession(encodedNumber).then(function(serialized) {
if (serialized === undefined) {
return undefined;
}
return Internal.SessionRecord.deserialize(serialized);
});
}, },
// encoding is an optional parameter - wrap() will only translate if one is provided // encoding is an optional parameter - wrap() will only translate if one is provided
encrypt: function(buffer, encoding) { encrypt: function(buffer, encoding) {
@ -36118,7 +36124,7 @@ SessionCipher.prototype = {
return this.storage.saveIdentity(this.remoteAddress.toString(), theirIdentityKey); return this.storage.saveIdentity(this.remoteAddress.toString(), theirIdentityKey);
}.bind(this)).then(function() { }.bind(this)).then(function() {
record.updateSessionState(session); record.updateSessionState(session);
return this.storage.storeSession(address, record).then(function() { return this.storage.storeSession(address, record.serialize()).then(function() {
return result; return result;
}); });
}.bind(this)); }.bind(this));
@ -36205,7 +36211,7 @@ SessionCipher.prototype = {
return this.storage.saveIdentity(this.remoteAddress.toString(), result.session.indexInfo.remoteIdentityKey); return this.storage.saveIdentity(this.remoteAddress.toString(), result.session.indexInfo.remoteIdentityKey);
}.bind(this)).then(function() { }.bind(this)).then(function() {
record.updateSessionState(result.session); record.updateSessionState(result.session);
return this.storage.storeSession(address, record).then(function() { return this.storage.storeSession(address, record.serialize()).then(function() {
return result.plaintext; return result.plaintext;
}); });
}.bind(this)); }.bind(this));
@ -36240,7 +36246,7 @@ SessionCipher.prototype = {
preKeyProto.message.toArrayBuffer(), session preKeyProto.message.toArrayBuffer(), session
).then(function(plaintext) { ).then(function(plaintext) {
record.updateSessionState(session); record.updateSessionState(session);
return this.storage.storeSession(address, record).then(function() { return this.storage.storeSession(address, record.serialize()).then(function() {
if (preKeyId !== undefined && preKeyId !== null) { if (preKeyId !== undefined && preKeyId !== null) {
return this.storage.removePreKey(preKeyId); return this.storage.removePreKey(preKeyId);
} }
@ -36438,7 +36444,7 @@ SessionCipher.prototype = {
} }
record.archiveCurrentState(); record.archiveCurrentState();
return this.storage.storeSession(address, record); return this.storage.storeSession(address, record.serialize());
}.bind(this)); }.bind(this));
}.bind(this)); }.bind(this));
}, },
@ -36452,7 +36458,7 @@ SessionCipher.prototype = {
} }
record.deleteAllSessions(); record.deleteAllSessions();
return this.storage.storeSession(address, record); return this.storage.storeSession(address, record.serialize());
}.bind(this)); }.bind(this));
}.bind(this)); }.bind(this));
} }

View file

@ -301,7 +301,7 @@
"rule": "jQuery-load(", "rule": "jQuery-load(",
"path": "js/signal_protocol_store.js", "path": "js/signal_protocol_store.js",
"line": " await ConversationController.load();", "line": " await ConversationController.load();",
"lineNumber": 908, "lineNumber": 894,
"reasonCategory": "falseMatch", "reasonCategory": "falseMatch",
"updated": "2018-09-15T00:38:04.183Z" "updated": "2018-09-15T00:38:04.183Z"
}, },