KxSystems / ldap

Kdb+ integration with LDAP
https://code.kx.com/q
Apache License 2.0
5 stars 5 forks source link

Enable start tls #126

Closed jlucid closed 1 year ago

jlucid commented 1 year ago

In this commit I am adding a function, .ldap.startTLS, which enables a startTLS connection with the server. startTLS works with the normal LDAP port ldap://:389 (not ldaps://)

This function is a wrapper around ldap_start_tls_s (See reference).

ldap_start_tls_s sends a StartTLS request to a server, waits for the reply, and then installs TLS handlers on the session if the request succeeded. The routine returns LDAP_SUCCESS if everything succeeded, otherwise it returns an LDAP error code.

The ldap_start_tls_s function takes 3 arguments, the session ID, ServerCtrls and ClientCtrls. Both ServerCtrls and ClientCtrls are being set to NULL to be consistent with what is done for ldap_sasl_bind_s. Hence, .ldap.startTLS only requires a single argument, the session ID.

To enable an LDAP node to accept only startTLS connections the olcSecurity setting should be set to tls=1 or higher

Example Usage:

q).ldap.init[1i;enlist `$"ldap://localhost:389"]  
q).ldap.setOption[1i;`LDAP_OPT_PROTOCOL_VERSION;3] 
q).ldap.startTLS[1i]  
0i  
q).ldap.bind[1i;`dn`cred!(dn;"password1")]