예제 #1
0
        protected override void OnAction(Microsoft.ManagementConsole.Action action, AsyncStatus status)
        {
            base.OnAction(action, status);

            switch ((int)action.Tag)
            {
            case ACTION_GET_SERVER_VERSION:
                MMCDlgHelper.ShowMessage(VMCACertificateService.GetVersion(ServerDTO));
                break;

            case ACTION_SHOW_ROOT_CERTIFICATE:
                ShowRootCertificate();
                break;

            case ACTION_ADD_ROOT_CERTIFICATE:
                AddRootCertificate();
                break;

            case ACTION_LOGIN:
                DoLogin();
                break;

            case ACTION_LOGOUT:
                DoLogout();
                break;
            }
        }
예제 #2
0
 public void ShowServerVersion()
 {
     UIErrorHelper.CheckedExec(delegate() {
         UIErrorHelper.ShowAlert(VMCACertificateService.GetVersion(ServerDTO), "Version");
     });
 }
예제 #3
0
        public override NSMenu MenuForEvent(NSEvent theEvent)
        {
            UIErrorHelper.CheckedExec(delegate() {
                CGPoint pt   = this.ConvertPointFromView(theEvent.LocationInWindow, null);
                _selectedRow = this.GetRow(pt);
                //get datasource and node information
                NSTableViewDataSource ds = (NSTableViewDataSource)this.DataSource;
                NSMenu menu = new NSMenu();
                if (_selectedRow >= 0)
                {
                    if (ds is NodesListView)
                    {
                        string data = (ds as NodesListView).Entries [(int)_selectedRow].DisplayName;
                        switch (data)
                        {
                        case "Key Pairs":
                            NSMenuItem createKeyPair = new NSMenuItem("Create Key Pair", HandleKeyPairRequest);
                            menu.AddItem(createKeyPair);
                            break;

                        case "Certificates":
                            NSMenuItem createCertificate = new NSMenuItem("Create Certificate", HandleCreateSelfSignedCertificate);
                            menu.AddItem(createCertificate);
                            break;

                        case "Signing Requests":
                            NSMenuItem createSigningRequest = new NSMenuItem("Create SigningRequest", HandleCreateSigningRequest);
                            menu.AddItem(createSigningRequest);
                            break;

                        default:
                            break;
                        }
                    }
                    else if (ds is CertificateDetailsListView || ds is PrivateCertsListView)
                    {
                        X509Certificate2 cert = null;
                        if (ds is CertificateDetailsListView)
                        {
                            CertificateDetailsListView lw = ds as CertificateDetailsListView;
                            cert = lw.Entries [(int)_selectedRow];
                            if (lw.CertificateState == (int)VMCA.CertificateState.Active)
                            {
                                NSMenuItem revokeCert = new NSMenuItem("Revoke Certificate", (object sender, EventArgs e) => {
                                    UIErrorHelper.CheckedExec(delegate() {
                                        VMCACertificateService.RevokeCertificate(cert, lw.ServerDto);
                                        NSNotificationCenter.DefaultCenter.PostNotificationName("ReloadAll", this);
                                    });
                                });
                                menu.AddItem(revokeCert);
                            }
                        }
                        if (ds is PrivateCertsListView)
                        {
                            cert = CertificateExtensions.GetX509Certificate2FromString((ds as PrivateCertsListView).Entries [(int)_selectedRow].Certificate);
                        }
                        NSMenuItem showCert = new NSMenuItem("Show Certificate", (object sender, EventArgs e) => {
                            CertificateService.DisplayX509Certificate2(this, cert);
                        });
                        menu.AddItem(showCert);

                        NSMenuItem showCertString = new NSMenuItem("Show Certificate String", (object sender, EventArgs e) => {
                            UIHelper.ShowGenericWindowAsSheet(VMCACertificate.GetCertificateAsString(cert), "Certificate String", VMCAAppEnvironment.Instance.MainWindow);
                        });
                        menu.AddItem(showCertString);

                        /* if (lw.CertificateState == -1) {
                         * NSMenuItem deleteString = new NSMenuItem ("Delete Certificate", (object sender, EventArgs e) => {
                         *  lw.ServerDto.PrivateCertificates.RemoveAll (x => x.Certificate.Equals (cert.ToString ()));
                         *  NSNotificationCenter.DefaultCenter.PostNotificationName ("ReloadTableView", this);
                         *
                         * });
                         * menu.AddItem (deleteString);
                         * }*/
                    }
                    else if (ds is CSRDetailListView)
                    {
                        CSRDetailListView lw = ds as CSRDetailListView;
                        var csr             = lw.Entries [(int)_selectedRow].CSR;
                        NSMenuItem showCert = new NSMenuItem("Show CSR", (object sender, EventArgs e) => {
                            UIHelper.ShowGenericWindowAsSheet(csr, "CSR", VMCAAppEnvironment.Instance.MainWindow);
                        });
                        menu.AddItem(showCert);
                    }
                    else if (ds is KeyPairDetailListView)
                    {
                        KeyPairDetailListView lw = ds as KeyPairDetailListView;
                        var privateKey           = lw.Entries [(int)_selectedRow].PrivateKey;
                        var publicKey            = lw.Entries [(int)_selectedRow].PublicKey;
                        KeyPairData keyPair      = new KeyPairData(privateKey, publicKey);
                        NSMenuItem showCert      = new NSMenuItem("Export KeyPair", (object sender, EventArgs e) => {
                            VMCAKeyPairNode.SaveKeyData(keyPair);
                        });
                        menu.AddItem(showCert);
                    }
                    NSMenu.PopUpContextMenu(menu, theEvent, theEvent.Window.ContentView);
                }
            });
            return(base.MenuForEvent(theEvent));
        }