Search in sources :

Example 1 with DecryptionErrorMessage

use of org.whispersystems.libsignal.protocol.DecryptionErrorMessage in project Signal-Android by signalapp.

the class MessageDecryptionUtil method handleRetry.

@NonNull
private static Job handleRetry(@NonNull Context context, @NonNull Recipient sender, @NonNull SignalServiceEnvelope envelope, @NonNull ProtocolException protocolException) {
    ContentHint contentHint = ContentHint.fromType(protocolException.getContentHint());
    int senderDevice = protocolException.getSenderDevice();
    long receivedTimestamp = System.currentTimeMillis();
    Optional<GroupId> groupId = Optional.absent();
    if (protocolException.getGroupId().isPresent()) {
        try {
            groupId = Optional.of(GroupId.push(protocolException.getGroupId().get()));
        } catch (BadGroupIdException e) {
            Log.w(TAG, "[" + envelope.getTimestamp() + "] Bad groupId!");
        }
    }
    Log.w(TAG, "[" + envelope.getTimestamp() + "] Could not decrypt a message with a type of " + contentHint);
    long threadId;
    if (groupId.isPresent()) {
        Recipient groupRecipient = Recipient.externalPossiblyMigratedGroup(context, groupId.get());
        threadId = SignalDatabase.threads().getOrCreateThreadIdFor(groupRecipient);
    } else {
        threadId = SignalDatabase.threads().getOrCreateThreadIdFor(sender);
    }
    switch(contentHint) {
        case DEFAULT:
            Log.w(TAG, "[" + envelope.getTimestamp() + "] Inserting an error right away because it's " + contentHint);
            SignalDatabase.sms().insertBadDecryptMessage(sender.getId(), senderDevice, envelope.getTimestamp(), receivedTimestamp, threadId);
            break;
        case RESENDABLE:
            Log.w(TAG, "[" + envelope.getTimestamp() + "] Inserting into pending retries store because it's " + contentHint);
            ApplicationDependencies.getPendingRetryReceiptCache().insert(sender.getId(), senderDevice, envelope.getTimestamp(), receivedTimestamp, threadId);
            ApplicationDependencies.getPendingRetryReceiptManager().scheduleIfNecessary();
            break;
        case IMPLICIT:
            Log.w(TAG, "[" + envelope.getTimestamp() + "] Not inserting any error because it's " + contentHint);
            break;
    }
    byte[] originalContent;
    int envelopeType;
    if (protocolException.getUnidentifiedSenderMessageContent().isPresent()) {
        originalContent = protocolException.getUnidentifiedSenderMessageContent().get().getContent();
        envelopeType = protocolException.getUnidentifiedSenderMessageContent().get().getType();
    } else {
        originalContent = envelope.getContent();
        envelopeType = envelopeTypeToCiphertextMessageType(envelope.getType());
    }
    DecryptionErrorMessage decryptionErrorMessage = DecryptionErrorMessage.forOriginalMessage(originalContent, envelopeType, envelope.getTimestamp(), senderDevice);
    return new SendRetryReceiptJob(sender.getId(), groupId, decryptionErrorMessage);
}
Also used : DecryptionErrorMessage(org.whispersystems.libsignal.protocol.DecryptionErrorMessage) ContentHint(org.whispersystems.signalservice.api.crypto.ContentHint) SendRetryReceiptJob(org.thoughtcrime.securesms.jobs.SendRetryReceiptJob) Recipient(org.thoughtcrime.securesms.recipients.Recipient) BadGroupIdException(org.thoughtcrime.securesms.groups.BadGroupIdException) ContentHint(org.whispersystems.signalservice.api.crypto.ContentHint) GroupId(org.thoughtcrime.securesms.groups.GroupId) NonNull(androidx.annotation.NonNull)

Example 2 with DecryptionErrorMessage

use of org.whispersystems.libsignal.protocol.DecryptionErrorMessage in project Signal-Android by WhisperSystems.

the class MessageDecryptionUtil method handleRetry.

