On Ubuntu 20.04 I found that I had to disable TLS1.3 by setting LDAPTLS_CIPHER_SUITE='NORMAL:!VERS-TLS1.3'
to get ldapsearch working against Google LDAP.
How I got here:
The ldapsearch command supports printing increased debug to the console by using the -d debuglevel
flag. Debug level 1 (-d1
) was enough for me, higher debug levels get very verbose and hard to read.
A simple debug command might look like this:
vagrant@focal:~$ ldapsearch -H ldaps://ldap.google.com:636 -d1
From here I could see that the certificate was untrusted:
...
attempting to connect:
connect success
TLS: peer cert untrusted or revoked (0x42)
TLS: can't connect: (unknown error code).
...
This didn't make any sense. The certificate being returned by ldap.google.com was valid and could be verified against my /etc/ssl/certs/ca-certificates.crt
using openssl s_client -connect ldap.google.com:636 -CAfile /etc/ssl/certs/ca-certificates.crt
but ldapsearch didn't trust it.
I finally came across this post on the OpenLDAP mailing list which explained the problem was with SNI not being supported which would cause Google to return an invalid self-signed cert. I wasn't able to find a proper fix, but the workaround at the bottom to disable TLS1.3 by setting the LDAPTLS_CIPHER_SUITE
environment variable worked for me because my OpenLDAP was using GnuTLS. If you're using OpenSSL you'll likely need to find a different workaround, but the root cause is probably still the same.