private async void QrCodeScannerControl_NewValidQrCode(QrCodeScannerControl sender, NewQrCodeEventArgs args)
        {
            IUriAction action = UriUtils.parse(new Uri(args.QR_CODE));

            if (action is RegisterIoTUriAction registerIoTUriAction)
            {
                await SharedUtils.CallDispatcherAsync(async() =>
                {
                    await qrCodeScanner.StopAsync();

                    UpdateViewState(State_2.Name);
                    VIEW_MODEL.MODEL.RegisterIoTUriAction = registerIoTUriAction;
                });
            }
        }
        public void OnQrCodeScannerShown(QrCodeScannerDialogDataTemplate model)
        {
            if (model.Success)
            {
                Uri uri = null;
                try
                {
                    uri = new Uri(model.QrCode);
                }
                catch (Exception e)
                {
                    Logger.Error("Failed to parse OMEMO fingerprint XMPP URI. Malformed URI: " + model.QrCode, e);
                    return;
                }

                if (string.Equals(uri.LocalPath.ToLowerInvariant(), MODEL.Chat.chatJabberId.ToLowerInvariant()))
                {
                    IUriAction action = UriUtils.parse(uri);

                    if (action is OmemoFingerprintUriAction fingerprintUriAction)
                    {
                        OmemoFingerprint fingerprint = OmemoSignalKeyDBManager.INSTANCE.getFingerprint(fingerprintUriAction.FINGERPRINT.ADDRESS, MODEL.Client.getXMPPAccount().getBareJid());
                        if (fingerprint is null)
                        {
                            fingerprint = fingerprintUriAction.FINGERPRINT;
                        }
                        fingerprint.trusted = true;
                        OmemoSignalKeyDBManager.INSTANCE.setFingerprint(fingerprint, MODEL.Client.getXMPPAccount().getBareJid());
                        Logger.Info("Scanned OMEMO fingerprint successful.");
                        Logger.Debug("Fingerprint: " + fingerprint.ADDRESS.ToString());
                        LoadFingerprints();
                    }
                    else
                    {
                        Logger.Warn("Failed to parse OMEMO fingerprint XMPP URI. Not an " + nameof(OmemoFingerprintUriAction) + ".");
                    }
                }
                else
                {
                    Logger.Warn("Failed to parse OMEMO fingerprint XMPP URI. Wrong chat: " + uri.LocalPath);
                }
            }
        }
示例#3
0
        public static UriAction ToUriAction(this IUriAction self)
        {
            if (self.Label == null)
            {
                throw new InvalidOperationException("The label cannot be null.");
            }

            if (self.Url == null)
            {
                throw new InvalidOperationException("The url cannot be null.");
            }

            if (self is UriAction uriAction)
            {
                return(uriAction);
            }

            return(new UriAction()
            {
                Label = self.Label,
                Url = self.Url
            });
        }
示例#4
0
        internal static UriAction Convert(IUriAction action)
        {
            if (action.Label == null)
            {
                throw new InvalidOperationException("The label cannot be null.");
            }

            if (action.Url == null)
            {
                throw new InvalidOperationException("The url cannot be null.");
            }

            if (action is UriAction uriAction)
            {
                return(uriAction);
            }

            return(new UriAction()
            {
                Label = action.Label,
                Url = action.Url
            });
        }
示例#5
0
        public void OnQrCodeScannerShown(QrCodeScannerDialogDataTemplate model)
        {
            if (model.Success)
            {
                Uri uri = null;
                try
                {
                    uri = new Uri(model.QrCode);
                }
                catch (Exception e)
                {
                    Logger.Error("Failed to parse OMEMO fingerprint XMPP URI. Malformed URI: " + model.QrCode, e);
                    return;
                }

                if (string.Equals(uri.LocalPath.ToLowerInvariant(), MODEL.Chat.Chat.bareJid.ToLowerInvariant()))
                {
                    IUriAction action = UriUtils.parse(uri);

                    if (action is OmemoFingerprintUriAction fingerprintUriAction)
                    {
                        OmemoDeviceModel device = MODEL.Chat.Chat.omemoInfo.devices.Where(d => d.deviceId == fingerprintUriAction.FINGERPRINT.ADDRESS.DEVICE_ID).FirstOrDefault();
                        using (MainDbContext ctx = new MainDbContext())
                        {
                            if (device is null)
                            {
                                device = new OmemoDeviceModel(fingerprintUriAction.FINGERPRINT.ADDRESS)
                                {
                                    fingerprint = new OmemoFingerprintModel(fingerprintUriAction.FINGERPRINT)
                                    {
                                        trusted = true
                                    }
                                };
                                ctx.Add(device);
                                MODEL.Chat.Chat.omemoInfo.devices.Add(device);
                                ctx.Update(MODEL.Chat.Chat.omemoInfo);
                            }
                            else
                            {
                                device.fingerprint.FromOmemoFingerprint(fingerprintUriAction.FINGERPRINT);
                                device.fingerprint.trusted = true;
                                ctx.Update(device.fingerprint.identityKey);
                                ctx.Update(device.fingerprint);
                            }
                        }

                        Logger.Info("Scanned OMEMO fingerprint successful.");
                        Logger.Debug("Fingerprint: " + fingerprintUriAction.FINGERPRINT.ADDRESS.ToString());
                        LoadFingerprints();
                    }
                    else
                    {
                        Logger.Warn("Failed to parse OMEMO fingerprint XMPP URI. Not an " + nameof(OmemoFingerprintUriAction) + ".");
                    }
                }
                else
                {
                    Logger.Warn("Failed to parse OMEMO fingerprint XMPP URI. Wrong chat: " + uri.LocalPath);
                }
            }
        }