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

The following examples show how to use org.whispersystems.signalservice.api.crypto.UntrustedIdentityException. 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
/**
 * Trust this the identity with this fingerprint
 *
 * @param name        username of the identity
 * @param fingerprint Fingerprint
 */
public boolean trustIdentityVerified(String name, byte[] fingerprint) throws InvalidNumberException {
    SignalServiceAddress address = canonicalizeAndResolveSignalServiceAddress(name);
    List<JsonIdentityKeyStore.Identity> ids = account.getSignalProtocolStore().getIdentities(address);
    if (ids == null) {
        return false;
    }
    for (JsonIdentityKeyStore.Identity id : ids) {
        if (!Arrays.equals(id.getIdentityKey().serialize(), fingerprint)) {
            continue;
        }

        account.getSignalProtocolStore().setIdentityTrustLevel(address, id.getIdentityKey(), TrustLevel.TRUSTED_VERIFIED);
        try {
            sendVerifiedMessage(address, id.getIdentityKey(), TrustLevel.TRUSTED_VERIFIED);
        } catch (IOException | UntrustedIdentityException e) {
            e.printStackTrace();
        }
        account.save();
        return true;
    }
    return false;
}
 
Example #2
Source File: MultiDeviceMessageRequestResponseJob.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onRun() throws IOException, UntrustedIdentityException {
  if (!TextSecurePreferences.isMultiDevice(context)) {
    Log.i(TAG, "Not multi device, aborting...");
    return;
  }

  SignalServiceMessageSender messageSender = ApplicationDependencies.getSignalServiceMessageSender();
  Recipient                  recipient     = Recipient.resolved(threadRecipient);


  MessageRequestResponseMessage response;

  if (recipient.isGroup()) {
    response = MessageRequestResponseMessage.forGroup(recipient.getGroupId().get().getDecodedId(), localToRemoteType(type));
  } else {
    response = MessageRequestResponseMessage.forIndividual(RecipientUtil.toSignalServiceAddress(context, recipient), localToRemoteType(type));
  }

  messageSender.sendMessage(SignalServiceSyncMessage.forMessageRequestResponse(response),
                            UnidentifiedAccessUtil.getAccessForSync(context));
}
 
Example #3
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 #4
Source File: RequestGroupInfoJob.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onRun() throws IOException, UntrustedIdentityException {
  SignalServiceGroup       group   = SignalServiceGroup.newBuilder(Type.REQUEST_INFO)
                                                       .withId(groupId.getDecodedId())
                                                       .build();

  SignalServiceDataMessage message = SignalServiceDataMessage.newBuilder()
                                                             .asGroupMessage(group)
                                                             .withTimestamp(System.currentTimeMillis())
                                                             .build();

  SignalServiceMessageSender messageSender = ApplicationDependencies.getSignalServiceMessageSender();
  Recipient                  recipient     = Recipient.resolved(source);

  messageSender.sendMessage(RecipientUtil.toSignalServiceAddress(context, recipient),
                            UnidentifiedAccessUtil.getAccessFor(context, recipient),
                            message);
}
 
Example #5
Source File: MultiDeviceContactUpdateJob.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
private void sendUpdate(SignalServiceMessageSender messageSender, File contactsFile, boolean complete)
    throws IOException, UntrustedIdentityException, NetworkException
{
  if (contactsFile.length() > 0) {
    FileInputStream               contactsFileStream = new FileInputStream(contactsFile);
    SignalServiceAttachmentStream attachmentStream   = SignalServiceAttachment.newStreamBuilder()
                                                                              .withStream(contactsFileStream)
                                                                              .withContentType("application/octet-stream")
                                                                              .withLength(contactsFile.length())
                                                                              .build();

    try {
      messageSender.sendMessage(SignalServiceSyncMessage.forContacts(new ContactsMessage(attachmentStream, complete)),
                                UnidentifiedAccessUtil.getAccessForSync(context));
    } catch (IOException ioe) {
      throw new NetworkException(ioe);
    }
  }
}
 
Example #6
Source File: Manager.java    From signald with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Trust this the identity with this safety number
 *
 * @param name         username of the identity
 * @param safetyNumber Safety number
 * @param level        level to trust the identity
 */
