コード例 #1
0
        private bool CertRequest(Func <VMCARequest, CertRequestDTO, X509Certificate2> func, VMCAServerDTO serverDTO)
        {
            bool bResult = false;

            MMCActionHelper.CheckedExec(delegate()
            {
                TypeDescriptor.AddAttributes(typeof(PrivateKeyDTO), new EditorAttribute
                                                 (typeof(PrivateKeyEditor), typeof(UITypeEditor)));
                TypeDescriptor.AddAttributes(typeof(PrivateKeyDTO), new CategoryAttribute("Security"));

                var dto           = new CertRequestDTO();
                var frm           = new GenericInputForm("Fill Certificate Request", "Create", dto);
                frm.Icon          = VMCASnapInEnvironment.Instance.GetIconResource(VMCAIconIndex.cert);
                frm.ApplyDelegate = MiscUtilsService.ApproveCertRequestHandler;
                if (!MMCDlgHelper.ShowForm(frm))
                {
                    return;
                }

                var request = new VMCARequest(serverDTO.VMCAClient);
                dto.FillRequest(request);
                var cert = func(request, dto);
                X509Certificate2UI.DisplayCertificate(cert);

                var localCertDTO = new PrivateCertificateDTO
                {
                    Certificate = Convert.ToBase64String(cert.RawData)
                };
                serverDTO.PrivateCertificates.Add(localCertDTO);
                bResult = true;
                VMCASnapInEnvironment.Instance.SaveLocalData();
            });
            return(bResult);
        }
コード例 #2
0
        public override void Refresh()
        {
            ResultNodes.Clear();

            var entriesNode = this.ScopeNode as VecsStoreEntriesNode;
            var dto         = entriesNode.ServerDTO;
            var storeName   = entriesNode.StoreName;
            var storePass   = "";

            MMCActionHelper.CheckedExec(delegate()
            {
                using (var session = new VecsStoreSession(dto.VecsClient, storeName, storePass))
                {
                    var lst = session.GetSecretKeys();
                    if (lst == null)
                    {
                        return;
                    }

                    foreach (var certDTO in lst)
                    {
                        var resultNode = new ResultNode {
                            DisplayName = certDTO.Alias
                        };
                        resultNode.ImageIndex = (int)VMCertStoreImageIndex.SecretKeys;
                        resultNode.Tag        = certDTO;
                        this.ResultNodes.Add(resultNode);
                    }
                }
            });
            this.Sort(0);
            this.DescriptionBarText = this.ResultNodes.Count.ToString();
        }
コード例 #3
0
        protected override void OnDelete(SyncStatus status)
        {
            if (!MMCDlgHelper.ShowConfirm(CommonConstants.GetSelectedDeleteMsg("secret keys", this.SelectedNodes.Count)))
            {
                return;
            }

            base.OnDelete(status);
            var entriesNode = this.ScopeNode as VecsStoreEntriesNode;
            var dto         = entriesNode.ServerDTO;
            var storeName   = entriesNode.StoreName;
            var storePass   = "";

            MMCActionHelper.CheckedExec(delegate()
            {
                using (var session = new VecsStoreSession(dto.VecsClient, storeName, storePass))
                {
                    foreach (ResultNode node in this.SelectedNodes)
                    {
                        var certDTO = node.Tag as Vecs.CertDTO;
                        session.DeleteCertificate(certDTO.Alias);
                    }
                }
            });
            Refresh();
        }
コード例 #4
0
        void FillCache(int itemIndex)
        {
            if (_viewCache.ContainsKey(itemIndex))
            {
                return;
            }

            MMCActionHelper.CheckedExec(delegate
            {
                var list = _context.GetCertificates();
                if (list != null)
                {
                    int i = 0;
                    foreach (var dto in list)
                    {
                        _viewCache[itemIndex + i] = dto;
                        i++;
                        if (i == 40)
                        {
                            break;
                        }
                    }
                    lstCertDetails.VirtualListSize = _viewCache.Count;
                }
            });
        }
コード例 #5
0
        void RevokeCertificate()
        {
            MMCActionHelper.CheckedExec(delegate()
            {
                var cert      = this.SelectedNodes[0].Tag as X509Certificate2;
                var serverDTO = (ScopeNode.Parent as VMCAServerNode).ServerDTO;
                var vmcaCert  = new VMCACertificate(serverDTO.VMCAClient, cert);
                vmcaCert.Revoke();
                ResultNodes.Remove(this.SelectedNodes[0] as ResultNode);
            });
            RefreshList();
            var parent = this.ScopeNode.Parent as VMCAServerNode;

            if (parent != null)
            {
                foreach (var node in parent.Children)
                {
                    var certNode = node as VMCACertsNode;
                    if (certNode != null && (CertificateState)certNode.Tag == CertificateState.Revoked)
                    {
                        certNode.DoRefresh();
                    }
                }
            }
        }
