在不更改.NET代码的情况下启用TLS 1.2 [英] Enabling TLS 1.2 without changing code in .NET
问题描述
SmtpClient
发送电子邮件的.NET 4.5.2应用程序。该应用程序安装在Windows 2012 R2服务器上。当我禁用TLS 1和TLS 1.1并仅启用TLS 1.2时,应用程序停止发送邮件。我认为这是因为.NET 4.5.2不支持v1.2。
我正在考虑以下步骤
1&>在Windows服务器上禁用TLS 1和TLS 1.1,并仅启用TLS 1.2。
2在Windows Server上安装.NET 4.8(&>)。
3>;将应用程序的目标框架更改为4.8(在csproj和web.config中),然后重新编译。
4>;部署应用程序。
问题
基于documentationStarting with .NET Framework 4.7.1, WCF defaults to the operating system configured version
1>;这是否仅适用于WCF,或者SMTP是否也将默认为操作系统配置的版本?
2;或者我是否需要将版本设置为显式类似System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
3&>现在是否可以设置TLS 1.2版本,将来TLS 1.3可用时,应用程序是否应自动默认为TLS 1.3?(无需再次更改代码)
推荐答案
这是否仅适用于WCF,或者SMTP是否也将默认为操作系统配置的版本?
否,this applies to all .NET Framework networking APIs that based on SslStream,包括SMTP以及HTTP和FTP。
或者我是否需要明确设置版本,如System.Net.ServicePointManager.SecurityProtocol=SecurityProtocolType.Tls12;
如果将应用编译为.NET 4.7或更高版本,则不需要将值设置为System.Net.ServicePointManager.SecurityProtocol
,因为它将设置为SystemDefault
,这意味着它将从操作系统或从系统管理员执行的任何自定义配置继承默认安全协议。
是否可以立即设置TLS 1.2版本,当将来TLS 1.3可用时,应用程序应自动默认为TLS 1.3?
是,您只需检查System.Net.ServicePointManager.SecurityProtocol
是否设置为非SystemDefault
的其他值(在.NET 4.7+中值为0
(零)),在这种情况下,您可以将其设置为TLS 1.2以覆盖它。
var securityProtocol = (int)System.Net.ServicePointManager.SecurityProtocol;
// 0 = SystemDefault in .NET 4.7+
if (securityProtocol != 0)
{
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
}
这篇关于在不更改.NET代码的情况下启用TLS 1.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!