Search in sources :

Example 1 with SignalServiceDataMessage

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

the class PushGroupSendJob method deliver.

private void deliver(MasterSecret masterSecret, OutgoingMediaMessage message, long filterRecipientId) throws IOException, RecipientFormattingException, InvalidNumberException, EncapsulatedExceptions, UndeliverableMessageException {
    SignalServiceMessageSender messageSender = messageSenderFactory.create();
    byte[] groupId = GroupUtil.getDecodedId(message.getRecipients().getPrimaryRecipient().getNumber());
    Recipients recipients = DatabaseFactory.getGroupDatabase(context).getGroupMembers(groupId, false);
    List<Attachment> scaledAttachments = scaleAttachments(masterSecret, MediaConstraints.PUSH_CONSTRAINTS, message.getAttachments());
    List<SignalServiceAttachment> attachmentStreams = getAttachmentsFor(masterSecret, scaledAttachments);
    List<SignalServiceAddress> addresses;
    if (filterRecipientId >= 0)
        addresses = getPushAddresses(filterRecipientId);
    else
        addresses = getPushAddresses(recipients);
    if (message.isGroup()) {
        OutgoingGroupMediaMessage groupMessage = (OutgoingGroupMediaMessage) message;
        GroupContext groupContext = groupMessage.getGroupContext();
        SignalServiceAttachment avatar = attachmentStreams.isEmpty() ? null : attachmentStreams.get(0);
        SignalServiceGroup.Type type = groupMessage.isGroupQuit() ? SignalServiceGroup.Type.QUIT : SignalServiceGroup.Type.UPDATE;
        SignalServiceGroup group = new SignalServiceGroup(type, groupId, groupContext.getName(), groupContext.getMembersList(), avatar);
        SignalServiceDataMessage groupDataMessage = new SignalServiceDataMessage(message.getSentTimeMillis(), group, null, null);
        messageSender.sendMessage(addresses, groupDataMessage);
    } else {
        SignalServiceGroup group = new SignalServiceGroup(groupId);
        SignalServiceDataMessage groupMessage = new SignalServiceDataMessage(message.getSentTimeMillis(), group, attachmentStreams, message.getBody(), false, (int) (message.getExpiresIn() / 1000), message.isExpirationUpdate());
        messageSender.sendMessage(addresses, groupMessage);
    }
}
Also used : Recipients(org.thoughtcrime.securesms.recipients.Recipients) SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) SignalServiceAttachment(org.whispersystems.signalservice.api.messages.SignalServiceAttachment) Attachment(org.thoughtcrime.securesms.attachments.Attachment) SignalServiceAttachment(org.whispersystems.signalservice.api.messages.SignalServiceAttachment) SignalServiceDataMessage(org.whispersystems.signalservice.api.messages.SignalServiceDataMessage) OutgoingGroupMediaMessage(org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) SignalServiceGroup(org.whispersystems.signalservice.api.messages.SignalServiceGroup) GroupContext(org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext)

Example 2 with SignalServiceDataMessage

use of org.whispersystems.signalservice.api.messages.SignalServiceDataMessage 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 3 with SignalServiceDataMessage

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

the class SignalServiceCipher method createSignalServiceMessage.

