客户端和服务器无法通信,因为它们没有通用算法 - ASP.NET C# VB Visual Basic IIS TLS

本文关键字:ASP NET 算法 VB TLS IIS Basic Visual 服务器 通信 因为 | 更新日期: 2023-09-27 18:29:00

我在使用 C# PayTrace 网关时遇到问题。下面的代码一直工作正常,直到昨天我相信他们由于贵宾犬漏洞利用而关闭了 SSL3。运行下面的代码时,我们收到以下消息。远程服务器已强制关闭连接。在对这个问题进行了一些研究之后,我们确定因为我们的IIS Server 7.5配置为仍然使用SSL3,C#默认为SSL3,PayTrace会强制关闭连接。然后,我们从服务器中删除了SSL3。然后导致以下错误:

客户端和服务器无法通信,因为它们没有通用算法。

我的猜测是,既然删除了SSL 3,我们需要在服务器上安装其他SSL算法。我们的IT人员声称TLS 1.1和TLS 1.2正在工作,ASP.NET 现在应该默认为它们。但是我觉得我们仍然需要在服务器上安装其他东西,我对SSL算法一无所知,所以我不知道从哪里开始。

var postUrl = new StringBuilder();
//Initialize url with configuration and parameter values...
postUrl.AppendFormat("UN~{0}|", this.MerchantLoginID);
postUrl.AppendFormat("PSWD~{0}|", this.MerchantTransactionKey);
postUrl.Append("TERMS~Y|METHOD~ProcessTranx|TRANXTYPE~Sale|"); 
postUrl.AppendFormat("CC~{0}|", cardNumber);
postUrl.AppendFormat("EXPMNTH~{0}|", expirationMonth.PadLeft(2, '0'));
postUrl.AppendFormat("EXPYR~{0}|", expirationYear);
postUrl.AppendFormat("AMOUNT~{0}|", transactionAmount);
postUrl.AppendFormat("BADDRESS~{0}|", this.AddressLine1);
postUrl.AppendFormat("BADDRESS2~{0}|", this.AddressLine2);
postUrl.AppendFormat("BCITY~{0}|", this.City);
postUrl.AppendFormat("BSTATE~{0}|", this.State);
postUrl.AppendFormat("BZIP~{0}|", this.Zip);
postUrl.AppendFormat("SADDRESS~{0}|", this.AddressLine1);
postUrl.AppendFormat("SADDRESS2~{0}|", this.AddressLine2);
postUrl.AppendFormat("SCITY~{0}|", this.City);
postUrl.AppendFormat("SSTATE~{0}|", this.State);
postUrl.AppendFormat("SZIP~{0}|", this.Zip);
if (!String.IsNullOrEmpty(this.Country))
{
    postUrl.AppendFormat("BCOUNTRY~{0}|", this.Country);
}
if (!String.IsNullOrEmpty(this.Description))
{
    postUrl.AppendFormat("DESCRIPTION~{0}|", this.Description);
}
if (!String.IsNullOrEmpty(this.InvoiceNumber))
{
    postUrl.AppendFormat("INVOICE~{0}|", this.InvoiceNumber);
}
if (this.IsTestMode)
{
    postUrl.AppendFormat("TEST~Y|");
}
//postUrl.Append();
WebClient wClient = new WebClient();
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
String sRequest = "PARMLIST=" + Url.Encode(postUrl.ToString());
wClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
string sResponse = "";
sResponse = wClient.UploadString(PayTraceUrl, sRequest);

此外,仅供参考,当我们连接到First Data E4网关时,也会发生此问题,因此它不仅仅是PayTrace的事情。我的猜测是,随着越来越多的网关关闭对SSL3的访问,我们将继续遇到其他网关的问题,直到可以在服务器上解决此问题。另外,我确实在网上找到了一些建议,有些建议在发出出站请求之前放置以下代码:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;

不幸的是,这也不起作用,同样的错误。这就是为什么我认为需要在IIS7.5服务器上安装其他东西。我只是不确定是什么。

客户端和服务器无法通信,因为它们没有通用算法 - ASP.NET C# VB Visual Basic IIS TLS

现在还有其他几篇关于此的帖子,它们都指向启用TLS 1.2。 任何不足都是不安全的。