public boolean trustIdentitySafetyNumber(String name, String safetyNumber, TrustLevel level) throws IOException {
    List<IdentityKeyStore.Identity> ids = accountData.axolotlStore.identityKeyStore.getIdentities(name);
    if (ids == null) {
        return false;
    }
    for (IdentityKeyStore.Identity id : ids) {
        if (!safetyNumber.equals(computeSafetyNumber(name, id.getIdentityKey()))) {
            continue;
        }

        accountData.axolotlStore.identityKeyStore.saveIdentity(name, id.getIdentityKey(), level);
        try {
            sendVerifiedMessage(name, id.getIdentityKey(), level);
        } catch (IOException | UntrustedIdentityException e) {
            logger.catching(e);
        }
        accountData.save();
        return true;
    }
    return false;
}
 
Example #7
Source File: Manager.java    From signald with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Trust this the identity with this fingerprint
 *
 * @param name        username of the identity
 * @param fingerprint Fingerprint
 * @param level       level at with to trust the identity
 */
public boolean trustIdentity(String name, byte[] fingerprint, TrustLevel level) throws IOException {
    List<IdentityKeyStore.Identity> ids = accountData.axolotlStore.identityKeyStore.getIdentities(name);
    if (ids == null) {
        return false;
    }
    for (IdentityKeyStore.Identity id : ids) {
        if (!Arrays.equals(id.getIdentityKey().serialize(), fingerprint)) {
            continue;
        }

        accountData.axolotlStore.identityKeyStore.saveIdentity(name, id.getIdentityKey(), level);
        try {
            sendVerifiedMessage(name, id.getIdentityKey(), level);
        } catch (IOException | UntrustedIdentityException e) {
            logger.catching(e);
        }
        accountData.save();
        return true;
    }
    return false;
}
 
Example #8
Source File: MultiDeviceReadUpdateJob.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onRun() throws IOException, UntrustedIdentityException {
  if (!TextSecurePreferences.isMultiDevice(context)) {
    Log.i(TAG, "Not multi device...");
    return;
  }

  List<ReadMessage> readMessages = new LinkedList<>();

  for (SerializableSyncMessageId messageId : messageIds) {
    Recipient recipient = Recipient.resolved(RecipientId.from(messageId.recipientId));
    readMessages.add(new ReadMessage(RecipientUtil.toSignalServiceAddress(context, recipient), messageId.timestamp));
  }

  SignalServiceMessageSender messageSender = ApplicationDependencies.getSignalServiceMessageSender();
  messageSender.sendMessage(SignalServiceSyncMessage.forRead(readMessages), UnidentifiedAccessUtil.getAccessForSync(context));
}
 
Example #9
Source File: MultiDeviceVerifiedUpdateJob.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onRun() throws IOException, UntrustedIdentityException {
  try {
    if (!TextSecurePreferences.isMultiDevice(context)) {
      Log.i(TAG, "Not multi device...");
      return;
    }

    if (destination == null) {
      Log.w(TAG, "No destination...");
      return;
    }

    SignalServiceMessageSender    messageSender        = ApplicationDependencies.getSignalServiceMessageSender();
    Recipient                     recipient            = Recipient.resolved(destination);
    VerifiedMessage.VerifiedState verifiedState        = getVerifiedState(verifiedStatus);
    SignalServiceAddress          verifiedAddress      = RecipientUtil.toSignalServiceAddress(context, recipient);
    VerifiedMessage               verifiedMessage      = new VerifiedMessage(verifiedAddress, new IdentityKey(identityKey, 0), verifiedState, timestamp);

    messageSender.sendMessage(SignalServiceSyncMessage.forVerified(verifiedMessage),
                              UnidentifiedAccessUtil.getAccessFor(context, recipient));
  } catch (InvalidKeyException e) {
    throw new IOException(e);
  }
}
 
Example #10
Source File: SendReadReceiptJob.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onRun() throws IOException, UntrustedIdentityException {
  if (!TextSecurePreferences.isReadReceiptsEnabled(context) || messageIds.isEmpty()) return;

  if (!RecipientUtil.isMessageRequestAccepted(context, threadId)) {
    Log.w(TAG, "Refusing to send receipts to untrusted recipient");
    return;
  }

  Recipient                   recipient      = Recipient.resolved(recipientId);
  SignalServiceMessageSender  messageSender  = ApplicationDependencies.getSignalServiceMessageSender();
  SignalServiceAddress        remoteAddress  = RecipientUtil.toSignalServiceAddress(context, recipient);
  SignalServiceReceiptMessage receiptMessage = new SignalServiceReceiptMessage(SignalServiceReceiptMessage.Type.READ, messageIds, timestamp);

  messageSender.sendReceipt(remoteAddress,
                            UnidentifiedAccessUtil.getAccessFor(context, Recipient.resolved(recipientId)),
                            receiptMessage);
}
 