コード例 #6
0
        public void CheckConnectivity()
        {
            bool success = false;

            MMCActionHelper.CheckedExec(delegate()
            {
                var addresses = Dns.GetHostAddresses(ServerDTO.Server);

                using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
                {
                    IAsyncResult result = socket.BeginConnect(addresses[0], 2020, null, null);
                    success             = result.AsyncWaitHandle.WaitOne(3 * 1000, true);
                    if (success)
                    {
                        success = socket.Connected;
                    }
                }
            });
            if (success)
            {
                MMCDlgHelper.ShowMessage("Connection successful");
            }
            else
            {
                MMCDlgHelper.ShowMessage("Could not connect to server");
            }
        }
コード例 #7
0
        void FillNodes(CertificateState filter)
        {
            MMCActionHelper.CheckedExec(delegate()
            {
                this.ResultNodes.Clear();

                var serverDTO = (ScopeNode.Parent as ChildScopeNode).ServerDTO;

                if ((int)filter == -1)
                {
                    if (serverDTO.PrivateCertificates != null)
                    {
                        foreach (var dto in serverDTO.PrivateCertificates)
                        {
                            AddCert(dto.Certificate.GetX509Certificate2FromString());
                        }
                    }
                }
                else
                {
                    using (var context = new VMCAEnumContext(serverDTO.VMCAClient, filter))
                    {
                        foreach (var cert in context.GetCertificates())
                        {
                            AddCert(cert);
                        }
                    }
                }
            });
        }
コード例 #8
0
ファイル: VMCACSRNode.cs プロジェクト: DhanashreeA/lightwave
        public static void CreateSigningRequest(VMCAServerDTO serverDTO)
        {
            MMCActionHelper.CheckedExec(delegate()
            {
                TypeDescriptor.AddAttributes(typeof(PrivateKeyDTO), new EditorAttribute
                                                 (typeof(PrivateKeyEditor), typeof(UITypeEditor)));
                TypeDescriptor.AddAttributes(typeof(PrivateKeyDTO), new CategoryAttribute("Security"));
                var dto           = new CertRequestDTO();
                var frm           = new GenericInputForm("Fill Signing Request", "Create", dto);
                frm.Icon          = VMCASnapInEnvironment.Instance.GetIconResource(VMCAIconIndex.cert);
                frm.ApplyDelegate = MiscUtilsService.ApproveCertRequestHandler;
                if (MMCDlgHelper.ShowForm(frm))
                {
                    using (var request = new VMCARequest(serverDTO.VMCAClient))
                    {
                        dto.FillRequest(request);
                        string csr = request.GetCSR(dto.PrivateKey.ToString());

                        serverDTO.SigningRequests.Add(new SigningRequestDTO {
                            CSR = csr, CreatedDateTime = DateTime.Now
                        });
                        MMCDlgHelper.ShowMessage(csr);
                    }
                }
            });
        }
コード例 #9
0
 void ShowStoreVersion()
 {
     MMCActionHelper.CheckedExec(delegate()
     {
         string version = "1.0.0";
         MMCDlgHelper.ShowMessage(version);
     });
 }
コード例 #10
0
 void ExportSigningRequest()
 {
     MMCActionHelper.CheckedExec(delegate()
     {
         var cert = this.SelectedNodes[0].Tag as SigningRequestDTO;
         MMCMiscUtil.SaveDataToFile(cert.CSR, "Save CSR", MMCUIConstants.CSR_FILTER);
     });
 }
コード例 #11
0
 public void ShowRootCertificate()
 {
     MMCActionHelper.CheckedExec(delegate()
     {
         var cert = ServerDTO.VMCAClient.GetRootCertificate();
         X509Certificate2UI.DisplayCertificate(cert);
     });
 }
コード例 #12
0
 void ExportKeyPair()
 {
     MMCActionHelper.CheckedExec(delegate()
     {
         var keypair     = this.SelectedNodes[0].Tag as KeyPairDTO;
         var keypairData = new KeyPairData(keypair.PublicKey, keypair.PrivateKey);
         Helper.SaveKeyData(keypairData);
     });
 }
コード例 #13
0
 void ShowSigningRequest()
 {
     MMCActionHelper.CheckedExec(delegate()
     {
         var cert = this.SelectedNodes[0].Tag as SigningRequestDTO;
         var frm  = new InfoForm(cert.CSR);
         frm.Icon = VMCASnapInEnvironment.Instance.GetIconResource(VMCAIconIndex.cert);
         this.SnapIn.Console.ShowDialog(frm);
     });
 }
