marcus
marcus

Reputation: 333

SecurityProtocol Tls 1.2 in .NET 2.0

I have an app that is compiled for both .NET 2.0 and 4.5 and they need to use the Tls 1.2 SecurityProtocol to connect to an API. Tls 1.2 is supported in .NET 4.5, but not in .NET 2.0, so I found this trick that apparently made Tls 1.2 work in .NET 2.0:

ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;

The only testing I've done so far is on my machine, which has .NET 4.5 installed on it, so I'm not sure this will really work on a machine that only has .NET 2.0 on it.

So my question is, is the above solution really working in .NET 2.0? And if so, why and how? I'm afraid I'm getting misleading test results on my machine because of the .NET 4.5 version I have installed on it, even if I'm running a .NET 2.0 compiled app.

Upvotes: 3

Views: 5955

Answers (2)

Belitz
Belitz

Reputation: 34

Microsoft Release a patch for TLS 1.2 support in .NET 3.5 (which is .NET 2.0)

Have a look at the follow link: https://support.microsoft.com/en-ca/help/3154519/support-for-tls-system-default-versions-included-in-the--net-framework

The specific registry keys you would need to update are located in the article above. I have ran this on both development and production environments and it works without issue. You'll also need to ensure the default protocols on both client and server are updated as well. The article should have everything you require.

Upvotes: 2

No - as you suspected, it is only working because you have .NET 4.5 installed as well.

Remember that unless you explicitly specify the runtime version in the executable's app.config file, the highest installed version of the Framework will be used. I'm certain that if you force your application to use .NET 2.0 via the config file, it will throw an exception when it runs and encounters the line of code you've highlighted, because 2.0 doesn't have the value 3072 (Tls12) defined in its version of the SecurityProtocolType enum.

Your only option for .NET 2.0 is a third-party library that supports TLS 1.2, although I am more curious as to why you cannot just upgrade the application to .NET 4.5 or higher.

Upvotes: 2

Related Questions