Example #11
Source File: Manager.java    From signald with GNU General Public License v3.0 6 votes vote down vote up
public SendMessageResult sendReceipt(SignalServiceReceiptMessage message, String recipient) throws IOException {
      SignalServiceAddress address = getSignalServiceAddress(recipient);
      if (address == null) {
          accountData.save();
          return null;
      }

      try {
          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.sendReceipt(address, getAccessFor(address), message);
return null;
          } catch (UntrustedIdentityException e) {
              accountData.axolotlStore.identityKeyStore.saveIdentity(e.getE164Number(), e.getIdentityKey(), TrustLevel.UNTRUSTED);
              return SendMessageResult.identityFailure(address, e.getIdentityKey());
          }
      } finally {
          accountData.save();
      }
  }
 
Example #12
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 #13
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 #14
Source File: WebRtcCallService.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onFailureContinue(Throwable error) {
  Log.w(TAG, error);

  if (callManager != null) {
    try {
      callManager.messageSendFailure(getCallId());
    } catch (CallException e) {
      callFailure("callManager.messageSendFailure() failed: ", e);
    }
  }

  if (activePeer == null) {
    return;
  }

  if (error instanceof UntrustedIdentityException) {
    sendMessage(WebRtcViewModel.State.UNTRUSTED_IDENTITY, activePeer, ((UntrustedIdentityException)error).getIdentityKey(), localCameraState, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled, isRemoteVideoOffer);
  } else if (error instanceof UnregisteredUserException) {
    sendMessage(WebRtcViewModel.State.NO_SUCH_USER, activePeer, localCameraState, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled, isRemoteVideoOffer);
  } else if (error instanceof IOException) {
    sendMessage(WebRtcViewModel.State.NETWORK_FAILURE, activePeer, localCameraState, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled, isRemoteVideoOffer);
  }

}
 
Example #15
Source File: Manager.java    From signald with GNU General Public License v3.0 6 votes vote down vote up
private List<SendMessageResult> sendUpdateGroupMessage(byte[] groupId, String recipient) throws IOException, EncapsulatedExceptions, UntrustedIdentityException, GroupNotFoundException, NotAGroupMemberException, AttachmentInvalidException {
    if (groupId == null) {
        return null;
    }
    GroupInfo g = getGroupForSending(groupId);

    if (!g.members.contains(recipient)) {
        return null;
    }

    SignalServiceDataMessage.Builder messageBuilder = getGroupUpdateMessageBuilder(g);

    // Send group message only to the recipient who requested it
    final List<String> membersSend = new ArrayList<>();
    membersSend.add(recipient);
    return sendMessage(messageBuilder, membersSend);
}
 
Example #16
Source File: SignalServiceMessageSender.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
private OutgoingPushMessageList getEncryptedMessages(PushServiceSocket            socket,
                                                     SignalServiceAddress         recipient,
                                                     Optional<UnidentifiedAccess> unidentifiedAccess,
                                                     long                         timestamp,
                                                     byte[]                       plaintext,
                                                     boolean                      online)
    throws IOException, InvalidKeyException, UntrustedIdentityException
{
  List<OutgoingPushMessage> messages = new LinkedList<>();

  if (!recipient.matches(localAddress) || unidentifiedAccess.isPresent()) {
    messages.add(getEncryptedMessage(socket, recipient, unidentifiedAccess, SignalServiceAddress.DEFAULT_DEVICE_ID, plaintext));
  }

  for (int deviceId : store.getSubDeviceSessions(recipient.getIdentifier())) {
    if (store.containsSession(new SignalProtocolAddress(recipient.getIdentifier(), deviceId))) {
      messages.add(getEncryptedMessage(socket, recipient, unidentifiedAccess, deviceId, plaintext));
    }
  }

  return new OutgoingPushMessageList(recipient.getIdentifier(), timestamp, messages, online);
}
 
Example #17
Source File: SignalServiceMessageSender.java    From libsignal-service-java with GNU General Public License v3.0 6 votes vote down vote up
private OutgoingPushMessageList getEncryptedMessages(PushServiceSocket            socket,
                                                     SignalServiceAddress         recipient,
                                                     Optional<UnidentifiedAccess> unidentifiedAccess,
                                                     long                         timestamp,
                                                     byte[]                       plaintext,
                                                     boolean                      online)
    throws IOException, InvalidKeyException, UntrustedIdentityException
{
  List<OutgoingPushMessage> messages = new LinkedList<>();

  if (!recipient.matches(localAddress) || unidentifiedAccess.isPresent()) {
    messages.add(getEncryptedMessage(socket, recipient, unidentifiedAccess, SignalServiceAddress.DEFAULT_DEVICE_ID, plaintext));
  }

  for (int deviceId : store.getSubDeviceSessions(recipient.getIdentifier())) {
    if (store.containsSession(new SignalProtocolAddress(recipient.getIdentifier(), deviceId))) {
      messages.add(getEncryptedMessage(socket, recipient, unidentifiedAccess, deviceId, plaintext));
    }
  }

  return new OutgoingPushMessageList(recipient.getIdentifier(), timestamp, messages, online);
}
 
Example #18
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 #19
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 #20
Source File: Manager.java    From signald with GNU General Public License v3.0 5 votes vote down vote up
private void sendGroups() throws IOException, UntrustedIdentityException {
    File groupsFile = Util.createTempFile();

    try {
        try (OutputStream fos = new FileOutputStream(groupsFile)) {
            DeviceGroupsOutputStream out = new DeviceGroupsOutputStream(fos);
            for (GroupInfo record : accountData.groupStore.getGroups()) {
                Optional<Integer> expirationTimer = Optional.<Integer>absent();
                Optional<String> color = Optional.<String>absent();
                out.write(new DeviceGroup(record.groupId, Optional.fromNullable(record.name),
                        new ArrayList<>(record.members), createGroupAvatarAttachment(record.groupId),
                        record.active, expirationTimer, color, false));
            }
        }

        if (groupsFile.exists() && groupsFile.length() > 0) {
            try (FileInputStream groupsFileStream = new FileInputStream(groupsFile)) {
                SignalServiceAttachmentStream attachmentStream = SignalServiceAttachment.newStreamBuilder()
                        .withStream(groupsFileStream)
                        .withContentType("application/octet-stream")
                        .withLength(groupsFile.length())
                        .build();

                sendSyncMessage(SignalServiceSyncMessage.forGroups(attachmentStream));
            }
        }
    } finally {
        try {
            Files.delete(groupsFile.toPath());
        } catch (IOException e) {
            logger.warn("Failed to delete groups temp file " + groupsFile + ": " + e.getMessage());
        }
    }
}
 
Example #21
Source File: SendContactsCommand.java    From signal-cli with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int handleCommand(final Namespace ns, final Manager m) {
    if (!m.isRegistered()) {
        System.err.println("User is not registered.");
        return 1;
    }
    try {
        m.sendContacts();
        return 0;
    } catch (IOException | UntrustedIdentityException e) {
        System.err.println("SendContacts error: " + e.getMessage());
        return 3;
    }
}
 
Example #22
Source File: EncapsulatedExceptions.java    From libsignal-service-java with GNU General Public License v3.0 5 votes vote down vote up
public EncapsulatedExceptions(UntrustedIdentityException e) {
  this.untrustedIdentityExceptions = new LinkedList<>();
  this.unregisteredUserExceptions  = new LinkedList<>();
  this.networkExceptions           = new LinkedList<>();

  this.untrustedIdentityExceptions.add(e);
}
 
Example #23
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 #24
Source File: Manager.java    From signald with GNU General Public License v3.0 5 votes vote down vote up
private List<SendMessageResult> sendGroupInfoRequest(byte[] groupId, String recipient) throws IOException, EncapsulatedExceptions, UntrustedIdentityException {
    if (groupId == null) {
        return null;
    }

    SignalServiceGroup.Builder group = SignalServiceGroup.newBuilder(SignalServiceGroup.Type.REQUEST_INFO)
            .withId(groupId);

    SignalServiceDataMessage.Builder messageBuilder = SignalServiceDataMessage.newBuilder().asGroupMessage(group.build());

    // Send group info request message to the recipient who sent us a message with this groupId
    final List<String> membersSend = new ArrayList<>();
    membersSend.add(recipient);
    return sendMessage(messageBuilder, membersSend);
}
 
