.Net Framework 4.6.1不默认为TLS 1.2

时间:2017-05-09 14:29:20

标签: .net ssl tls1.2 .net-4.6.1

我们的客户最近将安全协议升级到TLS 1.2。因此,我们将应用程序升级到4.6.1,期望安全协议将默认为TLS 1.2,但事实并非如此。知道为什么吗?

11 个答案:

答案 0 :(得分:38)

我遇到了类似的问题,这对我有用。

  1. 使用 <?php include("guestlist.php"); include("guestlist_connect.php"); ?> /*invites.HTML*/ <h2 >Invites & Guest List</h2> <table border="2"> <thead> <tr> <th>First Name</th> <th>Last Name</th> <th>Contact</th> <th>Invitation</th> </tr> </thead> <tbody> <?php $result = mysql_query("SELECT * FROM guestlist"); while( $row = mysql_fetch_assoc( $result ) ){ ?> <tr> <td><? php echo $row["fname"]; ?></td> <td><? php echo $row["lname"]; ?></td> <td><? php echo $row["email"]; ?></td> <td><? php echo $row["contact"]; ?></td> </tr> <?php } ?> // you forgot to end a while loop </tbody> </table> <?php mysql_close($connector); ?> </div><!--End Rightcontainer--> </div>

  2. 打开Powershell并检查支持的协议
  3. 运行以下2个cmdlet以设置.NET Framework strong cryptography registry keys

    在64位.Net Framework(版本4及更高版本)上设置强加密

    [Net.ServicePointManager]::SecurityProtocol

    在32位.Net Framework(版本4及更高版本)上设置强加密

    Set-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord

  4. 重新启动Powershell并使用Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord再次检查支持的协议

  5. 它现在也应该显示[Net.ServicePointManager]::SecurityProtocol

    希望这有帮助

答案 1 :(得分:16)

正如其他人所提到的,必须设置许多Windows注册表项才能在现有.NET应用程序中启用TLS 1.2,而无需在应用程序代码中明确设置协议版本。

为了默认生成.NET 4.x code select the strongest available protocol(即在代码中未明确指定协议时),需要以下注册表项:

在32位和64位版本的Windows上library(dplyr) x %>% group_by(grp = cumsum(lag(lead(from, default = last(from)) != as.character(to), default = TRUE))) %>% mutate(to = last(to)) %>% ungroup %>% select(-grp) # A tibble: 4 x 2 # from to # <fctr> <fctr> #1 A D #2 B D #3 C D #4 E E

在64位版本的Windows上HKLM\SOFTWARE\Microsoft\.NETFramework\4.0.30319\SchUseStrongCrypto: 0X00000001

在64位系统上运行时,在32位应用程序中启用TLS 1.2需要WOW6432Node值。

但这是快速简便的解决方案: https://github.com/TheLevelUp/pos-tls-patcher

更新

如果你的目标是.NET 4.6或4.7,你会对Transport Layer Security (TLS) best practices with the .NET Framework感兴趣。

请注意,上面链接的TLS Patcher非常符合Microsoft对现有.NET 4.0和4.5应用程序无法定位.NET 4.6或更高版本的建议。

答案 2 :(得分:15)

安全协议未默认为TLS 1.2的原因是因为.NET Framework 4.6.1中没有此默认值。很抱歉,如果这是重复已经说过的内容,但我想详细说明,我没有足够的声誉来发表评论。

4.6.2中也没有默认值,但是像上面提到的一个评论者一样,控制台应用程序似乎默认为TLS 1.2。我在针对4.6.2的网站项目中尝试了完全相同的代码,并且它没有默认为TLS 1.2。

4.7及更高版本的默认值为SecurityProtocolType.SystemDefault。

“这允许基于SslStream的.NET Framework网络API(例如FTP,HTTP和SMTP)从操作系统或系统管理员执行的任何自定义配置继承默认安全协议”

https://docs.microsoft.com/en-us/dotnet/api/system.net.servicepointmanager.securityprotocol?view=netframework-4.7#System_Net_ServicePointManager_SecurityProtocol

答案 3 :(得分:5)

  

MSDN:ServicePointManager.SecurityProtocol Property

     

此属性选择安全套接字层(SSL)的版本或   用于新连接的传输层安全性(TLS)协议   仅使用安全超文本传输​​协议(HTTPS)方案;   现有连接不会更改。 请注意,没有默认值   有意为此物业列出。

     

安全格局不断变化,默认协议和   保护水平随时间而变化,以避免已知   弱点。默认值因个别机器而异   配置,以及安装了哪些软件,以及在哪些软件上安装   补丁已被应用。

取自here

答案 4 :(得分:3)

我也遇到了问题。当本地应用程序尝试连接到支持TLS 1.1和TLS 1.2的服务器时,它曾经获取“远程主机强行关闭了现有连接”异常 或未正确启用TLS 1.1 / 1.2时,它会获得“ Win32Exception:客户端和服务器无法通信,因为它们不具有通用算法”

