public void AddPrivateKey () { AddPrivateKeyWindowController cwc = new AddPrivateKeyWindowController (); NSApplication.SharedApplication.BeginSheet (cwc.Window, VMCertStoreSnapInEnvironment.Instance.mainWindow, () => { }); nint result = NSApplication.SharedApplication.RunModalForWindow (cwc.Window); try { if (result == (nint)VMIdentityConstants.DIALOGOK) { var dto = cwc.PrivateKeyDTO; string storeName = (string)Tag; string storePass = ""; using (var session = new VecsStoreSession (ServerNode.ServerDTO.VecsClient, storeName, storePass)) { session.AddPrivateKeyEntry (dto.Alias, dto.PrivateKey, dto.Password, dto.Certificate); } UIErrorHelper.ShowAlert ("Private Entity Added", "Info"); ServerNode.UpdateStoreInfo (storeName); NSNotificationCenter.DefaultCenter.PostNotificationName ("ReloadTableView", this); } } catch (Exception e) { UIErrorHelper.ShowAlert (e.Message, "Alert"); } finally { VMCertStoreSnapInEnvironment.Instance.mainWindow.EndSheet (cwc.Window); cwc.Dispose (); } }
public override NSMenu MenuForEvent (NSEvent theEvent) { CGPoint pt = this.ConvertPointFromView (theEvent.LocationInWindow, null); _selectedRow = this.GetRow (pt); NSTableViewDataSource ds = (NSTableViewDataSource)this.DataSource; NSMenu menu = new NSMenu (); if (_selectedRow >= (nint)0) { if (ds is NodesListView) { string data = (ds as NodesListView).Entries [(int)_selectedRow].DisplayName; switch (data) { case "Private Entities": NSMenuItem addPrivateEntity = new NSMenuItem ("Add Private Entity", ((ds as NodesListView).Entries [(int)_selectedRow] as VecsPrivateKeysNode).AddPrivateKeyHandler); menu.AddItem (addPrivateEntity); break; case "Secret Keys": NSMenuItem createCertificate = new NSMenuItem ("Add Secret Key", ((ds as NodesListView).Entries [(int)_selectedRow] as VecsSecretKeysNode).AddSecretKey); menu.AddItem (createCertificate); break; case "Trusted Certs": NSMenuItem createSigningRequest = new NSMenuItem ("Create Certificate", ((ds as NodesListView).Entries [(int)_selectedRow] as VecsTrustedCertsNode).AddCertificate); menu.AddItem (createSigningRequest); break; default: break; } } else if (ds is CertificateDetailsListView) { CertificateDetailsListView lw = ds as CertificateDetailsListView; CertDTO cert = lw.Entries [(int)_selectedRow]; NSMenuItem showCert = new NSMenuItem ("Show Certificate", (object sender, EventArgs e) => CertificateService.DisplayX509Certificate2 (this, cert.Cert)); menu.AddItem (showCert); NSMenuItem deleteEntry = new NSMenuItem ("Delete", (object sender, EventArgs e) => { UIErrorHelper.CheckedExec (delegate() { if (UIErrorHelper.ConfirmDeleteOperation ("Are you sure?") == true) { using (var session = new VecsStoreSession (lw.ServerDto.VecsClient, lw.Store, "")) { session.DeleteCertificate (cert.Alias); } lw.Entries.Remove (cert); UIErrorHelper.ShowAlert ("", "Successfully deleted the entry."); NSNotificationCenter.DefaultCenter.PostNotificationName ("ReloadServerData", this); } }); }); menu.AddItem (deleteEntry); } NSMenu.PopUpContextMenu (menu, theEvent, theEvent.Window.ContentView); } return base.MenuForEvent (theEvent); }
public async void FillServerInfo () { try { var stores = ServerDTO.VecsClient.GetStores (); IsDetailsLoaded = true; StoresInfo.Clear (); foreach (var store in stores) { var storePass = ""; using (var session = new VecsStoreSession (ServerDTO.VecsClient, store, storePass)) { //store add StoresInfo.Add (store, new CertBagItem () { PrivateKeys = session.GetPrivateKeys ().Concat (session.GetEncryptedPrivateKeys ()).ToList (), SecretKeys = session.GetSecretKeys ().ToList (), Certs = session.GetCertificates ().ToList () }); } } CalculateKeyInfo (); } catch (Exception e) { // do nothing in async task. } }
public void AddSecretKey (object sender, EventArgs args) { UIErrorHelper.CheckedExec (delegate() { AddSecretKeyWindowController cwc = new AddSecretKeyWindowController (); NSApplication.SharedApplication.BeginSheet (cwc.Window, VMCertStoreSnapInEnvironment.Instance.mainWindow, () => { }); nint result = NSApplication.SharedApplication.RunModalForWindow (cwc.Window); try { if (result == (nint)VMIdentityConstants.DIALOGOK) { var dto = cwc.SecretKeyDTO; string storeName = (string)Tag; string storePass = ""; using (var session = new VecsStoreSession (ServerNode.ServerDTO.VecsClient, storeName, storePass)) { session.AddSecretKeyEntry (dto.Alias, dto.SecretKey, dto.Password, null); } ServerNode.UpdateStoreInfo (storeName); NSNotificationCenter.DefaultCenter.PostNotificationName ("ReloadTableView", this); } } finally { VMCertStoreSnapInEnvironment.Instance.mainWindow.EndSheet (cwc.Window); cwc.Dispose (); } }); }
public void UpdateStoreInfo (string storename) { UIErrorHelper.CheckedExec (delegate() { if (storename != null) { string storePass = ""; using (var session = new VecsStoreSession (ServerDTO.VecsClient, storename, storePass)) { // update store info if (StoresInfo.ContainsKey (storename)) { StoresInfo [storename] = new CertBagItem () { PrivateKeys = session.GetPrivateKeys ().Concat (session.GetEncryptedPrivateKeys ()).ToList (), SecretKeys = session.GetSecretKeys ().ToList (), Certs = session.GetCertificates ().ToList () }; CalculateKeyInfo (); } else { StoresInfo.Add (storename, new CertBagItem () { PrivateKeys = session.GetPrivateKeys ().Concat (session.GetEncryptedPrivateKeys ()).ToList (), SecretKeys = session.GetSecretKeys ().ToList (), Certs = session.GetCertificates ().ToList () }); NoStores++; } } } }); }