简体   繁体   English

强制 .NET 应用程序使用 TLS 1.2 或更高版本

[英]Forcing .NET application to use TLS 1.2 or later

I wonder how to force a .NET application targeting .NET Framework 4.8 to use TLS 1.2 or later (including future TLS versions).我想知道如何强制面向 .NET Framework 4.8 的 .NET 应用程序使用 TLS 1.2 或更高版本(包括未来的 TLS 版本)。

The application execute as a Windows service.应用程序作为 Windows 服务执行。 For >98% of the users, it is correctly using TLS 1.2 but in a couple of cases it tries to use older versions like TLS 1.0 or even SSL 3.0.对于 >98% 的用户,它正确使用 TLS 1.2,但在某些情况下,它会尝试使用旧版本,如 TLS 1.0 甚至 SSL 3.0。 The users who have had issues with it using older TLS versions has been able to resolve it by making registry changes, but telling users to reconfigure settings in Windows registry is a bit risky.使用旧 TLS 版本遇到问题的用户可以通过更改注册表来解决问题,但告诉用户重新配置 Windows 注册表中的设置有点冒险。

I have followed Microsofts recommendation to not hardcoded the application to use a specific TLS version and instead just rely on the OS default ( https://docs.microsoft.com/en-us/dotnet/framework/network-programming/tls ).我已遵循 Microsoft 的建议,不将应用程序硬编码为使用特定的 TLS 版本,而是仅依赖操作系统默认值 ( https://docs.microsoft.com/en-us/dotnet/framework/network-programming/tls )。

So what I wonder is: Is there some way in a .NET application to:所以我想知道的是:.NET 应用程序中有什么方法可以:

  1. Use the Windows default TLS version if it's TLS 1.2 or later.如果是 TLS 1.2 或更高版本,请使用 Windows 默认 TLS 版本。
  2. If the Windows default TLS version is SSL 3.0, TLS 1.0 or TLS 1.1 then use TLS 1.2 or later (including TLS 1.3)如果 Windows 默认 TLS 版本是 SSL 3.0、TLS 1.0 或 TLS 1.1,则使用 TLS 1.2 或更高版本(包括 TLS 1.3)

I know I can hardcode the TLS version using ServicePointManager.SecurityProtocol , but this goes against Microsofts recommendation and if I hardcode it to TLS 1.2 and 1.3, then whenever TLS 1.4 is used and the customers OS is patched to support it, my application will still use TLS 1.3 which I don't want.我知道我可以使用ServicePointManager.SecurityProtocol对 TLS 版本进行硬编码,但这违反了 Microsoft 的建议,如果我将其硬编码为 TLS 1.2 和 1.3,那么每当使用 TLS 1.4 并且客户操作系统被修补以支持它时,我的应用程序仍然会使用我不想要的 TLS 1.3。

What about adding TLS declaration before calling the action在调用操作之前添加 TLS 声明怎么样

public static void UploadFile()
    {
        System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM