From f8d462ead7ee98425aa6543be524e9499f456fd0 Mon Sep 17 00:00:00 2001 From: Claudia Murialdo Date: Thu, 30 May 2024 10:41:07 -0300 Subject: [PATCH 1/4] Support memcached and redis encrypted password. --- .../Providers/Cache/GxMemcached/GxMemcached.cs | 17 ++++++++++++++++- .../Providers/Cache/GxRedis/GxRedis.cs | 5 +++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/dotnet/src/dotnetframework/Providers/Cache/GxMemcached/GxMemcached.cs b/dotnet/src/dotnetframework/Providers/Cache/GxMemcached/GxMemcached.cs index 917758d7e..be53748a0 100644 --- a/dotnet/src/dotnetframework/Providers/Cache/GxMemcached/GxMemcached.cs +++ b/dotnet/src/dotnetframework/Providers/Cache/GxMemcached/GxMemcached.cs @@ -7,6 +7,7 @@ using Enyim.Caching; using Enyim.Caching.Configuration; using Enyim.Caching.Memcached; +using GeneXus.Encryption; using GeneXus.Services; using GeneXus.Utils; @@ -26,13 +27,21 @@ public Memcached() MemcachedClient InitCache() { GXServices services = ServiceFactory.GetGXServices(); - String address = string.Empty; + string address = string.Empty; + string password = string.Empty; + string username = string.Empty; if (services != null) { GXService providerService = ServiceFactory.GetGXServices()?.Get(GXServices.CACHE_SERVICE); if (providerService != null) { address = providerService.Properties.Get("CACHE_PROVIDER_ADDRESS"); + username = providerService.Properties.Get("CACHE_PROVIDER_USER"); + password = providerService.Properties.Get("CACHE_PROVIDER_PASSWORD"); + if (!string.IsNullOrEmpty(password)) + { + password = CryptoImpl.Decrypt(password); + } } } @@ -42,6 +51,12 @@ MemcachedClient InitCache() #else MemcachedClientConfiguration config = new MemcachedClientConfiguration(); #endif + if (!String.IsNullOrEmpty(username) || !String.IsNullOrEmpty(password)) + { + config.Authentication.Type = typeof(PlainTextAuthenticator); + config.Authentication.Parameters["userName"] = username; + config.Authentication.Parameters["password"] = password; + } if (!String.IsNullOrEmpty(address)) { foreach (string host in address.Split(',', ';', ' ')) { diff --git a/dotnet/src/dotnetframework/Providers/Cache/GxRedis/GxRedis.cs b/dotnet/src/dotnetframework/Providers/Cache/GxRedis/GxRedis.cs index 7007d736a..aa6ac89a3 100644 --- a/dotnet/src/dotnetframework/Providers/Cache/GxRedis/GxRedis.cs +++ b/dotnet/src/dotnetframework/Providers/Cache/GxRedis/GxRedis.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Text.Json; using System.Threading.Tasks; +using GeneXus.Encryption; using GeneXus.Services; using GeneXus.Utils; using StackExchange.Redis; @@ -38,6 +39,10 @@ public Redis() string address, password; address = providerService.Properties.Get("CACHE_PROVIDER_ADDRESS"); password = providerService.Properties.Get("CACHE_PROVIDER_PASSWORD"); + if (!string.IsNullOrEmpty(password)) + { + password = CryptoImpl.Decrypt(password); + } if (string.IsNullOrEmpty(address)) address = String.Format("localhost:{0}", REDIS_DEFAULT_PORT); From c0e57184605993cdbca795058e27478923c0bf6d Mon Sep 17 00:00:00 2001 From: Claudia Murialdo Date: Tue, 4 Jun 2024 10:49:54 -0300 Subject: [PATCH 2/4] Configure the Memcached client with the appropriate user and password for authentication --- .../Providers/Cache/GxMemcached/GxMemcached.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/dotnet/src/dotnetframework/Providers/Cache/GxMemcached/GxMemcached.cs b/dotnet/src/dotnetframework/Providers/Cache/GxMemcached/GxMemcached.cs index be53748a0..95c18263c 100644 --- a/dotnet/src/dotnetframework/Providers/Cache/GxMemcached/GxMemcached.cs +++ b/dotnet/src/dotnetframework/Providers/Cache/GxMemcached/GxMemcached.cs @@ -47,16 +47,16 @@ MemcachedClient InitCache() #if NETCORE var loggerFactory = new Microsoft.Extensions.Logging.Abstractions.NullLoggerFactory(); - MemcachedClientConfiguration config = new MemcachedClientConfiguration(loggerFactory, new MemcachedClientOptions()); -#else - MemcachedClientConfiguration config = new MemcachedClientConfiguration(); -#endif + MemcachedClientOptions options = new MemcachedClientOptions(); if (!String.IsNullOrEmpty(username) || !String.IsNullOrEmpty(password)) { - config.Authentication.Type = typeof(PlainTextAuthenticator); - config.Authentication.Parameters["userName"] = username; - config.Authentication.Parameters["password"] = password; + options.AddPlainTextAuthenticator(string.Empty, username, password); } + MemcachedClientConfiguration config = new MemcachedClientConfiguration(loggerFactory, options); +#else + + MemcachedClientConfiguration config = new MemcachedClientConfiguration(); +#endif if (!String.IsNullOrEmpty(address)) { foreach (string host in address.Split(',', ';', ' ')) { From 3692a9defa31ca6d3301ae40af76a6b99fed29cb Mon Sep 17 00:00:00 2001 From: Claudia Murialdo Date: Tue, 4 Jun 2024 12:17:06 -0300 Subject: [PATCH 3/4] Set missing zone for Memcached. --- .../Providers/Cache/GxMemcached/GxMemcached.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/dotnet/src/dotnetframework/Providers/Cache/GxMemcached/GxMemcached.cs b/dotnet/src/dotnetframework/Providers/Cache/GxMemcached/GxMemcached.cs index 95c18263c..2be5abbd5 100644 --- a/dotnet/src/dotnetframework/Providers/Cache/GxMemcached/GxMemcached.cs +++ b/dotnet/src/dotnetframework/Providers/Cache/GxMemcached/GxMemcached.cs @@ -56,6 +56,13 @@ MemcachedClient InitCache() #else MemcachedClientConfiguration config = new MemcachedClientConfiguration(); + if (!String.IsNullOrEmpty(username) || !String.IsNullOrEmpty(password)) + { + config.Authentication.Type = typeof(PlainTextAuthenticator); + config.Authentication.Parameters["userName"] = username; + config.Authentication.Parameters["password"] = password; + config.Authentication.Parameters["zone"] = string.Empty; + } #endif if (!String.IsNullOrEmpty(address)) { From b869611ba1fb2b01117d2305f26b9e0c1da3d04f Mon Sep 17 00:00:00 2001 From: Claudia Murialdo Date: Tue, 11 Jun 2024 13:24:59 -0300 Subject: [PATCH 4/4] Compatibility fix: Support encrypted and decrypted password at CloudServices.config for memcached and redis. --- .../Providers/Cache/GxMemcached/GxMemcached.cs | 7 +++++-- .../src/dotnetframework/Providers/Cache/GxRedis/GxRedis.cs | 6 +++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/dotnet/src/dotnetframework/Providers/Cache/GxMemcached/GxMemcached.cs b/dotnet/src/dotnetframework/Providers/Cache/GxMemcached/GxMemcached.cs index 2be5abbd5..8ee0e92bd 100644 --- a/dotnet/src/dotnetframework/Providers/Cache/GxMemcached/GxMemcached.cs +++ b/dotnet/src/dotnetframework/Providers/Cache/GxMemcached/GxMemcached.cs @@ -3,7 +3,6 @@ using System.Linq; using System.Security; using System.Text.Json; -using System.Text.Json.Serialization; using Enyim.Caching; using Enyim.Caching.Configuration; using Enyim.Caching.Memcached; @@ -40,7 +39,11 @@ MemcachedClient InitCache() password = providerService.Properties.Get("CACHE_PROVIDER_PASSWORD"); if (!string.IsNullOrEmpty(password)) { - password = CryptoImpl.Decrypt(password); + string ret = string.Empty; + if (CryptoImpl.Decrypt(ref ret, password)) + { + password = ret; + } } } } diff --git a/dotnet/src/dotnetframework/Providers/Cache/GxRedis/GxRedis.cs b/dotnet/src/dotnetframework/Providers/Cache/GxRedis/GxRedis.cs index aa6ac89a3..d8724d849 100644 --- a/dotnet/src/dotnetframework/Providers/Cache/GxRedis/GxRedis.cs +++ b/dotnet/src/dotnetframework/Providers/Cache/GxRedis/GxRedis.cs @@ -41,7 +41,11 @@ public Redis() password = providerService.Properties.Get("CACHE_PROVIDER_PASSWORD"); if (!string.IsNullOrEmpty(password)) { - password = CryptoImpl.Decrypt(password); + string ret = string.Empty; + if (CryptoImpl.Decrypt(ref ret, password)) + { + password = ret; + } } if (string.IsNullOrEmpty(address))