Esempio n. 1
0
        //--------------------------------------------------------Constructor:----------------------------------------------------------------\\
        #region --Constructors--


        #endregion
        //--------------------------------------------------------Set-, Get- Methods:---------------------------------------------------------\\
        #region --Set-, Get- Methods--


        #endregion
        //--------------------------------------------------------Misc Methods:---------------------------------------------------------------\\
        #region --Misc Methods (Public)--
        public async Task ResetOmemoDevicesAsync(XMPPClient client)
        {
            MODEL.ResettingDevices = true;
            OmemoDevices devices = new OmemoDevices();

            devices.IDS.Add(client.getXMPPAccount().omemoDeviceId);
            await client.OMEMO_COMMAND_HELPER.setDeviceListAsync(devices);

            MODEL.ResettingDevices = false;
        }
Esempio n. 2
0
 private async void onDeviceListResult(bool success, OmemoDevices devices)
 {
     await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
     {
         if (success)
         {
             omemoDevices_odc.setDevices(devices.DEVICES);
             refreshOmemoDevices_pgr.Visibility = Visibility.Collapsed;
             refreshOmemoDevices_btn.IsEnabled  = true;
         }
     });
 }
        public OmemoDevices getOmemoDevices(string chatJid, string accountJid)
        {
            List <OmemoDeviceTable> deviceTables = getDevices(chatJid, accountJid);
            OmemoDevices            devices      = new OmemoDevices();
            List <uint>             deviceIds    = new List <uint>();

            foreach (OmemoDeviceTable device in deviceTables)
            {
                devices.DEVICES.Add(device.deviceId);
            }
            return(devices);
        }
Esempio n. 4
0
        private void setDeviceListToOwnDevice()
        {
            if (resetDeviceListStatelessHelper != null)
            {
                resetDeviceListStatelessHelper.Dispose();
                resetDeviceListStatelessHelper = null;
            }
            OmemoDevices devices = new OmemoDevices();

            devices.DEVICES.Add(CONNECTION.account.omemoDeviceId);
            resetDeviceListStatelessHelper = new MessageResponseHelper <IQMessage>(CONNECTION, onResetDeviceListStatelessMessage, onResetDeviceListStatelessTimeout);
            OmemoSetDeviceListMessage msg = new OmemoSetDeviceListMessage(CONNECTION.account.getIdDomainAndResource(), devices);

            resetDeviceListStatelessHelper.start(msg);
        }
        public void setDevices(OmemoDevices devices, string chatJid, string accountId)
        {
            List <OmemoDeviceTable> deviceTables = new List <OmemoDeviceTable>();

            foreach (uint deviceId in devices.DEVICES)
            {
                deviceTables.Add(new OmemoDeviceTable()
                {
                    id        = OmemoDeviceTable.generateId(chatJid, accountId, deviceId),
                    accountId = accountId,
                    chatJid   = chatJid,
                    deviceId  = deviceId
                });
            }
            setDevices(deviceTables, chatJid);
        }
Esempio n. 6
0
        private void updateDevicesIfNeeded(OmemoDevices devicesRemote)
        {
            if (devicesRemote == null)
            {
                devicesRemote = new OmemoDevices();
            }

            bool updateDeviceList = false;

            // Device id hasn't been set. Pick a random, unique one:
            if (CONNECTION.account.omemoDeviceId == 0)
            {
                tmpDeviceId = CryptoUtils.generateOmemoDeviceIds(devicesRemote.DEVICES);
                devicesRemote.DEVICES.Add(tmpDeviceId);
                updateDeviceList = true;
            }
            else
            {
                if (!devicesRemote.DEVICES.Contains(CONNECTION.account.omemoDeviceId))
                {
                    devicesRemote.DEVICES.Add(CONNECTION.account.omemoDeviceId);
                    updateDeviceList = true;
                }
            }

            if (updateDeviceList)
            {
                setState(OmemoHelperState.UPDATING_DEVICE_LIST);
                Logger.Info("[OMEMO HELPER](" + CONNECTION.account.getIdAndDomain() + ") Updating device list.");
                if (updateDeviceListHelper != null)
                {
                    updateDeviceListHelper.Dispose();
                }
                updateDeviceListHelper = new MessageResponseHelper <IQMessage>(CONNECTION, updateDevicesIfNeededMsg, onTimeout);
                OmemoSetDeviceListMessage msg = new OmemoSetDeviceListMessage(CONNECTION.account.getIdDomainAndResource(), devicesRemote);
                updateDeviceListHelper.start(msg);
            }
            else if (!CONNECTION.account.omemoBundleInfoAnnounced)
            {
                announceBundleInfo();
            }
            else
            {
                setState(OmemoHelperState.ENABLED);
            }
            DEVICES = devicesRemote;
        }
Esempio n. 7
0
        /// <summary>
        /// If the OMEMO device list got changed and does not contain the local device id update it and add it again.
        /// </summary>
        /// <param name="msg">The received OmemoDeviceListEventMessage.</param>
        private async Task onOmemoDeviceListEventMessageAsync(OmemoDeviceListEventMessage msg)
        {
            string senderBareJid = Utils.getBareJidFromFullJid(msg.getFrom());

            if (string.Equals(senderBareJid, CONNECTION.account.getBareJid()))
            {
                if (!msg.DEVICES.IDS.Contains(CONNECTION.account.omemoDeviceId))
                {
                    msg.DEVICES.IDS.Add(CONNECTION.account.omemoDeviceId);
                    OmemoSetDeviceListMessage setMsg = new OmemoSetDeviceListMessage(CONNECTION.account.getFullJid(), msg.DEVICES);
                    await CONNECTION.SendAsync(setMsg, false);
                }
                DEVICES = msg.DEVICES;
            }

            OMEMO_STORE.StoreDevices(msg.DEVICES.toSignalProtocolAddressList(senderBareJid));
            OMEMO_STORE.StoreDeviceListSubscription(senderBareJid, new Tuple <OmemoDeviceListSubscriptionState, DateTime>(OmemoDeviceListSubscriptionState.SUBSCRIBED, DateTime.Now));
        }
