Ignore friend request messages that could not be decrypted

pull/10/head
sachaaaaa 7 years ago
parent 583fb2e6c6
commit 0283c6428f

@ -7,6 +7,7 @@
const IV_LENGTH = 16; const IV_LENGTH = 16;
FallBackSessionCipher = function (address) { FallBackSessionCipher = function (address) {
this.identityKeyString = address.getName();
this.pubKey = StringView.hexToArrayBuffer(address.getName()); this.pubKey = StringView.hexToArrayBuffer(address.getName());
this.encrypt = async (plaintext) => { this.encrypt = async (plaintext) => {
@ -37,11 +38,15 @@
const myKeyPair = await textsecure.storage.protocol.getIdentityKeyPair(); const myKeyPair = await textsecure.storage.protocol.getIdentityKeyPair();
const myPrivateKey = myKeyPair.privKey; const myPrivateKey = myKeyPair.privKey;
const symmetricKey = libsignal.Curve.calculateAgreement(this.pubKey, myPrivateKey); const symmetricKey = libsignal.Curve.calculateAgreement(this.pubKey, myPrivateKey);
const plaintext = await libsignal.crypto.decrypt(symmetricKey, cipherText, iv); try {
return plaintext; 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.FallBackSessionCipher = FallBackSessionCipher;
window.libloki.FallBackDecryptionError = FallBackDecryptionError;
})(); })();

@ -694,6 +694,9 @@ MessageReceiver.prototype.extend({
buffer.toArrayBuffer(), buffer.toArrayBuffer(),
error.identityKey error.identityKey
); );
} else {
// re-throw
throw error;
} }
const ev = new Event('error'); const ev = new Event('error');
ev.error = errorToThrow; ev.error = errorToThrow;
@ -820,7 +823,11 @@ MessageReceiver.prototype.extend({
handleContentMessage(envelope) { handleContentMessage(envelope) {
return this.decrypt(envelope, envelope.content).then(plaintext => return this.decrypt(envelope, envelope.content).then(plaintext =>
this.innerHandleContentMessage(envelope, plaintext) this.innerHandleContentMessage(envelope, plaintext)
); ).catch(e => {
if (e instanceof libloki.FallBackDecryptionError) {
console.log(e.message + ' Ignoring message.');
}
});
}, },
innerHandleContentMessage(envelope, plaintext) { innerHandleContentMessage(envelope, plaintext) {
const content = textsecure.protobuf.Content.decode(plaintext); const content = textsecure.protobuf.Content.decode(plaintext);

Loading…
Cancel
Save