Ignore decryption failures from blocked contacts

This commit is contained in:
AsamK 2022-01-15 16:24:25 +01:00
parent 3587d1c397
commit 365323f574
2 changed files with 35 additions and 20 deletions

View file

@ -97,6 +97,9 @@
{ {
"pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_IN\\E" "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" "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_RU\\E"
}, },
{
"pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SA\\E"
},
{ {
"pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SI\\E" "pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SI\\E"
}, },

View file

@ -121,18 +121,23 @@ public final class IncomingMessageHandler {
} catch (ProtocolInvalidKeyIdException | ProtocolInvalidKeyException | ProtocolNoSessionException | ProtocolInvalidMessageException e) { } catch (ProtocolInvalidKeyIdException | ProtocolInvalidKeyException | ProtocolNoSessionException | ProtocolInvalidMessageException e) {
logger.debug("Failed to decrypt incoming message", e); logger.debug("Failed to decrypt incoming message", e);
final var sender = account.getRecipientStore().resolveRecipient(e.getSender()); final var sender = account.getRecipientStore().resolveRecipient(e.getSender());
final var senderProfile = context.getProfileHelper().getRecipientProfile(sender); if (context.getContactHelper().isContactBlocked(sender)) {
final var selfProfile = context.getProfileHelper().getRecipientProfile(account.getSelfRecipientId()); logger.debug("Received invalid message from blocked contact, ignoring.");
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 { } else {
logger.debug("Received invalid message, queuing renew session action."); final var senderProfile = context.getProfileHelper().getRecipientProfile(sender);
actions.add(new RenewSessionAction(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; exception = e;
} catch (SelfSendException e) { } catch (SelfSendException e) {
@ -188,15 +193,9 @@ public final class IncomingMessageHandler {
SignalServiceEnvelope envelope, SignalServiceContent content, boolean ignoreAttachments SignalServiceEnvelope envelope, SignalServiceContent content, boolean ignoreAttachments
) { ) {
var actions = new ArrayList<HandleAction>(); var actions = new ArrayList<HandleAction>();
final RecipientId sender; final var senderPair = getSender(envelope, content);
final int senderDeviceId; final var sender = senderPair.first();
if (!envelope.isUnidentifiedSender() && envelope.hasSourceUuid()) { final var senderDeviceId = senderPair.second();
sender = context.getRecipientHelper().resolveRecipient(envelope.getSourceAddress());
senderDeviceId = envelope.getSourceDevice();
} else {
sender = context.getRecipientHelper().resolveRecipient(content.getSender());
senderDeviceId = content.getSenderDevice();
}
if (content.getSenderKeyDistributionMessage().isPresent()) { if (content.getSenderKeyDistributionMessage().isPresent()) {
final var message = content.getSenderKeyDistributionMessage().get(); final var message = content.getSenderKeyDistributionMessage().get();
@ -607,4 +606,14 @@ public final class IncomingMessageHandler {
} }
return actions; return actions;
} }
private Pair<RecipientId, Integer> 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());
}
}
} }