示例#1
0
 public void GetCertificateWithGoodAddress(string address)
 {
     var resolver = new DnsCertResolver(IPAddress.Parse(ServerIP)
                                        , TimeSpan.FromSeconds(5)
                                        , "hsgincubator.com"
                                        , false);
     X509Certificate2Collection certs = resolver.GetCertificates(new MailAddress(address));
     Assert.True(certs.Count > 0);
 }
示例#2
0
        private bool ResolveCertInDns(string domain, string outputFile)
        {
            DnsCertResolver resolver = new DnsCertResolver(m_dnsServer, TimeSpan.FromSeconds(5));
            resolver.Error += resolver_Error;

            MailAddress address = null;
            try
            {
                address = new MailAddress(domain);
            }
            catch
            {
            }
            X509Certificate2Collection certs;
            if (address != null)
            {
                Console.WriteLine("Resolving mail address {0} in DNS", domain);
                certs = resolver.GetCertificates(address);
            }
            else
            {
                certs = resolver.GetCertificatesForDomain(domain);
            }

            if (certs.IsNullOrEmpty())
            {
                return false;
            }

            Console.WriteLine("{0} found in DNS", certs.Count);
            foreach (X509Certificate2 cert in certs)
            {
                Console.WriteLine(cert.SubjectName.Name);
            }

            if (!string.IsNullOrEmpty(outputFile))
            {
                byte[] bytes = certs.Export(X509ContentType.Cert);
                File.WriteAllBytes(outputFile, bytes);
            }
            return true;
        }