簡體   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