[英]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服務器上安裝.NET 4.8。
3>將應用程序的目標框架更改為4.8(在csproj和web.config中)並重新編譯。
4>部署應用程序。
問題
基於文檔Starting 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 也默認為操作系統配置版本?
No, this applies to all .NET Framework networking APIs that based on SslStream , which includes SMTP, as well as HTTP and 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;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.