org.whispersystems.signalservice.api.crypto.UnidentifiedAccessPair Java Examples

The following examples show how to use org.whispersystems.signalservice.api.crypto.UnidentifiedAccessPair. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Manager.java    From signal-cli with GNU General Public License v3.0 6 votes vote down vote up
private SendMessageResult sendSelfMessage(SignalServiceDataMessage message) throws IOException {
    SignalServiceMessageSender messageSender = getMessageSender();

    SignalServiceAddress recipient = account.getSelfAddress();

    final Optional<UnidentifiedAccessPair> unidentifiedAccess = getAccessFor(recipient);
    SentTranscriptMessage transcript = new SentTranscriptMessage(Optional.of(recipient),
            message.getTimestamp(),
            message,
            message.getExpiresInSeconds(),
            Collections.singletonMap(recipient, unidentifiedAccess.isPresent()),
            false);
    SignalServiceSyncMessage syncMessage = SignalServiceSyncMessage.forSentTranscript(transcript);

    try {
        messageSender.sendMessage(syncMessage, unidentifiedAccess);
        return SendMessageResult.success(recipient, unidentifiedAccess.isPresent(), false);
    } catch (UntrustedIdentityException e) {
        account.getSignalProtocolStore().saveIdentity(resolveSignalServiceAddress(e.getIdentifier()), e.getIdentityKey(), TrustLevel.UNTRUSTED);
        return SendMessageResult.identityFailure(recipient, e.getIdentityKey());
    }
}
 
Example #2
Source File: Manager.java    From signal-cli with GNU General Public License v3.0 6 votes vote down vote up
private Optional<UnidentifiedAccessPair> getAccessFor(SignalServiceAddress recipient) {
    byte[] recipientUnidentifiedAccessKey = getTargetUnidentifiedAccessKey(recipient);
    byte[] selfUnidentifiedAccessKey = getSelfUnidentifiedAccessKey();
    byte[] selfUnidentifiedAccessCertificate = getSenderCertificate();

    if (recipientUnidentifiedAccessKey == null || selfUnidentifiedAccessKey == null || selfUnidentifiedAccessCertificate == null) {
        return Optional.absent();
    }

    try {
        return Optional.of(new UnidentifiedAccessPair(
                new UnidentifiedAccess(recipientUnidentifiedAccessKey, selfUnidentifiedAccessCertificate),
                new UnidentifiedAccess(selfUnidentifiedAccessKey, selfUnidentifiedAccessCertificate)
        ));
    } catch (InvalidCertificateException e) {
        return Optional.absent();
    }
}
 
Example #3
Source File: SignalServiceMessageSender.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Send a message to a group.
 *
 * @param recipients The group members.
 * @param message The group message.
 * @throws IOException
 */
public List<SendMessageResult> sendMessage(List<SignalServiceAddress>             recipients,
                                           List<Optional<UnidentifiedAccessPair>> unidentifiedAccess,
                                           boolean                                isRecipientUpdate,
                                           SignalServiceDataMessage               message)
    throws IOException, UntrustedIdentityException
{
  byte[]                  content            = createMessageContent(message);
  long                    timestamp          = message.getTimestamp();
  List<SendMessageResult> results            = sendMessage(recipients, getTargetUnidentifiedAccess(unidentifiedAccess), timestamp, content, false);
  boolean                 needsSyncInResults = false;

  for (SendMessageResult result : results) {
    if (result.getSuccess() != null && result.getSuccess().isNeedsSync()) {
      needsSyncInResults = true;
      break;
    }
  }

  if (needsSyncInResults || isMultiDevice.get()) {
    byte[] syncMessage = createMultiDeviceSentTranscriptContent(content, Optional.<SignalServiceAddress>absent(), timestamp, results, isRecipientUpdate);
    sendMessage(localAddress, Optional.<UnidentifiedAccess>absent(), timestamp, syncMessage, false);
  }

  return results;
}
 
