Search in sources :

Example 1 with DataMessage

use of org.whispersystems.signalservice.internal.push.SignalServiceProtos.DataMessage in project Signal-Android by WhisperSystems.

the class SignalServiceMessageSender method createMultiDeviceSentTranscriptContent.

private Content createMultiDeviceSentTranscriptContent(Content content, Optional<SignalServiceAddress> recipient, long timestamp, List<SendMessageResult> sendMessageResults, boolean isRecipientUpdate) {
    Content.Builder container = Content.newBuilder();
    SyncMessage.Builder syncMessage = createSyncMessageBuilder();
    SyncMessage.Sent.Builder sentMessage = SyncMessage.Sent.newBuilder();
    DataMessage dataMessage = content.getDataMessage();
    sentMessage.setTimestamp(timestamp);
    sentMessage.setMessage(dataMessage);
    for (SendMessageResult result : sendMessageResults) {
        if (result.getSuccess() != null) {
            SyncMessage.Sent.UnidentifiedDeliveryStatus.Builder builder = SyncMessage.Sent.UnidentifiedDeliveryStatus.newBuilder();
            builder.setDestinationUuid(result.getAddress().getServiceId().toString());
            if (result.getAddress().getNumber().isPresent()) {
                builder.setDestinationE164(result.getAddress().getNumber().get());
            }
            builder.setUnidentified(result.getSuccess().isUnidentified());
            sentMessage.addUnidentifiedStatus(builder.build());
        }
    }
    if (recipient.isPresent()) {
        sentMessage.setDestinationUuid(recipient.get().getServiceId().toString());
        if (recipient.get().getNumber().isPresent()) {
            sentMessage.setDestinationE164(recipient.get().getNumber().get());
        }
    }
    if (dataMessage.getExpireTimer() > 0) {
        sentMessage.setExpirationStartTimestamp(System.currentTimeMillis());
    }
    if (dataMessage.getIsViewOnce()) {
        dataMessage = dataMessage.toBuilder().clearAttachments().build();
        sentMessage.setMessage(dataMessage);
    }
    sentMessage.setIsRecipientUpdate(isRecipientUpdate);
    return container.setSyncMessage(syncMessage.setSent(sentMessage)).build();
}
Also used : SyncMessage(org.whispersystems.signalservice.internal.push.SignalServiceProtos.SyncMessage) SignalServiceSyncMessage(org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage) EnvelopeContent(org.whispersystems.signalservice.api.crypto.EnvelopeContent) PlaintextContent(org.whispersystems.libsignal.protocol.PlaintextContent) Content(org.whispersystems.signalservice.internal.push.SignalServiceProtos.Content) DataMessage(org.whispersystems.signalservice.internal.push.SignalServiceProtos.DataMessage) SignalServiceDataMessage(org.whispersystems.signalservice.api.messages.SignalServiceDataMessage) SendMessageResult(org.whispersystems.signalservice.api.messages.SendMessageResult)

Example 2 with DataMessage

use of org.whispersystems.signalservice.internal.push.SignalServiceProtos.DataMessage in project libsignal-service-java by signalapp.

the class SignalServiceMessageSender method createMultiDeviceSentTranscriptContent.

private byte[] createMultiDeviceSentTranscriptContent(byte[] content, Optional<SignalServiceAddress> recipient, long timestamp) {
    try {
        Content.Builder container = Content.newBuilder();
        SyncMessage.Builder syncMessage = createSyncMessageBuilder();
        SyncMessage.Sent.Builder sentMessage = SyncMessage.Sent.newBuilder();
        DataMessage dataMessage = Content.parseFrom(content).getDataMessage();
        sentMessage.setTimestamp(timestamp);
        sentMessage.setMessage(dataMessage);
        if (recipient.isPresent()) {
            sentMessage.setDestination(recipient.get().getNumber());
        }
        if (dataMessage.getExpireTimer() > 0) {
            sentMessage.setExpirationStartTimestamp(System.currentTimeMillis());
        }
        return container.setSyncMessage(syncMessage.setSent(sentMessage)).build().toByteArray();
    } catch (InvalidProtocolBufferException e) {
        throw new AssertionError(e);
    }
}
Also used : SyncMessage(org.whispersystems.signalservice.internal.push.SignalServiceProtos.SyncMessage) SignalServiceSyncMessage(org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage) Content(org.whispersystems.signalservice.internal.push.SignalServiceProtos.Content) SignalServiceDataMessage(org.whispersystems.signalservice.api.messages.SignalServiceDataMessage) DataMessage(org.whispersystems.signalservice.internal.push.SignalServiceProtos.DataMessage) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException)

