Exemple #1
0
        public void ControlPreviewKeyDown(KeyEventArgs e)
        {
            if (Keyboard.Modifiers != ModifierKeys.None && Keyboard.Modifiers != ModifierKeys.Shift)
            {
                return;
            }

            if (e.Key == Key.Y && buttonToResult.ContainsValue(AnyUiMessageBoxResult.Yes))
            {
                this.Result = AnyUiMessageBoxResult.Yes;
                ControlClosed?.Invoke();
            }
            if ((e.Key == Key.N || e.Key == Key.Escape) && buttonToResult.ContainsValue(AnyUiMessageBoxResult.No))
            {
                this.Result = AnyUiMessageBoxResult.No;
                ControlClosed?.Invoke();
            }
            if ((e.Key == Key.O || e.Key == Key.Return) && buttonToResult.ContainsValue(AnyUiMessageBoxResult.OK))
            {
                this.Result = AnyUiMessageBoxResult.OK;
                ControlClosed?.Invoke();
            }
            if ((e.Key == Key.C || e.Key == Key.Escape) && buttonToResult.ContainsValue(AnyUiMessageBoxResult.Cancel))
            {
                this.Result = AnyUiMessageBoxResult.Cancel;
                ControlClosed?.Invoke();
            }
        }
Exemple #2
0
        /// <summary>
        /// Show MessageBoxFlyout with contents
        /// </summary>
        /// <param name="message">Message on the main screen</param>
        /// <param name="caption">Caption string (title)</param>
        /// <param name="buttons">Buttons according to WPF standard messagebox</param>
        /// <param name="image">Image according to WPF standard messagebox</param>
        /// <returns></returns>
        public override AnyUiMessageBoxResult MessageBoxFlyoutShow(
            string message, string caption, AnyUiMessageBoxButton buttons, AnyUiMessageBoxImage image)
        {
            htmlEventType = "MessageBoxFlyoutShow";
            htmlEventInputs.Add(message);
            htmlEventInputs.Add(caption);
            htmlEventInputs.Add(buttons);
            htmlEventIn = true;
            Program.signalNewData(2); // build new tree

            while (!htmlEventOut)
            {
                ;
            }
            AnyUiMessageBoxResult r = AnyUiMessageBoxResult.None;

            if (htmlEventOutputs.Count == 1)
            {
                r = (AnyUiMessageBoxResult)htmlEventOutputs[0];
            }
            htmlEventOutputs.Clear();
            htmlEventType     = "";
            htmlEventOut      = false;
            htmlDotnetEventIn = false;
            return(r);
        }