Example #25
Source File: Manager.java    From signald with GNU General Public License v3.0 5 votes vote down vote up
public List<SendMessageResult> sendMessage(String messageText, List<SignalServiceAttachment> attachments, List<String> recipients, SignalServiceDataMessage.Quote quote)
        throws IOException, EncapsulatedExceptions, UntrustedIdentityException, AttachmentInvalidException {
    final SignalServiceDataMessage.Builder messageBuilder = SignalServiceDataMessage.newBuilder().withBody(messageText);
    if (attachments != null) {
        messageBuilder.withAttachments(attachments);
    }
    if(quote != null) {
      messageBuilder.withQuote(quote);
    }
    return sendMessage(messageBuilder, recipients);
}
 
Example #26
Source File: Manager.java    From signald with GNU General Public License v3.0 5 votes vote down vote up
public byte[] updateGroup(byte[] groupId, String name, List<String> members, String avatar) throws IOException, EncapsulatedExceptions, UntrustedIdentityException, GroupNotFoundException, AttachmentInvalidException, NotAGroupMemberException {
    if (groupId.length == 0) {
        groupId = null;
    }
    if (name.isEmpty()) {
        name = null;
    }
    if (members.size() == 0) {
        members = null;
    }
    if (avatar.isEmpty()) {
        avatar = null;
    }
    return sendUpdateGroupMessage(groupId, name, members, avatar);
}
 
Example #27
Source File: Manager.java    From signald with GNU General Public License v3.0 5 votes vote down vote up
private SignalServiceContent decryptMessage(SignalServiceEnvelope envelope) throws NoSessionException, LegacyMessageException, InvalidVersionException, InvalidMessageException, DuplicateMessageException, InvalidKeyException, InvalidKeyIdException, org.whispersystems.libsignal.UntrustedIdentityException, InvalidMetadataMessageException, InvalidMetadataVersionException, UntrustedIdentityException, ProtocolInvalidKeyIdException, ProtocolUntrustedIdentityException, ProtocolLegacyMessageException, ProtocolNoSessionException, ProtocolInvalidVersionException, ProtocolInvalidMessageException, ProtocolInvalidKeyException, ProtocolDuplicateMessageException, SelfSendException, UnsupportedDataMessageException {
    SignalServiceCipher cipher = new SignalServiceCipher(new SignalServiceAddress(accountData.username), accountData.axolotlStore, getCertificateValidator());
    try {
        return cipher.decrypt(envelope);
    } catch (ProtocolUntrustedIdentityException e) {
        // TODO We don't get the new untrusted identity from ProtocolUntrustedIdentityException anymore ... we need to get it from somewhere else
        // signalProtocolStore.saveIdentity(e.getSource(), e, TrustLevel.UNTRUSTED);
        throw e;
    }
}
 
Example #28
Source File: Manager.java    From signald with GNU General Public License v3.0 5 votes vote down vote up
private void requestSyncGroups() throws IOException {
    SignalServiceProtos.SyncMessage.Request r = SignalServiceProtos.SyncMessage.Request.newBuilder().setType(SignalServiceProtos.SyncMessage.Request.Type.GROUPS).build();
    SignalServiceSyncMessage message = SignalServiceSyncMessage.forRequest(new RequestMessage(r));
    try {
        sendSyncMessage(message);
    } catch (UntrustedIdentityException e) {
        logger.catching(e);
    }
}
 
Example #29
Source File: Manager.java    From signald with GNU General Public License v3.0 5 votes vote down vote up
public void requestSyncContacts() throws IOException {
    SignalServiceProtos.SyncMessage.Request r = SignalServiceProtos.SyncMessage.Request.newBuilder().setType(SignalServiceProtos.SyncMessage.Request.Type.CONTACTS).build();
    SignalServiceSyncMessage message = SignalServiceSyncMessage.forRequest(new RequestMessage(r));
    try {
        sendSyncMessage(message);
    } catch (UntrustedIdentityException e) {
        logger.catching(e);
    }
}
 
Example #30
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;
    }
}