• .NET4.0 加密通讯协议下TLS 的兼容支持问题.


    Study From 

    https://stackoverflow.com/questions/28286086/default-securityprotocol-in-net-4-5

    The default System.Net.ServicePointManager.SecurityProtocol in both .NET 4.0/4.5 is SecurityProtocolType.Tls|SecurityProtocolType.Ssl3.

    .NET 4.0 supports up to TLS 1.0 while .NET 4.5 supports up to TLS 1.2

    However, an application targeting .NET 4.0 can still support up to TLS 1.2 if .NET 4.5 is installed in the same environment. .NET 4.5 installs on top of .NET 4.0, replacing System.dll.

    I've verified this by observing the correct security protocol set in traffic with fiddler4 and by manually setting the enumerated values in a .NET 4.0 project:

    ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 |
    (SecurityProtocolType)768 | (SecurityProtocolType)3072;
    

    Reference:

    namespace System.Net
    {
        [System.Flags]
        public enum SecurityProtocolType
        {
           Ssl3 = 48,
           Tls = 192,
           Tls11 = 768,
           Tls12 = 3072,
        }
    }

    If you attempt the hack on an environment with ONLY .NET 4.0 installed, you will get the exception:

    Unhandled Exception: System.NotSupportedException: The requested security protocol is not supported. at System.Net.ServicePointManager.set_SecurityProtocol(SecurityProtocolType v alue)

    However, I wouldn't recommend this "hack" since a future patch, etc. may break it.*

    Therefore, I've decided the best route to remove support for SSLv3 is to:

    1. Upgrade all applications to .NET 4.5
    2. Add the following to boostrapping code to override the default and future proof it:

      System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

    *Someone correct me if this hack is wrong, but initial tests I see it works

  • 相关阅读:
    C++ assert()断言
    libcurl API:CURLOPT_REFERER的用法
    hdu 2821 Pusher (dfs)
    快速找到跟踪其他session产生的trc文件
    10635
    pat 1055 区间前k个
    闲话Cache:始篇
    闲话缓存:算法概述
    instance 怎么获得自己的 Metadata
    通过 dhcp-agent 访问 Metadata
  • 原文地址:https://www.cnblogs.com/jinanxiaolaohu/p/9677744.html
Copyright © 2020-2023  润新知