Пример #1
0
        private void handleEndSessionMessage(/*MasterSecretUnion     masterSecret,*/
            TextSecureEnvelope envelope,
            TextSecureDataMessage message /*,
                                           * Optional<Long>        smsMessageId*/)
        {
            /*EncryptingSmsDatabase smsDatabase = DatabaseFactory.getEncryptingSmsDatabase(context);
             * IncomingTextMessage incomingTextMessage = new IncomingTextMessage(envelope.getSource(),
             *                                                                  envelope.getSourceDevice(),
             *                                                                  (long)message.getTimestamp(),
             *                                                                  "", May<TextSecureGroup>.NoValue);
             *
             * long threadId;
             *
             * if (!smsMessageId.isPresent())
             * {
             *  IncomingEndSessionMessage incomingEndSessionMessage = new IncomingEndSessionMessage(incomingTextMessage);
             *  Pair<Long, Long> messageAndThreadId = smsDatabase.insertMessageInbox(masterSecret, incomingEndSessionMessage);
             *
             *  threadId = messageAndThreadId.second;
             * }
             * else
             * {
             *  smsDatabase.markAsEndSession(smsMessageId.get());
             *  threadId = smsDatabase.getThreadIdForMessage(smsMessageId.get());
             * }
             *
             * SessionStore sessionStore = new TextSecureSessionStore();
             * sessionStore.deleteAllSessions(envelope.getSource());*/

            //SecurityEvent.broadcastSecurityUpdateEvent(context, threadId);
            //MessageNotifier.updateNotification(context, masterSecret.getMasterSecret().orNull(), threadId);
        }
