【问题标题】:Enabling TLS 1.2 without changing code in .NET启用 TLS 1.2 而无需更改 .NET 中的代码
【发布时间】:2020-12-10 04:20:04
【问题描述】:

我有 .NET 4.5.2 应用程序,它使用 SmtpClient 发送电子邮件。该应用程序安装在 Windows 2012 R2 服务器上。当我禁用 TLS 1 和 TLS 1.1 并仅启用 TLS 1.2 时,应用程序会停止发送邮件。我认为这是因为 .NET 4.5.2 不支持 v1.2。

我正在考虑以下步骤

1>在 Windows Server 上禁用 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? (无需再次更改代码)

【问题讨论】:

  • 我希望你的应用没有托管在 Azure 应用服务中;如果这样做,您可以轻松导航到您的应用服务 > 设置 > TLS/SSL 设置 > 升级到 TLS 1.2 或首选。理想情况下,最高 TLS 是良好且安全的。

标签: c# .net tls1.2 smtpclient .net-4.8


【解决方案1】:

这仅适用于 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;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-10-31
    • 2016-04-27
    • 2018-12-11
    • 2020-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-03
    相关资源
    最近更新 更多