【问题标题】:C# Could not create ssl/tls secure channel on Windows 7/Windows Server, using TLS1.2C# 无法使用 TLS1.2 在 Windows 7/Windows Server 上创建 ssl/tls 安全通道
【发布时间】:2020-09-29 18:31:32
【问题描述】:

我知道有很多人在问这个问题,但我想我已经阅读了太久没有结果的答案和问题。

我有一个调用 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;
    }

我已经尝试过使用此处(以及网络上的许多答案)找到的“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 它可以工作。

【问题讨论】:

    标签: c# ssl windows-7 .net-4.5 tls1.2


    【解决方案1】:

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

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

    这是非常漫长的一周,我希望这个自动回答有一天会帮助到那里的人。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-02
      • 2021-03-23
      相关资源
      最近更新 更多