@NonNull
private static Job handleRetry(@NonNull Context context, @NonNull Recipient sender, @NonNull SignalServiceEnvelope envelope, @NonNull ProtocolException protocolException) {
    ContentHint contentHint = ContentHint.fromType(protocolException.getContentHint());
    int senderDevice = protocolException.getSenderDevice();
    long receivedTimestamp = System.currentTimeMillis();
    Optional<GroupId> groupId = Optional.absent();
    if (protocolException.getGroupId().isPresent()) {
        try {
            groupId = Optional.of(GroupId.push(protocolException.getGroupId().get()));
        } catch (BadGroupIdException e) {
            Log.w(TAG, "[" + envelope.getTimestamp() + "] Bad groupId!");
        }
    }
    Log.w(TAG, "[" + envelope.getTimestamp() + "] Could not decrypt a message with a type of " + contentHint);
    long threadId;
    if (groupId.isPresent()) {
        Recipient groupRecipient = Recipient.externalPossiblyMigratedGroup(context, groupId.get());
        threadId = SignalDatabase.threads().getOrCreateThreadIdFor(groupRecipient);
    } else {
        threadId = SignalDatabase.threads().getOrCreateThreadIdFor(sender);
    }
    switch(contentHint) {
        case DEFAULT:
            Log.w(TAG, "[" + envelope.getTimestamp() + "] Inserting an error right away because it's " + contentHint);
            SignalDatabase.sms().insertBadDecryptMessage(sender.getId(), senderDevice, envelope.getTimestamp(), receivedTimestamp, threadId);
            break;
        case RESENDABLE:
            Log.w(TAG, "[" + envelope.getTimestamp() + "] Inserting into pending retries store because it's " + contentHint);
            ApplicationDependencies.getPendingRetryReceiptCache().insert(sender.getId(), senderDevice, envelope.getTimestamp(), receivedTimestamp, threadId);
            ApplicationDependencies.getPendingRetryReceiptManager().scheduleIfNecessary();
            break;
        case IMPLICIT:
            Log.w(TAG, "[" + envelope.getTimestamp() + "] Not inserting any error because it's " + contentHint);
            break;
    }
    byte[] originalContent;
    int envelopeType;
    if (protocolException.getUnidentifiedSenderMessageContent().isPresent()) {
        originalContent = protocolException.getUnidentifiedSenderMessageContent().get().getContent();
        envelopeType = protocolException.getUnidentifiedSenderMessageContent().get().getType();
    } else {
        originalContent = envelope.getContent();
        envelopeType = envelopeTypeToCiphertextMessageType(envelope.getType());
    }
    DecryptionErrorMessage decryptionErrorMessage = DecryptionErrorMessage.forOriginalMessage(originalContent, envelopeType, envelope.getTimestamp(), senderDevice);
    return new SendRetryReceiptJob(sender.getId(), groupId, decryptionErrorMessage);
}
Also used : DecryptionErrorMessage(org.whispersystems.libsignal.protocol.DecryptionErrorMessage) ContentHint(org.whispersystems.signalservice.api.crypto.ContentHint) SendRetryReceiptJob(org.thoughtcrime.securesms.jobs.SendRetryReceiptJob) Recipient(org.thoughtcrime.securesms.recipients.Recipient) BadGroupIdException(org.thoughtcrime.securesms.groups.BadGroupIdException) ContentHint(org.whispersystems.signalservice.api.crypto.ContentHint) GroupId(org.thoughtcrime.securesms.groups.GroupId) NonNull(androidx.annotation.NonNull)

Aggregations

NonNull (androidx.annotation.NonNull)2 BadGroupIdException (org.thoughtcrime.securesms.groups.BadGroupIdException)2 GroupId (org.thoughtcrime.securesms.groups.GroupId)2 SendRetryReceiptJob (org.thoughtcrime.securesms.jobs.SendRetryReceiptJob)2 Recipient (org.thoughtcrime.securesms.recipients.Recipient)2 DecryptionErrorMessage (org.whispersystems.libsignal.protocol.DecryptionErrorMessage)2 ContentHint (org.whispersystems.signalservice.api.crypto.ContentHint)2