我正在试图做一个像这样的ldapsearch:
ldapsearch -x -D "uid=username,ou=people,dc=example" -w passw0rd -H ldaps://example.com "(objectClass=example)"
但它给了我这个错误:
ldap_sasl_bind(SIMPLE): Can't contact LDAP server (-1)
通过debugging,它是:
ldap_url_parse_ext(ldaps://example.com) ldap_create ldap_url_parse_ext(ldaps://example.com:636/??base) ldap_sasl_bind ldap_send_initial_request ldap_new_connection 1 1 0 ldap_int_open_connection ldap_connect_to_host: TCP example.com:636 ldap_new_socket: 3 ldap_prepare_socket: 3 ldap_connect_to_host: Trying XXXX:636 ldap_pvt_connect: fd: 3 tm: -1 async: 0 ldap_err2string ldap_sasl_bind(SIMPLE): Can't contact LDAP server (-1)
我认为这是SSL连接的问题。 但是,不,因为这个命令成功了:
openssl s_client -connect example.com:636
所以我不知道问题在哪里
有关更多信息,我在一个具有Ubuntu映像的容器(Docker)中,我的LDAPconfiguration是:
BASE dc=example URI ldaps://example.com TLS_REQCERT demand TLS_CACERT /etc/ldap/certificates/CA-cert.pem
你可以在/etc/ldap.conf中设置
TLS_REQCERT允许
正如你会怀疑的那样,它不会在未知的证书颁发机构上死亡。 看看man ldap.conf
TLS_REQCERT <level> Specifies what checks to perform on server certificates in a TLS session, if any. The <level> can be specified as one of the fol‐ lowing keywords: never The client will not request or check any server certifi‐ cate. allow The server certificate is requested. If no certificate is provided, the session proceeds normally. If a bad cer‐ tificate is provided, it will be ignored and the session proceeds normally. try The server certificate is requested. If no certificate is provided, the session proceeds normally. If a bad cer‐ tificate is provided, the session is immediately termi‐ nated. demand | hard These keywords are equivalent. The server certificate is requested. If no certificate is provided, or a bad cer‐ tificate is provided, the session is immediately termi‐ nated. This is the default setting.
一旦你确定ldapsearch正在工作,那么正确的做法是获得一个CA根证书的副本并导入到你的ubuntu系统存储中。
显然这是如图所示完成的: 这个超级用户的问题
或者你可以忽略它,在没有validation证书的情况下继续你的工作,但是你应该尽可能地validation它。
您将会注意到,debugging输出没有显示通信的SSL / TLS部分。 IIRC,为了让ldapsearch输出,你需要使用选项-v2 -d (可能具有更高的debugging级别)。
请注意,只是因为openssl的作品,并不意味着ldapsearch(openldap库)将在相同的地方查找证书信息。 另请注意,openssl s_client在默认情况下不validation证书。
您可以尝试将TLS_REQCERT设置为不作为debugging帮助。
我还build议使用strace -e trace=file -f ldapsearch ...来帮助发现哪些文件实际上正在被查找(以及是否有权限进入等)
Linux系统往往有多个ldapconfiguration文件(pam_ldap,nss_ldap,openldap命令,…)。 你使用了哪个文件?
其中一个问题,我一般会问在我的工作中询问类似问题的人是哪个语言堆栈是客户端编写的(或者说,正在使用哪个LDAP客户端API,例如OpenLDAP和OpenSSL,或者Java 1.7没有高安全性的附加组件,所以我可以找出哪些问题要考虑高于其他人)。 出于这个原因,不要指望像Java API这样的东西在你有了一个ldapsearch的工作调用之后就可以工作。
如果LDAP提供程序是在Windows Server 2012上运行的Active Directory,请参阅无法联系LDAPS和Server 2012的LDAP服务器(-1)
好吧,在网上search了很多,但我终于find了工作。 这是我做的。
TLS_CACERT /etc/ssl/certs/ca.pem
TLS_REQCERT永远不会
4A。 我添加了TLS_REQCERT内部原因。 根据自己的要求/风险使用该设置。
希望这可以帮助。