Esempio n. 1
0
        public void CreateTree(X509Chain chain)
        {
            List <String> created = new List <String>();

            //Todos os roots
            X509Certificate cert = null;

            do
            {
                cert = null;
                foreach (X509Certificate c in chain)
                {
                    if ((c.Subject.Common == c.Issuer.Common) && (!created.Exists(p => p == c.Subject.Common)))
                    {
                        cert = c;
                        break;
                    }
                }

                if (cert != null)
                {
                    CreateCA(cert.Subject);
                    created.Add(cert.Subject.Common);
                }
            } while (cert != null);

            //Todos os filhos e netos
            CertificateAuthority ca = null;

            do
            {
                cert = null;
                foreach (X509Certificate c in chain)
                {
                    if ((c.Subject.Common != c.Issuer.Common) && (created.Exists(p => p == c.Issuer.Common)) && (!created.Exists(p => p == c.Subject.Common)))
                    {
                        cert = c;
                        break;
                    }
                }

                if (cert != null)
                {
                    ca         = new CertificateAuthority();
                    ca.CertDir = certDir;
                    ca.LoadOrCreateCA(cert.Issuer);
                    ca.SignCert(cert.Subject);
                    created.Add(cert.Subject.Common);
                }
            } while (cert != null);
        }