Search in sources :

Example 41 with UntrustedIdentityException

use of org.whispersystems.signalservice.api.crypto.UntrustedIdentityException in project Signal-Android by signalapp.

the class PushTextSendJob method onPushSend.

@Override
public void onPushSend() throws IOException, NoSuchMessageException, UndeliverableMessageException, RetryLaterException {
    SignalLocalMetrics.IndividualMessageSend.onJobStarted(messageId);
    ExpiringMessageManager expirationManager = ApplicationDependencies.getExpiringMessageManager();
    MessageDatabase database = SignalDatabase.sms();
    SmsMessageRecord record = database.getSmsMessage(messageId);
    if (!record.isPending() && !record.isFailed()) {
        warn(TAG, String.valueOf(record.getDateSent()), "Message " + messageId + " was already sent. Ignoring.");
        return;
    }
    try {
        log(TAG, String.valueOf(record.getDateSent()), "Sending message: " + messageId + ",  Recipient: " + record.getRecipient().getId() + ", Thread: " + record.getThreadId());
        RecipientUtil.shareProfileIfFirstSecureMessage(context, record.getRecipient());
        Recipient recipient = record.getRecipient().resolve();
        byte[] profileKey = recipient.getProfileKey();
        UnidentifiedAccessMode accessMode = recipient.getUnidentifiedAccessMode();
        boolean unidentified = deliver(record);
        database.markAsSent(messageId, true);
        database.markUnidentified(messageId, unidentified);
        if (recipient.isSelf()) {
            SyncMessageId id = new SyncMessageId(recipient.getId(), record.getDateSent());
            SignalDatabase.mmsSms().incrementDeliveryReceiptCount(id, System.currentTimeMillis());
            SignalDatabase.mmsSms().incrementReadReceiptCount(id, System.currentTimeMillis());
        }
        if (unidentified && accessMode == UnidentifiedAccessMode.UNKNOWN && profileKey == null) {
            log(TAG, String.valueOf(record.getDateSent()), "Marking recipient as UD-unrestricted following a UD send.");
            SignalDatabase.recipients().setUnidentifiedAccessMode(recipient.getId(), UnidentifiedAccessMode.UNRESTRICTED);
        } else if (unidentified && accessMode == UnidentifiedAccessMode.UNKNOWN) {
            log(TAG, String.valueOf(record.getDateSent()), "Marking recipient as UD-enabled following a UD send.");
            SignalDatabase.recipients().setUnidentifiedAccessMode(recipient.getId(), UnidentifiedAccessMode.ENABLED);
        } else if (!unidentified && accessMode != UnidentifiedAccessMode.DISABLED) {
            log(TAG, String.valueOf(record.getDateSent()), "Marking recipient as UD-disabled following a non-UD send.");
            SignalDatabase.recipients().setUnidentifiedAccessMode(recipient.getId(), UnidentifiedAccessMode.DISABLED);
        }
        if (record.getExpiresIn() > 0) {
            database.markExpireStarted(messageId);
            expirationManager.scheduleDeletion(record.getId(), record.isMms(), record.getExpiresIn());
        }
        log(TAG, String.valueOf(record.getDateSent()), "Sent message: " + messageId);
    } catch (InsecureFallbackApprovalException e) {
        warn(TAG, String.valueOf(record.getDateSent()), "Failure", e);
        database.markAsPendingInsecureSmsFallback(record.getId());
        ApplicationDependencies.getMessageNotifier().notifyMessageDeliveryFailed(context, record.getRecipient(), record.getThreadId());
        ApplicationDependencies.getJobManager().add(new DirectoryRefreshJob(false));
    } catch (UntrustedIdentityException e) {
        warn(TAG, String.valueOf(record.getDateSent()), "Failure", e);
        RecipientId recipientId = Recipient.external(context, e.getIdentifier()).getId();
        database.addMismatchedIdentity(record.getId(), recipientId, e.getIdentityKey());
        database.markAsSentFailed(record.getId());
        database.markAsPush(record.getId());
        RetrieveProfileJob.enqueue(recipientId);
    } catch (ProofRequiredException e) {
        handleProofRequiredException(e, record.getRecipient(), record.getThreadId(), messageId, false);
    }
    SignalLocalMetrics.IndividualMessageSend.onJobFinished(messageId);
}
Also used : MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) UntrustedIdentityException(org.whispersystems.signalservice.api.crypto.UntrustedIdentityException) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) SmsMessageRecord(org.thoughtcrime.securesms.database.model.SmsMessageRecord) ExpiringMessageManager(org.thoughtcrime.securesms.service.ExpiringMessageManager) Recipient(org.thoughtcrime.securesms.recipients.Recipient) ProofRequiredException(org.whispersystems.signalservice.api.push.exceptions.ProofRequiredException) UnidentifiedAccessMode(org.thoughtcrime.securesms.database.RecipientDatabase.UnidentifiedAccessMode) InsecureFallbackApprovalException(org.thoughtcrime.securesms.transport.InsecureFallbackApprovalException) SyncMessageId(org.thoughtcrime.securesms.database.MessageDatabase.SyncMessageId)

Aggregations

UntrustedIdentityException (org.whispersystems.signalservice.api.crypto.UntrustedIdentityException)41 IOException (java.io.IOException)27 Recipient (org.thoughtcrime.securesms.recipients.Recipient)23 List (java.util.List)19 SendMessageResult (org.whispersystems.signalservice.api.messages.SendMessageResult)19 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)18 LinkedList (java.util.LinkedList)16 Optional (org.whispersystems.libsignal.util.guava.Optional)15 NonNull (androidx.annotation.NonNull)14 Collections (java.util.Collections)14 Collectors (java.util.stream.Collectors)14 Log (org.signal.core.util.logging.Log)14 ApplicationDependencies (org.thoughtcrime.securesms.dependencies.ApplicationDependencies)14 RecipientUtil (org.thoughtcrime.securesms.recipients.RecipientUtil)14 UnregisteredUserException (org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException)14 Context (android.content.Context)12 Nullable (androidx.annotation.Nullable)12 Set (java.util.Set)12 SignalDatabase (org.thoughtcrime.securesms.database.SignalDatabase)12 GroupId (org.thoughtcrime.securesms.groups.GroupId)12