コード例 #1
0
        private void HandleMessage(SignalServiceEnvelope envelope)
        {
            var  cipher    = new SignalServiceCipher(new SignalServiceAddress(App.Store.Username), new Store());
            var  content   = cipher.decrypt(envelope);
            long timestamp = Util.CurrentTimeMillis();

            if (content.Message != null)
            {
                SignalServiceDataMessage message = content.Message;
                if (message.EndSession)
                {
                    HandleSessionResetMessage(envelope, content, message, false, timestamp);
                }
                else if (message.IsGroupUpdate())
                {
                    if (message.Group.Type == SignalServiceGroup.GroupType.UPDATE)
                    {
                        HandleGroupUpdateMessage(envelope, content, message, false, timestamp);
                    }
                }
                else if (message.ExpirationUpdate)
                {
                    HandleExpirationUpdateMessage(envelope, content, message, false, timestamp);
                }
                else
                {
                    HandleSignalMessage(envelope, content, message, false, timestamp);
                }
            }
            else if (content.SynchronizeMessage != null)
            {
                if (content.SynchronizeMessage.getSent().HasValue)
                {
                    var syncMessage = content.SynchronizeMessage.getSent().ForceGetValue();
                    var dataMessage = syncMessage.getMessage();

                    if (dataMessage.EndSession)
                    {
                        HandleSessionResetMessage(envelope, content, dataMessage, true, timestamp);
                    }
                    else if (dataMessage.IsGroupUpdate())
                    {
                        if (dataMessage.Group.Type == SignalServiceGroup.GroupType.UPDATE)
                        {
                            HandleGroupUpdateMessage(envelope, content, dataMessage, true, timestamp);
                        }
                    }
                    else if (dataMessage.ExpirationUpdate)
                    {
                        HandleExpirationUpdateMessage(envelope, content, dataMessage, true, timestamp);
                    }
                    else
                    {
                        HandleSignalMessage(envelope, content, dataMessage, true, timestamp);
                    }
                }
                else if (content.SynchronizeMessage.getRead().HasValue)
                {
                    var readMessages = content.SynchronizeMessage.getRead().ForceGetValue();
                    foreach (var readMessage in readMessages)
                    {
                        //TODO
                    }
                }
            } //TODO callmessages
            else
            {
                Debug.WriteLine("HandleMessage got unrecognized message from " + envelope.getSource());
            }
        }
コード例 #2
0
        private void handleMessage(SignalServiceEnvelope envelope, May <long> smsMessageId)
        {
            try
            {
                SignalProtocolStore  axolotlStore = new TextSecureAxolotlStore();
                SignalServiceAddress localAddress = new SignalServiceAddress(TextSecurePreferences.getLocalNumber());
                SignalServiceCipher  cipher       = new SignalServiceCipher(localAddress, axolotlStore);

                SignalServiceContent content = cipher.decrypt(envelope);

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

                    if (message.isEndSession())
                    {
                        handleEndSessionMessage(envelope, message, smsMessageId);
                    }
                    else if (message.isGroupUpdate())
                    {
                        handleGroupMessage(envelope, message, smsMessageId);
                    }
                    else if (message.getAttachments().HasValue)
                    {
                        handleMediaMessage(envelope, message, smsMessageId);
                    }
                    else
                    {
                        handleTextMessage(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.isPreKeySignalMessage())
                {
                    App.Current.Worker.AddTaskActivities(new RefreshPreKeysTask());
                    //ApplicationContext.getInstance(context).getJobManager().add(new RefreshPreKeysJob(context));
                }
            }
            catch (InvalidVersionException e)
            {
                Log.Warn(e);
                handleInvalidVersionMessage(envelope, smsMessageId);
            }
            catch (InvalidMessageException e)
            {
                Log.Warn(e);
                handleCorruptMessage(envelope, smsMessageId);
            }
            catch (InvalidKeyIdException e)
            {
                Log.Warn(e);
                handleCorruptMessage(envelope, smsMessageId);
            }
            catch (InvalidKeyException e)
            {
                Log.Warn(e);
                handleCorruptMessage(envelope, smsMessageId);
            }
            catch (NoSessionException e)
            {
                Log.Warn(e);
                handleNoSessionMessage(envelope, smsMessageId);
            }
            catch (LegacyMessageException e)
            {
                Log.Warn(e);
                handleLegacyMessage(envelope, smsMessageId);
            }
            catch (DuplicateMessageException e)
            {
                Log.Warn(e);
                handleDuplicateMessage(envelope, smsMessageId);
            }
            catch (libsignal.exceptions.UntrustedIdentityException e)
            {
                Log.Warn(e);
                handleUntrustedIdentityMessage(envelope, smsMessageId);
            }
            catch (Exception e)
            {
                Log.Warn($"Unexpected Exception");
            }
        }