Home > Software design >  How do you enable TLS 1.2 on C# for kafka producer/consumer config?
How do you enable TLS 1.2 on C# for kafka producer/consumer config?

Time:02-03

I want to set communication over TLS1.2 in C# in java we do it by setting this property "ssl.enabled.protocols" looking for same functionality in c#

I'm using .Net core 3.1 and OS is linux package : confluent.Kafka version 1.7.0

CodePudding user response:

If you are using some web client or smtp email sender you can add this line before request

System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

CodePudding user response:

Put this somewhere at or near the very beginning of execution:

 System.Net.ServicePointManager.SecurityProtocol =
        SecurityProtocolType.Tls12             
            //  Only if you need them -
            //  | SecurityProtocolType.Tls13
            //  | SecurityProtocolType.Tls11 
            //  | SecurityProtocolType.Tls
        ;

Contrary to the misinformation in some of the comments above and below, it is not always guaranteed that TLS 1.2 will be on in every environment that it's available. Of course this is more of an issue for older OS's and .NET versions, but that doesn't mean TLS 1.2 can't be used - it just means you have to set it up explicitly.

Many sources will tell you this has to be done in the Windows registry in older environments, but you can also enable it through the code above.

See also this thread for additional detail.

Edit - After the OP's clarifying comment, I changed the |= to '=' because they actually want to DISABLE any TLS version besides 1.2.

  • Related