Пример #2
0
        /*private void handleGroupMessage(@NonNull MasterSecretUnion masterSecret,
         *                              @NonNull TextSecureEnvelope envelope,
         *                              @NonNull TextSecureDataMessage message,
         *                              @NonNull Optional<Long> smsMessageId)
         * {
         *  GroupMessageProcessor.process(context, masterSecret, envelope, message);
         *
         *  if (smsMessageId.isPresent())
         *  {
         *      DatabaseFactory.getSmsDatabase(context).deleteMessage(smsMessageId.get());
         *  }
         * }
         *
         * private void handleSynchronizeSentMessage(@NonNull MasterSecretUnion masterSecret,
         *                                        @NonNull SentTranscriptMessage message,
         *                                        @NonNull Optional<Long> smsMessageId)
         * throws MmsException
         * {
         * if (message.getMessage().getAttachments().isPresent()) {
         *      handleSynchronizeSentMediaMessage(masterSecret, message, smsMessageId);
         *  } else {
         *      handleSynchronizeSentTextMessage(masterSecret, message, smsMessageId);
         *  }
         * }
         *
         * private void handleSynchronizeRequestMessage(@NonNull MasterSecretUnion masterSecret,
         *                                           @NonNull RequestMessage message)
         * {
         *  if (message.isContactsRequest())
         *  {
         *      ApplicationContext.getInstance(context)
         *                        .getJobManager()
         *                        .add(new MultiDeviceContactUpdateJob(getContext()));
         *  }
         *
         *  if (message.isGroupsRequest())
         *  {
         *      ApplicationContext.getInstance(context)
         *                        .getJobManager()
         *                        .add(new MultiDeviceGroupUpdateJob(getContext()));
         *  }
         * }
         *
         * private void handleMediaMessage(@NonNull MasterSecretUnion masterSecret,
         *                              @NonNull TextSecureEnvelope envelope,
         *                              @NonNull TextSecureDataMessage message,
         *                              @NonNull Optional<Long> smsMessageId)
         * throws MmsException
         * {
         *  MmsDatabase database     = DatabaseFactory.getMmsDatabase(context);
         *  String localNumber  = TextSecurePreferences.getLocalNumber(context);
         *  IncomingMediaMessage mediaMessage = new IncomingMediaMessage(masterSecret, envelope.getSource(),
         *                                                       localNumber, message.getTimestamp(),
         *                                                       Optional.fromNullable(envelope.getRelay()),
         *                                                       message.getBody(),
         *                                                       message.getGroupInfo(),
         *                                                       message.getAttachments());
         *
         *  Pair<Long, Long> messageAndThreadId =  database.insertSecureDecryptedMessageInbox(masterSecret, mediaMessage, -1);
         *
         *  ApplicationContext.getInstance(context)
         *            .getJobManager()
         *            .add(new AttachmentDownloadJob(context, messageAndThreadId.first));
         *
         * if (smsMessageId.isPresent()) {
         *      DatabaseFactory.getSmsDatabase(context).deleteMessage(smsMessageId.get());
         *  }
         *
         *  MessageNotifier.updateNotification(context, masterSecret.getMasterSecret().orNull(), messageAndThreadId.second);
         * }
         *
         * private void handleSynchronizeSentMediaMessage(@NonNull MasterSecretUnion masterSecret,
         *                                             @NonNull SentTranscriptMessage message,
         *                                             @NonNull Optional<Long> smsMessageId)
         * throws MmsException
         * {
         *  MmsDatabase database     = DatabaseFactory.getMmsDatabase(context);
         *  Recipients recipients   = getSyncMessageDestination(message);
         *  OutgoingMediaMessage mediaMessage = new OutgoingMediaMessage(context, masterSecret, recipients,
         *                                                        message.getMessage().getAttachments().get(),
         *                                                        message.getMessage().getBody().orNull());
         *
         *  mediaMessage = new OutgoingSecureMediaMessage(mediaMessage);
         *
         *  long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipients);
         *  long messageId = database.insertMessageOutbox(masterSecret, mediaMessage, threadId, false, message.getTimestamp());
         *
         *  database.markAsSent(messageId, "push".getBytes(), 0);
         *  database.markAsPush(messageId);
         *
         *  ApplicationContext.getInstance(context)
         *                    .getJobManager()
         *                    .add(new AttachmentDownloadJob(context, messageId));
         *
         *  if (smsMessageId.isPresent())
         *  {
         *      DatabaseFactory.getSmsDatabase(context).deleteMessage(smsMessageId.get());
         *  }
         *  }
         */
        private void handleTextMessage(/*@NonNull MasterSecretUnion masterSecret,*/
            TextSecureEnvelope envelope,
            TextSecureDataMessage message /*,
                                           * @NonNull Optional<Long> smsMessageId*/)
        {
            MessageDatabase database = DatabaseFactory.getMessageDatabase();
            String          body     = message.getBody().HasValue ? message.getBody().ForceGetValue() : "";

            /*Pair<Long, Long> messageAndThreadId;
             *
             * if (smsMessageId.hasValue)
             * {
             *  messageAndThreadId = database.updateBundleMessageBody(masterSecret, smsMessageId.get(), body);
             * }
             * else
             * {*/
            IncomingTextMessage textMessage = new IncomingTextMessage(envelope.getSource(),
                                                                      envelope.getSourceDevice(),
                                                                      (long)message.getTimestamp(), body,
                                                                      message.getGroupInfo());

            textMessage = new IncomingEncryptedMessage(textMessage, body);
            /*messageAndThreadId = */ database.insertMessageInbox(/*masterSecret, */ textMessage);

            /*}
             *
             * MessageNotifier.updateNotification(context, masterSecret.getMasterSecret().orNull(), messageAndThreadId.second);*/
        }
        private async Task <byte[]> createMessageContent(TextSecureDataMessage message)// throws IOException
        {
            DataMessage.Builder builder = DataMessage.CreateBuilder();

            /*List<AttachmentPointer> pointers = createAttachmentPointers(message.getAttachments());
             *
             * if (!pointers.Any()) // TODO:check
             * {
             *  builder.AddRangeAttachments(pointers);
             * }*/

            if (message.getBody().HasValue)
            {
                builder.SetBody(message.getBody().ForceGetValue());
            }

            if (message.getGroupInfo().HasValue)
            {
                builder.SetGroup(await createGroupContent(message.getGroupInfo().ForceGetValue()));
            }

            if (message.isEndSession())
            {
                builder.SetFlags((uint)DataMessage.Types.Flags.END_SESSION);
            }

            return(builder.Build().ToByteArray());
        }
        /**
         * Send a message to a group.
         *
         * @param recipients The group members.
         * @param message The group message.
         * @throws IOException
         * @throws EncapsulatedExceptions
         */
        public async void sendMessage(List <TextSecureAddress> recipients, TextSecureDataMessage message)
        {
            byte[] content = await createMessageContent(message);

            ulong timestamp = message.getTimestamp();
            SendMessageResponse response = sendMessage(recipients, timestamp, content, true);

            try
            {
                if (response != null && response.getNeedsSync())
                {
                    byte[] syncMessage = createMultiDeviceSentTranscriptContent(content, May <TextSecureAddress> .NoValue, timestamp);
                    await sendMessage(localAddress, timestamp, syncMessage, false);
                }
            }
            catch (UntrustedIdentityException e)
            {
                throw new EncapsulatedExceptions(e);
            }
        }
