无法使用TLS获得OpenLDAP

我有一台CentOS 7主机上运行的OpenLDAP 2.4.39服务器,这个主机上只有一小部分数据。 如果不使用TLS,它会按预期工作。 我今天用dokuwiki进行身份validation。 我已经从Namecheap / Comodo购买了一个SSL,并试图让它工作。

例:

root@smtp:~# ldapsearch -h ldap.foo.bar -D cn=Manager,dc=foo,dc=bar -W -LLL -b ou=people,dc=foo,dc=bar "(uid=baz)" Enter LDAP Password: dn: uid=baz,ou=people,dc=foo,dc=bar objectClass: top objectClass: inetOrgPerson objectClass: organizationalPerson cn:: SGFucyDDhWdlIE1hcnRpbnNlbg== displayName:: SGFucyDDhWdlIE1hcnRpbnNlbg== givenName:: SGFucyDDhWdl mail: [email protected] mobile: 12345678 sn: Doe uid: baz 

如果我试图强制TLS,事情会改变。

 root@smtp:~# ldapsearch -h ldap.foo.bar -D cn=Manager,dc=foo,dc=bar -W -LLL -b ou=people,dc=foo,dc=bar -ZZ "(uid=baz)" ldap_start_tls: Connect error (-11) additional info: A TLS packet with unexpected length was received. root@smtp:~# ldapsearch -h ldap.foo.bar -D cn=Manager,dc=foo,dc=bar -W -LLL -b ou=people,dc=foo,dc=bar -ZZ -d -1 "(uid=baz)" ... ... TLS: can't connect: A TLS packet with unexpected length was received.. ldap_err2string ldap_start_tls: Connect error (-11) additional info: A TLS packet with unexpected length was received. 

LDAP服务器上的configuration。

 dn: cn=config objectClass: olcGlobal cn: config olcArgsFile: /var/run/openldap/slapd.args olcPidFile: /var/run/openldap/slapd.pid structuralObjectClass: olcGlobal entryUUID: 5760d8da-0f87-1035-85b1-9b4063f1519b creatorsName: cn=config createTimestamp: 20151025171240Z olcIdleTimeout: 300 olcLogLevel: none olcTLSCACertificateFile: /etc/openldap/tls/ldap.foo.bar.ca_bundle olcTLSCertificateFile: /etc/openldap/tls/ldap.foo.bar.crt olcTLSCertificateKeyFile: /etc/openldap/tls/ldap.foo.bar.key olcTLSCipherSuite: HIGH:MEDIUM:+SSLv2 entryCSN: 20151025205018.128335Z#000000#000#000000 modifiersName: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth modifyTimestamp: 20151025205018Z [root@ldap tls]# ls -l total 16 -rw-r--r-- 1 root root 5630 Oct 25 17:14 ldap.foo.bar.ca_bundle -rw-r--r-- 1 root root 2240 Oct 25 17:14 ldap.foo.bar.crt -r-------- 1 root root 3243 Oct 25 17:14 ldap.foo.bar.key [root@ldap tls]# file ldap.foo.bar.ca_bundle ldap.foo.bar.ca_bundle: PEM certificate [root@ldap tls]# file ldap.foo.bar.crt ldap.foo.bar.crt: PEM certificate [root@ldap tls]# file ldap.foo.bar.key ldap.foo.bar.key: PEM RSA private key 

客户端上的configuration:我已经将CA软件包添加到客户端CA证书。 客户端是一个Debian主机,我把它复制到/usr/local/share/ca-certificates/并运行命令update-ca-certificates

从我所能看到和阅读的内容来看,这应该起作用。 但事实并非如此。 如果我尝试从ldap服务器本身运行相同的search,它也不起作用。 我正在努力进一步debugging,因为我不知道从哪里开始。 任何build议,我可以看看到什么工作? 所有的configuration文件在发布前都已经过手动编辑,所以我可能犯了错误,但我不认为是这样。