Exemple #3
0
 private void StackPanelButton_Click(object sender, RoutedEventArgs e)
 {
     if (sender is Button && buttonToResult.ContainsKey(sender as Button))
     {
         this.Result = buttonToResult[sender as Button];
         ControlClosed?.Invoke();
     }
 }
        /// <summary>
        /// Show MessageBoxFlyout with contents
        /// </summary>
        /// <param name="message">Message on the main screen</param>
        /// <param name="caption">Caption string (title)</param>
        /// <param name="buttons">Buttons according to WPF standard messagebox</param>
        /// <param name="image">Image according to WPF standard messagebox</param>
        /// <returns></returns>
        public override AnyUiMessageBoxResult MessageBoxFlyoutShow(
            string message, string caption, AnyUiMessageBoxButton buttons, AnyUiMessageBoxImage image)
        {
            AnyUiHtmlEventSession found = null;

            lock (htmlDotnetLock)
            {
                foreach (var s in sessions)
                {
                    if (_bi.sessionNumber == s.sessionNumber)
                    {
                        found = s;
                        break;
                    }
                }
            }

            AnyUiMessageBoxResult r = AnyUiMessageBoxResult.None;

            if (found != null)
            {
                found.htmlEventInputs.Clear();
                found.htmlEventType = "MessageBoxFlyoutShow";
                found.htmlEventInputs.Add(message);
                found.htmlEventInputs.Add(caption);
                found.htmlEventInputs.Add(buttons);
                found.htmlEventIn = true;
                Program.signalNewData(2, found.sessionNumber); // build new tree

                while (!found.htmlEventOut)
                {
                    ;
                }
                if (found.htmlEventOutputs.Count == 1)
                {
                    r = (AnyUiMessageBoxResult)found.htmlEventOutputs[0];
                }

                found.htmlEventType = "";
                found.htmlEventOutputs.Clear();
                found.htmlEventOut = false;
                found.htmlEventInputs.Clear();
                found.htmlDotnetEventIn = false;
            }

            return(r);
        }
        private string CreateClientToken(SigningCredentials credential, string clientId, string audience,
                                         List <string> rootCertSubject,
                                         UiLambdaSet uiLambda = null)
        {
            string[]         x5c          = null;
            string           certFileName = certPfx;
            string           password     = certPfxPW;
            X509Certificate2 certificate  = null;

            if (credential == null)
            {
                AnyUiMessageBoxResult res = AnyUiMessageBoxResult.No;

                if (ssiURL == "")
                {
                    res = UiLambdaSet.MesssageBoxShow(uiLambda, "",
                                                      "Select certificate chain from certificate store? \n" +
                                                      "(otherwise use file Andreas_Orzelski_Chain.pfx)",
                                                      "Select certificate chain", AnyUiMessageBoxButton.YesNo);
                }

                if (res == AnyUiMessageBoxResult.No)
                {
                    credential = new X509SigningCredentials(new X509Certificate2(certPfx, certPfxPW));
                }
            }

            if (credential == null)
            {
                X509Store store = new X509Store("MY", StoreLocation.CurrentUser);
                store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);

                X509Certificate2Collection collection  = (X509Certificate2Collection)store.Certificates;
                X509Certificate2Collection fcollection = (X509Certificate2Collection)collection.Find(
                    X509FindType.FindByTimeValid, DateTime.Now, false);

                Boolean rootCertFound = false;
                X509Certificate2Collection fcollection2 = new X509Certificate2Collection();
                foreach (X509Certificate2 fc in fcollection)
                {
                    X509Chain fch = new X509Chain();
                    fch.Build(fc);
                    foreach (X509ChainElement element in fch.ChainElements)
                    {
                        if (rootCertSubject.Contains(element.Certificate.Subject))
                        {
                            rootCertFound = true;
                            fcollection2.Add(fc);
                        }
                    }
                }
                if (rootCertFound)
                {
                    fcollection = fcollection2;
                }

                X509Certificate2Collection scollection = X509Certificate2UI.SelectFromCollection(fcollection,
                                                                                                 "Test Certificate Select",
                                                                                                 "Select a certificate from the following list to get information on that certificate",
                                                                                                 X509SelectionFlag.SingleSelection);
                if (scollection.Count != 0)
                {
                    certificate = scollection[0];
                    X509Chain ch = new X509Chain();
                    ch.Build(certificate);

                    string[] X509Base64 = new string[ch.ChainElements.Count];

                    int j = 0;
                    foreach (X509ChainElement element in ch.ChainElements)
                    {
                        X509Base64[j++] = Convert.ToBase64String(element.Certificate.GetRawCertData());
                    }

                    x5c = X509Base64;
                }
            }
            else
            {
                // use old fixed certificate chain
                X509Certificate2Collection xc = new X509Certificate2Collection();
                xc.Import(certFileName, password, X509KeyStorageFlags.PersistKeySet);

                string[] X509Base64 = new string[xc.Count];

                int j   = xc.Count;
                var xce = xc.GetEnumerator();
                for (int i = 0; i < xc.Count; i++)
                {
                    xce.MoveNext();
                    X509Base64[--j] = Convert.ToBase64String(xce.Current.GetRawCertData());
                }
                x5c = X509Base64;

                certificate = new X509Certificate2(certFileName, password);
            }

            string email   = "";
            string subject = certificate.Subject;
            var    split   = subject.Split(new Char[] { ',' });

            if (split[0] != "")
            {
                var split2 = split[0].Split(new Char[] { '=' });
                if (split2[0] == "E")
                {
                    email = split2[1];
                }
            }
            Console.WriteLine("email: " + email);

            //
            StringBuilder builder = new StringBuilder();

            builder.AppendLine("-----BEGIN CERTIFICATE-----");
            builder.AppendLine(
                Convert.ToBase64String(certificate.RawData, Base64FormattingOptions.InsertLineBreaks));
            builder.AppendLine("-----END CERTIFICATE-----");

            if (ssiURL == "")
            {
                UiLambdaSet.MesssageBoxShow(uiLambda, builder.ToString(), "", "Client Certificate",
                                            AnyUiMessageBoxButton.OK);
            }

            credential = new X509SigningCredentials(certificate);
            // oz end

            var now = DateTime.UtcNow;

            var token = new JwtSecurityToken(
                clientId,
                audience,
                new List <Claim>()
            {
                new Claim(JwtClaimTypes.JwtId, Guid.NewGuid().ToString()),
                new Claim(JwtClaimTypes.Subject, clientId),
                new Claim(JwtClaimTypes.IssuedAt, now.ToEpochTime().ToString(), ClaimValueTypes.Integer64),
                // OZ
                new Claim(JwtClaimTypes.Email, email)
                // new Claim("x5c", x5c)
            },
                now,
                now.AddMinutes(1),
                credential)
            ;

            token.Header.Add("x5c", x5c);
            if (ssiURL != "")
            {
                //// Prover prover = new Prover("http://192.168.178.33:5001"); //AASX Package Explorer
                Prover prover = new Prover(ssiURL); //AASX Package Explorer

                string invitation = prover.CreateInvitation();

                token.Header.Add("ssiInvitation", invitation);

                UiLambdaSet.MesssageBoxShow(uiLambda, "ssiURL = " + ssiURL, "", "SSI Info",
                                            AnyUiMessageBoxButton.OK);
                UiLambdaSet.MesssageBoxShow(uiLambda,
                                            "credentialInfo = " + prover.cred_json_asstring, "", "VC for Presentation",
                                            AnyUiMessageBoxButton.OK);
            }

            var tokenHandler = new JwtSecurityTokenHandler();

            return(tokenHandler.WriteToken(token));
        }
