MichaCo / CacheManager

CacheManager is an open source caching abstraction layer for .NET written in C#. It supports various cache providers and implements many advanced features.
http://cachemanager.michaco.net
Apache License 2.0
2.33k stars 456 forks source link

Redis sslprotocols=tls12 support #318

Open code-junky opened 3 years ago

code-junky commented 3 years ago

Azure Redis has deprecated TLS 1.0 and 1.1 and will retire these protocols in the near future. According to Microsoft, StackExchange.Redis users need to add sslprotocols=tls12 to their connection string to support TLS 1.2.

Unfortunately, this doesn't seem to work for CacheManager. When adding this option to our connection string, it throws back an error with the same connection string but excludes this option. It seems like CacheManager reconstructs the string internally and doesn't support this particular option.

Here's the code we use to create the CacheManager instance:

CacheFactory.Build<string>(settings =>
    settings.WithUpdateMode(CacheUpdateMode.Up)
        .WithRedisConfiguration("redis", connectionString, redisDatabaseId)
        .WithRedisCacheHandle("redis", false)
);

Here's the redis connection string: myrediscacheurl.net:6380,password=myredisaccesskey,ssl=True,abortConnect=False,sslprotocols=tls12

Here's the error we're getting: Connection to 'myrediscacheurl.net:6380,password=****,ssl=True,abortConnect=False' failed.

Notice that the error excludes the sslprotocols=tls12 portion of the connection string? Has anyone else encountered this? Is there a known fix?

MichaCo commented 3 years ago

Yeah that looks like something I'd have to add to the configuration part of the Redis client.

The only work around right now would be to initializing the multiplexer yourself and pass the instance to CacheManager (there is an option to do that)

jkatsiotis commented 3 years ago

Redis .NET clients use the earliest TLS version by default on .NET Framework 4.5.2 or earlier, and use the latest TLS version on .NET Framework 4.6 or later. If you're using an older version of .NET Framework, you can enable TLS 1.2 manually

[source]

So I guess if you are using .NET 4.6 and above it should work without changing the connection string