-
- // Check if TLS_INSECURE is set. The handle is set to NULL due to the nature of
- // the LDAP_OPT_X_TLS_REQUIRE_CERT option. It can only be set globally and not per handle.
- if ($this->config['tls_insecure']) {
- // Setting also ignored?
- $this->ldap->setOption($ldapConnection, LDAP_OPT_X_TLS_REQUIRE_CERT, LDAP_OPT_X_TLS_NEVER);
- }
-
- if ($this->config['start_tls']) {
- // "&& $this->config['tls_cacertfile']" this condition was removed because:
- // This ldap option is totally ignored by PHP. (bug: https://bugs.php.net/bug.php?id=73558)
- // If we set 'TLS_CACERT /config/ca/bundle.pem' into /etc/openldap/ldap.conf and restart php, ldap_start_tls works.
- //$this->ldap->setOption($ldapConnection, LDAP_OPT_X_TLS_CACERTFILE, $this->config['tls_cacertfile']);
- ldap_start_tls($ldapConnection);
- }
+
+ // Start and verify TLS if it's enabled
+ if ($this->config['start_tls']) {
+ $started = $this->ldap->startTls($ldapConnection);
+ if (!$started) {
+ throw new LdapException('Could not start TLS connection');
+ }
+ }