现在发现 SSL 3 容易受到 POODLE 的攻击攻击:
System.Net.WebRequest 在连接到任何 https Uri 时使用哪个版本的 SSL/TLS?
我使用 WebRequest 连接到多个第 3 方 API。其中之一现在表示他们将阻止任何使用 SSL 3 的请求。但是 WebRequest 是 .Net 核心框架(使用 4.5)的一部分,因此它使用的版本并不明显。
最佳答案
这是一个重要的问题。 SSL 3 协议(protocol) (1996) 被 2014 年发布的 Poodle 攻击彻底破坏。IETF 已发布 "SSLv3 MUST NOT be used" . Web 浏览器正在抛弃它。 Mozilla Firefox和 Google Chrome已经这样做了。
检查浏览器协议(protocol)支持的两个优秀工具是 SSL Lab's client test和 https://www.howsmyssl.com/ .后者不需要 Javascript,因此您可以从 .NET 的 HttpClient 中尝试。 :
// set proxy if you need to
// WebRequest.DefaultWebProxy = new WebProxy("http://localhost:3128");
File.WriteAllText("howsmyssl-httpclient.html", new HttpClient().GetStringAsync("https://www.howsmyssl.com").Result);
// alternative using WebClient for older framework versions
// new WebClient().DownloadFile("https://www.howsmyssl.com/", "howsmyssl-webclient.html");
结果是该死的:
Your client is using TLS 1.0, which is very old, possibly susceptible to the BEAST attack, and doesn't have the best cipher suites available on it. Additions like AES-GCM, and SHA256 to replace MD5-SHA-1 are unavailable to a TLS 1.0 client as well as many more modern cipher suites.
这很令人担忧。它相当于 2006 年的 Internet Explorer 7。
要准确列出 HTTP 客户端支持哪些协议(protocol),您可以尝试以下特定版本的测试服务器:
var test_servers = new Dictionary<string, string>();
test_servers["SSL 2"] = "https://www.ssllabs.com:10200";
test_servers["SSL 3"] = "https://www.ssllabs.com:10300";
test_servers["TLS 1.0"] = "https://www.ssllabs.com:10301";
test_servers["TLS 1.1"] = "https://www.ssllabs.com:10302";
test_servers["TLS 1.2"] = "https://www.ssllabs.com:10303";
var supported = new Func<string, bool>(url =>
{
try { return new HttpClient().GetAsync(url).Result.IsSuccessStatusCode; }
catch { return false; }
});
var supported_protocols = test_servers.Where(server => supported(server.Value));
Console.WriteLine(string.Join(", ", supported_protocols.Select(x => x.Key)));
我使用的是 .NET Framework 4.6.2。我发现 HttpClient 仅支持 SSL 3 和 TLS 1.0。这很令人担忧。这与 2006 年的 Internet Explorer 7 相当。
更新: HttpClient 确实支持 TLS 1.1 和 1.2,但您必须在 System.Net.ServicePointManager.SecurityProtocol
手动打开它们.参见 https://stackoverflow.com/a/26392698/284795
我不知道为什么它使用开箱即用的错误协议(protocol)。这似乎是一个糟糕的设置选择,相当于一个主要的安全漏洞(我敢打赌很多应用程序不会更改默认设置)。我们如何举报?
关于c# - System.Net.WebRequest 支持哪些版本的 SSL/TLS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26414424/