Esempio n. 8
0
        private void showClient()
        {
            if (!omemoPviLoaded)
            {
                return;
            }

            omemoFingerprint_ofc.MyFingerprint = Client?.getXMPPAccount().getOmemoFingerprint();
            if (Client != null)
            {
                if (!Client.getXMPPAccount().hasOmemoKeys())
                {
                    omemoError_itbx.Text       = "OMEMO keys are corrupted. Please remove and add your account again!";
                    omemoError_itbx.Visibility = Visibility.Visible;
                }
                else
                {
                    omemoError_itbx.Visibility = Visibility.Collapsed;
                }

                OmemoDevices devices = Client.getOmemoHelper().DEVICES;
                if (devices != null)
                {
                    omemoDevices_odc.setDevices(devices.DEVICES);
                    omemoDevicesInfo_tbx.Visibility = Visibility.Collapsed;
                }
                else
                {
                    omemoDevices_odc.setDevices(new List <uint>());
                    omemoDevicesInfo_tbx.Visibility = Visibility.Visible;
                }

                uint deviceId = Client.getXMPPAccount().omemoDeviceId;
                if (deviceId != 0)
                {
                    omemoDeviceId_run.Text = deviceId.ToString();
                }
                else
                {
                    omemoDeviceId_run.Text = "-";
                }
            }
        }
Esempio n. 9
0
        private async Task updateDeviceListAsync(OmemoDevices devices)
        {
            setState(OmemoHelperState.UPDATING_DEVICE_LIST);

            // Make sure we set the item ID to "current":
            devices.setId();

            Logger.Info("[OMEMO HELPER](" + CONNECTION.account.getBareJid() + ") Updating device list.");
            MessageResponseHelperResult <IQMessage> result = await CONNECTION.OMEMO_COMMAND_HELPER.setDeviceListAsync(devices);

            if (result.STATE == MessageResponseHelperResultState.SUCCESS)
            {
                if (result.RESULT is IQMessage)
                {
                    Logger.Info("[OMEMO HELPER](" + CONNECTION.account.getBareJid() + ") Device list updated.");
                    if (CONNECTION.account.omemoDeviceId == 0)
                    {
                        CONNECTION.account.omemoDeviceId = tmpDeviceId;
                    }
                    if (!CONNECTION.account.omemoBundleInfoAnnounced)
                    {
                        await announceBundleInfoAsync();
                    }
                    else
                    {
                        setState(OmemoHelperState.ENABLED);
                    }
                }
                else if (result.RESULT is IQErrorMessage errMsg)
                {
                    Logger.Error("[OMEMO HELPER](" + CONNECTION.account.getBareJid() + ") Failed to set OMEMO device list to: " + CONNECTION.account.user.domainPart + "\n" + errMsg.ERROR_OBJ.ToString());
                    setState(OmemoHelperState.ERROR);
                }
            }
            else
            {
                onRequestError(result);
            }
        }
Esempio n. 10
0
        private async Task updateDevicesIfNeededAsync(OmemoDevices devicesRemote)
        {
            if (devicesRemote is null)
            {
                devicesRemote = new OmemoDevices();
            }

            bool updateDeviceList = false;

            // Device id hasn't been set. Pick a random, unique one:
            if (CONNECTION.account.omemoDeviceId == 0)
            {
                tmpDeviceId = CryptoUtils.generateOmemoDeviceIds(devicesRemote.IDS.ToList());
                devicesRemote.IDS.Add(tmpDeviceId);
                updateDeviceList = true;
            }
            else
            {
                if (!devicesRemote.IDS.Contains(CONNECTION.account.omemoDeviceId))
                {
                    devicesRemote.IDS.Add(CONNECTION.account.omemoDeviceId);
                    updateDeviceList = true;
                }
            }

            if (updateDeviceList)
            {
                await updateDeviceListAsync(devicesRemote);
            }
            else if (!CONNECTION.account.omemoBundleInfoAnnounced)
            {
                await announceBundleInfoAsync();
            }
            else
            {
                setState(OmemoHelperState.ENABLED);
            }
            DEVICES = devicesRemote;
        }
Esempio n. 11
0
        /// <summary>
        /// Sends an OmemoSetDeviceListMessage to update your OMEMO device list with the given devices.
        /// </summary>
        /// <param name="devices">The new OMEMO device list.</param>
        /// <returns>The OmemoSetDeviceListMessage result.</returns>
        public async Task <MessageResponseHelperResult <IQMessage> > setDeviceListAsync(OmemoDevices devices)
        {
            Predicate <IQMessage> predicate = (x) => { return(true); };
            AsyncMessageResponseHelper <IQMessage> helper = new AsyncMessageResponseHelper <IQMessage>(CONNECTION, predicate);
            OmemoSetDeviceListMessage msg = new OmemoSetDeviceListMessage(CONNECTION.account.getFullJid(), devices);

            return(await helper.startAsync(msg));
        }