Example #4
Source File: Manager.java    From signal-cli with GNU General Public License v3.0 6 votes vote down vote up
private Optional<UnidentifiedAccessPair> getAccessForSync() {
    byte[] selfUnidentifiedAccessKey = getSelfUnidentifiedAccessKey();
    byte[] selfUnidentifiedAccessCertificate = getSenderCertificate();

    if (selfUnidentifiedAccessKey == null || selfUnidentifiedAccessCertificate == null) {
        return Optional.absent();
    }

    try {
        return Optional.of(new UnidentifiedAccessPair(
                new UnidentifiedAccess(selfUnidentifiedAccessKey, selfUnidentifiedAccessCertificate),
                new UnidentifiedAccess(selfUnidentifiedAccessKey, selfUnidentifiedAccessCertificate)
        ));
    } catch (InvalidCertificateException e) {
        return Optional.absent();
    }
}
 
Example #5
Source File: SignalServiceMessageSender.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
private void sendMessage(VerifiedMessage message, Optional<UnidentifiedAccessPair> unidentifiedAccess)
    throws IOException, UntrustedIdentityException
{
  byte[] nullMessageBody = DataMessage.newBuilder()
                                      .setBody(Base64.encodeBytes(Util.getRandomLengthBytes(140)))
                                      .build()
                                      .toByteArray();

  NullMessage nullMessage = NullMessage.newBuilder()
                                       .setPadding(ByteString.copyFrom(nullMessageBody))
                                       .build();

  byte[] content          = Content.newBuilder()
                                   .setNullMessage(nullMessage)
                                   .build()
                                   .toByteArray();

  SendMessageResult result = sendMessage(message.getDestination(), getTargetUnidentifiedAccess(unidentifiedAccess), message.getTimestamp(), content, false);

  if (result.getSuccess().isNeedsSync()) {
    byte[] syncMessage = createMultiDeviceVerifiedContent(message, nullMessage.toByteArray());
    sendMessage(localAddress, Optional.<UnidentifiedAccess>absent(), message.getTimestamp(), syncMessage, false);
  }
}
 
Example #6
Source File: SignalServiceMessageSender.java    From libsignal-service-java with GNU General Public License v3.0 6 votes vote down vote up
private void sendMessage(VerifiedMessage message, Optional<UnidentifiedAccessPair> unidentifiedAccess)
    throws IOException, UntrustedIdentityException
{
  byte[] nullMessageBody = DataMessage.newBuilder()
                                      .setBody(Base64.encodeBytes(Util.getRandomLengthBytes(140)))
                                      .build()
                                      .toByteArray();

  NullMessage nullMessage = NullMessage.newBuilder()
                                       .setPadding(ByteString.copyFrom(nullMessageBody))
                                       .build();

  byte[] content          = Content.newBuilder()
                                   .setNullMessage(nullMessage)
                                   .build()
                                   .toByteArray();

  SendMessageResult result = sendMessage(message.getDestination(), getTargetUnidentifiedAccess(unidentifiedAccess), message.getTimestamp(), content, false);

  if (result.getSuccess().isNeedsSync()) {
    byte[] syncMessage = createMultiDeviceVerifiedContent(message, nullMessage.toByteArray());
    sendMessage(localAddress, Optional.<UnidentifiedAccess>absent(), message.getTimestamp(), syncMessage, false);
  }
}
 
Example #7
Source File: UnidentifiedAccessUtil.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
public static Optional<UnidentifiedAccessPair> getAccessForSync(@NonNull Context context) {
  try {
    byte[] ourUnidentifiedAccessKey         = UnidentifiedAccess.deriveAccessKeyFrom(ProfileKeyUtil.getSelfProfileKey());
    byte[] ourUnidentifiedAccessCertificate = TextSecurePreferences.getUnidentifiedAccessCertificate(context);

    if (TextSecurePreferences.isUniversalUnidentifiedAccess(context)) {
      ourUnidentifiedAccessKey = Util.getSecretBytes(16);
    }

    if (ourUnidentifiedAccessKey != null && ourUnidentifiedAccessCertificate != null) {
      return Optional.of(new UnidentifiedAccessPair(new UnidentifiedAccess(ourUnidentifiedAccessKey,
                                                                           ourUnidentifiedAccessCertificate),
                                                    new UnidentifiedAccess(ourUnidentifiedAccessKey,
                                                                           ourUnidentifiedAccessCertificate)));
    }

    return Optional.absent();
  } catch (InvalidCertificateException e) {
    Log.w(TAG, e);
    return Optional.absent();
  }
}
 
