mirror of
https://github.com/oxen-io/session-desktop.git
synced 2023-12-14 02:12:57 +01:00
Ignore friend request messages that could not be decrypted
This commit is contained in:
parent
583fb2e6c6
commit
0283c6428f
2 changed files with 15 additions and 3 deletions
|
@ -7,6 +7,7 @@
|
|||
const IV_LENGTH = 16;
|
||||
|
||||
FallBackSessionCipher = function (address) {
|
||||
this.identityKeyString = address.getName();
|
||||
this.pubKey = StringView.hexToArrayBuffer(address.getName());
|
||||
|
||||
this.encrypt = async (plaintext) => {
|
||||
|
@ -37,11 +38,15 @@
|
|||
const myKeyPair = await textsecure.storage.protocol.getIdentityKeyPair();
|
||||
const myPrivateKey = myKeyPair.privKey;
|
||||
const symmetricKey = libsignal.Curve.calculateAgreement(this.pubKey, myPrivateKey);
|
||||
const plaintext = await libsignal.crypto.decrypt(symmetricKey, cipherText, iv);
|
||||
return plaintext;
|
||||
try {
|
||||
return await libsignal.crypto.decrypt(symmetricKey, cipherText, iv);
|
||||
} catch(e) {
|
||||
throw new FallBackDecryptionError('Could not decrypt message from ' + this.identityKeyString + ' using FallBack encryption.')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
window.libloki.FallBackSessionCipher = FallBackSessionCipher;
|
||||
window.libloki.FallBackDecryptionError = FallBackDecryptionError;
|
||||
|
||||
})();
|
|
@ -694,6 +694,9 @@ MessageReceiver.prototype.extend({
|
|||
buffer.toArrayBuffer(),
|
||||
error.identityKey
|
||||
);
|
||||
} else {
|
||||
// re-throw
|
||||
throw error;
|
||||
}
|
||||
const ev = new Event('error');
|
||||
ev.error = errorToThrow;
|
||||
|
@ -820,7 +823,11 @@ MessageReceiver.prototype.extend({
|
|||
handleContentMessage(envelope) {
|
||||
return this.decrypt(envelope, envelope.content).then(plaintext =>
|
||||
this.innerHandleContentMessage(envelope, plaintext)
|
||||
);
|
||||
).catch(e => {
|
||||
if (e instanceof libloki.FallBackDecryptionError) {
|
||||
console.log(e.message + ' Ignoring message.');
|
||||
}
|
||||
});
|
||||
},
|
||||
innerHandleContentMessage(envelope, plaintext) {
|
||||
const content = textsecure.protobuf.Content.decode(plaintext);
|
||||
|
|
Loading…
Reference in a new issue