From d0fc755babd244f3b8d82573b84240915a653540 Mon Sep 17 00:00:00 2001 From: Tristan Touileb Date: Wed, 12 Nov 2025 01:00:53 +0100 Subject: [PATCH] =?UTF-8?q?Feat:=20Support=20des=20certificats=20SSL=20aut?= =?UTF-8?q?o-sign=C3=A9s=20pour=20l'authentification=20LDAP/AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ajout d'une option configurable (checkbox dans l'interface) pour permettre l'utilisation de certificats auto-signés avec STARTTLS. - Nouvelle checkbox dans Configuration > LDAP - Configuration des options LDAP_OPT_X_TLS_REQUIRE_CERT - Appliqué dans user::connect() et user::connectToLDAP() - Sécurisé par défaut (checkbox décochée = vérification stricte) - Requis pour environnements Samba4 AD avec certificats auto-signés Fixes #3136 --- core/class/user.class.php | 29 +++++++++++++++++++++++++++++ desktop/php/administration.php | 8 ++++++++ 2 files changed, 37 insertions(+) diff --git a/core/class/user.class.php b/core/class/user.class.php index 8f834215c1..41d6a17170 100644 --- a/core/class/user.class.php +++ b/core/class/user.class.php @@ -57,6 +57,14 @@ public static function connect(string $_login, string $_mdp) { $sMdp = (!is_sha512($_mdp)) ? sha512($_mdp) : $_mdp; if (config::byKey('ldap:enable') == '1' && function_exists('ldap_connect')) { log::add("connection", "info", __('LDAP Authentification', __FILE__)); + // Configurer la verification des certificats SSL pour les certificats auto-signes + if (config::byKey('ldap:allow_selfsigned')) { + putenv('LDAPTLS_REQCERT=never'); + ldap_set_option(NULL, LDAP_OPT_X_TLS_REQUIRE_CERT, LDAP_OPT_X_TLS_NEVER); + } else { + putenv('LDAPTLS_REQCERT=demand'); + ldap_set_option(NULL, LDAP_OPT_X_TLS_REQUIRE_CERT, LDAP_OPT_X_TLS_DEMAND); + } $ad = ldap_connect(config::byKey('ldap:host'), config::byKey('ldap:port')); if (!$ad) { log::add("connection", "info", __('Connection LDAP Error', __FILE__)); @@ -65,6 +73,12 @@ public static function connect(string $_login, string $_mdp) { log::add("connection", "info", __('LDAP Connection OK', __FILE__)); ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION, 3); ldap_set_option($ad, LDAP_OPT_REFERRALS, 0); + // Appliquer l'option certificats auto-signes sur la connexion avant STARTTLS + if (config::byKey('ldap:allow_selfsigned')) { + ldap_set_option($ad, LDAP_OPT_X_TLS_REQUIRE_CERT, LDAP_OPT_X_TLS_NEVER); + } else { + ldap_set_option($ad, LDAP_OPT_X_TLS_REQUIRE_CERT, LDAP_OPT_X_TLS_DEMAND); + } if (config::byKey('ldap:tls')) { if (!ldap_start_tls($ad)) { log::add("connection", "debug", __('start TLS KO', __FILE__)); @@ -153,9 +167,24 @@ public static function connect(string $_login, string $_mdp) { } public static function connectToLDAP() { + // Configurer la verification des certificats SSL pour les certificats auto-signes + if (config::byKey('ldap:allow_selfsigned')) { + putenv('LDAPTLS_REQCERT=never'); + ldap_set_option(NULL, LDAP_OPT_X_TLS_REQUIRE_CERT, LDAP_OPT_X_TLS_NEVER); + } else { + putenv('LDAPTLS_REQCERT=demand'); + ldap_set_option(NULL, LDAP_OPT_X_TLS_REQUIRE_CERT, LDAP_OPT_X_TLS_DEMAND); + } + $ad = ldap_connect(config::byKey('ldap:host'), config::byKey('ldap:port')); ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION, 3); ldap_set_option($ad, LDAP_OPT_REFERRALS, 0); + // Appliquer l'option certificats auto-signes sur la connexion avant STARTTLS + if (config::byKey('ldap:allow_selfsigned')) { + ldap_set_option($ad, LDAP_OPT_X_TLS_REQUIRE_CERT, LDAP_OPT_X_TLS_NEVER); + } else { + ldap_set_option($ad, LDAP_OPT_X_TLS_REQUIRE_CERT, LDAP_OPT_X_TLS_DEMAND); + } if (config::byKey('ldap:tls') && !ldap_start_tls($ad)) { return false; } diff --git a/desktop/php/administration.php b/desktop/php/administration.php index e89a5e1f0d..dc5c541bce 100644 --- a/desktop/php/administration.php +++ b/desktop/php/administration.php @@ -1608,6 +1608,14 @@ +
+ +
+ +
+