Esempio n. 1
0
 public static void SaveKeyData (KeyPairData data)
 {
     var save = NSSavePanel.SavePanel;
     save.AllowedFileTypes = new string[] { "pem" };
     nint result = save.RunModal ();
     if (result == (int)1) {
         string path = save.Url.Path;
         File.WriteAllText (path, data.PrivateKey);
     }
         
     result = save.RunModal ();
     if (result == (int)1) {
         string path = save.Url.Path;
         File.WriteAllText (path, data.PublicKey);
     }
 }
Esempio n. 2
0
        public  static void SaveKeyData (KeyPairData data)
        {
            UIErrorHelper.CheckedExec (delegate () {
                
                var save = NSSavePanel.SavePanel;
                save.AllowedFileTypes = new string[] { "key" };
                save.Title = "Save Private Key";
                nint result = save.RunModal ();
                if (result == (int)1) {
                    string path = save.Url.Path;
                    File.WriteAllText (path, data.PrivateKey);
                    UIErrorHelper.ShowAlert ("", "Private Key Saved");
                }

                save.Title = "Save Public Key";
                result = save.RunModal ();
                if (result == (int)1) {
                    string path = save.Url.Path;
                    File.WriteAllText (path, data.PublicKey);
                    UIErrorHelper.ShowAlert ("", "Public Key Saved");
                }
            });
        }
Esempio n. 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);
        }