Ejemplo n.º 1
0
        /* public IncomingTextMessage(Parcel in)
         * {
         *   this.message = in.readString();
         *   this.sender = in.readString();
         *   this.senderDeviceId = in.readInt();
         *   this.protocol = in.readInt();
         *   this.serviceCenterAddress = in.readString();
         *   this.replyPathPresent = (in.readInt() == 1);
         *   this.pseudoSubject = in.readString();
         *   this.sentTimestampMillis = in.readLong();
         *   this.groupId = in.readString();
         *   this.push = (in.readInt() == 1);
         * }*/

        public IncomingTextMessage(IncomingTextMessage message, String newBody)
        {
            this.Message              = newBody;
            this.Sender               = message.getSender();
            this.SenderDeviceId       = message.getSenderDeviceId();
            this.Protocol             = message.getProtocol();
            this.ServiceCenterAddress = message.getServiceCenterAddress();
            this.ReplyPathPresent     = message.isReplyPathPresent();
            this.PseudoSubject        = message.getPseudoSubject();
            this.SentTimestampMillis  = message.SentTimestampMillis;
            this.GroupId              = message.GroupId;
            this.Push = message.IsPush;
        }
Ejemplo n.º 2
0
 public IncomingGroupMessage(IncomingTextMessage b, TextSecureProtos.GroupContext groupContext, string body) : base(b, body)
 {
     this._groupContext = groupContext;
 }
Ejemplo n.º 3
0
 public IncomingGroupMessage(IncomingTextMessage b, SignalServiceProtos.GroupContext groupContext, string body) : base(b, body)
 {
     this._groupContext = groupContext;
 }
Ejemplo n.º 4
0
        /* public IncomingTextMessage(Parcel in)
         {
             this.message = in.readString();
             this.sender = in.readString();
             this.senderDeviceId = in.readInt();
             this.protocol = in.readInt();
             this.serviceCenterAddress = in.readString();
             this.replyPathPresent = (in.readInt() == 1);
             this.pseudoSubject = in.readString();
             this.sentTimestampMillis = in.readLong();
             this.groupId = in.readString();
             this.push = (in.readInt() == 1);
         }*/

        public IncomingTextMessage(IncomingTextMessage message, String newBody)
        {
            this.Message = newBody;
            this.Sender = message.getSender();
            this.SenderDeviceId = message.getSenderDeviceId();
            this.Protocol = message.getProtocol();
            this.ServiceCenterAddress = message.getServiceCenterAddress();
            this.ReplyPathPresent = message.isReplyPathPresent();
            this.PseudoSubject = message.getPseudoSubject();
            this.SentTimestampMillis = message.SentTimestampMillis;
            this.GroupId = message.GroupId;
            this.Push = message.IsPush;
        }
Ejemplo n.º 5
0
 public IncomingEncryptedMessage(IncomingTextMessage parent, string newBody)
     : base(parent, newBody)
 {
 }
Ejemplo n.º 6
0
        private Pair<long, long> insertPlaceholder(TextSecureEnvelope envelope)
        {
            var database = DatabaseFactory.getTextMessageDatabase(); //getEncryptingSmsDatabase(context);
            IncomingTextMessage textMessage = new IncomingTextMessage(envelope.getSource(), envelope.getSourceDevice(),
                                                                        envelope.getTimestamp(), "",
                                                                        May<TextSecureGroup>.NoValue);

            textMessage = new IncomingEncryptedMessage(textMessage, "");
            return database.InsertMessageInbox(textMessage);
        }
