The request was aborted: Could not create SSL/TLS secure channel

后端 未结 30 1750
遇见更好的自我
遇见更好的自我 2020-11-22 01:21

We are unable to connect to an HTTPS server using WebRequest because of this error message:

The request was aborted: Could not create SSL/TLS secur

相关标签:
30条回答
  • 2020-11-22 01:46

    The solution to this, in .NET 4.5 is

    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
    

    If you don’t have .NET 4.5 then use

    ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
    
    0 讨论(0)
  • 2020-11-22 01:46

    The top-voted answer will probably be enough for most people. However, in some circumstances, you could continue getting a "Could not create SSL/TLS secure channel" error even after forcing TLS 1.2. If so, you may want to consult this helpful article for additional troubleshooting steps. To summarize: independent of the TLS/SSL version issue, the client and server must agree on a "cipher suite." During the "handshake" phase of the SSL connection, the client will list its supported cipher-suites for the server to check against its own list. But on some Windows machines, certain common cipher-suites may have been disabled (seemingly due to well-intentioned attempts to limit attack surface), decreasing the possibility of the client & server agreeing on a cipher suite. If they cannot agree, then you may see "fatal alert code 40" in the event viewer and "Could not create SSL/TLS secure channel" in your .NET program.

    The aforementioned article explains how to list all of a machine's potentially-supported cipher suites and enable additional cipher suites through the Windows Registry. To help check which cipher suites are enabled on the client, try visiting this diagnostic page in MSIE. (Using System.Net tracing may give more definitive results.) To check which cipher suites are supported by the server, try this online tool (assuming that the server is Internet-accessible). It should go without saying that Registry edits must be done with caution, especially where networking is involved. (Is your machine a remote-hosted VM? If you were to break networking, would the VM be accessible at all?)

    In my company's case, we enabled several additional "ECDHE_ECDSA" suites via Registry edit, to fix an immediate problem and guard against future problems. But if you cannot (or will not) edit the Registry, then numerous workarounds (not necessarily pretty) come to mind. For example: your .NET program could delegate its SSL traffic to a separate Python program (which may itself work, for the same reason that Chrome requests may succeed where MSIE requests fail on an affected machine).

    0 讨论(0)
  • 2020-11-22 01:46

    In my case, the service account running the application did not have permission to access the private key. Once I gave this permission, the error went away

    1. mmc
    2. certificates
    3. Expand to personal
    4. select cert
    5. right click
    6. All tasks
    7. Manage private keys
    8. Add
    0 讨论(0)
  • 2020-11-22 01:47

    The approach with setting

    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
    

    Seems to be okay, because Tls1.2 is latest version of secure protocol. But I decided to look deeper and answer do we really need to hardcode it.

    Specs: Windows Server 2012R2 x64.

    From the internet there is told that .NetFramework 4.6+ must use Tls1.2 by default. But when I updated my project to 4.6 nothing happened. I have found some info that tells I need manually do some changes to enable Tls1.2 by default

    https://support.microsoft.com/en-in/help/3140245/update-to-enable-tls-1-1-and-tls-1-2-as-default-secure-protocols-in-wi

    But proposed windows update doesnt work for R2 version

    But what helped me is adding 2 values to registry. You can use next PS script so they will be added automatically

    Set-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord
    Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord
    

    That is kind of what I was looking for. But still I cant answer on question why NetFramework 4.6+ doesn't set this ...Protocol value automatically?

    0 讨论(0)
  • 2020-11-22 01:48

    The issue for me was that I was trying to deploy on IIS as a web service, I installed the certificate on the server, but the user that runs IIS didn't have the correct permissions on the certificate.

    How to give ASP.NET access to a private key in a certificate in the certificate store?

    0 讨论(0)
  • 2020-11-22 01:49

    I have struggled with this problem all day.

    When I created a new project with .NET 4.5 I finally got it to work.

    But if I downgraded to 4.0 I got the same problem again, and it was irreversable for that project (even when i tried to upgrade to 4.5 again).

    Strange no other error message but "The request was aborted: Could not create SSL/TLS secure channel." came up for this error

    0 讨论(0)
提交回复
热议问题