Exemple #6
0
        //
        // Mechanics
        //

        private void ButtonClose_Click(object sender, RoutedEventArgs e)
        {
            this.Result = AnyUiMessageBoxResult.None;
            ControlClosed?.Invoke();
        }
        /// <summary>
        /// Assumes, that the flyout is open and BLOCKS the message loop until a result button
        /// is being pressed!
        /// </summary>
        public AnyUiMessageBoxResult MessageBoxShow(
            string content, string text, string caption,
            AnyUiMessageBoxButton buttons)
        {
            // show tab page
            TabControlMain.SelectedItem = TabItemMessageBox;

            // set text portions
            TextBlockMessageBoxCaption.Text = "" + caption;
            TextBlockMessageBoxText.Text    = "" + text;
            if (caption.HasContent())
            {
                LogMessage(new StoredPrint(StoredPrint.Color.Yellow, "" + caption));
            }
            if (text.HasContent())
            {
                LogMessage(new StoredPrint("" + text));
            }
            if (content.HasContent())
            {
                LogMessage(new StoredPrint("" + content));
            }

            // set respective buttons
            _presetOkYes    = AnyUiMessageBoxResult.None;
            _presetNoCancel = AnyUiMessageBoxResult.None;

            ButtonMessageBoxOK.Visibility     = Visibility.Collapsed;
            ButtonMessageBoxCancel.Visibility = Visibility.Collapsed;
            ButtonMessageBoxYes.Visibility    = Visibility.Collapsed;
            ButtonMessageBoxNo.Visibility     = Visibility.Collapsed;

            if (buttons == AnyUiMessageBoxButton.OK)
            {
                ButtonMessageBoxOK.Visibility = Visibility.Visible;
                _presetOkYes = AnyUiMessageBoxResult.OK;
            }

            if (buttons == AnyUiMessageBoxButton.OKCancel)
            {
                ButtonMessageBoxOK.Visibility     = Visibility.Visible;
                ButtonMessageBoxCancel.Visibility = Visibility.Visible;
                _presetOkYes    = AnyUiMessageBoxResult.OK;
                _presetNoCancel = AnyUiMessageBoxResult.Cancel;
            }

            if (buttons == AnyUiMessageBoxButton.YesNo)
            {
                ButtonMessageBoxYes.Visibility = Visibility.Visible;
                ButtonMessageBoxNo.Visibility  = Visibility.Visible;
                _presetOkYes    = AnyUiMessageBoxResult.Yes;
                _presetNoCancel = AnyUiMessageBoxResult.No;
            }

            if (buttons == AnyUiMessageBoxButton.YesNoCancel)
            {
                ButtonMessageBoxCancel.Visibility = Visibility.Visible;
                ButtonMessageBoxYes.Visibility    = Visibility.Visible;
                ButtonMessageBoxNo.Visibility     = Visibility.Visible;
                _presetOkYes    = AnyUiMessageBoxResult.Yes;
                _presetNoCancel = AnyUiMessageBoxResult.Cancel;
            }

            // modified from StartFlyoverModal()
            // This will "block" execution of the current dispatcher frame
            // and run our frame until the dialog is closed.
            _dialogResult    = AnyUiMessageBoxResult.None;
            _dispatcherFrame = new DispatcherFrame();
            Dispatcher.PushFrame(_dispatcherFrame);

            return(_dialogResult);
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (sender == ButtonMsgSmaller && TextBoxMessages.FontSize >= 6.0)
            {
                TextBoxMessages.FontSize -= 2.0;
            }
            if (sender == ButtonMsgLarger && TextBoxMessages.FontSize < 99.0)
            {
                TextBoxMessages.FontSize += 2.0;
            }

            if (sender == ButtonStartSelect)
            {
                var dlg = new Microsoft.Win32.OpenFileDialog();
                if (_initialDirectory != null)
                {
                    dlg.InitialDirectory = _initialDirectory;
                    _initialDirectory    = null;
                }
                dlg.Filter =
                    "AASX package files (*.aasx)|*.aasx|AAS XML file (*.xml)|*.xml|" +
                    "AAS JSON file (*.json)|*.json|All files (*.*)|*.*";

                var res = dlg.ShowDialog();
                if (res == true)
                {
                    TextBoxStartLocation.Text = dlg.FileName;
                }
            }

            if (sender == ButtonStartProceed)
            {
                ProceedOnPageStart();
            }

            if (sender == ButtonPageSelectFromListProceed)
            {
                ProceedOnPageSelectFromList();
            }

            if (sender == ButtonPageCredentialsProceed)
            {
                ProceedOnPageCredentials();
            }

            if (sender == ButtonPageSummaryDone)
            {
                DoneOnPageSummary();
            }

            AnyUiMessageBoxResult tmpRes = AnyUiMessageBoxResult.None;

            if (sender == ButtonMessageBoxOK)
            {
                tmpRes = AnyUiMessageBoxResult.OK;
            }
            if (sender == ButtonMessageBoxCancel)
            {
                tmpRes = AnyUiMessageBoxResult.Cancel;
            }
            if (sender == ButtonMessageBoxYes)
            {
                tmpRes = AnyUiMessageBoxResult.Yes;
            }
            if (sender == ButtonMessageBoxNo)
            {
                tmpRes = AnyUiMessageBoxResult.No;
            }
            if (tmpRes != AnyUiMessageBoxResult.None)
            {
                if (_dispatcherFrame != null)
                {
                    _dispatcherFrame.Continue = false;
                }
                _dialogResult = tmpRes;
            }

            if (sender == ButtonMsgCopyLast)
            {
                System.Windows.Clipboard.SetText("" + _lastTextMessage);
            }

            if (sender == ButtonMsgCopyAll)
            {
                var tr = new TextRange(TextBoxMessages.Document.ContentStart, TextBoxMessages.Document.ContentEnd);
                System.Windows.Clipboard.SetText("" + tr.Text);
            }
        }