Search in sources :

Example 1 with EnvelopeContent

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

the class SignalServiceMessageSender method resendContent.

/**
 * Resend a previously-sent message.
 */
public SendMessageResult resendContent(SignalServiceAddress address, Optional<UnidentifiedAccessPair> unidentifiedAccess, long timestamp, Content content, ContentHint contentHint, Optional<byte[]> groupId) throws UntrustedIdentityException, IOException {
    EnvelopeContent envelopeContent = EnvelopeContent.encrypted(content, contentHint, groupId);
    Optional<UnidentifiedAccess> access = unidentifiedAccess.isPresent() ? unidentifiedAccess.get().getTargetUnidentifiedAccess() : Optional.absent();
    return sendMessage(address, access, timestamp, envelopeContent, false, null);
}
Also used : EnvelopeContent(org.whispersystems.signalservice.api.crypto.EnvelopeContent) UnidentifiedAccess(org.whispersystems.signalservice.api.crypto.UnidentifiedAccess)

Example 2 with EnvelopeContent

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

the class SignalServiceMessageSender method sendTyping.

/**
 * Send a typing indicator.
 *
 * @param recipient The destination
 * @param message The typing indicator to deliver
 */
public void sendTyping(SignalServiceAddress recipient, Optional<UnidentifiedAccessPair> unidentifiedAccess, SignalServiceTypingMessage message) throws IOException, UntrustedIdentityException {
    Content content = createTypingContent(message);
    EnvelopeContent envelopeContent = EnvelopeContent.encrypted(content, ContentHint.IMPLICIT, Optional.absent());
    sendMessage(recipient, getTargetUnidentifiedAccess(unidentifiedAccess), message.getTimestamp(), envelopeContent, true, null);
}
Also used : EnvelopeContent(org.whispersystems.signalservice.api.crypto.EnvelopeContent) PlaintextContent(org.whispersystems.libsignal.protocol.PlaintextContent) Content(org.whispersystems.signalservice.internal.push.SignalServiceProtos.Content) EnvelopeContent(org.whispersystems.signalservice.api.crypto.EnvelopeContent)

Example 3 with EnvelopeContent

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

the class SignalServiceMessageSender method sendDataMessage.

/**
 * Sends a message to a group using client-side fanout.
 *
 * @param partialListener A listener that will be called when an individual send is completed. Will be invoked on an arbitrary background thread, *not*
 *                        the calling thread.
 */
public List<SendMessageResult> sendDataMessage(List<SignalServiceAddress> recipients, List<Optional<UnidentifiedAccessPair>> unidentifiedAccess, boolean isRecipientUpdate, ContentHint contentHint, SignalServiceDataMessage message, LegacyGroupEvents sendEvents, PartialSendCompleteListener partialListener, CancelationSignal cancelationSignal) throws IOException, UntrustedIdentityException {
    Log.d(TAG, "[" + message.getTimestamp() + "] Sending a data message to " + recipients.size() + " recipients.");
    Content content = createMessageContent(message);
    EnvelopeContent envelopeContent = EnvelopeContent.encrypted(content, contentHint, message.getGroupId());
    long timestamp = message.getTimestamp();
    List<SendMessageResult> results = sendMessage(recipients, getTargetUnidentifiedAccess(unidentifiedAccess), timestamp, envelopeContent, false, partialListener, cancelationSignal);
    boolean needsSyncInResults = false;
    sendEvents.onMessageSent();
    for (SendMessageResult result : results) {
        if (result.getSuccess() != null && result.getSuccess().isNeedsSync()) {
            needsSyncInResults = true;
            break;
        }
    }
    if (needsSyncInResults || store.isMultiDevice()) {
        Optional<SignalServiceAddress> recipient = Optional.absent();
        if (!message.getGroupContext().isPresent() && recipients.size() == 1) {
            recipient = Optional.of(recipients.get(0));
        }
        Content syncMessage = createMultiDeviceSentTranscriptContent(content, recipient, timestamp, results, isRecipientUpdate);
        EnvelopeContent syncMessageContent = EnvelopeContent.encrypted(syncMessage, ContentHint.IMPLICIT, Optional.absent());
        sendMessage(localAddress, Optional.absent(), timestamp, syncMessageContent, false, null);
    }
    sendEvents.onSyncMessageSent();
    return results;
}
Also used : EnvelopeContent(org.whispersystems.signalservice.api.crypto.EnvelopeContent) PlaintextContent(org.whispersystems.libsignal.protocol.PlaintextContent) Content(org.whispersystems.signalservice.internal.push.SignalServiceProtos.Content) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) SendMessageResult(org.whispersystems.signalservice.api.messages.SendMessageResult) EnvelopeContent(org.whispersystems.signalservice.api.crypto.EnvelopeContent)