private SignalServiceDataMessage createSignalServiceMessage(SignalServiceEnvelope envelope, DataMessage content) throws InvalidMessageException {
    SignalServiceGroup groupInfo = createGroupInfo(envelope, content);
    List<SignalServiceAttachment> attachments = new LinkedList<>();
    boolean endSession = ((content.getFlags() & DataMessage.Flags.END_SESSION_VALUE) != 0);
    boolean expirationUpdate = ((content.getFlags() & DataMessage.Flags.EXPIRATION_TIMER_UPDATE_VALUE) != 0);
    boolean profileKeyUpdate = ((content.getFlags() & DataMessage.Flags.PROFILE_KEY_UPDATE_VALUE) != 0);
    SignalServiceDataMessage.Quote quote = createQuote(envelope, content);
    for (AttachmentPointer pointer : content.getAttachmentsList()) {
        attachments.add(createAttachmentPointer(envelope, pointer));
    }
    if (content.hasTimestamp() && content.getTimestamp() != envelope.getTimestamp()) {
        throw new InvalidMessageException("Timestamps don't match: " + content.getTimestamp() + " vs " + envelope.getTimestamp());
    }
    return new SignalServiceDataMessage(envelope.getTimestamp(), groupInfo, attachments, content.getBody(), endSession, content.getExpireTimer(), expirationUpdate, content.hasProfileKey() ? content.getProfileKey().toByteArray() : null, profileKeyUpdate, quote);
}
Also used : SignalServiceAttachment(org.whispersystems.signalservice.api.messages.SignalServiceAttachment) SignalServiceDataMessage(org.whispersystems.signalservice.api.messages.SignalServiceDataMessage) InvalidMessageException(org.whispersystems.libsignal.InvalidMessageException) SignalServiceGroup(org.whispersystems.signalservice.api.messages.SignalServiceGroup) SignalServiceAttachmentPointer(org.whispersystems.signalservice.api.messages.SignalServiceAttachmentPointer) AttachmentPointer(org.whispersystems.signalservice.internal.push.SignalServiceProtos.AttachmentPointer) LinkedList(java.util.LinkedList)

Example 4 with SignalServiceDataMessage

use of org.whispersystems.signalservice.api.messages.SignalServiceDataMessage in project Signal-Android by signalapp.

the class PushGroupSendJob method deliver.

private void deliver(OutgoingMediaMessage message, @Nullable Address filterAddress) throws IOException, RecipientFormattingException, InvalidNumberException, EncapsulatedExceptions, UndeliverableMessageException {
    String groupId = message.getRecipient().getAddress().toGroupString();
    Optional<byte[]> profileKey = getProfileKey(message.getRecipient());
    List<Address> recipients = getGroupMessageRecipients(groupId, messageId);
    MediaConstraints mediaConstraints = MediaConstraints.getPushMediaConstraints();
    List<Attachment> scaledAttachments = scaleAttachments(mediaConstraints, message.getAttachments());
    List<SignalServiceAttachment> attachmentStreams = getAttachmentsFor(scaledAttachments);
    List<SignalServiceAddress> addresses;
    if (filterAddress != null)
        addresses = getPushAddresses(filterAddress);
    else
        addresses = getPushAddresses(recipients);
    if (message.isGroup()) {
        OutgoingGroupMediaMessage groupMessage = (OutgoingGroupMediaMessage) message;
        GroupContext groupContext = groupMessage.getGroupContext();
        SignalServiceAttachment avatar = attachmentStreams.isEmpty() ? null : attachmentStreams.get(0);
        SignalServiceGroup.Type type = groupMessage.isGroupQuit() ? SignalServiceGroup.Type.QUIT : SignalServiceGroup.Type.UPDATE;
        SignalServiceGroup group = new SignalServiceGroup(type, GroupUtil.getDecodedId(groupId), groupContext.getName(), groupContext.getMembersList(), avatar);
        SignalServiceDataMessage groupDataMessage = SignalServiceDataMessage.newBuilder().withTimestamp(message.getSentTimeMillis()).asGroupMessage(group).build();
        messageSender.sendMessage(addresses, groupDataMessage);
    } else {
        SignalServiceGroup group = new SignalServiceGroup(GroupUtil.getDecodedId(groupId));
        SignalServiceDataMessage groupMessage = SignalServiceDataMessage.newBuilder().withTimestamp(message.getSentTimeMillis()).asGroupMessage(group).withAttachments(attachmentStreams).withBody(message.getBody()).withExpiration((int) (message.getExpiresIn() / 1000)).asExpirationUpdate(message.isExpirationUpdate()).withProfileKey(profileKey.orNull()).build();
        messageSender.sendMessage(addresses, groupMessage);
    }
}
Also used : Address(org.thoughtcrime.securesms.database.Address) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) SignalServiceAttachment(org.whispersystems.signalservice.api.messages.SignalServiceAttachment) Attachment(org.thoughtcrime.securesms.attachments.Attachment) SignalServiceAttachment(org.whispersystems.signalservice.api.messages.SignalServiceAttachment) SignalServiceDataMessage(org.whispersystems.signalservice.api.messages.SignalServiceDataMessage) OutgoingGroupMediaMessage(org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage) MediaConstraints(org.thoughtcrime.securesms.mms.MediaConstraints) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) SignalServiceGroup(org.whispersystems.signalservice.api.messages.SignalServiceGroup) GroupContext(org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext)

