Search in sources :

Example 1 with SignalServiceCallMessage

use of org.whispersystems.signalservice.api.messages.calls.SignalServiceCallMessage in project Signal-Android by WhisperSystems.

the class PushDecryptJob method handleMessage.

private void handleMessage(MasterSecretUnion masterSecret, SignalServiceEnvelope envelope, Optional<Long> smsMessageId) {
    try {
        GroupDatabase groupDatabase = DatabaseFactory.getGroupDatabase(context);
        SignalProtocolStore axolotlStore = new SignalProtocolStoreImpl(context);
        SignalServiceAddress localAddress = new SignalServiceAddress(TextSecurePreferences.getLocalNumber(context));
        SignalServiceCipher cipher = new SignalServiceCipher(localAddress, axolotlStore);
        SignalServiceContent content = cipher.decrypt(envelope);
        if (content.getDataMessage().isPresent()) {
            SignalServiceDataMessage message = content.getDataMessage().get();
            if (message.isEndSession())
                handleEndSessionMessage(masterSecret, envelope, message, smsMessageId);
            else if (message.isGroupUpdate())
                handleGroupMessage(masterSecret, envelope, message, smsMessageId);
            else if (message.isExpirationUpdate())
                handleExpirationUpdate(masterSecret, envelope, message, smsMessageId);
            else if (message.getAttachments().isPresent())
                handleMediaMessage(masterSecret, envelope, message, smsMessageId);
            else
                handleTextMessage(masterSecret, envelope, message, smsMessageId);
            if (message.getGroupInfo().isPresent() && groupDatabase.isUnknownGroup(message.getGroupInfo().get().getGroupId())) {
                handleUnknownGroupMessage(envelope, message.getGroupInfo().get());
            }
        } else if (content.getSyncMessage().isPresent()) {
            SignalServiceSyncMessage syncMessage = content.getSyncMessage().get();
            if (syncMessage.getSent().isPresent())
                handleSynchronizeSentMessage(masterSecret, envelope, syncMessage.getSent().get(), smsMessageId);
            else if (syncMessage.getRequest().isPresent())
                handleSynchronizeRequestMessage(masterSecret, syncMessage.getRequest().get());
            else if (syncMessage.getRead().isPresent())
                handleSynchronizeReadMessage(masterSecret, syncMessage.getRead().get(), envelope.getTimestamp());
            else
                Log.w(TAG, "Contains no known sync types...");
        } else if (content.getCallMessage().isPresent()) {
            Log.w(TAG, "Got call message...");
            SignalServiceCallMessage message = content.getCallMessage().get();
            if (message.getOfferMessage().isPresent())
                handleCallOfferMessage(envelope, message.getOfferMessage().get(), smsMessageId);
            else if (message.getAnswerMessage().isPresent())
                handleCallAnswerMessage(envelope, message.getAnswerMessage().get());
            else if (message.getIceUpdateMessages().isPresent())
                handleCallIceUpdateMessage(envelope, message.getIceUpdateMessages().get());
            else if (message.getHangupMessage().isPresent())
                handleCallHangupMessage(envelope, message.getHangupMessage().get(), smsMessageId);
        } else {
            Log.w(TAG, "Got unrecognized message...");
        }
        if (envelope.isPreKeySignalMessage()) {
            ApplicationContext.getInstance(context).getJobManager().add(new RefreshPreKeysJob(context));
        }
    } catch (InvalidVersionException e) {
        Log.w(TAG, e);
        handleInvalidVersionMessage(masterSecret, envelope, smsMessageId);
    } catch (InvalidMessageException | InvalidKeyIdException | InvalidKeyException | MmsException e) {
        Log.w(TAG, e);
        handleCorruptMessage(masterSecret, envelope, smsMessageId);
    } catch (NoSessionException e) {
        Log.w(TAG, e);
        handleNoSessionMessage(masterSecret, envelope, smsMessageId);
    } catch (LegacyMessageException e) {
        Log.w(TAG, e);
        handleLegacyMessage(masterSecret, envelope, smsMessageId);
    } catch (DuplicateMessageException e) {
        Log.w(TAG, e);
        handleDuplicateMessage(masterSecret, envelope, smsMessageId);
    } catch (UntrustedIdentityException e) {
        Log.w(TAG, e);
        handleUntrustedIdentityMessage(masterSecret, envelope, smsMessageId);
    }
}
Also used : InvalidMessageException(org.whispersystems.libsignal.InvalidMessageException) UntrustedIdentityException(org.whispersystems.libsignal.UntrustedIdentityException) SignalServiceCipher(org.whispersystems.signalservice.api.crypto.SignalServiceCipher) InvalidVersionException(org.whispersystems.libsignal.InvalidVersionException) InvalidKeyException(org.whispersystems.libsignal.InvalidKeyException) SignalServiceSyncMessage(org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage) SignalServiceContent(org.whispersystems.signalservice.api.messages.SignalServiceContent) NoSessionException(org.whispersystems.libsignal.NoSessionException) SignalServiceDataMessage(org.whispersystems.signalservice.api.messages.SignalServiceDataMessage) SignalProtocolStore(org.whispersystems.libsignal.state.SignalProtocolStore) MmsException(ws.com.google.android.mms.MmsException) DuplicateMessageException(org.whispersystems.libsignal.DuplicateMessageException) SignalProtocolStoreImpl(org.thoughtcrime.securesms.crypto.storage.SignalProtocolStoreImpl) GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) SignalServiceCallMessage(org.whispersystems.signalservice.api.messages.calls.SignalServiceCallMessage) InvalidKeyIdException(org.whispersystems.libsignal.InvalidKeyIdException) LegacyMessageException(org.whispersystems.libsignal.LegacyMessageException)

