This section describes the transport layer security options for LDAP, and especially how to enable LDAPS on ApacheDS.
Several requirements related to security can be easily accomplished with the help of SSL technology (Secure Socket Layer) or its standardized successor TLS (Transport Layer Security, RFC 2246). Among these are the protection of data against eavesdropping and modification, when on transit between client and server (data integrity), and the authentication of a server toward a client with the help of a certificate.
There are two approaches to utilize these technologies in the LDAP world.
The first option is comparable to HTTPS and inserts an SSL/TLS layer between the TCP/IP protocol and LDAP. Establishing a connection like this is normally provided via a different server port (port 636 is common, it is a well-known port, like port 389 is for LDAP). In URIs the schema "ldaps" is specified (for instance ldaps://zanzibar:636/) instead of "ldap". It is possible to write programs which switch between ldap and ldaps without changes in the source, if the connection data is configured external.
In the second option a client establishes at first a "normal" LDAP connection. With a special request (extended operation StartTLS) it tries to switch to secure communication afterwards. It is not necessary to change the port for this, the communication continues on the established connection. The client may go back to the original connection state ("TLS Closure Alert"), in doing so protecting only selected parts of the communication.
Both ways to utilize SSL/TLS within LDAP require the configuration of the server with an appropriate certificate.
ApacheDS 1.5.5 supports both options and requires a JDK 1.5 or above. The feature is enabled by default, but you may need to configure it. There are some steps to follow in order to obtain a SSL enabled server.
In order to keep it simple for beginners, you don't need any certificate to get LDAPS working. The latest version generates its own self signed certificate. From the user point of view, it's just a matter of enabling the ldaps service to get it working.
However, if one wants to use a signed certificate, another configuration is needed, where you tell the server about the keystore to use, and the certificate password to use.
There is nothing to do but enabling SSL and specifying the port to use in the server.xml configuration file :
That's it, the server is LDAPS capable !
|The default server.xml configuration file contains an typo, by default the port is set to 10686.|
A certificate is a signed public key (signed normally by a third party, a certificate authority, CA).
There are different options
We will do it the last way (self-signed), primarily because it's easy and fast (you won't have to pay nor to wait to obtain your certificate)
First it is necessary to create a key pair (public/private key) for your server, zanzibar in our case. One option is to use the JDK tool keytool for this task. In the following example, we use these options
|-genkey||command to generate a key pair|
|-keyalg||"RSA"||algorithm to be used to generate the key pair, in our case, default is "DSA"|
|-dname||"cn=zanzibar, ou=ApacheDS, o=ASF, c=US"||the X.500 Distinguished Name to be associated with alias, used as the issuer and subject fields in the self-signed certificate|
|-alias||zanzibar||name to refer the entry within the keystore|
|-keystore||zanzibar.ks||keystore file location|
|-storepass||secret||password used to protect the integrity of the keystore|
|-validity||730||number of days for which the certificate should be considered valid, default is 90|
Learn more about keytool at the manpage.
Another option is to use graphical tools for key creation like Portecle, which is basically a user-friendly front-end for keytool with comparable functionality. For a first impression see a screen shot below.
Enabling SSL in Apache Directory Server and using the key pair created as above is quite easy. Simply put the keystore file in the conf directory of ApacheDS, and enable ldaps. Here is the fragment from server.xml on how to do so.
The following properties were used
|keystoreFile||none||path of the X509 (or JKS) certificate file for LDAPS|
|certificatePassword||changeit||password which is used to load the LDAPS certificate file|
|port||10636||LDAPS TCP/IP port number to listen to|
|enableSSL||true||sets if SSL is enabled or not|
After modification of the server.xml, the server has to be restarted in order to take effect.
After restarting the server, you should have a server offering both ldap and ldaps. How to verify whether it works?
Apache Directory Studio happily supports ldaps connections. Enter the connection data (hostname and port) and select "Use SSL encryption" from the dropdown, if you create or modify a connection:
Afterwards the connection behaves like LDAP does. No difference in functionality, but the transmission is secured by SSL.
Because our self-signed certificate is not trustworthy, many tools will present a warning (as Studio does in version 1.5.0). You will likely be able to view the certificate, and decide to continue (accepting the certificate always or this session only), like with web browsers.
If you use other graphical clients, the behavior will be comparable. Sometimes clients don't allow to connect to a server, if the certificate is not trustworthy. This is for instance the case for Java clients using JNDI.
The following simple Java program tries to connect via JNDI/JSSE (Java Secure Socket Extension) and LDAPS to ldaps://zanzibar:10636
It causes a CommunicationException, if the certificate is not trusted:
In order to make the client trust our server, one option is to share a self signed certificate.
So we export the certificate (DER format) using keytool like this:
Please note that you don't want to share the server keystore file itself with arbitrary clients, because it holds the private key. Instead we create a separate keystore trusted.ks with the help of keytool. We import the certificate zanzibar.cer like this:
Instead of using the command line version of keytool, it is also possible to perform the certificate export and import operations with Portecle or any other graphical frontend. This is for instance how the trusted.ks files with the imported certificate looks like in Portecle.
Clients may use this keystore in order to connect to the server. Therefore they can configure trusted.ks as the trusted store via the environment like this:
Another option would be to import the certificate in the default keystore of the JRE installation (within $JAVA_HOME/jre/lib/security). For a test certificate this proceeding is not appropriate.
In practice connection establishment with LDAP over SSL may lead to various problems. In order to eliminate the errors it is helpful to see communication-specific debug information. The system property javax.net.debug is available for this task. The value "ssl" provides information about the certificates in the used key store, the server certificate, and the steps during establishing of the SSL connection (handshake):
You should be able to determine any SSL-related configuration problem with the help of this log.