Store arrayBuffers in database for remote identity keys
This commit is contained in:
parent
68af1ae1ea
commit
70eed938d9
3 changed files with 13 additions and 16 deletions
|
@ -289,18 +289,11 @@ SecretSessionCipher.prototype = {
|
|||
signalProtocolStore,
|
||||
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 ourIdentity = await signalProtocolStore.getIdentityKeyPair();
|
||||
const theirIdentity = fromEncodedBinaryToArrayBuffer(
|
||||
openSession.indexInfo.remoteIdentityKey
|
||||
await signalProtocolStore.loadIdentityKey(destinationAddress.getName())
|
||||
);
|
||||
|
||||
const ephemeral = await libsignal.Curve.async.generateKeyPair();
|
||||
|
|
|
@ -35837,7 +35837,7 @@ SessionBuilder.prototype = {
|
|||
record.updateSessionState(session);
|
||||
return Promise.all([
|
||||
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));
|
||||
|
@ -36080,9 +36080,12 @@ SessionCipher.prototype = {
|
|||
msg.ciphertext = ciphertext;
|
||||
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);
|
||||
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.set(new Uint8Array(encodedMsg), 33*2 + 1);
|
||||
|
||||
|
@ -36093,13 +36096,13 @@ SessionCipher.prototype = {
|
|||
result.set(new Uint8Array(mac, 0, 8), encodedMsg.byteLength + 1);
|
||||
|
||||
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) {
|
||||
if (!trusted) {
|
||||
throw new Error('Identity key changed');
|
||||
}
|
||||
}).then(function() {
|
||||
return this.storage.saveIdentity(this.remoteAddress.toString(), session.indexInfo.remoteIdentityKey);
|
||||
return this.storage.saveIdentity(this.remoteAddress.toString(), theirIdentityKey);
|
||||
}.bind(this)).then(function() {
|
||||
record.updateSessionState(session);
|
||||
return this.storage.storeSession(address, record.serialize()).then(function() {
|
||||
|
|
|
@ -76,14 +76,15 @@ InMemorySignalProtocolStore.prototype = {
|
|||
return Promise.resolve(toString(identityKey) === toString(trusted));
|
||||
},
|
||||
loadIdentityKey(identifier) {
|
||||
if (identifier === null || identifier === undefined)
|
||||
if (identifier === null || identifier === undefined) {
|
||||
throw new Error('Tried to get identity key for undefined/null key');
|
||||
}
|
||||
return Promise.resolve(this.get(`identityKey${identifier}`));
|
||||
},
|
||||
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');
|
||||
|
||||
}
|
||||
const address = libsignal.SignalProtocolAddress.fromString(identifier);
|
||||
|
||||
const existing = this.get(`identityKey${address.getName()}`);
|
||||
|
|
Loading…
Reference in a new issue