public EnterpriseKey(Uri Uri, String Name, Boolean allowCreateNewServerCert = true) { this.dnsName = Uri.Host; this.name = Name; //A senha dos certificados é o hash da URI da empresa System.Security.Cryptography.SHA1Managed sha = new System.Security.Cryptography.SHA1Managed(); Byte[] hash = sha.ComputeHash(Encoding.UTF8.GetBytes(this.dnsName)); key = BitConverter.ToString(hash).Replace("-", ""); ca = new CertificateAuthority(key); if (allowCreateNewServerCert) { ca.LoadOrCreateCA("IAMServerCertificateRoot.pfx", "IAM Server Certificate Root"); } else { ca.LoadCA("IAMServerCertificateRoot.pfx"); } if (ca.RootCA == null) { throw new Exception("Error loading/creating CA Cert"); } }
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); }