コード例 #14
0
 void ShowCertificateString()
 {
     MMCActionHelper.CheckedExec(delegate()
     {
         var cert = this.SelectedNodes[0].Tag as X509Certificate2;
         var frm  = new InfoForm(VMCACertificate.GetCertificateAsString(cert));
         frm.Icon = VMCASnapInEnvironment.Instance.GetIconResource(VMCAIconIndex.cert);
         MMCDlgHelper.ShowForm(frm);
     });
 }
コード例 #15
0
        void InitData()
        {
            var node = _formView.ScopeNode as VMCACertsNode;
            var dto  = node.ServerDTO;

            MMCActionHelper.CheckedExec(delegate()
            {
                _context = new VMCAEnumContext(dto.VMCAClient, (VMCA.CertificateState)node.Tag);
            });
            RefreshList();
        }
コード例 #16
0
 protected override void OnRefresh(AsyncStatus status)
 {
     base.OnRefresh(status);
     MMCActionHelper.CheckedExec(delegate()
     {
         if (ListView != null)
         {
             ListView.Refresh();
         }
     });
 }
コード例 #17
0
 void ShowCertificateDetails()
 {
     MMCActionHelper.CheckedExec(delegate
     {
         var certDTO = this.SelectedNodes[0].Tag as Vecs.CertDTO;
         if (certDTO.Cert != null)
         {
             X509Certificate2UI.DisplayCertificate(certDTO.Cert);
         }
     });
 }
コード例 #18
0
 void RevokeCertificate()
 {
     MMCActionHelper.CheckedExec(delegate()
     {
         var cert      = this.SelectedNodes[0].Tag as X509Certificate2;
         var serverDTO = (ScopeNode.Parent as VMCAServerNode).ServerDTO;
         var vmcaCert  = new VMCACertificate(serverDTO.VMCAClient, cert);
         vmcaCert.Revoke();
         ResultNodes.Remove(this.SelectedNodes[0] as ResultNode);
     });
 }
コード例 #19
0
        protected override void OnDelete(SyncStatus status)
        {
            if (!MMCDlgHelper.ShowConfirm(CommonConstants.GetDeleteMsg("store", StoreName)))
            {
                return;
            }

            MMCActionHelper.CheckedExec(delegate
            {
                base.OnDelete(status);
                ServerDTO.VecsClient.DeleteStore(StoreName);
                Parent.Children.Remove(this);
            });
        }
コード例 #20
0
 void CreateStore()
 {
     MMCActionHelper.CheckedExec(delegate()
     {
         var frm = new FormVecsCreateCertStore();
         if (MMCDlgHelper.ShowForm(frm))
         {
             var dto = frm.CertStoreDTO;
             ServerDTO.VecsClient.CreateStore(dto.StoreName, dto.Password);
             var node = new VecsStoreNode(ServerDTO, dto.StoreName);
             this.Children.Add(node);
         }
     });
 }
コード例 #21
0
 public void DoLogout()
 {
     MMCActionHelper.CheckedExec(delegate
     {
         if (ServerDTO.IsLoggedIn)
         {
             ServerDTO.Cleanup();
             this.Children.Clear();
             this.ActionsPaneItems.Clear();
             this.ActionsPaneItems.Add(new Microsoft.ManagementConsole.Action("Login",
                                                                              "Login", -1, ACTION_LOGIN));
         }
     });
 }
コード例 #22
0
        bool CreateKeyPair()
        {
            bool bResult = false;

            MMCActionHelper.CheckedExec(delegate()
            {
                var frm = new CreateKeyPairForm();
                if (MMCDlgHelper.ShowForm(frm))
                {
                    ServerDTO.KeyPairs.Add(frm.DTO);
                    bResult = true;
                }
            });
            return(bResult);
        }
コード例 #23
0
        void RefreshStores()
        {
            this.Children.Clear();
            MMCActionHelper.CheckedExec(delegate()
            {
                var client = new Vecs.VecsClient(ServerDTO.Server, ServerDTO.UserName, ServerDTO.Password);
                var stores = client.GetStores();

                foreach (var store in stores)
                {
                    var activeNode = new VecsStoreNode(ServerDTO, store);
                    this.Children.Add(activeNode);
                }
            });
        }