Example 4 with EnvelopeContent

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

the class SignalServiceMessageSender method sendVerifiedSyncMessage.

private SendMessageResult sendVerifiedSyncMessage(VerifiedMessage message) throws IOException, UntrustedIdentityException {
    byte[] nullMessageBody = DataMessage.newBuilder().setBody(Base64.encodeBytes(Util.getRandomLengthBytes(140))).build().toByteArray();
    NullMessage nullMessage = NullMessage.newBuilder().setPadding(ByteString.copyFrom(nullMessageBody)).build();
    Content content = Content.newBuilder().setNullMessage(nullMessage).build();
    EnvelopeContent envelopeContent = EnvelopeContent.encrypted(content, ContentHint.IMPLICIT, Optional.absent());
    SendMessageResult result = sendMessage(message.getDestination(), Optional.absent(), message.getTimestamp(), envelopeContent, false, null);
    if (result.getSuccess().isNeedsSync()) {
        Content syncMessage = createMultiDeviceVerifiedContent(message, nullMessage.toByteArray());
        EnvelopeContent syncMessageContent = EnvelopeContent.encrypted(syncMessage, ContentHint.IMPLICIT, Optional.absent());
        sendMessage(localAddress, Optional.absent(), message.getTimestamp(), syncMessageContent, false, null);
    }
    return result;
}
Also used : NullMessage(org.whispersystems.signalservice.internal.push.SignalServiceProtos.NullMessage) EnvelopeContent(org.whispersystems.signalservice.api.crypto.EnvelopeContent) PlaintextContent(org.whispersystems.libsignal.protocol.PlaintextContent) Content(org.whispersystems.signalservice.internal.push.SignalServiceProtos.Content) SendMessageResult(org.whispersystems.signalservice.api.messages.SendMessageResult) EnvelopeContent(org.whispersystems.signalservice.api.crypto.EnvelopeContent)

Example 5 with EnvelopeContent

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

the class SignalServiceMessageSender method sendCallMessage.

public List<SendMessageResult> sendCallMessage(List<SignalServiceAddress> recipients, List<Optional<UnidentifiedAccessPair>> unidentifiedAccess, SignalServiceCallMessage message) throws IOException {
    Content content = createCallContent(message);
    EnvelopeContent envelopeContent = EnvelopeContent.encrypted(content, ContentHint.DEFAULT, Optional.absent());
    return sendMessage(recipients, getTargetUnidentifiedAccess(unidentifiedAccess), System.currentTimeMillis(), envelopeContent, false, null, null);
}
Also used : EnvelopeContent(org.whispersystems.signalservice.api.crypto.EnvelopeContent) PlaintextContent(org.whispersystems.libsignal.protocol.PlaintextContent) Content(org.whispersystems.signalservice.internal.push.SignalServiceProtos.Content) EnvelopeContent(org.whispersystems.signalservice.api.crypto.EnvelopeContent)

Aggregations

EnvelopeContent (org.whispersystems.signalservice.api.crypto.EnvelopeContent)28 PlaintextContent (org.whispersystems.libsignal.protocol.PlaintextContent)26 Content (org.whispersystems.signalservice.internal.push.SignalServiceProtos.Content)24 SendMessageResult (org.whispersystems.signalservice.api.messages.SendMessageResult)8 NullMessage (org.whispersystems.signalservice.internal.push.SignalServiceProtos.NullMessage)4 ByteString (com.google.protobuf.ByteString)2 IOException (java.io.IOException)2 UnidentifiedAccess (org.whispersystems.signalservice.api.crypto.UnidentifiedAccess)2 SignalServiceAddress (org.whispersystems.signalservice.api.push.SignalServiceAddress)2