【问题标题】:can not bind to the LDAP directory with secure connection with php无法通过与 php 的安全连接绑定到 LDAP 目录
【发布时间】:2012-02-08 18:59:24
【问题描述】:

安装信息:
我有两台 Windows 服务器。其中一个(Windows Server 2008 R2)是具有 Active Directory (AD) 的域控制器 (DC)。它的名称是 s1.xyz.com。第二台(Windows Server 2003 R2)服务器正在运行 IIS,PHP.SSL 证书安装在第二台服务器上。

我已在 DC 服务器上安装 Active Directory 证书服务以充当证书颁发机构 (CA) 并使用以下链接启用 LDAP over SSL(LDAPS):
http://www.christowles.com/2010/11/enable-ldap-over-ssl-ldaps-on-windows.html

有什么问题:
实际上,我想为 AD 用户设置密码,所以我的要求是安全连接(LDAPS)。 我可以在不安全的端口 (389) 上成功连接到 DC 并访问 AD 数据,但是 我无法使用 PHP ldap_bind() 函数在安全连接(端口 636)上绑定用户。 当我运行脚本时,它给出“ldap_bind() [function.ldap-bind]:无法绑定到服务器:无法联系 LDAP 服务器”错误。

代码:

$ip="xxx.xxx.xxx.xx";

$ldaps_url="ldaps://s1.xyz.com:636/";

$ldap_url="s1.xyz.com";

$ldapUsername ="Administrator@xyz.com";

$ldapPassword="x1y1z1";

$ds=ldap_connect($ldaps_url);

//$ds=ldap_connect($ip,636);

ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION,3);

ldap_set_option($ds, LDAP_OPT_REFERRALS,0);

$bth=ldap_bind($ds, $ldapUsername, $ldapPassword);

ldap_unbind($ds);

$ds="";

【问题讨论】:

标签: php ssl active-directory ldap ca


【解决方案1】:

可能 s1.xyz.com 无法解析。改用 ip 试试。比如 ldaps://ip.goes.here:636。

【讨论】:

  • IP 地址的问题是该IP 地址可能没有颁发服务器证书(它们通常颁发给主机名)。
  • 感谢 Todd Murray。我也尝试使用域控制器 (DC) 服务器的 IP 地址进行连接,但也失败了。
【解决方案2】:

如果您使用 SSL(例如 ldaps)并且 ldap_bind 抛出 'Unable to bind to server:' 错误,请检查 ldap_connect 中使用的主机名是否与 SSL 中的“CN”匹配LDAP 服务器上的证书。例如:

<?
    ldap_connect('ldaps://ldap01');
   // 'ldap01' should match the CN in your LDAP server's SSL cert, otherwise the subsequent ldap_bind() will throw a bind error

?>

您可以使用 Microsoft MMC 查看您的证书。

【讨论】:

  • 谢谢@JPBlanc。我使用 MS MMC 查看了我的 SSL 证书,它的主题字段值是“s1.xyz.com”,实际上我想绑定它。现在我的 ssl 证书在证书中(本地计算机)-> 个人-> MMC 向导中的证书文件夹。我里面有多个证书。我不知道到底是什么问题。请帮助。
猜你喜欢
  • 1970-01-01
  • 2019-04-02
  • 1970-01-01
  • 2019-11-25
  • 1970-01-01
  • 2014-09-24
  • 2017-07-26
  • 2023-03-13
  • 2011-03-30
相关资源
最近更新 更多