LDAPS握手失败errno 21是目录 – 遇到文件结尾

我已经build立了一个CentOS 7的openLDAP传递authentication服务器

它将通过Microsoft Active Directory上托pipe的数据库上的LDAP对用户进行身份validation。

如果我使用LDAP,则可以获得成功的查询响应://

但是,LDAPS://将发生证书握手错误。

我正在使用以PFX格式从GoDaddy购买的证书。

我发现了一些可能的解决scheme,但目前为止没有任何作用

我努力了:

  1. 禁用SELinux进行testing
  2. 将PFX证书转换为PEM以及DER
  3. 使用certutil来解释这个MozNSS数据库: http : //www.openldap.org/faq/data/cache/1514.html

    pk12util -d / path / to / certdb -i /path/to/file.p12

我发现这个页面https://stackoverflow.com/questions/13732826/convert-pem-to-crt-and-key但是我不知道用什么命令来获得正确的格式证书为openLDAP。

我试过这些:

openssl x509 -outform der -in certificate.pem -out certificate.der openssl x509 -outform der -in certificate.pem -out certificate.crt 

当我运行一个ldapsearch时:

 ldapsearch -H ldaps://192.168.1.69 -b "OU=Administration,DC=domain,DC=com" -v -LLL -D "CN=ServiceLDAP,OU=Administration,DC=domain,DC=com" "(samaccountname=someuser)" -w secretpass -d1 

这些是我得到的错误:

 ldap_url_parse_ext(ldaps://192.168.1.32) ldap_initialize( ldaps://192.168.1.32:636/??base ) ldap_create ldap_url_parse_ext(ldaps://192.168.1.32:636/??base) ldap_sasl_bind ldap_send_initial_request ldap_new_connection 1 1 0 ldap_int_open_connection ldap_connect_to_host: TCP 192.168.1.32:636 ldap_new_socket: 4 ldap_prepare_socket: 4 ldap_connect_to_host: Trying 192.168.1.32:636 ldap_pvt_connect: fd: 4 tm: -1 async: 0 attempting to connect: connect success TLS: certdb config: configDir='/etc/openldap/certs' tokenDescription='ldap(0)' certPrefix='' keyPrefix='' flags=readOnly TLS: using moznss security dir /etc/openldap/certs prefix . TLS: error: tlsm_PR_Recv returned 0 - error 21:Is a directory TLS: error: connect - force handshake failure: errno 21 - moznss error -5938 TLS: can't connect: TLS error -5938:Encountered end of file. ldap_err2string ldap_sasl_bind(SIMPLE): Can't contact LDAP server (-1) 

我能够解决这个问题。

证书和密钥的正确格式:

 openssl pkcs12 -in ./ACertFromGoDaddy.pfx -nocerts -out privatekey.pem -nodes openssl pkcs12 -in ./ACertFromGoDaddy.pfx -nokeys -out publiccert.pem -nodes 

我把这些证书放在./openldap/certs中,我可以通过制作一个ldif文件并使用slapadd加载slapd来configurationslapd:

slapadd -n0 -F /etc/openldap/slapd.d/ -l ./mod_ssl.ldif

我的mod_ssl.ldif文件的内容是:

 dn: cn=config changetype: modify add: olcTLSCACertificateFile olcTLSCACertificateFile: /etc/openldap/certs/publiccert.pem - add: olcTLSCertificateFile olcTLSCertificateFile: /etc/openldap/certs/publiccert.pem - add: olcTLSCertificateKeyFile olcTLSCertificateKeyFile: /etc/openldap/certs/privatekey.pem 

然后,我可以在本地和远程执行ldapsearch:

 ldapsearch -H ldaps://192.168.1.69 -b "OU=Administration,DC=domain,DC=com" -v -LLL -D "CN=ServiceLDAP,OU=Administration,DC=domain,DC=com" "(samaccountname=someuser)" -w secretpass -d1