private ListViewItem CreateListViewItem(CtfCertificate ctfCertificate, Color color)
        {
            ListViewItem lvi = new ListViewItem();

            lvi.Text = ctfCertificate.EntityId;
            lvi.ForeColor = color;

            lvi.SubItems.Add(ctfCertificate.Type);
            lvi.SubItems.Add(ctfCertificate.KeyUse);
            lvi.SubItems.Add(ctfCertificate.Cert.SubjectName.Name);
            lvi.Tag = ctfCertificate;

            return lvi;
        }
        private void AddInstalledCertificateItem(CtfCertificate ctfCertificate)
        {
            ListViewItem lvi = null;

            if (!string.IsNullOrEmpty(ctfCertificate.EntityId))
            {
                lvi = CreateListViewItem(ctfCertificate, Color.Black);
            }
            else
            {
                lvi = CreateListViewItem(ctfCertificate, Color.Red);
            }

            listInstalledCertificates.Items.Add(lvi);
        }
        private void AddAvailableCertificateItem(CtfCertificate ctfCertificate)
        {
            ListViewItem lvi = CreateListViewItem(ctfCertificate, Color.Black);

            listAvailableCertificates.Items.Add(lvi);
        }
        private void UpdateCertificateDetails(CtfCertificate cert)
        {
            this.subjectTextBox.Text = cert.Cert.Subject;

            this.issuerTextBox.Text = cert.Cert.Issuer;

            this.validTextBox.Text = "From <" + cert.Cert.GetEffectiveDateString() + "> To <" + cert.Cert.GetExpirationDateString() + ">";

            this.serialNumberTextBox.Text = cert.Cert.SerialNumber;

            this.thumbprintTextBox.Text = cert.Cert.Thumbprint;

            this.signatureAlgorithmTextBox.Text = cert.Cert.SignatureAlgorithm.FriendlyName;
        }
 public void ShowCertificateGui(CtfCertificate cert)
 {
     X509Certificate2UI.DisplayCertificate(cert.Cert, this.Handle);
 }
        private List<CtfCertificate> GetAllCtfCertificates(string roleTypeFilter)
        {
            string roleType = RoleTypeFromFilter(roleTypeFilter);

            List<CtfCertificate> certs = new List<CtfCertificate>();

            EntitiesDescriptorType entitiesDescriptor = _entitiesDescriptor;

            bool displayAll = (roleTypeFilter == "Display All");

            foreach (object o in entitiesDescriptor.Items)
            {
                EntityDescriptorType ed = o as EntityDescriptorType;
                if (ed != null)
                {
                    foreach (object obj in ed.Items)
                    {
                        Type type = obj.GetType();

                        string entityType = MapEntityTypeToString(type);

                        RoleDescriptorType rd = obj as RoleDescriptorType;

                        if (rd != null && (displayAll || type.Name == roleType))
                        {
                            foreach (KeyDescriptorType keyDesc in rd.KeyDescriptor)
                            {
                                foreach (object ob in keyDesc.KeyInfo.Items)
                                {
                                    if (ob != null)
                                    {
                                        X509DataType x509 = ob as X509DataType;
                                        if (x509 != null)
                                        {
                                            foreach (object o2 in x509.Items)
                                            {
                                                if (o2 != null)
                                                {
                                                    Type certType = o2.GetType();

                                                    if (certType == typeof(byte[]))
                                                    {
                                                        byte[] bytes = o2 as byte[];

                                                        X509Certificate2 x509Cert = new X509Certificate2(bytes);

                                                        CtfCertificate ctfCert = new CtfCertificate(ed.entityID, keyDesc.use.ToString(), entityType, x509Cert);
                                                        certs.Add(ctfCert);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return certs;
        }