您可以在 .NET 3.5 中使用 patch.
执行此操作。可以在 .NET 4.0 和 4.5 中使用一行代码执行此操作

      ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;//.NET 4.5ServicePointManager.SecurityProtocol = (SecurityProtocolType(3072;.NET 4.0
    

在 .NET 4.6 中,它自动使用 TLS 1.2。

有关更多详细信息,请参阅此处:.NET 对 TLS 的支持。

就我而言,即使项目的目标框架是 4.7.1,我仍然收到相同的错误,解决方案是将 system.web 下的 web.config 中的 httpRuntime 更改为 4.7.1!

在之前的回答中,建议对 .Net 4.5 使用以下代码行:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; // .NET 4.5

我鼓励您将该值或到现有值中,如下所示:

ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12; // .NET 4.5

如果您查看值列表,您会注意到它们是 2 的幂。 这样,将来当事情转向TLS 2.0时,您的代码仍然可以工作。

我的应用程序在 .net 4.7.2 中运行。最简单的解决方案是将其添加到配置中:

  <system.web>
    <httpRuntime targetFramework="4.7.2"/>
  </system.web>

有两种可能的情况,在我的情况下,我使用了第二点。

    如果您在生产环境中
  1. 遇到此问题,并且可以轻松地将新代码部署到生产环境中,则可以使用以下解决方案。

    您可以在进行 api 调用之前添加以下代码行,

    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; // .NET 4.5

  2. 如果您无法部署新代码,并且希望使用生产中存在的相同代码来解决,则可以通过更改某些配置设置文件来完成此问题。您可以在配置文件中添加其中任何一个。

<runtime>
    <AppContextSwitchOverrides value="Switch.System.Net.DontEnableSchUseStrongCrypto=false"/>
  </runtime>

<runtime>
  <AppContextSwitchOverrides value="Switch.System.Net.DontEnableSystemDefaultTlsVersions=false"/>
</runtime>

此问题已解决。事实证明,我们的 IT 人员是正确的。TLS 1.1 和 TLS 1.2 都安装在服务器上。但是,问题是我们的网站以 ASP.NET 4.0 运行,您必须拥有 ASP.NET 4.5 才能运行 TLS 1.1 或 TLS 1.2。因此,为了解决这个问题,我们的IT人员必须重新启用TLS 1.0以允许与PayTrace的连接。

简而言之,错误消息"客户端和服务器无法通信,因为它们没有通用算法",这是因为服务器上没有可用的SSL协议与PayTrace的服务器进行通信。

更新:请不要在服务器上启用TLS 1.0,这是一个临时修复程序,不再适用,因为现在有更好的解决方法可以确保强大的安全实践。请参阅接受的解决方案答案。