Example #8
Source File: SignalServiceMessageSender.java    From libsignal-service-java with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Send a message to a group.
 *
 * @param recipients The group members.
 * @param message The group message.
 * @throws IOException
 */
public List<SendMessageResult> sendMessage(List<SignalServiceAddress>             recipients,
                                           List<Optional<UnidentifiedAccessPair>> unidentifiedAccess,
                                           boolean                                isRecipientUpdate,
                                           SignalServiceDataMessage               message)
    throws IOException, UntrustedIdentityException
{
  byte[]                  content            = createMessageContent(message);
  long                    timestamp          = message.getTimestamp();
  List<SendMessageResult> results            = sendMessage(recipients, getTargetUnidentifiedAccess(unidentifiedAccess), timestamp, content, false);
  boolean                 needsSyncInResults = false;

  for (SendMessageResult result : results) {
    if (result.getSuccess() != null && result.getSuccess().isNeedsSync()) {
      needsSyncInResults = true;
      break;
    }
  }

  if (needsSyncInResults || isMultiDevice.get()) {
    byte[] syncMessage = createMultiDeviceSentTranscriptContent(content, Optional.<SignalServiceAddress>absent(), timestamp, results, isRecipientUpdate);
    sendMessage(localAddress, Optional.<UnidentifiedAccess>absent(), timestamp, syncMessage, false);
  }

  return results;
}
 
Example #9
Source File: Manager.java    From signald with GNU General Public License v3.0 5 votes vote down vote up
public List<Optional<UnidentifiedAccessPair>> getAccessFor(Collection<SignalServiceAddress> recipients) {
    List<Optional<UnidentifiedAccessPair>> result = new ArrayList<>(recipients.size());
    for (SignalServiceAddress recipient : recipients) {
        result.add(Optional.<UnidentifiedAccessPair>absent());
    }
    return result;
}
 
Example #10
Source File: Manager.java    From signald with GNU General Public License v3.0 5 votes vote down vote up
private void sendSyncMessage(SignalServiceSyncMessage message)
        throws IOException, UntrustedIdentityException {
    SignalServiceMessageSender messageSender = new SignalServiceMessageSender(serviceConfiguration, accountData.username, accountData.password,
            accountData.deviceId, accountData.axolotlStore, USER_AGENT, true, Optional.fromNullable(messagePipe), Optional.fromNullable(unidentifiedMessagePipe), Optional.<SignalServiceMessageSender.EventListener>absent());
    try {
        messageSender.sendMessage(message, Optional.<UnidentifiedAccessPair>absent());
    } catch (UntrustedIdentityException e) {
        accountData.axolotlStore.identityKeyStore.saveIdentity(e.getE164Number(), e.getIdentityKey(), TrustLevel.UNTRUSTED);
        throw e;
    }
}
 
Example #11
Source File: SignalServiceMessageSender.java    From libsignal-service-java with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Send a read receipt for a received message.
 *
 * @param recipient The sender of the received message you're acknowledging.
 * @param message The read receipt to deliver.
 * @throws IOException
 * @throws UntrustedIdentityException
 */
public void sendReceipt(SignalServiceAddress recipient,
                        Optional<UnidentifiedAccessPair> unidentifiedAccess,
                        SignalServiceReceiptMessage message)
    throws IOException, UntrustedIdentityException
{
  byte[] content = createReceiptContent(message);

  sendMessage(recipient, getTargetUnidentifiedAccess(unidentifiedAccess), message.getWhen(), content, false);
}
 