Example 5 with SignalServiceDataMessage

use of org.whispersystems.signalservice.api.messages.SignalServiceDataMessage in project Signal-Android by signalapp.

the class PushTextSendJob method deliver.

private void deliver(SmsMessageRecord message) throws UntrustedIdentityException, InsecureFallbackApprovalException, RetryLaterException {
    try {
        SignalServiceAddress address = getPushAddress(message.getIndividualRecipient().getAddress());
        Optional<byte[]> profileKey = getProfileKey(message.getIndividualRecipient());
        SignalServiceDataMessage textSecureMessage = SignalServiceDataMessage.newBuilder().withTimestamp(message.getDateSent()).withBody(message.getBody()).withExpiration((int) (message.getExpiresIn() / 1000)).withProfileKey(profileKey.orNull()).asEndSessionMessage(message.isEndSession()).build();
        messageSender.sendMessage(address, textSecureMessage);
    } catch (UnregisteredUserException e) {
        Log.w(TAG, e);
        throw new InsecureFallbackApprovalException(e);
    } catch (IOException e) {
        Log.w(TAG, e);
        throw new RetryLaterException(e);
    }
}
Also used : SignalServiceDataMessage(org.whispersystems.signalservice.api.messages.SignalServiceDataMessage) UnregisteredUserException(org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) RetryLaterException(org.thoughtcrime.securesms.transport.RetryLaterException) IOException(java.io.IOException) InsecureFallbackApprovalException(org.thoughtcrime.securesms.transport.InsecureFallbackApprovalException)

Aggregations

SignalServiceDataMessage (org.whispersystems.signalservice.api.messages.SignalServiceDataMessage)29 SignalServiceAddress (org.whispersystems.signalservice.api.push.SignalServiceAddress)14 Recipient (org.thoughtcrime.securesms.recipients.Recipient)10 SignalServiceAttachment (org.whispersystems.signalservice.api.messages.SignalServiceAttachment)10 MessageId (org.thoughtcrime.securesms.database.model.MessageId)8 GroupDatabase (org.thoughtcrime.securesms.database.GroupDatabase)7 SignalServiceMessageSender (org.whispersystems.signalservice.api.SignalServiceMessageSender)7 SendMessageResult (org.whispersystems.signalservice.api.messages.SendMessageResult)7 SignalServiceGroup (org.whispersystems.signalservice.api.messages.SignalServiceGroup)7 Attachment (org.thoughtcrime.securesms.attachments.Attachment)6 RetryLaterException (org.thoughtcrime.securesms.transport.RetryLaterException)6 IOException (java.io.IOException)5 SyncMessageId (org.thoughtcrime.securesms.database.MessageDatabase.SyncMessageId)5 GroupId (org.thoughtcrime.securesms.groups.GroupId)5 NotPushRegisteredException (org.thoughtcrime.securesms.net.NotPushRegisteredException)5 InsecureFallbackApprovalException (org.thoughtcrime.securesms.transport.InsecureFallbackApprovalException)5 UndeliverableMessageException (org.thoughtcrime.securesms.transport.UndeliverableMessageException)5 ServerRejectedException (org.whispersystems.signalservice.api.push.exceptions.ServerRejectedException)5 NonNull (androidx.annotation.NonNull)4 GroupRecord (org.thoughtcrime.securesms.database.GroupDatabase.GroupRecord)4