From: AsamK Date: Sat, 15 Jan 2022 15:24:25 +0000 (+0100) Subject: Ignore decryption failures from blocked contacts X-Git-Tag: v0.10.1~4 X-Git-Url: https://git.nmode.ca/signal-cli/commitdiff_plain/365323f57473677f6973fcaf85a7877e68eee4a5?ds=sidebyside Ignore decryption failures from blocked contacts --- diff --git a/graalvm-config-dir/resource-config.json b/graalvm-config-dir/resource-config.json index e16270b1..e2f9db0e 100644 --- a/graalvm-config-dir/resource-config.json +++ b/graalvm-config-dir/resource-config.json @@ -97,6 +97,9 @@ { "pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_IN\\E" }, + { + "pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_IR\\E" + }, { "pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_IT\\E" }, @@ -145,6 +148,9 @@ { "pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_RU\\E" }, + { + "pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SA\\E" + }, { "pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SI\\E" }, diff --git a/lib/src/main/java/org/asamk/signal/manager/helper/IncomingMessageHandler.java b/lib/src/main/java/org/asamk/signal/manager/helper/IncomingMessageHandler.java index 3aaccfdc..0ef974e0 100644 --- a/lib/src/main/java/org/asamk/signal/manager/helper/IncomingMessageHandler.java +++ b/lib/src/main/java/org/asamk/signal/manager/helper/IncomingMessageHandler.java @@ -121,18 +121,23 @@ public final class IncomingMessageHandler { } catch (ProtocolInvalidKeyIdException | ProtocolInvalidKeyException | ProtocolNoSessionException | ProtocolInvalidMessageException e) { logger.debug("Failed to decrypt incoming message", e); final var sender = account.getRecipientStore().resolveRecipient(e.getSender()); - final var senderProfile = context.getProfileHelper().getRecipientProfile(sender); - final var selfProfile = context.getProfileHelper().getRecipientProfile(account.getSelfRecipientId()); - if (e.getSenderDevice() != account.getDeviceId() - && senderProfile != null - && senderProfile.getCapabilities().contains(Profile.Capability.senderKey) - && selfProfile != null - && selfProfile.getCapabilities().contains(Profile.Capability.senderKey)) { - logger.debug("Received invalid message, requesting message resend."); - actions.add(new SendRetryMessageRequestAction(sender, e, envelope)); + if (context.getContactHelper().isContactBlocked(sender)) { + logger.debug("Received invalid message from blocked contact, ignoring."); } else { - logger.debug("Received invalid message, queuing renew session action."); - actions.add(new RenewSessionAction(sender)); + final var senderProfile = context.getProfileHelper().getRecipientProfile(sender); + final var selfProfile = context.getProfileHelper() + .getRecipientProfile(account.getSelfRecipientId()); + if (e.getSenderDevice() != account.getDeviceId() + && senderProfile != null + && senderProfile.getCapabilities().contains(Profile.Capability.senderKey) + && selfProfile != null + && selfProfile.getCapabilities().contains(Profile.Capability.senderKey)) { + logger.debug("Received invalid message, requesting message resend."); + actions.add(new SendRetryMessageRequestAction(sender, e, envelope)); + } else { + logger.debug("Received invalid message, queuing renew session action."); + actions.add(new RenewSessionAction(sender)); + } } exception = e; } catch (SelfSendException e) { @@ -188,15 +193,9 @@ public final class IncomingMessageHandler { SignalServiceEnvelope envelope, SignalServiceContent content, boolean ignoreAttachments ) { var actions = new ArrayList(); - final RecipientId sender; - final int senderDeviceId; - if (!envelope.isUnidentifiedSender() && envelope.hasSourceUuid()) { - sender = context.getRecipientHelper().resolveRecipient(envelope.getSourceAddress()); - senderDeviceId = envelope.getSourceDevice(); - } else { - sender = context.getRecipientHelper().resolveRecipient(content.getSender()); - senderDeviceId = content.getSenderDevice(); - } + final var senderPair = getSender(envelope, content); + final var sender = senderPair.first(); + final var senderDeviceId = senderPair.second(); if (content.getSenderKeyDistributionMessage().isPresent()) { final var message = content.getSenderKeyDistributionMessage().get(); @@ -607,4 +606,14 @@ public final class IncomingMessageHandler { } return actions; } + + private Pair getSender(SignalServiceEnvelope envelope, SignalServiceContent content) { + if (!envelope.isUnidentifiedSender() && envelope.hasSourceUuid()) { + return new Pair<>(context.getRecipientHelper().resolveRecipient(envelope.getSourceAddress()), + envelope.getSourceDevice()); + } else { + return new Pair<>(context.getRecipientHelper().resolveRecipient(content.getSender()), + content.getSenderDevice()); + } + } }