Default SecurityProtocol in .NET 4.5

前端 未结 17 1945
一生所求
一生所求 2020-11-22 03:24

What is the default security protocol for communicating with servers that support up to TLS 1.2? Will .NET by default, choose the highest security

17条回答
  •  佛祖请我去吃肉
    2020-11-22 04:18

    I got the problem when my customer upgraded TLS from 1.0 to 1.2. My application is using .net framework 3.5 and run on server. So i fixed it by this way:

    1. Fix the program

    Before call HttpWebRequest.GetResponse() add this command:

    ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolTypeExtensions.Tls11 | SecurityProtocolTypeExtensions.Tls12;
    

    Extensions 2 DLLs by adding 2 new classes: System.Net and System.Security.Authentication

        namespace System.Net
        {
            using System.Security.Authentication;
            public static class SecurityProtocolTypeExtensions
            {
                public const SecurityProtocolType Tls12 = (SecurityProtocolType)SslProtocolsExtensions.Tls12;
                public const SecurityProtocolType Tls11 = (SecurityProtocolType)SslProtocolsExtensions.Tls11;
                public const SecurityProtocolType SystemDefault = (SecurityProtocolType)0;
            }
        } 
    
        namespace System.Security.Authentication
        {
            public static class SslProtocolsExtensions
            {
                public const SslProtocols Tls12 = (SslProtocols)0x00000C00;
                public const SslProtocols Tls11 = (SslProtocols)0x00000300;
            }
        } 
    
    1. Update Microsoft batch

    Download batch:

    • For windows 2008 R2: windows6.1-kb3154518-x64.msu
    • For windows 2012 R2: windows8.1-kb3154520-x64.msu

    For download batch and more details you can see here:

    https://support.microsoft.com/en-us/help/3154518/support-for-tls-system-default-versions-included-in-the-.net-framework-3.5.1-on-windows-7-sp1-and-server-2008-r2-sp1

提交回复
热议问题