Skip to content

Core\Ldap::Tls

Says whether a connection to a directory is encrypted.

Core\Ldap::Tls is declared in the class Core\Ldap. The tls field of the settings that Core\Ldap::open takes is one of its cases.

Tls::Required is the default. An ldaps:// URL starts with TLS, and an ldap:// URL switches to TLS before it sends the password. When TLS is not possible, the connection throws an error.

Tls::None sends the password and every result as plain text. Anybody on the network can read them and change them. A program may use it only for a host the person who runs the server lists in [capabilities.ldap] cleartext in nvs.toml. For every other host, the connection throws a Core\Ldap\LdapError with the kind EncryptionRequired.

Good to know: use Tls::None only for a test server or a server on the same machine.

Examples

The examples below run with this configuration file.

nvs.toml
# The program may open a directory on `127.0.0.1`.
# `cleartext` also allows a connection to that host without encryption.
[capabilities.ldap]
open = ["127.0.0.1"]
cleartext = ["127.0.0.1"]

A test server without encryption

<?nvs
// Shows how to connect to a directory without encryption, for a test server on this machine.
// requires: samba-ad
// `Tls::None` sends the password and every result as plain text. The host must be listed
// in `[capabilities.ldap] cleartext` in `nvs.toml`. Without `tls`, the value is `Tls::Required`.
var $test = Core\Ldap::open({
url: 'ldap://127.0.0.1:16389',
user: 'CN=Reader,OU=Company,DC=example,DC=test',
password: 'Novis-reader-1',
tls: Core\Ldap::Tls::None,
});
// `whoami` returns the account the connection uses. This prints `u:EXAMPLE\Reader`.
echo $test->whoami(), "\n";
Output
u:EXAMPLE\Reader