Skip to content

Commit d87c04f

Browse files
committed
Feat: Support des certificats SSL auto-signés pour l'authentification LDAP/AD
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
1 parent a0fd920 commit d87c04f

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

core/class/user.class.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ public static function connect(string $_login, string $_mdp) {
5757
$sMdp = (!is_sha512($_mdp)) ? sha512($_mdp) : $_mdp;
5858
if (config::byKey('ldap:enable') == '1' && function_exists('ldap_connect')) {
5959
log::add("connection", "info", __('LDAP Authentification', __FILE__));
60+
// Configurer la verification des certificats SSL pour les certificats auto-signes
61+
if (config::byKey('ldap:allow_selfsigned')) {
62+
putenv('LDAPTLS_REQCERT=never');
63+
ldap_set_option(NULL, LDAP_OPT_X_TLS_REQUIRE_CERT, LDAP_OPT_X_TLS_NEVER);
64+
} else {
65+
putenv('LDAPTLS_REQCERT=demand');
66+
ldap_set_option(NULL, LDAP_OPT_X_TLS_REQUIRE_CERT, LDAP_OPT_X_TLS_DEMAND);
67+
}
6068
$ad = ldap_connect(config::byKey('ldap:host'), config::byKey('ldap:port'));
6169
if (!$ad) {
6270
log::add("connection", "info", __('Connection LDAP Error', __FILE__));
@@ -65,6 +73,12 @@ public static function connect(string $_login, string $_mdp) {
6573
log::add("connection", "info", __('LDAP Connection OK', __FILE__));
6674
ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION, 3);
6775
ldap_set_option($ad, LDAP_OPT_REFERRALS, 0);
76+
// Appliquer l'option certificats auto-signes sur la connexion avant STARTTLS
77+
if (config::byKey('ldap:allow_selfsigned')) {
78+
ldap_set_option($ad, LDAP_OPT_X_TLS_REQUIRE_CERT, LDAP_OPT_X_TLS_NEVER);
79+
} else {
80+
ldap_set_option($ad, LDAP_OPT_X_TLS_REQUIRE_CERT, LDAP_OPT_X_TLS_DEMAND);
81+
}
6882
if (config::byKey('ldap:tls')) {
6983
if (!ldap_start_tls($ad)) {
7084
log::add("connection", "debug", __('start TLS KO', __FILE__));
@@ -153,9 +167,24 @@ public static function connect(string $_login, string $_mdp) {
153167
}
154168

155169
public static function connectToLDAP() {
170+
// Configurer la verification des certificats SSL pour les certificats auto-signes
171+
if (config::byKey('ldap:allow_selfsigned')) {
172+
putenv('LDAPTLS_REQCERT=never');
173+
ldap_set_option(NULL, LDAP_OPT_X_TLS_REQUIRE_CERT, LDAP_OPT_X_TLS_NEVER);
174+
} else {
175+
putenv('LDAPTLS_REQCERT=demand');
176+
ldap_set_option(NULL, LDAP_OPT_X_TLS_REQUIRE_CERT, LDAP_OPT_X_TLS_DEMAND);
177+
}
178+
156179
$ad = ldap_connect(config::byKey('ldap:host'), config::byKey('ldap:port'));
157180
ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION, 3);
158181
ldap_set_option($ad, LDAP_OPT_REFERRALS, 0);
182+
// Appliquer l'option certificats auto-signes sur la connexion avant STARTTLS
183+
if (config::byKey('ldap:allow_selfsigned')) {
184+
ldap_set_option($ad, LDAP_OPT_X_TLS_REQUIRE_CERT, LDAP_OPT_X_TLS_NEVER);
185+
} else {
186+
ldap_set_option($ad, LDAP_OPT_X_TLS_REQUIRE_CERT, LDAP_OPT_X_TLS_DEMAND);
187+
}
159188
if (config::byKey('ldap:tls') && !ldap_start_tls($ad)) {
160189
return false;
161190
}

desktop/php/administration.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,6 +1608,14 @@
16081608
<input type="checkbox" class="configKey form-control" data-l1key="ldap:tls">
16091609
</div>
16101610
</div>
1611+
<div class="form-group">
1612+
<label class="col-md-3 col-sm-4 col-xs-12 control-label">{{Autoriser certificats auto-signés}}
1613+
<sup><i class="fas fa-question-circle" tooltip="{{Désactiver la vérification des certificats SSL pour les certificats auto-signés (requis pour Samba AD)}}"></i></sup>
1614+
</label>
1615+
<div class="col-md-3 col-sm-4 col-xs-12">
1616+
<input type="checkbox" class="configKey form-control" data-l1key="ldap:allow_selfsigned">
1617+
</div>
1618+
</div>
16111619
<div class="form-group">
16121620
<label class="col-md-3 col-sm-4 col-xs-12 control-label">{{Hôte}}
16131621
<sup><i class="fas fa-question-circle" tooltip="{{URL utilisée pour contacter la base, en précisant le type de connexion (e.g ldap(s)://URL)}}"></i></sup>

0 commit comments

Comments
 (0)