Search in sources :

Example 16 with UntrustedIdentityException

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

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)

Example 17 with UntrustedIdentityException

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

the class SignalServiceMessageSender method sendMessage.

private List<SendMessageResult> sendMessage(List<SignalServiceAddress> recipients, List<Optional<UnidentifiedAccess>> unidentifiedAccess, long timestamp, EnvelopeContent content, boolean online, PartialSendCompleteListener partialListener, CancelationSignal cancelationSignal) throws IOException {
    Log.d(TAG, "[" + timestamp + "] Sending to " + recipients.size() + " recipients.");
    enforceMaxContentSize(content);
    long startTime = System.currentTimeMillis();
    List<Future<SendMessageResult>> futureResults = new LinkedList<>();
    Iterator<SignalServiceAddress> recipientIterator = recipients.iterator();
    Iterator<Optional<UnidentifiedAccess>> unidentifiedAccessIterator = unidentifiedAccess.iterator();
    while (recipientIterator.hasNext()) {
        SignalServiceAddress recipient = recipientIterator.next();
        Optional<UnidentifiedAccess> access = unidentifiedAccessIterator.next();
        futureResults.add(executor.submit(() -> {
            SendMessageResult result = sendMessage(recipient, access, timestamp, content, online, cancelationSignal);
            if (partialListener != null) {
                partialListener.onPartialSendComplete(result);
            }
            return result;
        }));
    }
    List<SendMessageResult> results = new ArrayList<>(futureResults.size());
    recipientIterator = recipients.iterator();
    for (Future<SendMessageResult> futureResult : futureResults) {
        SignalServiceAddress recipient = recipientIterator.next();
        try {
            results.add(futureResult.get());
        } catch (ExecutionException e) {
            if (e.getCause() instanceof UntrustedIdentityException) {
                Log.w(TAG, e);
                results.add(SendMessageResult.identityFailure(recipient, ((UntrustedIdentityException) e.getCause()).getIdentityKey()));
            } else if (e.getCause() instanceof UnregisteredUserException) {
                Log.w(TAG, "[" + timestamp + "] Found unregistered user.");
                results.add(SendMessageResult.unregisteredFailure(recipient));
            } else if (e.getCause() instanceof PushNetworkException) {
                Log.w(TAG, e);
                results.add(SendMessageResult.networkFailure(recipient));
            } else if (e.getCause() instanceof ServerRejectedException) {
                Log.w(TAG, e);
                throw ((ServerRejectedException) e.getCause());
            } else if (e.getCause() instanceof ProofRequiredException) {
                Log.w(TAG, e);
                results.add(SendMessageResult.proofRequiredFailure(recipient, (ProofRequiredException) e.getCause()));
            } else {
                throw new IOException(e);
            }
        } catch (InterruptedException e) {
            throw new IOException(e);
        }
    }
    double sendsForAverage = 0;
    for (SendMessageResult result : results) {
        if (result.getSuccess() != null && result.getSuccess().getDuration() != -1) {
            sendsForAverage++;
        }
    }
    double average = 0;
    if (sendsForAverage > 0) {
        for (SendMessageResult result : results) {
            if (result.getSuccess() != null && result.getSuccess().getDuration() != -1) {
                average += result.getSuccess().getDuration() / sendsForAverage;
            }
        }
    }
    Log.d(TAG, "[" + timestamp + "] Completed send to " + recipients.size() + " recipients in " + (System.currentTimeMillis() - startTime) + " ms, with an average time of " + Math.round(average) + " ms per send.");
    return results;
}
Also used : UntrustedIdentityException(org.whispersystems.signalservice.api.crypto.UntrustedIdentityException) UnregisteredUserException(org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException) PushNetworkException(org.whispersystems.signalservice.api.push.exceptions.PushNetworkException) Optional(org.whispersystems.libsignal.util.guava.Optional) ArrayList(java.util.ArrayList) ServerRejectedException(org.whispersystems.signalservice.api.push.exceptions.ServerRejectedException) ProofRequiredException(org.whispersystems.signalservice.api.push.exceptions.ProofRequiredException) IOException(java.io.IOException) LinkedList(java.util.LinkedList) SendMessageResult(org.whispersystems.signalservice.api.messages.SendMessageResult) UnidentifiedAccess(org.whispersystems.signalservice.api.crypto.UnidentifiedAccess) Future(java.util.concurrent.Future) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) ExecutionException(java.util.concurrent.ExecutionException)

Example 18 with UntrustedIdentityException

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

the class PushGroupSendJob method onPushSend.

