Implement simple handling of incoming decryption error message

This commit is contained in:
AsamK 2021-12-20 14:01:24 +01:00
parent 1f48ce1f39
commit baed2b7ead
4 changed files with 29 additions and 3 deletions

View file

@ -233,6 +233,16 @@ public final class IncomingMessageHandler {
if (content.getDecryptionErrorMessage().isPresent()) { if (content.getDecryptionErrorMessage().isPresent()) {
var message = content.getDecryptionErrorMessage().get(); var message = content.getDecryptionErrorMessage().get();
logger.debug("Received a decryption error message (resend request for {})", message.getTimestamp()); logger.debug("Received a decryption error message (resend request for {})", message.getTimestamp());
if (message.getRatchetKey().isPresent()) {
if (message.getDeviceId() == account.getDeviceId() && account.getSessionStore()
.isCurrentRatchetKey(sender, senderDeviceId, message.getRatchetKey().get())) {
logger.debug("Renewing the session with sender");
actions.add(new RenewSessionAction(sender));
}
} else {
logger.debug("Reset shared sender keys with this recipient");
account.getSenderKeyStore().deleteSharedWith(sender);
}
} }
if (content.getDataMessage().isPresent()) { if (content.getDataMessage().isPresent()) {

View file

@ -75,7 +75,9 @@ public class SenderKeyRecordStore implements org.whispersystems.libsignal.groups
cachedSenderKeys.clear(); cachedSenderKeys.clear();
final var keys = getKeysLocked(recipientId); final var keys = getKeysLocked(recipientId);
for (var key : keys) { for (var key : keys) {
if (key.distributionId.equals(distributionId)) deleteSenderKeyLocked(key); if (key.distributionId.equals(distributionId)) {
deleteSenderKeyLocked(key);
}
} }
} }
} }

View file

@ -163,10 +163,11 @@ public class SenderKeySharedStore {
public void deleteAllFor(final DistributionId distributionId) { public void deleteAllFor(final DistributionId distributionId) {
synchronized (sharedSenderKeys) { synchronized (sharedSenderKeys) {
sharedSenderKeys.remove(distributionId.asUuid()); if (sharedSenderKeys.remove(distributionId.asUuid()) != null) {
saveLocked(); saveLocked();
} }
} }
}
public void mergeRecipients(RecipientId recipientId, RecipientId toBeMergedRecipientId) { public void mergeRecipients(RecipientId recipientId, RecipientId toBeMergedRecipientId) {
synchronized (sharedSenderKeys) { synchronized (sharedSenderKeys) {

View file

@ -7,6 +7,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.whispersystems.libsignal.NoSessionException; import org.whispersystems.libsignal.NoSessionException;
import org.whispersystems.libsignal.SignalProtocolAddress; import org.whispersystems.libsignal.SignalProtocolAddress;
import org.whispersystems.libsignal.ecc.ECPublicKey;
import org.whispersystems.libsignal.protocol.CiphertextMessage; import org.whispersystems.libsignal.protocol.CiphertextMessage;
import org.whispersystems.libsignal.state.SessionRecord; import org.whispersystems.libsignal.state.SessionRecord;
import org.whispersystems.signalservice.api.SignalServiceSessionStore; import org.whispersystems.signalservice.api.SignalServiceSessionStore;
@ -91,6 +92,18 @@ public class SessionStore implements SignalServiceSessionStore {
} }
} }
public boolean isCurrentRatchetKey(RecipientId recipientId, int deviceId, ECPublicKey ratchetKey) {
final var key = new Key(recipientId, deviceId);
synchronized (cachedSessions) {
final var session = loadSessionLocked(key);
if (session == null) {
return false;
}
return session.currentRatchetKeyMatches(ratchetKey);
}
}
@Override @Override
public void storeSession(SignalProtocolAddress address, SessionRecord session) { public void storeSession(SignalProtocolAddress address, SessionRecord session) {
final var key = getKey(address); final var key = getKey(address);