The drawback of self-signed certificate is that the private and public keys are in the same file. Therefore, the private key is passed to client machines, causing protential risk of interfereing the connection. A more secured way is to use ca certificate to generate private and public keys for both clients and servers. The ca certificate can be obtained from a third party issuing authority. For internal use in the lab, ca certificate generated by openssl can be used. The following is the guide to configure openldap to use a generated ca certificates. An additional benefit of using ca certificates is that, the same CA certificate can be used to sign multiple ldap servers. Therefore only one certificate is needed for openldap clients to access multiple servers.
For generation of Ca certificates, three shell scripts are used, which are adapted from Gary Tan. The first script (cr_ssl_certs_openldap.sh) generates the CA certificate, and use it to sign the certificate for the master openldap server. The next one (cr_unsigned_ssl_cert.sh) produced an unsigned certificate on the slave openldap server and the third one( sign_ssl_cert_from_slave.sh) uses the CA key generated by the first script to sign the unsigned certificate to be used on the slave ldap server.
These script will be using a modified openssl.cnf file, which is attached with this page. The main modification is to introduce a subjectAltName attribute that contain the DNS name of the load balancer's virtual host, in this way the problem of host name mismatch caused by load balancers will be solved. To do this, add the following line in the [ usr_cert ] section of openssl.cnf:
subjectAltName=DNS:ldap.blueprint.org
To use the scripts, create a folder on the master ldap server (CA for example, on sophia). Copy cr_ssl_certs_openldap.sh,sign_ssl_cert_from_slave, and openssl.cnf attached with this page to the folder. Run the script by ./cr_ssl_certs_openldap.sh. The first section of this script will create a CA certificate and key. A strong password is needed for the cakey generated. There will be prompts asking for parameters of the certificate such as country code. Follow the default (which can be modified in the openssl.conf file) except change the cn to “Ca certificate”. The next section of the script would create a certificate for openldap and sign it using the ca certificate. When prompt for common name, enter the host name of the ldap server. When the certificate is signed, copy the certificate file generated to the openldap folder, and configure proper permissions.
cp cacert.pem /etc/openldap/
cp newcert.pem /etc/openldap/slapd-cert-ldap1.pem
cp newreq.pem /etc/openldap/slapd-key-ldap1.pem
chomd 640 /etc/openldap/slapd-key-ldap1.pem
chown ldap:ldap /etc/openldap/*.pem
To generate a certificate for slave ldap server, run cr_unsigned_ssl_cert.sh with openssl.cnf on the slave ldap server. Note the common name asked must be the host name of the slave ldap server. It would generate an unsigned ldap certificate/ key pair on the slave ldap server. Then run sign_ssl_cert_from_slave.sh on the master ldap server. It would ask for host name of the slave server and the directory the unsigned certs are stored. Then down load the certs and use the CA key to sign that file. After running the script copy the signed certificate to the openldap folder of the slave server and change to proper permissions.
scp cacert.pem slave-ldap:/etc/openldap/
scp newcert_slave.pem slave-ldap:/etc/openldap/slapd-cert-ldap2.pem
scp newreq_slave.pem slave-ldap:/etc/openldap/slapd-key-ldap2.pem
on the slave server:
chmod 640 /etc/openldap/slapd-key-ldap1.pem
chown ldap:ldap /etc/openldap/*.pem
Now specify the ca certs and ldap keys in the slapd.conf of ldap server and restart ldap service. e.g. on sophia:
TLSCACertificateFile /etc/openldap/cacert.pem
TLSCertificateFile /etc/openldap/slapd-cert-ldap1.pem
TLSCertificateKeyFile /etc/openldap/slapd-key-ldap1.pem
And copy the cacert.pem to the /etc/openldap/cacerts/ folder of all the openldap clients, and use authconfig-tui to refresh the cache
Now the clients can use the cacerts.pem certificate to access multifple openldap servers, which is needed for replication of LDAP servers.