Example 2 with SignalServiceCallMessage

use of org.whispersystems.signalservice.api.messages.calls.SignalServiceCallMessage in project libsignal-service-java by signalapp.

the class SignalServiceMessageSender method createCallContent.

private byte[] createCallContent(SignalServiceCallMessage callMessage) {
    Content.Builder container = Content.newBuilder();
    CallMessage.Builder builder = CallMessage.newBuilder();
    if (callMessage.getOfferMessage().isPresent()) {
        OfferMessage offer = callMessage.getOfferMessage().get();
        builder.setOffer(CallMessage.Offer.newBuilder().setId(offer.getId()).setDescription(offer.getDescription()));
    } else if (callMessage.getAnswerMessage().isPresent()) {
        AnswerMessage answer = callMessage.getAnswerMessage().get();
        builder.setAnswer(CallMessage.Answer.newBuilder().setId(answer.getId()).setDescription(answer.getDescription()));
    } else if (callMessage.getIceUpdateMessages().isPresent()) {
        List<IceUpdateMessage> updates = callMessage.getIceUpdateMessages().get();
        for (IceUpdateMessage update : updates) {
            builder.addIceUpdate(CallMessage.IceUpdate.newBuilder().setId(update.getId()).setSdp(update.getSdp()).setSdpMid(update.getSdpMid()).setSdpMLineIndex(update.getSdpMLineIndex()));
        }
    } else if (callMessage.getHangupMessage().isPresent()) {
        builder.setHangup(CallMessage.Hangup.newBuilder().setId(callMessage.getHangupMessage().get().getId()));
    } else if (callMessage.getBusyMessage().isPresent()) {
        builder.setBusy(CallMessage.Busy.newBuilder().setId(callMessage.getBusyMessage().get().getId()));
    }
    container.setCallMessage(builder);
    return container.build().toByteArray();
}
Also used : IceUpdateMessage(org.whispersystems.signalservice.api.messages.calls.IceUpdateMessage) Content(org.whispersystems.signalservice.internal.push.SignalServiceProtos.Content) SignalServiceCallMessage(org.whispersystems.signalservice.api.messages.calls.SignalServiceCallMessage) CallMessage(org.whispersystems.signalservice.internal.push.SignalServiceProtos.CallMessage) OfferMessage(org.whispersystems.signalservice.api.messages.calls.OfferMessage) AnswerMessage(org.whispersystems.signalservice.api.messages.calls.AnswerMessage)

