用于OpenLdap配置的Php证书SSL

时间:2013-10-08 12:56:36

标签: php ssl openldap

我在LinuxMint本地工作,并在virtualbox中安装了带有openldap的UbuntuServer。现在我配置遵循本指南 http://help.ubuntu-it.org/12.04/server/serverguide/it/ubuntu-1204-server.pdf TLS / SSL身份验证。 我已在客户端(linuxmint)Xampp中安装并使用以下命令配置/etc/ldap/ldap.conf:

TLS_CACERT      /etc/ssl/certs/192.168.1.46_slapd_cert.pem
TLS_REQCERT never

我尝试连接php函数:

<?php
// This code goes directly to the 636 SSL port

$ldaphost = "ldaps://192.168.1.46";
$ldapUsername  = "cn=admin,dc=company,dc=com";
$ldapPassword = "secret";


$ds = ldap_connect($ldaphost);

if(!ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3)){
print "Could not set LDAPv3\r\n";
}
else {
// now we need to bind to the ldap server
$bth = ldap_bind($ds, $ldapUsername, $ldapPassword) or die("\r\nCould not connect to LDAP server\r\n");
}
?>

但不起作用..

如果我在我的终端尝试:

ldapsearch -x -H ldaps://192.168.1.46 -b "cn=company,cn=com"

它有效!! 但是通过php为什么?..我尝试在/ opt / lampp / etc / openldap中配置ldap.conf但没有结果..

1 个答案:

答案 0 :(得分:1)

我使用openldap和 centos 中的apache / php。也许它很相似。

  1. 我的 ldap.conf 位于 /etc/ldap.conf
  2. 我配置了* TLS_REQCERT allow *
  3. 我必须在同一目录中生成证书的哈希值作为符号链接:
  4. ln -s /etc/ssl/certs/192.168.1.46_slapd_cert.pem `openssl x509 -hash -noout -in /etc/ssl/certs/192.168.1.46_slapd_cert.pem`.0
    

    在我的 Ubuntu (没有ldapsupport)上存在函数 c_rehash 。如果我在那里安装一个撤销列表,我必须以这种方式重新使用此功能重新列入所有的反叛者:

    cd /etc/ssl/certs/
    c_rehash /etc/ssl/certs/
    

    可能会为您的CA创建正确的哈希值。