private static void CheckCertificateDomain(ConfiguredEndpoint endpoint)
{
bool domainFound = false;
X509Certificate2 serverCertificate = new X509Certificate2(endpoint.Description.ServerCertificate);
// check the certificate domains.
IList<string> domains = Utils.GetDomainsFromCertficate(serverCertificate);
if (domains != null)
{
string hostname = endpoint.EndpointUrl.DnsSafeHost;
if (hostname == "localhost" || hostname == "127.0.0.1")
{
hostname = System.Net.Dns.GetHostName();
}
for (int ii = 0; ii < domains.Count; ii++)
{
if (String.Compare(hostname, domains[ii], StringComparison.InvariantCultureIgnoreCase) == 0)
{
domainFound = true;
break;
}
}
}
if (!domainFound)
{
throw new ServiceResultException(StatusCodes.BadCertificateHostNameInvalid);
}
}