Example 3 with SignalServiceCallMessage

use of org.whispersystems.signalservice.api.messages.calls.SignalServiceCallMessage in project Signal-Android by WhisperSystems.

the class WebRtcActionProcessor method handleSendHangup.

@NonNull
protected final WebRtcServiceState handleSendHangup(@NonNull WebRtcServiceState currentState, @NonNull CallMetadata callMetadata, @NonNull HangupMetadata hangupMetadata, boolean broadcast) {
    Log.i(tag, "handleSendHangup(): id: " + callMetadata.getCallId().format(callMetadata.getRemoteDevice()));
    HangupMessage hangupMessage = new HangupMessage(callMetadata.getCallId().longValue(), hangupMetadata.getType(), hangupMetadata.getDeviceId(), hangupMetadata.isLegacy());
    Integer destinationDeviceId = broadcast ? null : callMetadata.getRemoteDevice();
    SignalServiceCallMessage callMessage = SignalServiceCallMessage.forHangup(hangupMessage, true, destinationDeviceId);
    webRtcInteractor.sendCallMessage(callMetadata.getRemotePeer(), callMessage);
    return currentState;
}
Also used : HangupMessage(org.whispersystems.signalservice.api.messages.calls.HangupMessage) SignalServiceCallMessage(org.whispersystems.signalservice.api.messages.calls.SignalServiceCallMessage) NonNull(androidx.annotation.NonNull)

Example 4 with SignalServiceCallMessage

use of org.whispersystems.signalservice.api.messages.calls.SignalServiceCallMessage in project Signal-Android by WhisperSystems.

the class WebRtcActionProcessor method handleSendBusy.

@NonNull
protected final WebRtcServiceState handleSendBusy(@NonNull WebRtcServiceState currentState, @NonNull CallMetadata callMetadata, boolean broadcast) {
    Log.i(tag, "handleSendBusy(): id: " + callMetadata.getCallId().format(callMetadata.getRemoteDevice()));
    BusyMessage busyMessage = new BusyMessage(callMetadata.getCallId().longValue());
    Integer destinationDeviceId = broadcast ? null : callMetadata.getRemoteDevice();
    SignalServiceCallMessage callMessage = SignalServiceCallMessage.forBusy(busyMessage, true, destinationDeviceId);
    webRtcInteractor.sendCallMessage(callMetadata.getRemotePeer(), callMessage);
    return currentState;
}
Also used : BusyMessage(org.whispersystems.signalservice.api.messages.calls.BusyMessage) SignalServiceCallMessage(org.whispersystems.signalservice.api.messages.calls.SignalServiceCallMessage) NonNull(androidx.annotation.NonNull)

Example 5 with SignalServiceCallMessage

use of org.whispersystems.signalservice.api.messages.calls.SignalServiceCallMessage in project Signal-Android by WhisperSystems.

the class SignalServiceContent method createCallMessage.