Ejemplo n.º 7
0
        private void handleUntrustedIdentityMessage(TextSecureEnvelope envelope, May<long> smsMessageId)
        {
            try
            {
                var database = DatabaseFactory.getTextMessageDatabase(); //getEncryptingSmsDatabase(context);
                Recipients recipients = RecipientFactory.getRecipientsFromString(envelope.getSource(), false);
                long recipientId = recipients.getPrimaryRecipient().getRecipientId();
                PreKeyWhisperMessage whisperMessage = new PreKeyWhisperMessage(envelope.getLegacyMessage());
                IdentityKey identityKey = whisperMessage.getIdentityKey();
                String encoded = Base64.encodeBytes(envelope.getLegacyMessage());
                IncomingTextMessage textMessage = new IncomingTextMessage(envelope.getSource(), envelope.getSourceDevice(),
                                                                               envelope.getTimestamp(), encoded,
                                                                               May<TextSecureGroup>.NoValue);

                if (!smsMessageId.HasValue)
                {
                    IncomingPreKeyBundleMessage bundleMessage = new IncomingPreKeyBundleMessage(textMessage, encoded);
                    Pair<long, long> messageAndThreadId = database.InsertMessageInbox(bundleMessage);

                    database.SetMismatchedIdentity(messageAndThreadId.first(), recipientId, identityKey);
                    //MessageNotifier.updateNotification(context, masterSecret.getMasterSecret().orNull(), messageAndThreadId.second);
                }
                else
                {
                    var messageId = smsMessageId.ForceGetValue();
                    database.UpdateMessageBody(messageId, encoded);
                    database.MarkAsPreKeyBundle(messageId);
                    database.SetMismatchedIdentity(messageId, recipientId, identityKey);
                }
            }
            catch (InvalidMessageException e)
            {
                throw new InvalidOperationException(e.Message);
            }
            catch (InvalidVersionException e)
            {
                throw new InvalidOperationException(e.Message);
            }
        }
Ejemplo n.º 8
0
        private void handleTextMessage(/*@NonNull MasterSecretUnion masterSecret,*/
                                       TextSecureEnvelope envelope,
                                       TextSecureDataMessage message,
                                       May<long> smsMessageId)
        {
            var textMessageDatabase = DatabaseFactory.getTextMessageDatabase();
            String body = message.getBody().HasValue ? message.getBody().ForceGetValue() : "";


            IncomingTextMessage textMessage = new IncomingTextMessage(envelope.getSource(),
                                                                      envelope.getSourceDevice(),
                                                                      message.getTimestamp(), body,
                                                                      message.getGroupInfo());

            textMessage = new IncomingEncryptedMessage(textMessage, body);
            var messageAndThreadId = textMessageDatabase.InsertMessageInbox(textMessage);
            
            ToastHelper.NotifyNewMessage(messageAndThreadId.second());
        }
Ejemplo n.º 9
0
        private void handleEndSessionMessage(TextSecureEnvelope envelope,
                                             TextSecureDataMessage message,
                                             May<long> smsMessageId)
        {
            var smsDatabase = DatabaseFactory.getTextMessageDatabase();//getEncryptingSmsDatabase(context);
            var incomingTextMessage = new IncomingTextMessage(envelope.getSource(),
                                                                                envelope.getSourceDevice(),
                                                                                message.getTimestamp(),
                                                                                "", May<TextSecureGroup>.NoValue);

            long threadId;

            if (!smsMessageId.HasValue)
            {
                IncomingEndSessionMessage incomingEndSessionMessage = new IncomingEndSessionMessage(incomingTextMessage);
                Pair<long, long> messageAndThreadId = smsDatabase.InsertMessageInbox(incomingEndSessionMessage);

                threadId = messageAndThreadId.second();
            }
            else
            {
                var messageId = smsMessageId.ForceGetValue();
                smsDatabase.MarkAsEndSession(messageId);
                threadId = smsDatabase.GetThreadIdForMessage(messageId);
            }

            SessionStore sessionStore = new TextSecureAxolotlStore();
            sessionStore.DeleteAllSessions(envelope.getSource());

            //SecurityEvent.broadcastSecurityUpdateEvent(context, threadId);
            //MessageNotifier.updateNotification(context, masterSecret.getMasterSecret().orNull(), threadId);
        }
Ejemplo n.º 10
0
 public Pair<long, long> InsertMessageInbox(IncomingTextMessage message)
 {
     return InsertMessageInbox(message, MessageTypes.BASE_INBOX_TYPE);
 }
