2

我目前正在处理连接到服务器以检索配置文件的代码。这需要通过 HTTPS 以安全的方式进行。我发现当前的实现并不能真正满足这个要求:

HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create("https://www.configserver.com/...");

if (ReloadGlobals.IgnoreSSLErrors) // always true
    httpWebRequest.AuthenticationLevel = AuthenticationLevel.None;

if (m_ReloadConfig.DontCheckSSLCert) // always true
    ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(OnCheckSSLCert);

httpWebesponse = (HttpWebResponse)httpWebRequest.GetResponse();

远程回调是这样实现的:

private static bool OnCheckSSLCert(object sender, System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Security.Cryptography.X509Certificates.X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
    return true;
}

我对 HTTPS 不太了解,但即使我也能看出这没有多大意义,而且看起来像是一种解决方法。所以我需要找到一种方法来以适当的方式实现这一点。

我很感谢每一条建议。

编辑:部分要求:

一旦确定了配置服务器的地址和 URL,对端必须与该 IP 地址建立 HTTPS 连接。如果提供了配置服务器的可选 URL,则证书必须与 [RFC2818] 中描述的 URL 中的域名匹配;否则,证书必须与 [RFC2818] 中描述的覆盖名称匹配。如果 HTTPS 证书通过名称匹配,节点必须获取配置文件的新副本。

4

0 回答 0