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

我有一个C#PayTrace网关的问题。 下面的代码工作正常,直到昨天我认为由于Poodle Exploit而关闭了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); 

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

 ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls; 

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

现在有几个关于此的post,它们都指向启用TLS 1.2。 少一点是不安全的。

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

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

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

有关更多详细信息,请参见此处: .NET支持TLS

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

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

-Eric Niemiec

(务必备份您的注册表!!)

 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 4.5的这行代码:

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

我会鼓励你把这个值或者任何现有的值都这样:

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

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

就我而言,即使Project的Project Framework为4.7.1,我仍然得到相同的错误,解决方案是将system.web下的web.config中的httpRuntime更改为4.7.1!

经过几天的捣乱,我对问题的最终解决需要两件事;

1)我们将这行代码添加到我们的所有.Net库中,这些库对已禁用SSL v3的其他供应商进行绑定api调用。

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

2)这是运行ASP.Net 4.0站点时需要的最终和完整的注册表更改,并且在升级到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 

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

将注册表项导入注册表后,不应要求在代码中进行更改

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;

下面是x64 windows OS所需的所有注册表项和值。 如果你有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