Example #12
Source File: SignalServiceMessageSender.java    From libsignal-service-java with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Send a typing indicator.
 *
 * @param recipient The destination
 * @param message The typing indicator to deliver
 * @throws IOException
 * @throws UntrustedIdentityException
 */
public void sendTyping(SignalServiceAddress recipient,
                       Optional<UnidentifiedAccessPair> unidentifiedAccess,
                       SignalServiceTypingMessage message)
    throws IOException, UntrustedIdentityException
{
  byte[] content = createTypingContent(message);

  sendMessage(recipient, getTargetUnidentifiedAccess(unidentifiedAccess), message.getTimestamp(), content, true);
}
 
Example #13
Source File: SignalServiceMessageSender.java    From libsignal-service-java with GNU General Public License v3.0 5 votes vote down vote up
public void sendTyping(List<SignalServiceAddress>             recipients,
                       List<Optional<UnidentifiedAccessPair>> unidentifiedAccess,
                       SignalServiceTypingMessage             message)
    throws IOException
{
  byte[] content = createTypingContent(message);
  sendMessage(recipients, getTargetUnidentifiedAccess(unidentifiedAccess), message.getTimestamp(), content, true);
}
 
Example #14
Source File: SignalServiceMessageSender.java    From libsignal-service-java with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Send a call setup message to a single recipient.
 *
 * @param recipient The message's destination.
 * @param message The call message.
 * @throws IOException
 */
public void sendCallMessage(SignalServiceAddress recipient,
                            Optional<UnidentifiedAccessPair> unidentifiedAccess,
                            SignalServiceCallMessage message)
    throws IOException, UntrustedIdentityException
{
  byte[] content = createCallContent(message);
  sendMessage(recipient, getTargetUnidentifiedAccess(unidentifiedAccess), System.currentTimeMillis(), content, false);
}
 
Example #15
Source File: SignalServiceMessageSender.java    From libsignal-service-java with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Send a message to a single recipient.
 *
 * @param recipient The message's destination.
 * @param message The message.
 * @throws UntrustedIdentityException
 * @throws IOException
 */
public SendMessageResult sendMessage(SignalServiceAddress             recipient,
                                     Optional<UnidentifiedAccessPair> unidentifiedAccess,
                                     SignalServiceDataMessage         message)
    throws UntrustedIdentityException, IOException
{
  byte[]            content   = createMessageContent(message);
  long              timestamp = message.getTimestamp();
  SendMessageResult result    = sendMessage(recipient, getTargetUnidentifiedAccess(unidentifiedAccess), timestamp, content, false);

  if (result.getSuccess() != null && result.getSuccess().isNeedsSync()) {
    byte[] syncMessage = createMultiDeviceSentTranscriptContent(content, Optional.of(recipient), timestamp, Collections.singletonList(result), false);
    sendMessage(localAddress, Optional.<UnidentifiedAccess>absent(), timestamp, syncMessage, false);
  }

  if (message.isEndSession()) {
    if (recipient.getUuid().isPresent()) {
      store.deleteAllSessions(recipient.getUuid().get().toString());
    }
    if (recipient.getNumber().isPresent()) {
      store.deleteAllSessions(recipient.getNumber().get());
    }

    if (eventListener.isPresent()) {
      eventListener.get().onSecurityEvent(recipient);
    }
  }

  return result;
}
 
