From e23873a1c266b6f605b7e122d5664d4345b37e2b Mon Sep 17 00:00:00 2001 From: Lars Date: Mon, 19 Feb 2024 17:01:40 +0100 Subject: [PATCH 1/2] Added ignore certificates option --- .../Frends.LDAP.AddUserToGroups/AddUserToGroups.cs | 8 +++++++- .../Definitions/Connection.cs | 5 +++++ .../Frends.LDAP.CreateUser/CreateUser.cs | 8 +++++++- .../Frends.LDAP.CreateUser/Definitions/Connection.cs | 5 +++++ .../Frends.LDAP.DeleteUser/Definitions/Connection.cs | 5 +++++ .../Frends.LDAP.DeleteUser/DeleteUser.cs | 8 +++++++- .../Definitions/Connection.cs | 5 +++++ .../RemoveUserFromGroups.cs | 8 +++++++- .../Definitions/Connection.cs | 5 +++++ .../Frends.LDAP.SearchObjects/SearchObjects.cs | 10 +++++++++- .../Frends.LDAP.UpdateUser/Definitions/Connection.cs | 5 +++++ .../Frends.LDAP.UpdateUser/UpdateUser.cs | 8 +++++++- 12 files changed, 74 insertions(+), 6 deletions(-) diff --git a/Frends.LDAP.AddUserToGroups/Frends.LDAP.AddUserToGroups/AddUserToGroups.cs b/Frends.LDAP.AddUserToGroups/Frends.LDAP.AddUserToGroups/AddUserToGroups.cs index 79d6b54..09254d3 100644 --- a/Frends.LDAP.AddUserToGroups/Frends.LDAP.AddUserToGroups/AddUserToGroups.cs +++ b/Frends.LDAP.AddUserToGroups/Frends.LDAP.AddUserToGroups/AddUserToGroups.cs @@ -22,7 +22,13 @@ public static Result AddUserToGroups([PropertyTab] Input input, [PropertyTab] Co if (string.IsNullOrWhiteSpace(connection.Host) || string.IsNullOrWhiteSpace(connection.User) || string.IsNullOrWhiteSpace(connection.Password)) throw new Exception("AddUserToGroups error: Connection parameters missing."); - LdapConnection conn = new(); + LdapConnectionOptions ldco = new LdapConnectionOptions(); + + if (connection.IgnoreCertificates) { + ldco.ConfigureRemoteCertificateValidationCallback((sender, certificate, chain, errors) => true); + } + + LdapConnection conn = new LdapConnection(ldco); try { diff --git a/Frends.LDAP.AddUserToGroups/Frends.LDAP.AddUserToGroups/Definitions/Connection.cs b/Frends.LDAP.AddUserToGroups/Frends.LDAP.AddUserToGroups/Definitions/Connection.cs index 6eb6f4e..a2b8401 100644 --- a/Frends.LDAP.AddUserToGroups/Frends.LDAP.AddUserToGroups/Definitions/Connection.cs +++ b/Frends.LDAP.AddUserToGroups/Frends.LDAP.AddUserToGroups/Definitions/Connection.cs @@ -25,6 +25,11 @@ public class Connection /// true public bool SecureSocketLayer { get; set; } + /// + /// Ignore server certificates + /// + public bool IgnoreCertificates { get; set; } + /// /// Connection is protected by TLS. /// diff --git a/Frends.LDAP.CreateUser/Frends.LDAP.CreateUser/CreateUser.cs b/Frends.LDAP.CreateUser/Frends.LDAP.CreateUser/CreateUser.cs index 1cd9e78..7463000 100644 --- a/Frends.LDAP.CreateUser/Frends.LDAP.CreateUser/CreateUser.cs +++ b/Frends.LDAP.CreateUser/Frends.LDAP.CreateUser/CreateUser.cs @@ -21,7 +21,13 @@ public static Result CreateUser([PropertyTab] Input input, [PropertyTab] Connect if (string.IsNullOrWhiteSpace(connection.Host) || string.IsNullOrWhiteSpace(connection.User) || string.IsNullOrWhiteSpace(connection.Password)) throw new Exception("Connection parameters missing."); - LdapConnection conn = new(); + LdapConnectionOptions ldco = new LdapConnectionOptions(); + + if (connection.IgnoreCertificates) { + ldco.ConfigureRemoteCertificateValidationCallback((sender, certificate, chain, errors) => true); + } + + LdapConnection conn = new LdapConnection(ldco); try { diff --git a/Frends.LDAP.CreateUser/Frends.LDAP.CreateUser/Definitions/Connection.cs b/Frends.LDAP.CreateUser/Frends.LDAP.CreateUser/Definitions/Connection.cs index f3cb4b0..dd8f10d 100644 --- a/Frends.LDAP.CreateUser/Frends.LDAP.CreateUser/Definitions/Connection.cs +++ b/Frends.LDAP.CreateUser/Frends.LDAP.CreateUser/Definitions/Connection.cs @@ -25,6 +25,11 @@ public class Connection /// true public bool SecureSocketLayer { get; set; } + /// + /// Ignore server certificates + /// + public bool IgnoreCertificates { get; set; } + /// /// Connection is protected by TLS. /// diff --git a/Frends.LDAP.DeleteUser/Frends.LDAP.DeleteUser/Definitions/Connection.cs b/Frends.LDAP.DeleteUser/Frends.LDAP.DeleteUser/Definitions/Connection.cs index bdb0a71..2a8f41a 100644 --- a/Frends.LDAP.DeleteUser/Frends.LDAP.DeleteUser/Definitions/Connection.cs +++ b/Frends.LDAP.DeleteUser/Frends.LDAP.DeleteUser/Definitions/Connection.cs @@ -25,6 +25,11 @@ public class Connection /// true public bool SecureSocketLayer { get; set; } + /// + /// Ignore server certificates + /// + public bool IgnoreCertificates { get; set; } + /// /// Connection is protected by TLS. /// diff --git a/Frends.LDAP.DeleteUser/Frends.LDAP.DeleteUser/DeleteUser.cs b/Frends.LDAP.DeleteUser/Frends.LDAP.DeleteUser/DeleteUser.cs index 582037f..13df451 100644 --- a/Frends.LDAP.DeleteUser/Frends.LDAP.DeleteUser/DeleteUser.cs +++ b/Frends.LDAP.DeleteUser/Frends.LDAP.DeleteUser/DeleteUser.cs @@ -21,7 +21,13 @@ public static Result DeleteUser([PropertyTab] Input input, [PropertyTab] Connect if (string.IsNullOrWhiteSpace(connection.Host) || string.IsNullOrWhiteSpace(connection.User) || string.IsNullOrWhiteSpace(connection.Password)) throw new Exception("Connection parameters missing."); - LdapConnection conn = new(); + LdapConnectionOptions ldco = new LdapConnectionOptions(); + + if (connection.IgnoreCertificates) { + ldco.ConfigureRemoteCertificateValidationCallback((sender, certificate, chain, errors) => true); + } + + LdapConnection conn = new LdapConnection(ldco); try { diff --git a/Frends.LDAP.RemoveUserFromGroups/Frends.LDAP.RemoveUserFromGroups/Definitions/Connection.cs b/Frends.LDAP.RemoveUserFromGroups/Frends.LDAP.RemoveUserFromGroups/Definitions/Connection.cs index 68fa142..1515c58 100644 --- a/Frends.LDAP.RemoveUserFromGroups/Frends.LDAP.RemoveUserFromGroups/Definitions/Connection.cs +++ b/Frends.LDAP.RemoveUserFromGroups/Frends.LDAP.RemoveUserFromGroups/Definitions/Connection.cs @@ -25,6 +25,11 @@ public class Connection /// true public bool SecureSocketLayer { get; set; } + /// + /// Ignore server certificates + /// + public bool IgnoreCertificates { get; set; } + /// /// Connection is protected by TLS. /// diff --git a/Frends.LDAP.RemoveUserFromGroups/Frends.LDAP.RemoveUserFromGroups/RemoveUserFromGroups.cs b/Frends.LDAP.RemoveUserFromGroups/Frends.LDAP.RemoveUserFromGroups/RemoveUserFromGroups.cs index 95afc6d..3b44d2e 100644 --- a/Frends.LDAP.RemoveUserFromGroups/Frends.LDAP.RemoveUserFromGroups/RemoveUserFromGroups.cs +++ b/Frends.LDAP.RemoveUserFromGroups/Frends.LDAP.RemoveUserFromGroups/RemoveUserFromGroups.cs @@ -22,7 +22,13 @@ public static Result RemoveUserFromGroups([PropertyTab] Input input, [PropertyTa if (string.IsNullOrWhiteSpace(connection.Host) || string.IsNullOrWhiteSpace(connection.User) || string.IsNullOrWhiteSpace(connection.Password)) throw new Exception("RemoveUserFromGroups error: Connection parameters missing."); - LdapConnection conn = new(); + LdapConnectionOptions ldco = new LdapConnectionOptions(); + + if (connection.IgnoreCertificates) { + ldco.ConfigureRemoteCertificateValidationCallback((sender, certificate, chain, errors) => true); + } + + LdapConnection conn = new LdapConnection(ldco); try { diff --git a/Frends.LDAP.SearchObjects/Frends.LDAP.SearchObjects/Definitions/Connection.cs b/Frends.LDAP.SearchObjects/Frends.LDAP.SearchObjects/Definitions/Connection.cs index e4e5601..2a443a2 100644 --- a/Frends.LDAP.SearchObjects/Frends.LDAP.SearchObjects/Definitions/Connection.cs +++ b/Frends.LDAP.SearchObjects/Frends.LDAP.SearchObjects/Definitions/Connection.cs @@ -25,6 +25,11 @@ public class Connection /// true public bool SecureSocketLayer { get; set; } + /// + /// Ignore server certificates + /// + public bool IgnoreCertificates { get; set; } + /// /// Connection is protected by TLS. /// diff --git a/Frends.LDAP.SearchObjects/Frends.LDAP.SearchObjects/SearchObjects.cs b/Frends.LDAP.SearchObjects/Frends.LDAP.SearchObjects/SearchObjects.cs index f954256..423ffd1 100644 --- a/Frends.LDAP.SearchObjects/Frends.LDAP.SearchObjects/SearchObjects.cs +++ b/Frends.LDAP.SearchObjects/Frends.LDAP.SearchObjects/SearchObjects.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Threading; +using System.Security.Cryptography.X509Certificates; namespace Frends.LDAP.SearchObjects; @@ -25,7 +26,14 @@ public static Result SearchObjects([PropertyTab] Input input, [PropertyTab] Conn if (string.IsNullOrWhiteSpace(connection.Host) || string.IsNullOrWhiteSpace(connection.User) || string.IsNullOrWhiteSpace(connection.Password)) throw new Exception("Connection parameters missing."); - var conn = new LdapConnection(); + + LdapConnectionOptions ldco = new LdapConnectionOptions(); + + if (connection.IgnoreCertificates) { + ldco.ConfigureRemoteCertificateValidationCallback((sender, certificate, chain, errors) => true); + } + + LdapConnection conn = new LdapConnection(ldco); var defaultPort = connection.SecureSocketLayer ? 636 : 389; var atr = new List(); var searchResults = new List(); diff --git a/Frends.LDAP.UpdateUser/Frends.LDAP.UpdateUser/Definitions/Connection.cs b/Frends.LDAP.UpdateUser/Frends.LDAP.UpdateUser/Definitions/Connection.cs index 44279ae..a1bab4c 100644 --- a/Frends.LDAP.UpdateUser/Frends.LDAP.UpdateUser/Definitions/Connection.cs +++ b/Frends.LDAP.UpdateUser/Frends.LDAP.UpdateUser/Definitions/Connection.cs @@ -25,6 +25,11 @@ public class Connection /// true public bool SecureSocketLayer { get; set; } + /// + /// Ignore server certificates + /// + public bool IgnoreCertificates { get; set; } + /// /// Connection is protected by TLS. /// diff --git a/Frends.LDAP.UpdateUser/Frends.LDAP.UpdateUser/UpdateUser.cs b/Frends.LDAP.UpdateUser/Frends.LDAP.UpdateUser/UpdateUser.cs index 1097564..a3d7046 100644 --- a/Frends.LDAP.UpdateUser/Frends.LDAP.UpdateUser/UpdateUser.cs +++ b/Frends.LDAP.UpdateUser/Frends.LDAP.UpdateUser/UpdateUser.cs @@ -36,7 +36,13 @@ public static Result UpdateUser([PropertyTab] Input input, [PropertyTab] Connect if (input.Attributes.Length == 0) throw new Exception("UpdateUser error: Attributes missing."); - LdapConnection conn = new(); + LdapConnectionOptions ldco = new LdapConnectionOptions(); + + if (connection.IgnoreCertificates) { + ldco.ConfigureRemoteCertificateValidationCallback((sender, certificate, chain, errors) => true); + } + + LdapConnection conn = new LdapConnection(ldco); try { From 2c21aea7339f8bb87230237b7cd2c7750fc8259e Mon Sep 17 00:00:00 2001 From: Lars Date: Mon, 19 Feb 2024 17:18:41 +0100 Subject: [PATCH 2/2] Update version numbers --- .../Frends.LDAP.AddUserToGroups.csproj | 2 +- .../Frends.LDAP.CreateUser/Frends.LDAP.CreateUser.csproj | 2 +- .../Frends.LDAP.DeleteUser/Frends.LDAP.DeleteUser.csproj | 2 +- .../Frends.LDAP.RemoveUserFromGroups.csproj | 2 +- .../Frends.LDAP.SearchObjects/Frends.LDAP.SearchObjects.csproj | 2 +- .../Frends.LDAP.UpdateUser/Frends.LDAP.UpdateUser.csproj | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Frends.LDAP.AddUserToGroups/Frends.LDAP.AddUserToGroups/Frends.LDAP.AddUserToGroups.csproj b/Frends.LDAP.AddUserToGroups/Frends.LDAP.AddUserToGroups/Frends.LDAP.AddUserToGroups.csproj index f823688..ba4df8a 100644 --- a/Frends.LDAP.AddUserToGroups/Frends.LDAP.AddUserToGroups/Frends.LDAP.AddUserToGroups.csproj +++ b/Frends.LDAP.AddUserToGroups/Frends.LDAP.AddUserToGroups/Frends.LDAP.AddUserToGroups.csproj @@ -2,7 +2,7 @@ net6.0 - 1.0.0 + 1.1.0 Frends Frends Frends diff --git a/Frends.LDAP.CreateUser/Frends.LDAP.CreateUser/Frends.LDAP.CreateUser.csproj b/Frends.LDAP.CreateUser/Frends.LDAP.CreateUser/Frends.LDAP.CreateUser.csproj index 1a40c1b..1468b09 100644 --- a/Frends.LDAP.CreateUser/Frends.LDAP.CreateUser/Frends.LDAP.CreateUser.csproj +++ b/Frends.LDAP.CreateUser/Frends.LDAP.CreateUser/Frends.LDAP.CreateUser.csproj @@ -2,7 +2,7 @@ net6.0 - 1.0.0 + 1.1.0 Frends Frends Frends diff --git a/Frends.LDAP.DeleteUser/Frends.LDAP.DeleteUser/Frends.LDAP.DeleteUser.csproj b/Frends.LDAP.DeleteUser/Frends.LDAP.DeleteUser/Frends.LDAP.DeleteUser.csproj index 1b6a1d2..50d9ea4 100644 --- a/Frends.LDAP.DeleteUser/Frends.LDAP.DeleteUser/Frends.LDAP.DeleteUser.csproj +++ b/Frends.LDAP.DeleteUser/Frends.LDAP.DeleteUser/Frends.LDAP.DeleteUser.csproj @@ -2,7 +2,7 @@ net6.0 - 1.0.0 + 1.1.0 Frends Frends Frends diff --git a/Frends.LDAP.RemoveUserFromGroups/Frends.LDAP.RemoveUserFromGroups/Frends.LDAP.RemoveUserFromGroups.csproj b/Frends.LDAP.RemoveUserFromGroups/Frends.LDAP.RemoveUserFromGroups/Frends.LDAP.RemoveUserFromGroups.csproj index 28557fb..bcef342 100644 --- a/Frends.LDAP.RemoveUserFromGroups/Frends.LDAP.RemoveUserFromGroups/Frends.LDAP.RemoveUserFromGroups.csproj +++ b/Frends.LDAP.RemoveUserFromGroups/Frends.LDAP.RemoveUserFromGroups/Frends.LDAP.RemoveUserFromGroups.csproj @@ -2,7 +2,7 @@ net6.0 - 1.0.0 + 1.1.0 Frends Frends Frends diff --git a/Frends.LDAP.SearchObjects/Frends.LDAP.SearchObjects/Frends.LDAP.SearchObjects.csproj b/Frends.LDAP.SearchObjects/Frends.LDAP.SearchObjects/Frends.LDAP.SearchObjects.csproj index f85a457..c3f32b3 100644 --- a/Frends.LDAP.SearchObjects/Frends.LDAP.SearchObjects/Frends.LDAP.SearchObjects.csproj +++ b/Frends.LDAP.SearchObjects/Frends.LDAP.SearchObjects/Frends.LDAP.SearchObjects.csproj @@ -2,7 +2,7 @@ net6.0 - 1.0.0 + 1.1.0 Frends Frends Frends diff --git a/Frends.LDAP.UpdateUser/Frends.LDAP.UpdateUser/Frends.LDAP.UpdateUser.csproj b/Frends.LDAP.UpdateUser/Frends.LDAP.UpdateUser/Frends.LDAP.UpdateUser.csproj index 5286773..2633468 100644 --- a/Frends.LDAP.UpdateUser/Frends.LDAP.UpdateUser/Frends.LDAP.UpdateUser.csproj +++ b/Frends.LDAP.UpdateUser/Frends.LDAP.UpdateUser/Frends.LDAP.UpdateUser.csproj @@ -2,7 +2,7 @@ net6.0 - 1.1.0 + 1.2.0 Frends Frends Frends