C#无法在Windows7Windows服务器上创建ssltls安全通道,使用的是TLS1.2。

问题描述 投票:0回答:1

我知道有很多人在问这个问题,但是我想我看了太长时间的答案和问题都没有结果。

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

我使用.NET Framework 4.5的TLS1.2(说实话,真正的应用程序是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.comen-ushelp3140245update to-enable-tls-1-1 and-tls-1-2 as-default-secure-protocols-in-wi。

我也几乎把我找到的所有系统注册表的修改组合都做过了。

我打算检查密码,但我不是那么专业,不随便搜索一下就知道该去哪里找,不知道有什么奇怪的东西。

有谁有解决这个问题的妙招吗?都快把我们逼疯了。

谢谢大家了

EDIT:用http代替https就可以了。

c# ssl windows-7 .net-4.5 tls1.2
1个回答
0
投票

最后,我们弄明白了:似乎.NET Framework使用Internet Explorer的cyphers来保证https调用的安全。在Windows 7中,IE11不支持任何服务器端安装的cyphers:这就是为什么不能创建安全的SSLTLS通道。

我们解决了这个问题,在服务器端添加了一个较旧的cypher,但我们正计划将Curl (https:/curl.haxx.sewindows。),以避免使用不安全的cyphers。

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

© www.soinside.com 2019 - 2024. All rights reserved.