Example #16
Source File: SignalServiceMessageSender.java    From libsignal-service-java with GNU General Public License v3.0 5 votes vote down vote up
public void sendMessage(SignalServiceSyncMessage message, Optional<UnidentifiedAccessPair> unidentifiedAccess)
    throws IOException, UntrustedIdentityException
{
  byte[] content;

  if (message.getContacts().isPresent()) {
    content = createMultiDeviceContactsContent(message.getContacts().get().getContactsStream().asStream(),
                                               message.getContacts().get().isComplete());
  } else if (message.getGroups().isPresent()) {
    content = createMultiDeviceGroupsContent(message.getGroups().get().asStream());
  } else if (message.getRead().isPresent()) {
    content = createMultiDeviceReadContent(message.getRead().get());
  } else if (message.getViewOnceOpen().isPresent()) {
    content = createMultiDeviceViewOnceOpenContent(message.getViewOnceOpen().get());
  } else if (message.getBlockedList().isPresent()) {
    content = createMultiDeviceBlockedContent(message.getBlockedList().get());
  } else if (message.getConfiguration().isPresent()) {
    content = createMultiDeviceConfigurationContent(message.getConfiguration().get());
  } else if (message.getSent().isPresent()) {
    content = createMultiDeviceSentTranscriptContent(message.getSent().get(), unidentifiedAccess);
  } else if (message.getStickerPackOperations().isPresent()) {
    content = createMultiDeviceStickerPackOperationContent(message.getStickerPackOperations().get());
  } else if (message.getFetchType().isPresent()) {
    content = createMultiDeviceFetchTypeContent(message.getFetchType().get());
  } else if (message.getVerified().isPresent()) {
    sendMessage(message.getVerified().get(), unidentifiedAccess);
    return;
  } else {
    throw new IOException("Unsupported sync message!");
  }

  long timestamp = message.getSent().isPresent() ? message.getSent().get().getTimestamp()
                                                 : System.currentTimeMillis();

  sendMessage(localAddress, Optional.<UnidentifiedAccess>absent(), timestamp, content, false);
}
 
Example #17
Source File: SignalServiceMessageSender.java    From libsignal-service-java with GNU General Public License v3.0 5 votes vote down vote up
private byte[] createMultiDeviceSentTranscriptContent(SentTranscriptMessage transcript, Optional<UnidentifiedAccessPair> unidentifiedAccess) throws IOException {
  SignalServiceAddress address = transcript.getDestination().get();
  SendMessageResult    result  = SendMessageResult.success(address, unidentifiedAccess.isPresent(), true);

  return createMultiDeviceSentTranscriptContent(createMessageContent(transcript.getMessage()),
                                                Optional.of(address),
                                                transcript.getTimestamp(),
                                                Collections.singletonList(result),
                                                false);
}
 
Example #18
Source File: SignalServiceMessageSender.java    From libsignal-service-java with GNU General Public License v3.0 5 votes vote down vote up
private Optional<UnidentifiedAccess> getTargetUnidentifiedAccess(Optional<UnidentifiedAccessPair> unidentifiedAccess) {
  if (unidentifiedAccess.isPresent()) {
    return unidentifiedAccess.get().getTargetUnidentifiedAccess();
  }

  return Optional.absent();
}
 
Example #19
Source File: SignalServiceMessageSender.java    From libsignal-service-java with GNU General Public License v3.0 5 votes vote down vote up
private List<Optional<UnidentifiedAccess>> getTargetUnidentifiedAccess(List<Optional<UnidentifiedAccessPair>> unidentifiedAccess) {
  List<Optional<UnidentifiedAccess>> results = new LinkedList<>();

  for (Optional<UnidentifiedAccessPair> item : unidentifiedAccess) {
    if (item.isPresent()) results.add(item.get().getTargetUnidentifiedAccess());
    else                  results.add(Optional.<UnidentifiedAccess>absent());
  }

  return results;
}
 
Example #20
Source File: Manager.java    From signal-cli with GNU General Public License v3.0 5 votes vote down vote up
private List<Optional<UnidentifiedAccessPair>> getAccessFor(Collection<SignalServiceAddress> recipients) {
    List<Optional<UnidentifiedAccessPair>> result = new ArrayList<>(recipients.size());
    for (SignalServiceAddress recipient : recipients) {
        result.add(getAccessFor(recipient));
    }
    return result;
}
 
Example #21
Source File: Manager.java    From signal-cli with GNU General Public License v3.0 5 votes vote down vote up
private Optional<UnidentifiedAccess> getUnidentifiedAccess(SignalServiceAddress recipient) {
    Optional<UnidentifiedAccessPair> unidentifiedAccess = getAccessFor(recipient);

    if (unidentifiedAccess.isPresent()) {
        return unidentifiedAccess.get().getTargetUnidentifiedAccess();
    }

    return Optional.absent();
}
 
Example #22
Source File: ProfileUtil.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private static Optional<UnidentifiedAccess> getUnidentifiedAccess(@NonNull Context context, @NonNull Recipient recipient) {
  Optional<UnidentifiedAccessPair> unidentifiedAccess = UnidentifiedAccessUtil.getAccessFor(context, recipient);

  if (unidentifiedAccess.isPresent()) {
    return unidentifiedAccess.get().getTargetUnidentifiedAccess();
  }

  return Optional.absent();
}
 
Example #23
Source File: SignalServiceMessageSender.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Send a typing indicator.
 *
 * @param recipient The destination
 * @param message The typing indicator to deliver
 * @throws IOException
 * @throws UntrustedIdentityException
 */
public void sendTyping(SignalServiceAddress recipient,
                       Optional<UnidentifiedAccessPair> unidentifiedAccess,
                       SignalServiceTypingMessage message)
    throws IOException, UntrustedIdentityException
{
  byte[] content = createTypingContent(message);

  sendMessage(recipient, getTargetUnidentifiedAccess(unidentifiedAccess), message.getTimestamp(), content, true);
}
 
Example #24
Source File: SignalServiceMessageSender.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
public void sendTyping(List<SignalServiceAddress>             recipients,
                       List<Optional<UnidentifiedAccessPair>> unidentifiedAccess,
                       SignalServiceTypingMessage             message)
    throws IOException
{
  byte[] content = createTypingContent(message);
  sendMessage(recipients, getTargetUnidentifiedAccess(unidentifiedAccess), message.getTimestamp(), content, true);
}
 
Example #25
Source File: SignalServiceMessageSender.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Send a call setup message to a single recipient.
 *
 * @param recipient The message's destination.
 * @param message The call message.
 * @throws IOException
 */
public void sendCallMessage(SignalServiceAddress recipient,
                            Optional<UnidentifiedAccessPair> unidentifiedAccess,
                            SignalServiceCallMessage message)
    throws IOException, UntrustedIdentityException
{
  byte[] content = createCallContent(message);
  sendMessage(recipient, getTargetUnidentifiedAccess(unidentifiedAccess), System.currentTimeMillis(), content, false);
}
 
Example #26
Source File: SignalServiceMessageSender.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Send a message to a single recipient.
 *
 * @param recipient The message's destination.
 * @param message The message.
 * @throws UntrustedIdentityException
 * @throws IOException
 */
public SendMessageResult sendMessage(SignalServiceAddress             recipient,
                                     Optional<UnidentifiedAccessPair> unidentifiedAccess,
                                     SignalServiceDataMessage         message)
    throws UntrustedIdentityException, IOException
{
  byte[]            content   = createMessageContent(message);
  long              timestamp = message.getTimestamp();
  SendMessageResult result    = sendMessage(recipient, getTargetUnidentifiedAccess(unidentifiedAccess), timestamp, content, false);

  if (result.getSuccess() != null && result.getSuccess().isNeedsSync()) {
    byte[] syncMessage = createMultiDeviceSentTranscriptContent(content, Optional.of(recipient), timestamp, Collections.singletonList(result), false);
    sendMessage(localAddress, Optional.<UnidentifiedAccess>absent(), timestamp, syncMessage, false);
  }

  if (message.isEndSession()) {
    if (recipient.getUuid().isPresent()) {
      store.deleteAllSessions(recipient.getUuid().get().toString());
    }
    if (recipient.getNumber().isPresent()) {
      store.deleteAllSessions(recipient.getNumber().get());
    }

    if (eventListener.isPresent()) {
      eventListener.get().onSecurityEvent(recipient);
    }
  }

  return result;
}
 