Example 3 with DataMessage

use of org.whispersystems.signalservice.internal.push.SignalServiceProtos.DataMessage in project libsignal-service-java by signalapp.

the class SignalServiceCipher method decrypt.

/**
 * Decrypt a received {@link SignalServiceEnvelope}
 *
 * @param envelope The received SignalServiceEnvelope
 *
 * @return a decrypted SignalServiceContent
 * @throws InvalidVersionException
 * @throws InvalidMessageException
 * @throws InvalidKeyException
 * @throws DuplicateMessageException
 * @throws InvalidKeyIdException
 * @throws UntrustedIdentityException
 * @throws LegacyMessageException
 * @throws NoSessionException
 */
public SignalServiceContent decrypt(SignalServiceEnvelope envelope) throws InvalidVersionException, InvalidMessageException, InvalidKeyException, DuplicateMessageException, InvalidKeyIdException, UntrustedIdentityException, LegacyMessageException, NoSessionException {
    try {
        SignalServiceContent content = new SignalServiceContent();
        if (envelope.hasLegacyMessage()) {
            DataMessage message = DataMessage.parseFrom(decrypt(envelope, envelope.getLegacyMessage()));
            content = new SignalServiceContent(createSignalServiceMessage(envelope, message));
        } else if (envelope.hasContent()) {
            Content message = Content.parseFrom(decrypt(envelope, envelope.getContent()));
            if (message.hasDataMessage()) {
                content = new SignalServiceContent(createSignalServiceMessage(envelope, message.getDataMessage()));
            } else if (message.hasSyncMessage() && localAddress.getNumber().equals(envelope.getSource())) {
                content = new SignalServiceContent(createSynchronizeMessage(envelope, message.getSyncMessage()));
            } else if (message.hasCallMessage()) {
                content = new SignalServiceContent(createCallMessage(message.getCallMessage()));
            } else if (message.hasReceiptMessage()) {
                content = new SignalServiceContent(createReceiptMessage(envelope, message.getReceiptMessage()));
            }
        }
        return content;
    } catch (InvalidProtocolBufferException e) {
        throw new InvalidMessageException(e);
    }
}
Also used : SignalServiceContent(org.whispersystems.signalservice.api.messages.SignalServiceContent) InvalidMessageException(org.whispersystems.libsignal.InvalidMessageException) SignalServiceDataMessage(org.whispersystems.signalservice.api.messages.SignalServiceDataMessage) DataMessage(org.whispersystems.signalservice.internal.push.SignalServiceProtos.DataMessage) SignalServiceContent(org.whispersystems.signalservice.api.messages.SignalServiceContent) Content(org.whispersystems.signalservice.internal.push.SignalServiceProtos.Content) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException)

Aggregations

SignalServiceDataMessage (org.whispersystems.signalservice.api.messages.SignalServiceDataMessage)3 Content (org.whispersystems.signalservice.internal.push.SignalServiceProtos.Content)3 DataMessage (org.whispersystems.signalservice.internal.push.SignalServiceProtos.DataMessage)3 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)2 SignalServiceSyncMessage (org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage)2 SyncMessage (org.whispersystems.signalservice.internal.push.SignalServiceProtos.SyncMessage)2 InvalidMessageException (org.whispersystems.libsignal.InvalidMessageException)1 PlaintextContent (org.whispersystems.libsignal.protocol.PlaintextContent)1 EnvelopeContent (org.whispersystems.signalservice.api.crypto.EnvelopeContent)1 SendMessageResult (org.whispersystems.signalservice.api.messages.SendMessageResult)1 SignalServiceContent (org.whispersystems.signalservice.api.messages.SignalServiceContent)1