繁体   English   中英

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

[英]C# Could not create ssl/tls secure channel on Windows 7/Windows Server, using TLS1.2

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

我有一个 C# 应用程序调用 web 服务。 在 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 的测试应用程序管理,仍然有同样的问题:所以它与解决方法无关)。

与 Postman 的相同调用即使在 Windows7 中也能正常工作。

这是我的代码

    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 它可以工作。

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

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

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

为了让它成功,您需要将 .NET 框架更新到 4.6.2 或更高版本。 下面的链接引用了以下句子:“ NET Framework 4.6.2 and later supports TLS 1.1 and TLS 1.2. ”否则,此补丁将不起作用。

https://learn.microsoft.com/en-us/mem/configmgr/core/plan-design/security/enable-tls-1-2-client

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM