public void CertificateDnsResolve(string[] args) { string domain = args.GetRequiredValue(0); IPAddress server = IPAddress.Parse(args.GetOptionalValue(1, "8.8.8.8")); string fallbackDomain = args.GetOptionalValue(2, null); DnsCertResolver resolver = new DnsCertResolver(server, TimeSpan.FromSeconds(5), fallbackDomain); MailAddress address = null; try { address = new MailAddress(domain); } catch { } X509Certificate2Collection certs; if (address != null) { this.WriteLine("Resolving mail address {0}", domain); certs = resolver.GetCertificates(address); } else { certs = resolver.GetCertificatesForDomain(domain); } Print(certs); }
public void TestD1(string subject) { AgentSettings settings = AgentSettings.Load(TestRealResolversXml); DirectAgent agent = settings.CreateAgent(); ICertificateResolver resolver = agent.PublicCertResolver; Assert.NotNull(resolver); var email = new MailAddress(subject); X509Certificate2Collection certs = resolver.GetCertificates(email); Assert.NotNull(certs); Assert.True(certs.Count == 1); Assert.Equal(subject, certs[0].ExtractEmailNameOrName()); AssertCert(certs[0], true); // // Now prove the standard dns resolver will also return the Address Cert. // resolver = new DnsCertResolver(IPAddress.Parse(Dns_Server)); Assert.NotNull(resolver); certs = resolver.GetCertificates(email); Assert.NotNull(certs); Assert.True(certs.Count == 1); Assert.Equal(subject, certs[0].ExtractEmailNameOrName()); AssertCert(certs[0], true); }
void Validate(ICertificateResolver resolver, string ip, int timeout) { Assert.True(resolver is DnsCertResolver); DnsCertResolver dnsResolver = resolver as DnsCertResolver; Assert.True(dnsResolver.Server.ToString() == ip); Assert.True(dnsResolver.Timeout.TotalMilliseconds == timeout); }
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); }
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); }