在获得请求后稍后添加。

 Oct 25 20:50:54 ldap slapd[21177]: daemon: shutdown requested and initiated. Oct 25 20:50:54 ldap slapd[21177]: slapd shutdown: waiting for 0 operations/tasks to finish Oct 25 20:50:54 ldap slapd[21177]: slapd stopped. Oct 25 20:50:54 ldap slapd[21670]: @(#) $OpenLDAP: slapd 2.4.39 (Sep 29 2015 13:31:12) $ [email protected]:/builddir/build/BUILD/openldap-2.4.39/openldap-2.4.39/servers/slapd Oct 25 20:50:54 ldap slapd[21673]: hdb_db_open: warning - no DB_CONFIG file found in directory /var/lib/ldap: (2). Expect poor performance for suffix "dc=foo,dc=bar". Oct 25 20:50:54 ldap slapd[21673]: slapd starting Oct 25 21:23:19 ldap slapd[21673]: <= bdb_equality_candidates: (uid) not indexed Oct 25 21:23:19 ldap slapd[21673]: <= bdb_equality_candidates: (gidNumber) not indexed Oct 25 21:23:19 ldap slapd[21673]: <= bdb_equality_candidates: (memberUid) not indexed Oct 25 21:23:19 ldap slapd[21673]: <= bdb_equality_candidates: (uid) not indexed Oct 25 21:23:19 ldap slapd[21673]: <= bdb_equality_candidates: (gidNumber) not indexed Oct 25 21:23:19 ldap slapd[21673]: <= bdb_equality_candidates: (memberUid) not indexed Oct 26 07:30:08 ldap slapd[21673]: daemon: shutdown requested and initiated. Oct 26 07:30:08 ldap slapd[21673]: slapd shutdown: waiting for 0 operations/tasks to finish Oct 26 07:30:08 ldap slapd[21673]: slapd stopped. Oct 26 07:30:08 ldap slapd[23274]: @(#) $OpenLDAP: slapd 2.4.39 (Sep 29 2015 13:31:12) $ [email protected]:/builddir/build/BUILD/openldap-2.4.39/openldap-2.4.39/servers/slapd Oct 26 07:30:08 ldap slapd[23275]: slapd starting [root@ldap log]# 

我看到这个日志之后,把/usr/share/openldap-servers/DB_CONFIG.example添加到/ var / lib / ldap / DB_CONFIG,并完成了一个systemctl restart slapd 。 我并没有把注意力放在正确的索引上,因为我希望TLS能够先行。

一般来说,

  • 通过SSL Swiss Army Openssl命令的帮助,通常可以比输出全面的C / S SSL应用程序更容易地诊断出TLS / SSL错误; 这里esp openssl的s_client子命令可能会有所帮助。
  • olc通过组合多个olcLogLevels提供丰富的诊断输出; 表5.1:debugging OpenLDAP 的slapd.conf引用的级别 。 如果我的记忆没有背叛我,它的标志数字上小于或等于'BER',它启用(也)SSL / TLS跟踪。

这就是说 – 从上面olc列表看来

 olcTLSVerifyClient 

不存在,更不用说设置为“需求”或“允许”。

 MECH_AND_URL="-H ldapi:///" # or whatever your setup needs; your mileage may vary ldapsearch -b cn=config $MECH_AND_URL "(cn=config)" olcTLSVerifyClient -LLL 

如果这确实没有产生什么,请创build并设置它:

 ldapmodify $MECH_AND_URL <<EOF dn: cn=config changetype: modify add: olcTLSVerifyClient olcTLSVerifyClient: allow - EOF 

我的问题的答案比首先想到的要简单。 在我以前的configuration中,我有以下设置。

 olcTLSCipherSuite: HIGH:MEDIUM:+SSLv2 

正如你所看到的,它没有明确允许TLS。 我重新configuration这个设置,现在工作完美无瑕。

 olcTLSCipherSuite: HIGH:+SSLv3:+TLSv1:MEDIUM:+SSLv2:@STRENGTH:+SHA:+MD5:!NULL 

我可能会在稍后删除SSLv2和MD5。 如果客户不支持其他任何事情,我不能决定让他们在哪里至less给他们一个有用的措施。