コード例 #24
0
 void AddRootCertificate()
 {
     MMCActionHelper.CheckedExec(delegate()
     {
         var dto = new AddCertificateDTO {
             PrivateKey = new PrivateKeyDTO()
         };
         var frm = new FormAddRootCert(dto);
         if (MMCDlgHelper.ShowForm(frm))
         {
             var cert = File.ReadAllText(dto.Certificate);
             ServerDTO.VMCAClient.AddRootCertificate(cert, "", dto.PrivateKey.ToString());
         }
     });
 }
コード例 #25
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            MMCActionHelper.CheckedExec(delegate()
            {
                var data         = VMCAKeyPair.Create((uint)numKeyLength.Value);
                rdoPaste.Checked = true;

                if (MessageBox.Show("Do you want to save the keys created?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    Helper.SaveKeyData(data);
                }

                txtKeyData.Text = data.PrivateKey;
            });
        }
コード例 #26
0
        bool CreateKeyPair()
        {
            bool bResult = false;

            MMCActionHelper.CheckedExec(delegate()
            {
                var frm = new CreateKeyPairForm();
                if (MMCDlgHelper.ShowForm(frm))
                {
                    ServerDTO.KeyPairs.Add(frm.DTO);
                    bResult = true;
                    VMCASnapInEnvironment.Instance.SaveLocalData();
                }
            });
            return(bResult);
        }
コード例 #27
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            MMCActionHelper.CheckedExec(delegate()
            {
                var keyPair         = VMCAKeyPair.Create((uint)numKeyLength.Value);
                DTO.CreatedDateTime = DateTime.Now;
                DTO.KeyLength       = (int)numKeyLength.Value;
                DTO.PrivateKey      = keyPair.PrivateKey;
                DTO.PublicKey       = keyPair.PublicKey;

                if (MessageBox.Show("Do you want to save the keys created?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    Helper.SaveKeyData(keyPair);
                }
            });
        }
コード例 #28
0
 public async Task DoLogout()
 {
     MMCActionHelper.CheckedExec(delegate()
     {
         if (ServerDTO.IsLoggedIn)
         {
             ServerDTO.Cleanup();
             this.ActionsPaneItems.Clear();
             this.Children.Clear();
             this.ActionsPaneItems.Add(new Microsoft.ManagementConsole.Action("Login",
                                                                              "Login", -1, ACTION_LOGIN));
             this.ActionsPaneItems.Add(new Microsoft.ManagementConsole.Action("Check connectivity",
                                                                              "Check connectivity", -1, ACTION_CHECK_CONNECTIVITY));
         }
     });
 }
コード例 #29
0
        public override void Refresh()
        {
            ResultNodes.Clear();

            var entriesNode = this.ScopeNode as VecsStoreEntriesNode;
            var dto         = entriesNode.ServerDTO;
            var storeName   = entriesNode.StoreName;
            var storePass   = "";

            MMCActionHelper.CheckedExec(delegate()
            {
                using (var session = new VecsStoreSession(dto.VecsClient, storeName, storePass))
                {
                    var lst = session.GetCertificates();
                    if (lst == null)
                    {
                        return;
                    }

                    foreach (var certDTO in lst)
                    {
                        var resultNode = new ResultNode {
                            DisplayName = certDTO.Alias
                        };
                        resultNode.ImageIndex = (int)VMCertStoreImageIndex.TrustedCert;
                        if (certDTO.Cert != null)
                        {
                            resultNode.SubItemDisplayNames.Add(certDTO.Cert.Subject);
                            resultNode.SubItemDisplayNames.Add(certDTO.Cert.Issuer);
                            resultNode.SubItemDisplayNames.Add(certDTO.Cert.NotBefore.ToShortDateString());
                            resultNode.SubItemDisplayNames.Add(certDTO.Cert.NotAfter.ToShortDateString());
                            resultNode.SubItemDisplayNames.Add(certDTO.Cert.GetKeyUsage());
                            resultNode.Tag = certDTO;
                        }

                        this.ResultNodes.Add(resultNode);
                    }
                }
            });
            this.Sort(0);
            this.DescriptionBarText = this.ResultNodes.Count.ToString();
        }
コード例 #30
0
 void AddPrivateKey()
 {
     MMCActionHelper.CheckedExec(delegate()
     {
         var frm = new FormAddPrivateKey();
         if (MMCDlgHelper.ShowForm(frm))
         {
             var dto          = frm.PrivateKeyDTO;
             string storeName = (string)Tag;
             string storePass = "";
             using (var session = new VecsStoreSession(ServerDTO.VecsClient, storeName, storePass))
             {
                 session.AddPrivateKeyEntry(dto.Alias, dto.PrivateKey, dto.Password, dto.Certificate);
             }
             if (ListView != null)
             {
                 ListView.Refresh();
             }
         }
     });
 }