I have a .NET 4.8 application which is a small Excel Add-in (thus running in Office/Excel) which performs HTTP (REST) requests and shows the data in Excel.
On the webserver we reconfigured to only allow TLS 1.2 and suddenly the HTTP Requests do not work anymore with this WebException:
The underlying connection was closed: An unexpected error occurred on a send.
Test-client OSes are Windows 10 and 8 (fully patched). Thus supporting TLS 1.2 according to https://learn.microsoft.com/en-us/dotnet/framework/network-programming/tls : "Supported, and enabled by default."
Executing the following in PowerShell gives:
[Net.ServicePointManager]::SecurityProtocol
SystemDefault
The following registry keys - which are often mentioned in documentation and blogs - are NOT set (they do not exist - also not the WOW6432Node variants):
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319\SystemDefaultTlsVersions
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319\SchUseStrongCrypto
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\WinHttp\DefaultSecureProtocols
Setting HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319\SchUseStrongCrypto=1
"fixes" the problem.
I can also manually enable TLS 1.2 and the problem goes away, but that removes control from the OS back to the application, which does not seem to be the underlying idea of .NET 4.8:
ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12 | SecurityProtocolType.Tls13;
My questions:
- How can I find out what
SystemDefault
evaluates to in .NET. How can I find this? - Why does TLS 1.2 not seem to enabled without setting registry keys?
- My assumption is that TLS 1.2 should be supported with .NET 4.8 without any system modifications (like registry keys) and without any code changes. Is this assumption wrong?
Addition I found these Github .net issues which seem to describe what I experience:
GitHub: Not getting default values on .NET 4.7.2 on Windows 10 (1709)
Unfortunately I have no machines old enough to not have the KB update yet. I may not be asking at the right place here, but is it possible that .NET 4.8 requires registry keys to get proper TLS 1.2 working?
ServicePointManager.SecurityProtocol = SystemDefault
is the default when you are (actually) targeting .Net 4.8, so setting / addingSystemDefaultTlsVersions
is irrelevant. If your app gets the expected results adding and settingSchUseStrongCrypto
, then you're not actually targeting .Net 4.8 (or you think your app is, but a dependency may not), since this Key is not relevant in .Net 4.8. You can useapp.config
to opt-out, otherwise you opt-in by default. Since you're on Windows 10, the default is TLS1.2. TLS13 is not functional (except in Windows Server 2021). – CosimoServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
(not|=
) is only required in Windows 7 / Windows Server 2008 R2 or to enable the Protocol in a debugging section if you use Visual Studio versions prior to 2017 (it's a debugger issue). – CosimoServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12
to my release code. BTW my idea was with the|=
that TLS1.2 gets added to whatever .NET sets. – IndubitabilitySchUseStrongCrypto = 1
in the Registry, then you're not using .Net 4.8: that .Net version has automatic opt-in for this (the Registry key is useless). You can only opt-out. Check your build and the dependencies / libraries / whatever that query HTTPS resources. – Cosimo<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
in myproject.csproj
so that does target 4.8 AFAIK. Can there be anything else that would force a lower version of .NET 4.8 to be targeted or used? – Indubitabilityapp.config
, see whether you have othersku
options there. Anyway, I think you're on the right track now. – Cosimo