@Override
public void onPushSend(MasterSecret masterSecret) throws MmsException, IOException, NoSuchMessageException {
    MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
    OutgoingMediaMessage message = database.getOutgoingMessage(masterSecret, messageId);
    try {
        deliver(masterSecret, message, filterRecipientId);
        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()) {
            Recipient recipient = RecipientFactory.getRecipientsFromString(context, nfe.getE164number(), false).getPrimaryRecipient();
            failures.add(new NetworkFailure(recipient.getRecipientId()));
        }
        for (UntrustedIdentityException uie : e.getUntrustedIdentityExceptions()) {
            Recipient recipient = RecipientFactory.getRecipientsFromString(context, uie.getE164Number(), false).getPrimaryRecipient();
            database.addMismatchedIdentity(messageId, recipient.getRecipientId(), 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) OutgoingMediaMessage(org.thoughtcrime.securesms.mms.OutgoingMediaMessage) Recipient(org.thoughtcrime.securesms.recipients.Recipient) NetworkFailure(org.thoughtcrime.securesms.database.documents.NetworkFailure) UndeliverableMessageException(org.thoughtcrime.securesms.transport.UndeliverableMessageException) LinkedList(java.util.LinkedList) List(java.util.List) NetworkFailureException(org.whispersystems.signalservice.api.push.exceptions.NetworkFailureException) RecipientFormattingException(org.thoughtcrime.securesms.recipients.RecipientFormattingException) MmsDatabase(org.thoughtcrime.securesms.database.MmsDatabase)

Example 19 with UntrustedIdentityException

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

the class WebRtcCallService method handleOutgoingCall.

private void handleOutgoingCall(Intent intent) {
    Log.w(TAG, "handleOutgoingCall...");
    if (callState != CallState.STATE_IDLE)
        throw new IllegalStateException("Dialing from non-idle?");
    try {
        this.callState = CallState.STATE_DIALING;
        this.recipient = getRemoteRecipient(intent);
        this.callId = SecureRandom.getInstance("SHA1PRNG").nextLong();
        this.pendingIceUpdates = new LinkedList<>();
        initializeVideo();
        sendMessage(WebRtcViewModel.State.CALL_OUTGOING, recipient, localVideoEnabled, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
        lockManager.updatePhoneState(LockManager.PhoneState.IN_CALL);
        audioManager.initializeAudioForCall();
        audioManager.startOutgoingRinger(OutgoingRinger.Type.SONAR);
        bluetoothStateManager.setWantsConnection(true);
        setCallInProgressNotification(TYPE_OUTGOING_RINGING, recipient);
        DatabaseFactory.getSmsDatabase(this).insertOutgoingCall(recipient.getNumber());
        timeoutExecutor.schedule(new TimeoutRunnable(this.callId), 2, TimeUnit.MINUTES);
        retrieveTurnServers().addListener(new SuccessOnlyListener<List<PeerConnection.IceServer>>(this.callState, this.callId) {

            @Override
            public void onSuccessContinue(List<PeerConnection.IceServer> result) {
                try {
                    boolean isAlwaysTurn = TextSecurePreferences.isTurnOnly(WebRtcCallService.this);
                    WebRtcCallService.this.peerConnection = new PeerConnectionWrapper(WebRtcCallService.this, peerConnectionFactory, WebRtcCallService.this, localRenderer, result, isAlwaysTurn);
                    WebRtcCallService.this.dataChannel = WebRtcCallService.this.peerConnection.createDataChannel(DATA_CHANNEL_NAME);
                    WebRtcCallService.this.dataChannel.registerObserver(WebRtcCallService.this);
                    SessionDescription sdp = WebRtcCallService.this.peerConnection.createOffer(new MediaConstraints());
                    WebRtcCallService.this.peerConnection.setLocalDescription(sdp);
                    Log.w(TAG, "Sending offer: " + sdp.description);
                    ListenableFutureTask<Boolean> listenableFutureTask = sendMessage(recipient, SignalServiceCallMessage.forOffer(new OfferMessage(WebRtcCallService.this.callId, sdp.description)));
                    listenableFutureTask.addListener(new FailureListener<Boolean>(callState, callId) {

                        @Override
                        public void onFailureContinue(Throwable error) {
                            Log.w(TAG, error);
                            if (error instanceof UntrustedIdentityException) {
                                sendMessage(WebRtcViewModel.State.UNTRUSTED_IDENTITY, recipient, ((UntrustedIdentityException) error).getIdentityKey(), localVideoEnabled, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
                            } else if (error instanceof UnregisteredUserException) {
                                sendMessage(WebRtcViewModel.State.NO_SUCH_USER, recipient, localVideoEnabled, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
                            } else if (error instanceof IOException) {
                                sendMessage(WebRtcViewModel.State.NETWORK_FAILURE, recipient, localVideoEnabled, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
                            }
                            terminate();
                        }
                    });
                } catch (PeerConnectionException e) {
                    Log.w(TAG, e);
                    terminate();
                }
            }
        });
    } catch (NoSuchAlgorithmException e) {
        throw new AssertionError(e);
    }
}
Also used : SessionDescription(org.webrtc.SessionDescription) UntrustedIdentityException(org.whispersystems.signalservice.api.crypto.UntrustedIdentityException) UnregisteredUserException(org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException) PeerConnection(org.webrtc.PeerConnection) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) PeerConnectionWrapper(org.thoughtcrime.securesms.webrtc.PeerConnectionWrapper) MediaConstraints(org.webrtc.MediaConstraints) ListenableFutureTask(org.thoughtcrime.securesms.util.ListenableFutureTask) PeerConnectionException(org.thoughtcrime.securesms.webrtc.PeerConnectionWrapper.PeerConnectionException) OfferMessage(org.whispersystems.signalservice.api.messages.calls.OfferMessage) List(java.util.List) LinkedList(java.util.LinkedList)

Example 20 with UntrustedIdentityException

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

the class WebRtcCallService method handleOutgoingCall.

private void handleOutgoingCall(Intent intent) {
    Log.w(TAG, "handleOutgoingCall...");
    if (callState != CallState.STATE_IDLE)
        throw new IllegalStateException("Dialing from non-idle?");
    try {
        this.callState = CallState.STATE_DIALING;
        this.recipient = getRemoteRecipient(intent);
        this.callId = SecureRandom.getInstance("SHA1PRNG").nextLong();
        this.pendingOutgoingIceUpdates = new LinkedList<>();
        initializeVideo();
        sendMessage(WebRtcViewModel.State.CALL_OUTGOING, recipient, localVideoEnabled, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
        lockManager.updatePhoneState(LockManager.PhoneState.IN_CALL);
        audioManager.initializeAudioForCall();
        audioManager.startOutgoingRinger(OutgoingRinger.Type.SONAR);
        bluetoothStateManager.setWantsConnection(true);
        setCallInProgressNotification(TYPE_OUTGOING_RINGING, recipient);
        DatabaseFactory.getSmsDatabase(this).insertOutgoingCall(recipient.getAddress());
        timeoutExecutor.schedule(new TimeoutRunnable(this.callId), 2, TimeUnit.MINUTES);
        retrieveTurnServers().addListener(new SuccessOnlyListener<List<PeerConnection.IceServer>>(this.callState, this.callId) {

            @Override
            public void onSuccessContinue(List<PeerConnection.IceServer> result) {
                try {
                    boolean isAlwaysTurn = TextSecurePreferences.isTurnOnly(WebRtcCallService.this);
                    WebRtcCallService.this.peerConnection = new PeerConnectionWrapper(WebRtcCallService.this, peerConnectionFactory, WebRtcCallService.this, localRenderer, result, isAlwaysTurn);
                    WebRtcCallService.this.dataChannel = WebRtcCallService.this.peerConnection.createDataChannel(DATA_CHANNEL_NAME);
                    WebRtcCallService.this.dataChannel.registerObserver(WebRtcCallService.this);
                    SessionDescription sdp = WebRtcCallService.this.peerConnection.createOffer(new MediaConstraints());
                    WebRtcCallService.this.peerConnection.setLocalDescription(sdp);
                    Log.w(TAG, "Sending offer: " + sdp.description);
                    ListenableFutureTask<Boolean> listenableFutureTask = sendMessage(recipient, SignalServiceCallMessage.forOffer(new OfferMessage(WebRtcCallService.this.callId, sdp.description)));
                    listenableFutureTask.addListener(new FailureListener<Boolean>(callState, callId) {

                        @Override
                        public void onFailureContinue(Throwable error) {
                            Log.w(TAG, error);
                            if (error instanceof UntrustedIdentityException) {
                                sendMessage(WebRtcViewModel.State.UNTRUSTED_IDENTITY, recipient, ((UntrustedIdentityException) error).getIdentityKey(), localVideoEnabled, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
                            } else if (error instanceof UnregisteredUserException) {
                                sendMessage(WebRtcViewModel.State.NO_SUCH_USER, recipient, localVideoEnabled, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
                            } else if (error instanceof IOException) {
                                sendMessage(WebRtcViewModel.State.NETWORK_FAILURE, recipient, localVideoEnabled, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
                            }
                            terminate();
                        }
                    });
                } catch (PeerConnectionException e) {
                    Log.w(TAG, e);
                    terminate();
                }
            }
        });
    } catch (NoSuchAlgorithmException e) {
        throw new AssertionError(e);
    }
}
Also used : SessionDescription(org.webrtc.SessionDescription) UntrustedIdentityException(org.whispersystems.signalservice.api.crypto.UntrustedIdentityException) UnregisteredUserException(org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException) PeerConnection(org.webrtc.PeerConnection) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) PeerConnectionWrapper(org.thoughtcrime.securesms.webrtc.PeerConnectionWrapper) MediaConstraints(org.webrtc.MediaConstraints) ListenableFutureTask(org.thoughtcrime.securesms.util.ListenableFutureTask) PeerConnectionException(org.thoughtcrime.securesms.webrtc.PeerConnectionWrapper.PeerConnectionException) OfferMessage(org.whispersystems.signalservice.api.messages.calls.OfferMessage) List(java.util.List) LinkedList(java.util.LinkedList)

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