Search in sources :

Example 1 with UntrustedIdentityException

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

the class PushMediaSendJob method onPushSend.

@Override
public void onPushSend(MasterSecret masterSecret) throws RetryLaterException, MmsException, NoSuchMessageException, UndeliverableMessageException {
    ExpiringMessageManager expirationManager = ApplicationContext.getInstance(context).getExpiringMessageManager();
    MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
    OutgoingMediaMessage message = database.getOutgoingMessage(masterSecret, messageId);
    try {
        deliver(masterSecret, message);
        database.markAsSent(messageId, true);
        markAttachmentsUploaded(messageId, message.getAttachments());
        if (message.getExpiresIn() > 0 && !message.isExpirationUpdate()) {
            database.markExpireStarted(messageId);
            expirationManager.scheduleDeletion(messageId, true, message.getExpiresIn());
        }
    } catch (InsecureFallbackApprovalException ifae) {
        Log.w(TAG, ifae);
        database.markAsPendingInsecureSmsFallback(messageId);
        notifyMediaMessageDeliveryFailed(context, messageId);
        ApplicationContext.getInstance(context).getJobManager().add(new DirectoryRefreshJob(context));
    } catch (UntrustedIdentityException uie) {
        Log.w(TAG, uie);
        Recipients recipients = RecipientFactory.getRecipientsFromString(context, uie.getE164Number(), false);
        long recipientId = recipients.getPrimaryRecipient().getRecipientId();
        database.addMismatchedIdentity(messageId, recipientId, uie.getIdentityKey());
        database.markAsSentFailed(messageId);
    }
}
Also used : UntrustedIdentityException(org.whispersystems.signalservice.api.crypto.UntrustedIdentityException) Recipients(org.thoughtcrime.securesms.recipients.Recipients) ExpiringMessageManager(org.thoughtcrime.securesms.service.ExpiringMessageManager) OutgoingMediaMessage(org.thoughtcrime.securesms.mms.OutgoingMediaMessage) InsecureFallbackApprovalException(org.thoughtcrime.securesms.transport.InsecureFallbackApprovalException) MmsDatabase(org.thoughtcrime.securesms.database.MmsDatabase)

Example 2 with UntrustedIdentityException

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

the class PushTextSendJob method onPushSend.

@Override
public void onPushSend(MasterSecret masterSecret) throws NoSuchMessageException, RetryLaterException {
    ExpiringMessageManager expirationManager = ApplicationContext.getInstance(context).getExpiringMessageManager();
    EncryptingSmsDatabase database = DatabaseFactory.getEncryptingSmsDatabase(context);
    SmsMessageRecord record = database.getMessage(masterSecret, messageId);
    try {
        Log.w(TAG, "Sending message: " + messageId);
        deliver(record);
        database.markAsSent(messageId, true);
        if (record.getExpiresIn() > 0) {
            database.markExpireStarted(messageId);
            expirationManager.scheduleDeletion(record.getId(), record.isMms(), record.getExpiresIn());
        }
    } catch (InsecureFallbackApprovalException e) {
        Log.w(TAG, e);
        database.markAsPendingInsecureSmsFallback(record.getId());
        MessageNotifier.notifyMessageDeliveryFailed(context, record.getRecipients(), record.getThreadId());
        ApplicationContext.getInstance(context).getJobManager().add(new DirectoryRefreshJob(context));
    } catch (UntrustedIdentityException e) {
        Log.w(TAG, e);
        Recipients recipients = RecipientFactory.getRecipientsFromString(context, e.getE164Number(), false);
        long recipientId = recipients.getPrimaryRecipient().getRecipientId();
        database.addMismatchedIdentity(record.getId(), recipientId, e.getIdentityKey());
        database.markAsSentFailed(record.getId());
        database.markAsPush(record.getId());
    }
}
Also used : UntrustedIdentityException(org.whispersystems.signalservice.api.crypto.UntrustedIdentityException) Recipients(org.thoughtcrime.securesms.recipients.Recipients) SmsMessageRecord(org.thoughtcrime.securesms.database.model.SmsMessageRecord) EncryptingSmsDatabase(org.thoughtcrime.securesms.database.EncryptingSmsDatabase) ExpiringMessageManager(org.thoughtcrime.securesms.service.ExpiringMessageManager) InsecureFallbackApprovalException(org.thoughtcrime.securesms.transport.InsecureFallbackApprovalException)

Example 3 with UntrustedIdentityException

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

the class PushGroupSendJob method onPushSend.