启用TLS 1.0也解决了我们的问题(在禁用SSL v3之后(。 (服务器 2012 R2 与 ASP.net 4.0 网站处理 PPI 支付服务(。 这是我用来按照我想要的方式设置所有内容的 RegEdit 脚本。 我们只禁用了客户端的SSL v3,而不是服务器,因为这样做破坏了我们尚未准备好处理的其他事情。 将站点升级到 .Net 4.5.2 后,我们将再次禁用 TLS 1.0。

此脚本为客户端启用除 SSL v3 之外的所有协议、服务器和客户端。

请务必备份您的注册表!

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE'SYSTEM'CurrentControlSet'Control'SecurityProviders'SCHANNEL'Protocols'SSL 3.0'Client]
"Enabled"=dword:00000000
[HKEY_LOCAL_MACHINE'SYSTEM'CurrentControlSet'Control'SecurityProviders'SCHANNEL'Protocols'SSL 3.0'Server]
"Enabled"=dword:00000001
[HKEY_LOCAL_MACHINE'SYSTEM'CurrentControlSet'Control'SecurityProviders'SCHANNEL'Protocols'TLS 1.0'Client]
"Enabled"=dword:00000001
[HKEY_LOCAL_MACHINE'SYSTEM'CurrentControlSet'Control'SecurityProviders'SCHANNEL'Protocols'TLS 1.0'Client]
"DisabledByDefault"=dword:00000000
[HKEY_LOCAL_MACHINE'SYSTEM'CurrentControlSet'Control'SecurityProviders'SCHANNEL'Protocols'TLS 1.0'Server]
"Enabled"=dword:00000001
[HKEY_LOCAL_MACHINE'SYSTEM'CurrentControlSet'Control'SecurityProviders'SCHANNEL'Protocols'TLS 1.0'Server]
"DisabledByDefault"=dword:00000000
[HKEY_LOCAL_MACHINE'SYSTEM'CurrentControlSet'Control'SecurityProviders'SCHANNEL'Protocols'TLS 1.1'Client]
"Enabled"=dword:00000001
[HKEY_LOCAL_MACHINE'SYSTEM'CurrentControlSet'Control'SecurityProviders'SCHANNEL'Protocols'TLS 1.1'Client]
"DisabledByDefault"=dword:00000000
[HKEY_LOCAL_MACHINE'SYSTEM'CurrentControlSet'Control'SecurityProviders'SCHANNEL'Protocols'TLS 1.1'Server]
"Enabled"=dword:00000001
[HKEY_LOCAL_MACHINE'SYSTEM'CurrentControlSet'Control'SecurityProviders'SCHANNEL'Protocols'TLS 1.1'Server]
"DisabledByDefault"=dword:00000000
[HKEY_LOCAL_MACHINE'SYSTEM'CurrentControlSet'Control'SecurityProviders'SCHANNEL'Protocols'TLS 1.2'Client]
"Enabled"=dword:00000001
[HKEY_LOCAL_MACHINE'SYSTEM'CurrentControlSet'Control'SecurityProviders'SCHANNEL'Protocols'TLS 1.2'Client]
"DisabledByDefault"=dword:00000000
[HKEY_LOCAL_MACHINE'SYSTEM'CurrentControlSet'Control'SecurityProviders'SCHANNEL'Protocols'TLS 1.2'Server]
"Enabled"=dword:00000001
[HKEY_LOCAL_MACHINE'SYSTEM'CurrentControlSet'Control'SecurityProviders'SCHANNEL'Protocols'TLS 1.2'Server]
"DisabledByDefault"=dword:00000000

就我而言,我通过在.Net框架中启用最后一个TLS版本来解决问题,如本文所述:

https://learn.microsoft.com/dotnet/framework/network-programming/tls

设置以下注册表项:

[HKEY_LOCAL_MACHINE'SOFTWARE'Microsoft'.NETFramework'v4.0.30319] "SystemDefaultTlsVersions"=dword:00000001
[HKEY_LOCAL_MACHINE'SOFTWARE'Wow6432Node'Microsoft'.NETFramework'v4.0.30319] "SystemDefaultTlsVersions"=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

您需要检查与此相关的几件事。

每当抛出与建立安全连接相关的此类错误时,请尝试在 Powershell 中使用计算机名称或 uri(如"www.google.com"(运行如下所示的脚本,以获取每种不同协议类型的结果:

 function Test-SocketSslProtocols {
    
    [CmdletBinding()] 
    param(
        [Parameter(Mandatory=$true)][string]$ComputerName,
        [int]$Port = 443,
        [string[]]$ProtocolNames = $null
        )
    #set results list    
    $ProtocolStatusObjArr = [System.Collections.ArrayList]@()

    if($ProtocolNames -eq $null){
        #if parameter $ProtocolNames empty get system list
        $ProtocolNames = [System.Security.Authentication.SslProtocols] | Get-Member -Static -MemberType Property | Where-Object { $_.Name -notin @("Default", "None") } | ForEach-Object { $_.Name }
    }
 
    foreach($ProtocolName in $ProtocolNames){
        #create and connect socket
        #use default port 443 unless defined otherwise
        #if the port specified is not listening it will throw in error
        #ensure listening port is a tls exposed port
        $Socket = New-Object System.Net.Sockets.Socket([System.Net.Sockets.SocketType]::Stream, [System.Net.Sockets.ProtocolType]::Tcp)
        $Socket.Connect($ComputerName, $Port)
        #initialize default obj
        $ProtocolStatusObj = [PSCustomObject]@{
            Computer = $ComputerName
            Port = $Port 
            ProtocolName = $ProtocolName
            IsActive = $false
            KeySize = $null
            SignatureAlgorithm = $null
            Certificate = $null
        }
        try {
            #create netstream
            $NetStream = New-Object System.Net.Sockets.NetworkStream($Socket, $true)
            #wrap stream in security sslstream
            $SslStream = New-Object System.Net.Security.SslStream($NetStream, $true)
            $SslStream.AuthenticateAsClient($ComputerName, $null, $ProtocolName, $false)
         
            $RemoteCertificate = [System.Security.Cryptography.X509Certificates.X509Certificate2]$SslStream.RemoteCertificate
            $ProtocolStatusObj.IsActive = $true
            $ProtocolStatusObj.KeySize = $RemoteCertificate.PublicKey.Key.KeySize
            $ProtocolStatusObj.SignatureAlgorithm = $RemoteCertificate.SignatureAlgorithm.FriendlyName
            $ProtocolStatusObj.Certificate = $RemoteCertificate
        } 
        catch  {
            $ProtocolStatusObj.IsActive = $false
            Write-Error "Failure to connect to machine $ComputerName using protocol: $ProtocolName."
            Write-Error $_
        }   
        finally {
            
            $SslStream.Close()
        
        }
        [void]$ProtocolStatusObjArr.Add($ProtocolStatusObj)
    }
    Write-Output $ProtocolStatusObjArr
}
Test-SocketSslProtocols -ComputerName "www.google.com"

它将尝试建立套接字连接,并为每次尝试和成功的连接返回完整的对象。

看到返回的内容后,通过 regedit 检查您的计算机注册表(将"regedit"放入运行或查找"注册表编辑器"(,放置

Computer'HKEY_LOCAL_MACHINE'SYSTEM'CurrentControlSet'Control'SecurityProviders'SCHANNEL

,并确保为尝试连接到的任何服务器启用了适当的 TLS 协议(根据从脚本返回的结果(。根据需要进行调整,然后重置计算机(这是必需的(。再次尝试连接 powershell 脚本,看看得到的结果。如果仍然不成功,请确保需要启用的算法、哈希和密码正在缩小需要启用的范围(IISCrypto 是一个很好的应用程序,可以免费获得。它将为您提供在所有这些内容所在的SChannel注册表中启用或禁用的内容的实时视图(。

另请记住您当前安装的 Windows 版本、DotNet 版本和更新,因为尽管在 Windows 10 中默认启用了许多 TLS 选项,但以前的版本需要补丁才能启用该选项。

最后一件事:TLS是一条双向的街道(请记住这一点(,其想法是服务器拥有可用的东西与客户端一样重要。如果服务器仅提供使用某些算法通过TLS 1.2进行连接,则任何客户端都无法连接其他任何内容。此外,如果客户端不会与某个协议或密码套件以外的任何其他内容连接,则连接将不起作用。浏览器也是需要考虑的事情,因为它们在 HTTP2 上强制错误,尽管实际上没有错误(他们抛出它以尝试让人们升级,但注册表设置确实存在以修改此行为(。

在搞砸了几天之后,我对我们的问题的最终修复需要两件事;

1( 我们将这行代码添加到我们所有的 .Net 库中,这些库向其他也禁用了 SSL v3 的供应商发出绑定 api 调用。

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls; // (.Net 4 and below)

2( 这是运行 4.0 站点时需要 ASP.Net 最终和完整的注册表更改,并且在升级到 ASP.Net 4.5 后需要稍作更改。

重新启动服务器后 - 在此之后所有问题都消失了。

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE'SYSTEM'CurrentControlSet'Control'SecurityProviders'SCHANNEL'Protocols'SSL 2.0'Client]
"DisabledByDefault"=dword:00000001
[HKEY_LOCAL_MACHINE'SYSTEM'CurrentControlSet'Control'SecurityProviders'SCHANNEL'Protocols'SSL 2.0'Client]
"Enabled"=dword:00000000
[HKEY_LOCAL_MACHINE'SYSTEM'CurrentControlSet'Control'SecurityProviders'SCHANNEL'Protocols'SSL 2.0'Server]
"DisabledByDefault"=dword:00000001
[HKEY_LOCAL_MACHINE'SYSTEM'CurrentControlSet'Control'SecurityProviders'SCHANNEL'Protocols'SSL 2.0'Server]
"Enabled"=dword:00000000
[HKEY_LOCAL_MACHINE'SYSTEM'CurrentControlSet'Control'SecurityProviders'SCHANNEL'Protocols'SSL 3.0'Client]
"DisabledByDefault"=dword:00000001
[HKEY_LOCAL_MACHINE'SYSTEM'CurrentControlSet'Control'SecurityProviders'SCHANNEL'Protocols'SSL 3.0'Client]
"Enabled"=dword:00000000
[HKEY_LOCAL_MACHINE'SYSTEM'CurrentControlSet'Control'SecurityProviders'SCHANNEL'Protocols'SSL 3.0'Server]
"DisabledByDefault"=dword:00000001
[HKEY_LOCAL_MACHINE'SYSTEM'CurrentControlSet'Control'SecurityProviders'SCHANNEL'Protocols'SSL 3.0'Server]
"Enabled"=dword:00000000
[HKEY_LOCAL_MACHINE'SYSTEM'CurrentControlSet'Control'SecurityProviders'SCHANNEL'Protocols'TLS 1.0'Client]
"Enabled"=dword:00000001
[HKEY_LOCAL_MACHINE'SYSTEM'CurrentControlSet'Control'SecurityProviders'SCHANNEL'Protocols'TLS 1.0'Client]
"DisabledByDefault"=dword:00000000
[HKEY_LOCAL_MACHINE'SYSTEM'CurrentControlSet'Control'SecurityProviders'SCHANNEL'Protocols'TLS 1.0'Server]
"Enabled"=dword:00000001
[HKEY_LOCAL_MACHINE'SYSTEM'CurrentControlSet'Control'SecurityProviders'SCHANNEL'Protocols'TLS 1.0'Server]
"DisabledByDefault"=dword:00000000
[HKEY_LOCAL_MACHINE'SYSTEM'CurrentControlSet'Control'SecurityProviders'SCHANNEL'Protocols'TLS 1.1'Client]
"Enabled"=dword:00000001
[HKEY_LOCAL_MACHINE'SYSTEM'CurrentControlSet'Control'SecurityProviders'SCHANNEL'Protocols'TLS 1.1'Client]
"DisabledByDefault"=dword:00000000
[HKEY_LOCAL_MACHINE'SYSTEM'CurrentControlSet'Control'SecurityProviders'SCHANNEL'Protocols'TLS 1.1'Server]
"Enabled"=dword:00000001
[HKEY_LOCAL_MACHINE'SYSTEM'CurrentControlSet'Control'SecurityProviders'SCHANNEL'Protocols'TLS 1.1'Server]
"DisabledByDefault"=dword:00000000
[HKEY_LOCAL_MACHINE'SYSTEM'CurrentControlSet'Control'SecurityProviders'SCHANNEL'Protocols'TLS 1.2'Client]
"Enabled"=dword:00000001
[HKEY_LOCAL_MACHINE'SYSTEM'CurrentControlSet'Control'SecurityProviders'SCHANNEL'Protocols'TLS 1.2'Client]
"DisabledByDefault"=dword:00000000
[HKEY_LOCAL_MACHINE'SYSTEM'CurrentControlSet'Control'SecurityProviders'SCHANNEL'Protocols'TLS 1.2'Server]
"Enabled"=dword:00000001
[HKEY_LOCAL_MACHINE'SYSTEM'CurrentControlSet'Control'SecurityProviders'SCHANNEL'Protocols'TLS 1.2'Server]
"DisabledByDefault"=dword:00000000

我通过将应用程序从 .Net Framework 4.5 升级到 4.6.2 来修复此错误。

TLS-1.2

已正确安装在服务器上,并且禁用了 TLS-1.1 等旧版本。但是,.Net 4.5 不支持 TLS-1.2。

在以前的答案中,缺少一些可能不存在的注册表项。它们是SchUseStrongCrypto,必须存在才能允许TLS协议正常工作。

注册表项导入注册表后,不应要求对代码进行更改,例如

ServicePointManager.SecurityProtocol = SecurityProtocolType.TLS;

下面是x64 Windows操作系统所需的所有注册表项和值。如果您有 32 位操作系统 (x86(,只需删除最后 2 行。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

> 从Windows Server 2012连接时,我遇到了同样的错误。我通过使用 IIS 加密可执行文件更改 TLS 和 SSL 设置来解决。具体来说,我禁用了服务器协议SSL 3.0和TLS 1.0。我还禁用了客户端协议SSL 3.0(我相信这就是诀窍(。我使用正常工作的服务器作为确定理想设置的基础。屏幕截图 - IIS 加密设置

Microsoft有一个Powershell脚本来解决这个问题(它对我有用(:

红绿灯强制实施

If (-Not (Test-Path 'HKLM:'SOFTWARE'WOW6432Node'Microsoft'.NETFramework'v4.0.30319'))
{
    New-Item 'HKLM:'SOFTWARE'WOW6432Node'Microsoft'.NETFramework'v4.0.30319' -Force | Out-Null
}
New-ItemProperty -Path 'HKLM:'SOFTWARE'WOW6432Node'Microsoft'.NETFramework'v4.0.30319' -Name 'SystemDefaultTlsVersions' -Value '1' -PropertyType 'DWord' -Force | Out-Null
New-ItemProperty -Path 'HKLM:'SOFTWARE'WOW6432Node'Microsoft'.NETFramework'v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -PropertyType 'DWord' -Force | Out-Null
If (-Not (Test-Path 'HKLM:'SOFTWARE'Microsoft'.NETFramework'v4.0.30319'))
{
    New-Item 'HKLM:'SOFTWARE'Microsoft'.NETFramework'v4.0.30319' -Force | Out-Null
}
New-ItemProperty -Path 'HKLM:'SOFTWARE'Microsoft'.NETFramework'v4.0.30319' -Name 'SystemDefaultTlsVersions' -Value '1' -PropertyType 'DWord' -Force | Out-Null
New-ItemProperty -Path 'HKLM:'SOFTWARE'Microsoft'.NETFramework'v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -PropertyType 'DWord' -Force | Out-Null
If (-Not (Test-Path 'HKLM:'SYSTEM'CurrentControlSet'Control'SecurityProviders'SCHANNEL'Protocols'TLS 1.2'Server'))
{
    New-Item 'HKLM:'SYSTEM'CurrentControlSet'Control'SecurityProviders'SCHANNEL'Protocols'TLS 1.2'Server' -Force | Out-Null
}
New-ItemProperty -Path 'HKLM:'SYSTEM'CurrentControlSet'Control'SecurityProviders'SCHANNEL'Protocols'TLS 1.2'Server' -Name 'Enabled' -Value '1' -PropertyType 'DWord' -Force | Out-Null
New-ItemProperty -Path 'HKLM:'SYSTEM'CurrentControlSet'Control'SecurityProviders'SCHANNEL'Protocols'TLS 1.2'Server' -Name 'DisabledByDefault' -Value '0' -PropertyType 'DWord' -Force | Out-Null
If (-Not (Test-Path 'HKLM:'SYSTEM'CurrentControlSet'Control'SecurityProviders'SCHANNEL'Protocols'TLS 1.2'Client'))
{
    New-Item 'HKLM:'SYSTEM'CurrentControlSet'Control'SecurityProviders'SCHANNEL'Protocols'TLS 1.2'Client' -Force | Out-Null
}
New-ItemProperty -Path 'HKLM:'SYSTEM'CurrentControlSet'Control'SecurityProviders'SCHANNEL'Protocols'TLS 1.2'Client' -Name 'Enabled' -Value '1' -PropertyType 'DWord' -Force | Out-Null
New-ItemProperty -Path 'HKLM:'SYSTEM'CurrentControlSet'Control'SecurityProviders'SCHANNEL'Protocols'TLS 1.2'Client' -Name 'DisabledByDefault' -Value '0' -PropertyType 'DWord' -Force | Out-Null
Write-Host 'TLS 1.2 has been enabled. You must restart the Windows Server for the changes to take affect.' -ForegroundColor Cyan

对我来说,命令:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

返回错误:

术语"ServicePointManager.SecurityProtocol"不被识别为名称cmdlet、函数、脚本文件或可操作程序。

而 THIS 命令有效:

[Net.ServicePointManager]::SecurityProtocol = 'tls12'

阅读此线程后,我在管理员模式下使用注册编辑器修复了 Windows 11 中的问题,然后转到:

HKEY_LOCAL_MACHINE''系统''当前控制集''控制''安全提供程序''SCHANNEL''协议''TLS 1.0''

  • 您将找到客户端和服务器文件夹。转到"启用"文件并将值更改为"1"。之后转到"默认禁用"文件并更改为值"0"。

请记住:在两个文件夹中执行相同的操作:CLient 和服务器。