Ejemplo n.º 11
0
        protected Pair<long, long> InsertMessageInbox(IncomingTextMessage message, long type)
        { // TODO : https://github.com/WhisperSystems/Signal-Android/blob/e9b53cc164d7ae2d838cc211dbd88b7fd4f5669e/src/org/thoughtcrime/securesms/database/SmsDatabase.java
            if (message.isPreKeyBundle())
            {
                type |= MessageTypes.KEY_EXCHANGE_BIT | MessageTypes.KEY_EXCHANGE_BUNDLE_BIT;
            }
            else if (message.isSecureMessage())
            {
                type |= MessageTypes.SECURE_MESSAGE_BIT;
            }
            /*else if (message.isGroup()) TODO: GROUP enable
            {
                type |= MessageTypes.SECURE_MESSAGE_BIT;
                if (((IncomingGroupMessage)message).isUpdate()) type |= MessageTypes.GROUP_UPDATE_BIT;
                else if (((IncomingGroupMessage)message).isQuit()) type |= MessageTypes.GROUP_QUIT_BIT;
            }*/
            else if (message.IsEndSession)
            {
                type |= MessageTypes.SECURE_MESSAGE_BIT;
                type |= MessageTypes.END_SESSION_BIT;
            }

            if (message.IsPush) type |= MessageTypes.PUSH_MESSAGE_BIT;

            Recipients recipients;

            if (message.getSender() != null)
            {
                recipients = RecipientFactory.getRecipientsFromString(message.getSender(), true);
            }
            else
            {
                //Log.w(TAG, "Sender is null, returning unknown recipient");
                recipients = new Recipients(Recipient.getUnknownRecipient());
            }

            Recipients groupRecipients;

            if (message.GroupId == null)
            {
                groupRecipients = null;
            }
            else
            {
                groupRecipients = RecipientFactory.getRecipientsFromString(message.GroupId, true);
            }

            bool unread = /*org.thoughtcrime.securesms.util.Util.isDefaultSmsProvider() ||*/
                                    message.isSecureMessage() || message.isPreKeyBundle();

            long threadId;

            if (groupRecipients == null) threadId = DatabaseFactory.getThreadDatabase().GetThreadIdForRecipients(recipients); // TODO CHECK
            else threadId = DatabaseFactory.getThreadDatabase().GetThreadIdForRecipients(groupRecipients);

            /*ContentValues values = new ContentValues(6);
            values.put(ADDRESS, message.getSender());
            values.put(ADDRESS_DEVICE_ID, message.getSenderDeviceId());
            values.put(DATE_RECEIVED, System.currentTimeMillis());
            values.put(DATE_SENT, message.getSentTimestampMillis());
            values.put(PROTOCOL, message.getProtocol());
            values.put(READ, unread ? 0 : 1);

            if (!TextUtils.isEmpty(message.getPseudoSubject()))
                values.put(SUBJECT, message.getPseudoSubject());

            values.put(REPLY_PATH_PRESENT, message.isReplyPathPresent());
            values.put(SERVICE_CENTER, message.getServiceCenterAddress());
            values.put(BODY, message.getMessageBody());
            values.put(TYPE, type);
            values.put(THREAD_ID, threadId);*/

            var insert = new Message()
            {
                Address = message.getSender(),
                AddressDeviceId = message.getSenderDeviceId(),
                DateReceived = TimeUtil.GetDateTimeMillis(), // force precision to millis not to ticks
                DateSent = TimeUtil.GetDateTime(message.SentTimestampMillis),
                Read = !unread,
                Body = message.getMessageBody(),
                Type = type,
                ThreadId = threadId
            };

            long rows = conn.Insert(insert);

            long messageId = insert.MessageId;

            if (unread)
            {
                DatabaseFactory.getThreadDatabase().SetUnread(threadId);
            }

            DatabaseFactory.getThreadDatabase().Refresh(threadId);
            notifyConversationListeners(threadId);
            //jobManager.add(new TrimThreadJob(context, threadId)); // TODO

            return new Pair<long, long>(messageId, threadId);
        }
Ejemplo n.º 12
0
 public IncomingEncryptedMessage(IncomingTextMessage parent, string newBody)
     : base(parent, newBody)
 {
 }
Ejemplo n.º 13
0
 public IncomingPreKeyBundleMessage(IncomingTextMessage b, string newBody) : base(b, newBody)
 {
 }
 public IncomingPreKeyBundleMessage(IncomingTextMessage b, string newBody) : base(b, newBody)
 {
 }