Could not create SSL/TLS secure channel, despite setting ServerCertificateValidationCallback

后端 未结 8 1533
醉酒成梦
醉酒成梦 2020-12-04 17:29

I\'m trying to establish SSL/TLS connection to test server with self-signed certificate. Communication through unsecure channel worked without issues.

相关标签:
8条回答
  • 2020-12-04 17:42

    Just as a follow up for anyone still running into this – I had added the ServicePointManager.SecurityProfile options as noted in the solution:

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

    And yet I continued to get the same “The request was aborted: Could not create SSL/TLS secure channel” error. I was attempting to connect to some older voice servers with HTTPS SOAP API interfaces (i.e. voice mail, IP phone systems etc… installed years ago). These only support SSL3 connections as they were last updated years ago.

    One would think including SSl3 in the list of SecurityProtocols would do the trick here, but it didn’t. The only way I could force the connection was to include ONLY the Ssl3 protocol and no others:

    ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
    

    Then the connection goes through – seems like a bug to me but this didn’t start throwing errors until recently on tools I provide for these servers that have been out there for years – I believe Microsoft has started rolling out system changes that have updated this behavior to force TLS connections unless there is no other alternative.

    Anyway – if you’re still running into this against some old sites/servers, it’s worth giving it a try.

    0 讨论(0)
  • 2020-12-04 17:46

    In my case TLS1_2 was enabled both on client and server but the server was using MD5 while client disabled it. So, test both client and server on http://ssllabs.com or test using openssl/s_client to see what's happening. Also, check the selected cipher using Wireshark.

    0 讨论(0)
  • 2020-12-04 17:47

    You are doing it right with ServerCertificateValidationCallback. This is not the problem you are facing. The problem you are facing is most likely the version of SSL/TLS protocol.

    For example, if your server offers only SSLv3 and TLSv10 and your client needs TLSv12 then you will receive this error message. What you need to do is to make sure that both client and server have a common protocol version supported.

    When I need a client that is able to connect to as many servers as possible (rather than to be as secure as possible) I use this (together with setting the validation callback):

      ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
    
    0 讨论(0)
  • 2020-12-04 17:58

    move this line: ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

    Before this line: HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);

    Original post: KB4344167 security update breaks TLS Code

    0 讨论(0)
  • 2020-12-04 18:01

    TLS 1.0 and 1.1 are now End of Life. A package on our Amazon web server updated, and we started getting this error.

    The answer is above, but you shouldn't use tls or tls11 anymore.

    Specifically for ASP.Net, add this to one of your startup methods.

            public Startup()
            {
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12;
    

    but I'm sure that something like this will work in many other cases.

    0 讨论(0)
  • 2020-12-04 18:02

    We have been solving the same problem just today, and all you need to do is to increase the runtime version of .NET

    4.5.2 didn't work for us with the above problem, while 4.6.1 was OK

    If you need to keep the .NET version, then set

    ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
    
    0 讨论(0)
提交回复
热议问题