PHP connect AD with LDAP over SSL (LDAPs)

《Server is unwilling to perform》之后的三个多月,终于有了测试环境。节后的第一个工作日,用了一个下午的时间进行测试,终于成功了。

主要参考文档为adldapLDAP over SSL

环境:win2003 server 用于安装ad和ca,ubuntu做为webserver,安装apache2和php

准备工作:运行phpinfo(),确认php环境已经支持openssl和openldap,关于php环境的配置不多说了。

step 1:安装CA,用来颁发证书,微软或者第三方的都可以,我装的微软的CA,这里很简单

参考文档:安装windows server 2003 证书服务(CA) 企业数字证书认证服务

setp 2:创建证书,并使ad下的ldap开启对ssl的支持,配置完成之后可以使用ldp.exe来测试ldaps连接是否成功,这里也很简单,照着文档做就OK。

参考文档:How to enable LDAP over SSL with a third-party certification authority (千万别看中文的,机器翻译实在是挺愁人)

如何使用 MMC 管理单元查看证书

step 3:导出证书,将cer格式的证书转换成pem格式,放在webserver(linux)上;配置ldap.conf,使apache可以使用证书。

参考文档:Communicating between OpenLDAP and Active Directory over SSL

实际上我的大部分时间都在测试第三步,证书转换很简单,照搬文档中的命令就可以了,但在配置ldap.conf的时候我有点糊涂,一方面是因为ubuntu上ldap.conf的路径不同,让我有点犹豫,不过经过反复测试还是搞定了。ubuntu下,修改/etc/ldap/ldap.conf,将原有内容全部删除(至少在我的测试环境中保留原有内容是不成功的),然后写入如下两句:

TLS_CACERT /var/www/cert/certnew.pem #证书的绝对路径

TLS_REQCERT never

done.

Comments (3)

  1. Nerr  / Reply

    Subject = “CN=
    Subject = “CN=dcname,DC=domainname,DC=com”

  2. akiler  / Reply

    就是下面的代码,subject里应该填什么呢?DNS应该体现在哪里呢?希望能指点指点,谢谢
    ;—————– request.inf —————–

    [Version]

    Signature=”$Windows NT$

    [NewRequest]

    Subject = “CN=” ; replace with the FQDN of the DC
    KeySpec = 1
    KeyLength = 1024
    ; Can be 1024, 2048, 4096, 8192, or 16384.
    ; Larger key sizes are more secure, but have
    ; a greater impact on performance.
    Exportable = TRUE
    MachineKeySet = TRUE
    SMIME = False
    PrivateKeyArchive = FALSE
    UserProtected = FALSE
    UseExistingKeySet = FALSE
    ProviderName = “Microsoft RSA SChannel Cryptographic Provider”
    ProviderType = 12
    RequestType = PKCS10
    KeyUsage = 0xa0

    [EnhancedKeyUsageExtension]

    OID=1.3.6.1.5.5.7.3.1 ; this is for Server Authentication

    ;———————————————–

  3. akiler  / Reply

    能给个创建LDAP的证书的例子(php)吗? 我在创建时,系统说DNS名不可用。

Leave a Reply

Allowed Tags - You may use these HTML tags and attributes in your comment.

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

 :wink:  :-|  :-x  :twisted:  :)  8-O  :(  :roll:  :-P  :oops:  :-o  :mrgreen:  :lol:  :idea:  :-D  :evil:  :cry:  8)  :arrow:  :-?  :?:  :!:

Pingbacks (0)

› No pingbacks yet.