Пример #5
0
        private void deliver(SmsMessageRecord message)
        {
            try
            {
                TextSecureAddress     address           = getPushAddress(message.getIndividualRecipient().getNumber());
                TextSecureDataMessage textSecureMessage = TextSecureDataMessage.newBuilder()
                                                          .withTimestamp((ulong)TimeUtil.GetUnixTimestampMillis(message.getDateSent()))
                                                          .withBody(message.getBody().getBody())
                                                          .asEndSessionMessage(message.isEndSession())
                                                          .build();

                Debug.WriteLine("TextSendTask deliver");
                messageSender.sendMessage(address, textSecureMessage);
            }
            catch (InvalidNumberException e /*| UnregisteredUserException e*/) {
                //Log.w(TAG, e);
                //throw new InsecureFallbackApprovalException(e);
            } catch (Exception e)
            {
                //Log.w(TAG, e);
                //throw new RetryLaterException(e);
            }
        }
        /**
         * Send a message to a single recipient.
         *
         * @param recipient The message's destination.
         * @param message The message.
         * @throws UntrustedIdentityException
         * @throws IOException
         */
        public async void sendMessage(TextSecureAddress recipient, TextSecureDataMessage message)
        {
            byte[] content = await createMessageContent(message);

            ulong timestamp = message.getTimestamp();
            SendMessageResponse response = await sendMessage(recipient, timestamp, content, true);

            if (response != null && response.getNeedsSync())
            {
                byte[] syncMessage = createMultiDeviceSentTranscriptContent(content, new May <TextSecureAddress>(recipient), timestamp);
                await sendMessage(localAddress, timestamp, syncMessage, false);
            }

            if (message.isEndSession())
            {
                store.DeleteAllSessions(recipient.getNumber());

                if (eventListener.HasValue)
                {
                    eventListener.ForceGetValue().onSecurityEvent(recipient);
                }
            }
        }
Пример #7
0
 public SentTranscriptMessage(ulong timestamp, TextSecureDataMessage message)
 {
     this.destination = May <string> .NoValue;
     this.timestamp   = timestamp;
     this.message     = message;
 }
Пример #8
0
 public SentTranscriptMessage(String destination, ulong timestamp, TextSecureDataMessage message)
 {
     this.destination = new May <string>(destination);
     this.timestamp   = timestamp;
     this.message     = message;
 }
Пример #9
0
        private void handleMessage(/*MasterSecretUnion masterSecret, */ TextSecureEnvelope envelope /*, Optional<Long> smsMessageId*/)
        {
            try
            {
                AxolotlStore      axolotlStore = new TextSecureAxolotlStore();
                TextSecureAddress localAddress = new TextSecureAddress(TextSecurePreferences.getLocalNumber());
                TextSecureCipher  cipher       = new TextSecureCipher(localAddress, axolotlStore);

                TextSecureContent content = cipher.decrypt(envelope);

                if (content.getDataMessage().HasValue)
                {
                    TextSecureDataMessage message = content.getDataMessage().ForceGetValue();

                    if (message.isEndSession())
                    {
                        handleEndSessionMessage(/*masterSecret, */ envelope, message /*, smsMessageId*/);
                    }
                    //else if (message.isGroupUpdate()) handleGroupMessage(masterSecret, envelope, message, smsMessageId);
                    //else if (message.getAttachments().isPresent()) handleMediaMessage(masterSecret, envelope, message, smsMessageId);
                    else
                    {
                        handleTextMessage(/*masterSecret, */ envelope, message /*, smsMessageId*/);
                    }
                }

                /*else if (content.getSyncMessage().HasValue) TODO: SYNC enable
                 * {
                 *  TextSecureSyncMessage syncMessage = content.getSyncMessage().ForceGetValue();
                 *
                 *  if (syncMessage.getSent().HasValue) handleSynchronizeSentMessage(masterSecret, syncMessage.getSent().ForceGetValue(), smsMessageId);
                 *  else if (syncMessage.getRequest().HasValue) handleSynchronizeRequestMessage(masterSecret, syncMessage.getRequest().ForceGetValue());
                 * }*/

                if (envelope.isPreKeyWhisperMessage())
                {
                    App.Current.Worker.AddTaskActivities(new RefreshPreKeysTask());
                    //ApplicationContext.getInstance(context).getJobManager().add(new RefreshPreKeysJob(context));
                }
            }
            catch (InvalidVersionException e)
            {
                //Log.w(TAG, e);
                //handleInvalidVersionMessage(masterSecret, envelope, smsMessageId);
            }

            /* catch (InvalidMessageException | InvalidKeyIdException | InvalidKeyException | MmsException e) {
             *   Log.w(TAG, e);
             *   handleCorruptMessage(masterSecret, envelope, smsMessageId);
             * } catch (NoSessionException e)
             * {
             *   Log.w(TAG, e);
             *   handleNoSessionMessage(masterSecret, envelope, smsMessageId);
             * }
             * catch (LegacyMessageException e)
             * {
             *   Log.w(TAG, e);
             *   handleLegacyMessage(masterSecret, envelope, smsMessageId);
             * }
             * catch (DuplicateMessageException e)
             * {
             *   Log.w(TAG, e);
             *   handleDuplicateMessage(masterSecret, envelope, smsMessageId);
             * }
             * catch (UntrustedIdentityException e)
             * {
             *   Log.w(TAG, e);
             *   handleUntrustedIdentityMessage(masterSecret, envelope, smsMessageId);
             * }*/
        }
 public SentTranscriptMessage(ulong timestamp, TextSecureDataMessage message)
 {
     this.destination = May<string>.NoValue;
     this.timestamp = timestamp;
     this.message = message;
 }
 public SentTranscriptMessage(String destination, ulong timestamp, TextSecureDataMessage message)
 {
     this.destination = new May<string>(destination);
     this.timestamp = timestamp;
     this.message = message;
 }