private static SignalServiceCallMessage createCallMessage(SignalServiceProtos.CallMessage content) {
    boolean isMultiRing = content.getMultiRing();
    Integer destinationDeviceId = content.hasDestinationDeviceId() ? content.getDestinationDeviceId() : null;
    if (content.hasOffer()) {
        SignalServiceProtos.CallMessage.Offer offerContent = content.getOffer();
        return SignalServiceCallMessage.forOffer(new OfferMessage(offerContent.getId(), offerContent.hasSdp() ? offerContent.getSdp() : null, OfferMessage.Type.fromProto(offerContent.getType()), offerContent.hasOpaque() ? offerContent.getOpaque().toByteArray() : null), isMultiRing, destinationDeviceId);
    } else if (content.hasAnswer()) {
        SignalServiceProtos.CallMessage.Answer answerContent = content.getAnswer();
        return SignalServiceCallMessage.forAnswer(new AnswerMessage(answerContent.getId(), answerContent.hasSdp() ? answerContent.getSdp() : null, answerContent.hasOpaque() ? answerContent.getOpaque().toByteArray() : null), isMultiRing, destinationDeviceId);
    } else if (content.getIceUpdateCount() > 0) {
        List<IceUpdateMessage> iceUpdates = new LinkedList<>();
        for (SignalServiceProtos.CallMessage.IceUpdate iceUpdate : content.getIceUpdateList()) {
            iceUpdates.add(new IceUpdateMessage(iceUpdate.getId(), iceUpdate.hasOpaque() ? iceUpdate.getOpaque().toByteArray() : null, iceUpdate.hasSdp() ? iceUpdate.getSdp() : null));
        }
        return SignalServiceCallMessage.forIceUpdates(iceUpdates, isMultiRing, destinationDeviceId);
    } else if (content.hasLegacyHangup()) {
        SignalServiceProtos.CallMessage.Hangup hangup = content.getLegacyHangup();
        return SignalServiceCallMessage.forHangup(new HangupMessage(hangup.getId(), HangupMessage.Type.fromProto(hangup.getType()), hangup.getDeviceId(), content.hasLegacyHangup()), isMultiRing, destinationDeviceId);
    } else if (content.hasHangup()) {
        SignalServiceProtos.CallMessage.Hangup hangup = content.getHangup();
        return SignalServiceCallMessage.forHangup(new HangupMessage(hangup.getId(), HangupMessage.Type.fromProto(hangup.getType()), hangup.getDeviceId(), content.hasLegacyHangup()), isMultiRing, destinationDeviceId);
    } else if (content.hasBusy()) {
        SignalServiceProtos.CallMessage.Busy busy = content.getBusy();
        return SignalServiceCallMessage.forBusy(new BusyMessage(busy.getId()), isMultiRing, destinationDeviceId);
    } else if (content.hasOpaque()) {
        SignalServiceProtos.CallMessage.Opaque opaque = content.getOpaque();
        return SignalServiceCallMessage.forOpaque(new OpaqueMessage(opaque.getData().toByteArray(), null), isMultiRing, destinationDeviceId);
    }
    return SignalServiceCallMessage.empty();
}
Also used : IceUpdateMessage(org.whispersystems.signalservice.api.messages.calls.IceUpdateMessage) SignalServiceCallMessage(org.whispersystems.signalservice.api.messages.calls.SignalServiceCallMessage) AnswerMessage(org.whispersystems.signalservice.api.messages.calls.AnswerMessage) LinkedList(java.util.LinkedList) SignalServiceProtos(org.whispersystems.signalservice.internal.push.SignalServiceProtos) HangupMessage(org.whispersystems.signalservice.api.messages.calls.HangupMessage) OfferMessage(org.whispersystems.signalservice.api.messages.calls.OfferMessage) BusyMessage(org.whispersystems.signalservice.api.messages.calls.BusyMessage) OpaqueMessage(org.whispersystems.signalservice.api.messages.calls.OpaqueMessage)

Aggregations

SignalServiceCallMessage (org.whispersystems.signalservice.api.messages.calls.SignalServiceCallMessage)14 NonNull (androidx.annotation.NonNull)8 OfferMessage (org.whispersystems.signalservice.api.messages.calls.OfferMessage)8 GroupDatabase (org.thoughtcrime.securesms.database.GroupDatabase)6 Recipient (org.thoughtcrime.securesms.recipients.Recipient)5 AnswerMessage (org.whispersystems.signalservice.api.messages.calls.AnswerMessage)5 OpaqueMessage (org.whispersystems.signalservice.api.messages.calls.OpaqueMessage)5 Context (android.content.Context)4 ResultReceiver (android.os.ResultReceiver)4 Nullable (androidx.annotation.Nullable)4 Stream (com.annimon.stream.Stream)4 Collection (java.util.Collection)4 List (java.util.List)4 Set (java.util.Set)4 UUID (java.util.UUID)4 Log (org.signal.core.util.logging.Log)4 CallException (org.signal.ringrtc.CallException)4 CallId (org.signal.ringrtc.CallId)4 CallManager (org.signal.ringrtc.CallManager)4 GroupCall (org.signal.ringrtc.GroupCall)4