예제 #1
0
        void buttonSelectAuthorizedCerts_Click(object sender, EventArgs e)
        {
            try
            {
                SafeCertificateStore storeHandle = CertificateManager.GetCertificateStorePointer(machineName);

                SafeCertificateContext prev = new SafeCertificateContext();
                SafeCertificateContext crt  = new SafeCertificateContext();

                X509Certificate2Collection certificateCollection = new X509Certificate2Collection();
                do
                {
#pragma warning suppress 56523
                    crt = SafeNativeMethods.CertFindCertificateInStore(
                        storeHandle,
                        SafeNativeMethods.X509_ASN_ENCODING,
                        0,
                        SafeNativeMethods.CERT_FIND_ANY,
                        IntPtr.Zero,
                        prev);
                    prev = crt;
                    if (!crt.IsInvalid)
                    {
                        certificateCollection.Add(crt.GetNewX509Certificate());
                    }
                } while (!crt.IsInvalid);

                storeHandle.Close();
                prev.Close();
                crt.Close();

                AcceptedCertificatesForm dlg          = new AcceptedCertificatesForm(certificateCollection, config.X509GlobalAcl);
                DialogResult             dialogResult = dlg.ShowDialog(this);

                if (dialogResult == DialogResult.OK)
                {
                    this.config.X509GlobalAcl = dlg.AllowedCertificates;
                    if (this.config.X509GlobalAcl.Length > 0)
                    {
                        Utilities.Log("selected allowed client cert [0]: " + this.config.X509GlobalAcl[0]);
                    }
                    ComponentChanged();
                }
            }
            catch (WsatAdminException ex)
            {
                HandleException(ex);
            }
        }
예제 #2
0
파일: WSATControl.cs 프로젝트: mind0n/hive
        void buttonSelectAuthorizedCerts_Click(object sender, EventArgs e)
        {
            try
            {
                SafeCertificateStore storeHandle = CertificateManager.GetCertificateStorePointer(machineName);

                SafeCertificateContext prev = new SafeCertificateContext();
                SafeCertificateContext crt = new SafeCertificateContext();

                X509Certificate2Collection certificateCollection = new X509Certificate2Collection();
                do
                {
#pragma warning suppress 56523
                    crt = SafeNativeMethods.CertFindCertificateInStore(
                        storeHandle,
                        SafeNativeMethods.X509_ASN_ENCODING,
                        0,
                        SafeNativeMethods.CERT_FIND_ANY,
                        IntPtr.Zero,
                        prev);
                    prev = crt;
                    if (!crt.IsInvalid)
                    {
                        certificateCollection.Add(crt.GetNewX509Certificate());
                    }
                } while (!crt.IsInvalid);

                storeHandle.Close();
                prev.Close();
                crt.Close();

                AcceptedCertificatesForm dlg = new AcceptedCertificatesForm(certificateCollection, config.X509GlobalAcl);
                DialogResult dialogResult = dlg.ShowDialog(this);

                if (dialogResult == DialogResult.OK)
                {
                    this.config.X509GlobalAcl = dlg.AllowedCertificates;
                    if (this.config.X509GlobalAcl.Length > 0)
                    {
                        Utilities.Log("selected allowed client cert [0]: " + this.config.X509GlobalAcl[0]);
                    }
                    ComponentChanged();
                }
            }
            catch (WsatAdminException ex)
            {
                HandleException(ex);
            }
        }