C# 无法使用 TLS1.2 在 Windows 7/Windows Server 上创建 ssl/tls 安全通道

Sim*_*rra 3 c# ssl windows-7 .net-4.5 tls1.2

我知道有很多人问这个问题,但我想我已经阅读了答案和问题很长时间了,但没有任何结果。

我有一个调用 Web 服务的 C# 应用程序。在 Windows 10 上一切正常,但当我在 Windows 7(或 Windows Server 2008 R2 或 Windows Server 2012)上运行该应用程序时,会抛出异常“无法创建 ssl/tls 安全通道”。

我将 TLS1.2 与 .NET Framework 4.5 结合使用(说实话,真正的应用程序是 4.0,我正在使用解决方法来启用 TLS1.2,但我已经使用 4.5 和本机 TLS1 创建了一个测试应用程序。 2管理,仍然有同样的问题:所以它与解决方法无关)。

即使在 Windows7 上,使用 Postman 进行相同的调用也能正常工作。

这是我的代码

    public static LicenseInfoDTO GetLicenseInfo()
    {
        LicenseInfoDTO result = null;

        Uri uri =_myUri;

        try
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
            ServicePointManager.Expect100Continue = true;

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
            request.Accept = "application/json";
            request.Headers.Add("AuthToken", SECURITY_TOKEN);
            request.Method = "GET";

            WebResponse response = request.GetResponse();

            using (StreamReader reader = new StreamReader(response.GetResponseStream()))
            {
                JsonSerializer serializer = new JsonSerializer();
                result = (LicenseInfoDTO)serializer.Deserialize(reader, typeof(LicenseInfoDTO));
            }
        }
        catch (Exception ex)
        {
            logger.Error($"Error calling SEQUAR to get info for license {license}", ex);
        }

        return result;
    }
Run Code Online (Sandbox Code Playgroud)

我已经尝试过在这里找到的“Microsoft EasyFix”(以及网上的许多答案),但没有结果。 https://support.microsoft.com/en-us/help/3140245/update-to-enable-tls-1-1-and-tls-1-2-as-default-secure-protocols-in-wi

我还对我发现的系统注册表进行了几乎所有更改组合。

我要检查密码,但我不太专业,不知道在哪里查找而不随机搜索一些奇怪的东西。

有没有人有一个神奇的解决方案?这让我们发疯。

谢谢你!

编辑:使用 http 而不是 https 它可以工作。

Sim*_*rra 5

最后,我们弄清楚了:.NET Framework 似乎使用 Internet Explorer 密码来保护 https 调用。在 Windows 7 中,IE11 不支持服务器端安装的任何密码:这就是无法创建安全 SSL/TLS 通道的原因。

我们通过添加较旧的密码服务器端解决了这个问题,但我们计划包含 Curl ( https://curl.haxx.se/windows/ ) 以避免使用不安全的密码。

这是漫长的一周,我希望有一天这个自动回复能对那里的人有所帮助。