Search in sources :

Example 1 with Content

use of org.whispersystems.signalservice.internal.push.SignalServiceProtos.Content 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 2 with Content

use of org.whispersystems.signalservice.internal.push.SignalServiceProtos.Content 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

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