【发布时间】:2018-06-14 03:08:25
【问题描述】:
我们有 asp.net mvc 使用的 Wcf 服务(核心服务)。该核心服务与其他第三方服务集成以实现一些用例。所有这些第三方服务端点都通过https 公开,但在支持的 SSL/TLS 版本(1.0、1.1、1.2)方面有所不同。
我们对此没有太多控制权,只是在连接任何给定的第三方服务之前粘贴特定的(受支持的)SSL/TLS 版本。即,每当核心服务想要使用任何第三方服务时,它将ServicePointManager.SecurityProtocol 设置为支持的 SSL/TLS 版本(第三方要求我们使用 x.x 或更高版本进行连接)。
// brief expression of logic which switch TLS version 1.2
var currentSecurityProtocol = ServicePointManager.SecurityProtocol; // get the current security protocol.
try
{
ServicePointManager.ServerCertificateValidationCallback += delegate { return true; };
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
//now get/post data to/from third party service
}
catch (Exception ex)
{
//report it
}
finally
{
ServicePointManager.SecurityProtocol = currentSecurityProtocol;
ServicePointManager.ServerCertificateValidationCallback = null;
}
问题:
- 如何重新实现上述TLS版本切换逻辑才能工作 在多线程环境中无缝连接?
我设法编写了通过锁定ServicePointManager.SecurityProtocol 属性来同步访问的逻辑。但是这种尝试会影响其他连接客户端的性能(当他们使用任何其他第三方产品/服务时)
【问题讨论】:
-
多线程不会影响 TLS 的工作方式。
ServicePointManager.SecurityProtocol是一个标志,带有您愿意接受的 TLS 版本。服务器和客户端将协商并选择双方都可接受的最高版本。 -
顺便说一句,您应该至少需要 TLS11。 1.0 不被认为是安全的。您应该考虑要求 TLS12,除非对方有重大理由仅在短时间内降级。航空公司、银行、谷歌等已经需要 TLS1.2
标签: c# asp.net .net asp.net-mvc wcf