Example #27
Source File: SignalServiceMessageSender.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
public void sendMessage(SignalServiceSyncMessage message, Optional<UnidentifiedAccessPair> unidentifiedAccess)
    throws IOException, UntrustedIdentityException
{
  byte[] content;

  if (message.getContacts().isPresent()) {
    content = createMultiDeviceContactsContent(message.getContacts().get().getContactsStream().asStream(),
                                               message.getContacts().get().isComplete());
  } else if (message.getGroups().isPresent()) {
    content = createMultiDeviceGroupsContent(message.getGroups().get().asStream());
  } else if (message.getRead().isPresent()) {
    content = createMultiDeviceReadContent(message.getRead().get());
  } else if (message.getViewOnceOpen().isPresent()) {
    content = createMultiDeviceViewOnceOpenContent(message.getViewOnceOpen().get());
  } else if (message.getBlockedList().isPresent()) {
    content = createMultiDeviceBlockedContent(message.getBlockedList().get());
  } else if (message.getConfiguration().isPresent()) {
    content = createMultiDeviceConfigurationContent(message.getConfiguration().get());
  } else if (message.getSent().isPresent()) {
    content = createMultiDeviceSentTranscriptContent(message.getSent().get(), unidentifiedAccess);
  } else if (message.getStickerPackOperations().isPresent()) {
    content = createMultiDeviceStickerPackOperationContent(message.getStickerPackOperations().get());
  } else if (message.getFetchType().isPresent()) {
    content = createMultiDeviceFetchTypeContent(message.getFetchType().get());
  } else if (message.getMessageRequestResponse().isPresent()) {
    content = createMultiDeviceMessageRequestResponseContent(message.getMessageRequestResponse().get());
  } else if (message.getKeys().isPresent()) {
    content = createMultiDeviceSyncKeysContent(message.getKeys().get());
  } else if (message.getVerified().isPresent()) {
    sendMessage(message.getVerified().get(), unidentifiedAccess);
    return;
  } else {
    throw new IOException("Unsupported sync message!");
  }

  long timestamp = message.getSent().isPresent() ? message.getSent().get().getTimestamp()
                                                 : System.currentTimeMillis();

  sendMessage(localAddress, Optional.<UnidentifiedAccess>absent(), timestamp, content, false);
}
 
Example #28
Source File: SignalServiceMessageSender.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private byte[] createMultiDeviceSentTranscriptContent(SentTranscriptMessage transcript, Optional<UnidentifiedAccessPair> unidentifiedAccess) throws IOException {
  SignalServiceAddress address = transcript.getDestination().get();
  SendMessageResult    result  = SendMessageResult.success(address, unidentifiedAccess.isPresent(), true);

  return createMultiDeviceSentTranscriptContent(createMessageContent(transcript.getMessage()),
                                                Optional.of(address),
                                                transcript.getTimestamp(),
                                                Collections.singletonList(result),
                                                false);
}
 
Example #29
Source File: SignalServiceMessageSender.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private Optional<UnidentifiedAccess> getTargetUnidentifiedAccess(Optional<UnidentifiedAccessPair> unidentifiedAccess) {
  if (unidentifiedAccess.isPresent()) {
    return unidentifiedAccess.get().getTargetUnidentifiedAccess();
  }

  return Optional.absent();
}
 
Example #30
Source File: SignalServiceMessageSender.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private List<Optional<UnidentifiedAccess>> getTargetUnidentifiedAccess(List<Optional<UnidentifiedAccessPair>> unidentifiedAccess) {
  List<Optional<UnidentifiedAccess>> results = new LinkedList<>();

  for (Optional<UnidentifiedAccessPair> item : unidentifiedAccess) {
    if (item.isPresent()) results.add(item.get().getTargetUnidentifiedAccess());
    else                  results.add(Optional.<UnidentifiedAccess>absent());
  }

  return results;
}