Store arrayBuffers in database for remote identity keys

This commit is contained in:
Scott Nonnenberg 2018-10-26 11:37:51 -07:00
parent 68af1ae1ea
commit 70eed938d9
3 changed files with 13 additions and 16 deletions

View file

@ -289,18 +289,11 @@ SecretSessionCipher.prototype = {
signalProtocolStore, signalProtocolStore,
destinationAddress destinationAddress
); );
const sessionRecord = await sessionCipher.getRecord(
destinationAddress.toString()
);
const openSession = sessionRecord.getOpenSession();
if (!openSession) {
throw new Error('No active session');
}
const message = await sessionCipher.encrypt(paddedPlaintext); const message = await sessionCipher.encrypt(paddedPlaintext);
const ourIdentity = await signalProtocolStore.getIdentityKeyPair(); const ourIdentity = await signalProtocolStore.getIdentityKeyPair();
const theirIdentity = fromEncodedBinaryToArrayBuffer( const theirIdentity = fromEncodedBinaryToArrayBuffer(
openSession.indexInfo.remoteIdentityKey await signalProtocolStore.loadIdentityKey(destinationAddress.getName())
); );
const ephemeral = await libsignal.Curve.async.generateKeyPair(); const ephemeral = await libsignal.Curve.async.generateKeyPair();

View file

@ -35837,7 +35837,7 @@ SessionBuilder.prototype = {
record.updateSessionState(session); record.updateSessionState(session);
return Promise.all([ return Promise.all([
this.storage.storeSession(address, record.serialize()), this.storage.storeSession(address, record.serialize()),
this.storage.saveIdentity(this.remoteAddress.toString(), session.indexInfo.remoteIdentityKey) this.storage.saveIdentity(this.remoteAddress.toString(), device.identityKey)
]); ]);
}.bind(this)); }.bind(this));
}.bind(this)); }.bind(this));
@ -36080,9 +36080,12 @@ SessionCipher.prototype = {
msg.ciphertext = ciphertext; msg.ciphertext = ciphertext;
var encodedMsg = msg.toArrayBuffer(); var encodedMsg = msg.toArrayBuffer();
var ourIdentityKeyBuffer = util.toArrayBuffer(ourIdentityKey.pubKey);
var theirIdentityKey = util.toArrayBuffer(session.indexInfo.remoteIdentityKey);
var macInput = new Uint8Array(encodedMsg.byteLength + 33*2 + 1); var macInput = new Uint8Array(encodedMsg.byteLength + 33*2 + 1);
macInput.set(new Uint8Array(util.toArrayBuffer(ourIdentityKey.pubKey)));
macInput.set(new Uint8Array(util.toArrayBuffer(session.indexInfo.remoteIdentityKey)), 33); macInput.set(new Uint8Array(ourIdentityKeyBuffer));
macInput.set(new Uint8Array(theirIdentityKey), 33);
macInput[33*2] = (3 << 4) | 3; macInput[33*2] = (3 << 4) | 3;
macInput.set(new Uint8Array(encodedMsg), 33*2 + 1); macInput.set(new Uint8Array(encodedMsg), 33*2 + 1);
@ -36093,13 +36096,13 @@ SessionCipher.prototype = {
result.set(new Uint8Array(mac, 0, 8), encodedMsg.byteLength + 1); result.set(new Uint8Array(mac, 0, 8), encodedMsg.byteLength + 1);
return this.storage.isTrustedIdentity( return this.storage.isTrustedIdentity(
this.remoteAddress.getName(), util.toArrayBuffer(session.indexInfo.remoteIdentityKey), this.storage.Direction.SENDING this.remoteAddress.getName(), theirIdentityKey, this.storage.Direction.SENDING
).then(function(trusted) { ).then(function(trusted) {
if (!trusted) { if (!trusted) {
throw new Error('Identity key changed'); throw new Error('Identity key changed');
} }
}).then(function() { }).then(function() {
return this.storage.saveIdentity(this.remoteAddress.toString(), session.indexInfo.remoteIdentityKey); 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.serialize()).then(function() { return this.storage.storeSession(address, record.serialize()).then(function() {

View file

@ -76,14 +76,15 @@ InMemorySignalProtocolStore.prototype = {
return Promise.resolve(toString(identityKey) === toString(trusted)); return Promise.resolve(toString(identityKey) === toString(trusted));
}, },
loadIdentityKey(identifier) { loadIdentityKey(identifier) {
if (identifier === null || identifier === undefined) if (identifier === null || identifier === undefined) {
throw new Error('Tried to get identity key for undefined/null key'); throw new Error('Tried to get identity key for undefined/null key');
}
return Promise.resolve(this.get(`identityKey${identifier}`)); return Promise.resolve(this.get(`identityKey${identifier}`));
}, },
saveIdentity(identifier, identityKey) { saveIdentity(identifier, identityKey) {
if (identifier === null || identifier === undefined) if (identifier === null || identifier === undefined) {
throw new Error('Tried to put identity key for undefined/null key'); throw new Error('Tried to put identity key for undefined/null key');
}
const address = libsignal.SignalProtocolAddress.fromString(identifier); const address = libsignal.SignalProtocolAddress.fromString(identifier);
const existing = this.get(`identityKey${address.getName()}`); const existing = this.get(`identityKey${address.getName()}`);