我已经安装了 Ubuntu Desktop 18.04 和 LAMP,启用了 LDAP 等。我能够通过 LDAP 和端口 389 进行连接。当我尝试与 636 上的 LDAPS 连接时,我被阻止了。我已经在 Windows 中使用 LDP 连接到服务器以验证 SSL 是否已启用,并且我可以在 LDP 程序中使用 SSL 连接到服务器。
这是一个全新的虚拟机,具有运行 Ubuntu 18.04 桌面的桥接网络连接。我尝试了多组代码和不同的 AD 用户帐户,从基本用户帐户到域管理员帐户。
<?php
$ldaphost = "ldaps://my.domain.controller"; //edited for security purposes
$ldapport = 636;
$lconn = ldap_connect($ldaphost) // also tried $lconn = ldap_connect($ldaphost,$ldapport); to no avail
or die("Could not connect to host!");
如前所述,如果我将其更改为标准 LDAP,以便我知道它已正确启用,它就可以工作。我已经在网上搜索了几个小时,其他都没有帮助。
LDP 计划提供以下信息:
0x0 = ldap_unbind(ld);
ld = ldap_sslinit("my.domain.controller", 636, 1);
Error 0 = ldap_set_option(hLdap, LDAP_OPT_PROTOCOL_VERSION, 3);
Error 0 = ldap_connect(hLdap, NULL);
Error 0 = ldap_get_option(hLdap,LDAP_OPT_SSL,(void*)&lv);
Host supports SSL, SSL cipher strength = 256 bits
Established connection to my.domain.controller.
Retrieving base DSA information...
Getting 1 entries:
编辑:最终成为证书错误。他们没有被前任政府正确设置。现在正在努力修复它们。
您将需要验证一些内容:
- 来自 DC 的 CA 证书安装在 Ubuntu 服务器上。
- 从 CA 签名的 SSL 证书与证书的 CN 中的 FQDN(或 IP- 取决于 LDAPS uri 的写入方式(安装在 Ubuntu 服务器上。
- 如果使用 openldap 进行连接的任何部分,请像这样修改您的 ldap.conf:
BASE dc=domain,dc=com
URI ldaps://dc.domain.com:636
TLS_CACERT /path/to/ca-cert.cer
TLS_REQCERT DEMAND
然后 LDAP 搜索应返回包含类似于以下内容的查询的结果:
ldapsearch -x -H ldaps://dc.domain.com -D 'CN=LDAP-bind,OU=Service Accounts,OU=Accounts,DC=domain,DC=com' -W -b 'OU=Accounts,DC=domain,DC=com'
这些是我在将 Web 应用程序设置为通过 LDAPS 进行身份验证→为Microsoft Active Directory 服务器启用基于 SSL 的 LDAP 时遵循的说明
这是我用来测试来自不同客户端服务器的 LDAPS 连接的代码。
class LDAP {
public function connect($host, $user, $pass){
$ds = ldap_connect($host);
if(!ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3)){
print "Could not set LDAPv3";
} else {
$ldap = ldap_bind($ds, $user, $pass);
}
if(strpos($host, 'ldaps://') !== false){
$ssl = ' over SSL';
$host = str_replace('ldaps://', '', $host);
} else {
$ssl = null;
$host = str_replace('ldap://', '', $host);
}
if($ldap) {
//$host = str_replace('ldap://', replace, subject)
echo '<b>LDAP</b> : <u>Microsoft AD</u> <br /><br />
Connection to <u>' . $host . '</u>' . $ssl . ' was successful! <br /><br />
[WebServer] ←→ [LDAP Server] <br /><br />
<b>Status:</b> <u>Up</u> ✔ <br />';
} else {
echo 'Connection to <u>' . $host . '</u>' . $ssl . ' was NOT successful. Please try again. <br /><br />
[WebServer] ←x→ [LDAP Server] <br /><br />
<b>Status:</b> <u>Down</u> ✖ <br />';
}
}
public function disconnect(){
$ldap = null;
}
} # class ldap
$LDAP = new LDAP();
$host = "ldaps://dc.domain.com";
$user = "svc.ldap@domain.com";
$pass = "password1";
$LDAP->connect($host, $user, $pass);
$LDAP->disconnect();
// echo 'HOST['.$host.'] USER['.$user.']'; // toggle to troubleshoot db connection