下面是x64 Windows OS所需的所有注册表项和值。 如果您使用的是32位操作系统(x86),则只需删除最后两行。 注册表脚本将禁用TLS 1.0。 需要重启操作系统。

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols]

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\SSL 2.0]

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\SSL 2.0\Client]
"DisabledByDefault"=dword:00000001
"enabled"=dword:00000000

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\SSL 2.0\server]
"disabledbydefault"=dword:00000001
"enabled"=dword:00000000

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\ssl 3.0]

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\ssl 3.0\client]
"disabledbydefault"=dword:00000001
"enabled"=dword:00000000

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\ssl 3.0\server]
"disabledbydefault"=dword:00000001
"enabled"=dword:00000000

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\tls 1.0]

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\tls 1.0\client]
"disabledbydefault"=dword:00000001
"enabled"=dword:00000000

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\tls 1.0\server]
"disabledbydefault"=dword:00000001
"enabled"=dword:00000000

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\tls 1.1]

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\tls 1.1\client]
"disabledbydefault"=dword:00000000
"enabled"=dword:00000001

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\tls 1.1\server]
"disabledbydefault"=dword:00000000
"enabled"=dword:00000001

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\tls 1.2]

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\tls 1.2\client]
"disabledbydefault"=dword:00000000
"enabled"=dword:00000001

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\tls 1.2\server]
"disabledbydefault"=dword:00000000
"enabled"=dword:00000001

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319]
"SchUseStrongCrypto"=dword:00000001

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\v4.0.30319]
"SchUseStrongCrypto"=dword:00000001

答案 5 :(得分:2)

基于以下链接

https://docs.microsoft.com/en-us/dotnet/framework/network-programming/tls

我添加了

AppContext.SetSwitch("Switch.System.Net.DontEnableSystemDefaultTlsVersions", false);

我的代码,这为我解决了这个问题。默认情况下,这意味着操作系统支持的最高级别,这与默认情况下从4.7及更高版本获得的行为相同。

答案 6 :(得分:1)

我执行了以下步骤以使用最新的安全协议TLS v.1.2:

在注册表中禁用旧协议SSL2.0,SSL3.0,TLS1.0,TLS1.1,启用TLS1.2并为.NET Framework启用强加密。

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\SSL 2.0\Server]
"DisabledByDefault"=dword:00000001
"Enabled"=dword:00000000

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\SSL 2.0\Client]
"DisabledByDefault"=dword:00000001
"Enabled"=dword:00000000

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\SSL 3.0\Server]
"DisabledByDefault"=dword:00000001
"Enabled"=dword:00000000

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\SSL 3.0\Client]
"DisabledByDefault"=dword:00000001
"Enabled"=dword:00000000

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.0\Server]
"DisabledByDefault"=dword:00000001
"Enabled"=dword:00000000

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.0\Client]
"DisabledByDefault"=dword:00000001
"Enabled"=dword:00000000

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.1\Server]
"DisabledByDefault"=dword:00000001
"Enabled"=dword:00000000

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.1\Client]
"DisabledByDefault"=dword:00000001
"Enabled"=dword:00000000

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Server]
"DisabledByDefault"=dword:00000000
"Enabled"=dword:00000001

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client]
"DisabledByDefault"=dword:00000000
"Enabled"=dword:00000001

[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\.NETFramework\v4.0.30319]
"SystemDefaultTlsVersions"=dword:00000001
"SchUseStrongCrypto"=dword:00000001

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319]
"SystemDefaultTlsVersions"=dword:00000001
"SchUseStrongCrypto"=dword:00000001

答案 7 :(得分:0)

我在初始页面的代码中使用了这个。该应用程序是使用.NET Framework 4.6.1的VB.NET中的Web表单

System.Net.ServicePointManager.SecurityProtocol =  System.Net.SecurityProtocolType.Tls12

答案 8 :(得分:0)

在IIS中托管.NET 4.6.2应用程序时,我们遇到了类似的问题。

我们可以通过向Web.config中添加httpRuntime元素来解决该问题。没有它,我们的服务不会默认为TLS 1.2。

<httpRuntime targetFramework="4.6.2" />

有关更多信息,请参见https://docs.microsoft.com/en-us/dotnet/api/system.web.configuration.httpruntimesection?view=netframework-4.7.2

答案 9 :(得分:0)

我在我的api中尝试了以下代码,该代码不适用于Kaltura帐户集成(因为将Kaltura API升级为TLS 1.2),然后它开始工作。 .net框架为4.5.2,服务器为Windows Server 2008 R2,托管应用程序。

#region To handle TLS (Transport Layer Security) Version and support
            var assembly = Assembly.GetExecutingAssembly();
            var attributes = assembly.GetCustomAttributes(typeof(TargetFrameworkAttribute), false);
            var version = (TargetFrameworkAttribute)attributes[0];

            SecurityProtocolType flag;
            if (Enum.TryParse("Tls11", out flag))
                ServicePointManager.SecurityProtocol |= flag;
            if (Enum.TryParse("Tls12", out flag))
                ServicePointManager.SecurityProtocol |= flag;
#endregion

谢谢。

答案 10 :(得分:0)