@Override
public void onPushSend() throws MmsException, IOException, NoSuchMessageException {
    MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
    OutgoingMediaMessage message = database.getOutgoingMessage(messageId);
    try {
        deliver(message, filterAddress == null ? null : Address.fromSerialized(filterAddress));
        database.markAsSent(messageId, true);
        markAttachmentsUploaded(messageId, message.getAttachments());
        if (message.getExpiresIn() > 0 && !message.isExpirationUpdate()) {
            database.markExpireStarted(messageId);
            ApplicationContext.getInstance(context).getExpiringMessageManager().scheduleDeletion(messageId, true, message.getExpiresIn());
        }
    } catch (InvalidNumberException | RecipientFormattingException | UndeliverableMessageException e) {
        Log.w(TAG, e);
        database.markAsSentFailed(messageId);
        notifyMediaMessageDeliveryFailed(context, messageId);
    } catch (EncapsulatedExceptions e) {
        Log.w(TAG, e);
        List<NetworkFailure> failures = new LinkedList<>();
        for (NetworkFailureException nfe : e.getNetworkExceptions()) {
            failures.add(new NetworkFailure(Address.fromSerialized(nfe.getE164number())));
        }
        for (UntrustedIdentityException uie : e.getUntrustedIdentityExceptions()) {
            database.addMismatchedIdentity(messageId, Address.fromSerialized(uie.getE164Number()), uie.getIdentityKey());
        }
        database.addFailures(messageId, failures);
        if (e.getNetworkExceptions().isEmpty() && e.getUntrustedIdentityExceptions().isEmpty()) {
            database.markAsSent(messageId, true);
            markAttachmentsUploaded(messageId, message.getAttachments());
        } else {
            database.markAsSentFailed(messageId);
            notifyMediaMessageDeliveryFailed(context, messageId);
        }
    }
}
Also used : EncapsulatedExceptions(org.whispersystems.signalservice.api.push.exceptions.EncapsulatedExceptions) UntrustedIdentityException(org.whispersystems.signalservice.api.crypto.UntrustedIdentityException) InvalidNumberException(org.whispersystems.signalservice.api.util.InvalidNumberException) UndeliverableMessageException(org.thoughtcrime.securesms.transport.UndeliverableMessageException) OutgoingMediaMessage(org.thoughtcrime.securesms.mms.OutgoingMediaMessage) LinkedList(java.util.LinkedList) List(java.util.List) NetworkFailureException(org.whispersystems.signalservice.api.push.exceptions.NetworkFailureException) NetworkFailure(org.thoughtcrime.securesms.database.documents.NetworkFailure) RecipientFormattingException(org.thoughtcrime.securesms.recipients.RecipientFormattingException) MmsDatabase(org.thoughtcrime.securesms.database.MmsDatabase)

Example 4 with UntrustedIdentityException

use of org.whispersystems.signalservice.api.crypto.UntrustedIdentityException in project libsignal-service-java by signalapp.

the class SignalServiceMessageSender method sendMessage.

/**
 * Send a message to a group.
 *
 * @param recipients The group members.
 * @param message The group message.
 * @throws IOException
 * @throws EncapsulatedExceptions
 */
public void sendMessage(List<SignalServiceAddress> recipients, SignalServiceDataMessage message) throws IOException, EncapsulatedExceptions {
    byte[] content = createMessageContent(message);
    long timestamp = message.getTimestamp();
    SendMessageResponseList response = sendMessage(recipients, timestamp, content);
    try {
        if (response.getNeedsSync()) {
            byte[] syncMessage = createMultiDeviceSentTranscriptContent(content, Optional.<SignalServiceAddress>absent(), timestamp);
            sendMessage(localAddress, timestamp, syncMessage, false);
        }
    } catch (UntrustedIdentityException e) {
        response.addException(e);
    }
    if (response.hasExceptions()) {
        throw new EncapsulatedExceptions(response.getUntrustedIdentities(), response.getUnregisteredUsers(), response.getNetworkExceptions());
    }
}
Also used : EncapsulatedExceptions(org.whispersystems.signalservice.api.push.exceptions.EncapsulatedExceptions) SendMessageResponseList(org.whispersystems.signalservice.internal.push.SendMessageResponseList) UntrustedIdentityException(org.whispersystems.signalservice.api.crypto.UntrustedIdentityException)

Example 5 with UntrustedIdentityException

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

the class AutomaticSessionResetJob method sendNullMessage.

private void sendNullMessage() throws IOException {
    Recipient recipient = Recipient.resolved(recipientId);
    if (recipient.isUnregistered()) {
        Log.w(TAG, recipient.getId() + " not registered!");
        return;
    }
    SignalServiceMessageSender messageSender = ApplicationDependencies.getSignalServiceMessageSender();
    SignalServiceAddress address = RecipientUtil.toSignalServiceAddress(context, recipient);
    Optional<UnidentifiedAccessPair> unidentifiedAccess = UnidentifiedAccessUtil.getAccessFor(context, recipient);
    try {
        messageSender.sendNullMessage(address, unidentifiedAccess);
    } catch (UntrustedIdentityException e) {
        Log.w(TAG, "Unable to send null message.");
    }
}
Also used : UntrustedIdentityException(org.whispersystems.signalservice.api.crypto.UntrustedIdentityException) SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) Recipient(org.thoughtcrime.securesms.recipients.Recipient) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) UnidentifiedAccessPair(org.whispersystems.signalservice.api.crypto.UnidentifiedAccessPair)

Aggregations

UntrustedIdentityException (org.whispersystems.signalservice.api.crypto.UntrustedIdentityException)27 IOException (java.io.IOException)15 List (java.util.List)12 Recipient (org.thoughtcrime.securesms.recipients.Recipient)12 LinkedList (java.util.LinkedList)10 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)9 SendMessageResult (org.whispersystems.signalservice.api.messages.SendMessageResult)9 UnregisteredUserException (org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException)8 Collections (java.util.Collections)7 Collectors (java.util.stream.Collectors)7 Optional (org.whispersystems.libsignal.util.guava.Optional)7 NonNull (androidx.annotation.NonNull)6 Set (java.util.Set)6 Log (org.signal.core.util.logging.Log)6 ApplicationDependencies (org.thoughtcrime.securesms.dependencies.ApplicationDependencies)6 OutgoingMediaMessage (org.thoughtcrime.securesms.mms.OutgoingMediaMessage)6 RecipientUtil (org.thoughtcrime.securesms.recipients.RecipientUtil)6 InvalidKeyException (org.whispersystems.libsignal.InvalidKeyException)6 SignalServiceMessageSender (org.whispersystems.signalservice.api.SignalServiceMessageSender)6 Context (android.content.Context)5