phpldapadmin não consegue se conectar ao servidor LDAP usando ldaps

3

Atualizar

Eu consegui reproduzir o problema em uma escala menor usando um script php simples que tenta uma ligação LDAP. A partir desse script, recebi mais resultados de depuração, o que me permite identificar o problema real. Então estou reescrevendo esta questão.

Cenário

Estou tentando configurar um ambiente LDAP no meu servidor Debian Wheezy.
Eu quero proteger a comunicação com o servidor usando um certificado SSL válido (ou seja, não é auto-assinado). Eu estou usando uma versão auto-compilada do OpenLDAP porque a versão mais recente no repositório Debian não suporta hashes de senhas SHA2.

Detalhes do problema

Eu posso usar este simples script PHP para tentar ligar ao meu servidor LDAP.

<?php
        error_reporting(E_ALL);
        ini_set('display_errors', 'On');
        /* if I remove this, it doesn't work */
        putenv('LDAPTLS_CACERT=/path/to/my/root.ca');
        $uri='ldaps://localhost';
        if (!ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, 7) ) {
                die('log level option failed\n');
        }
        $ldap = ldap_connect($uri) or die ('connect failed');
        if ( !ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3) ) {
                die('protocol version set failed\n');
        }
        if ( !ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0) ) {
                die('referrals option set failed\n');
        }
        $dn = 'cn=root,dc=domain,dc=tld';
        $pw = '...';
        $bind = ldap_bind($ldap, $dn, $pw);
        if ($bind) {
                echo 'bind succeeded\n';
        } else {
                echo 'bind failed\n';
        }
        ldap_close($ldap);
        echo '<p>blubb</p>';
?>

A ligação falha e o script produz as seguintes mensagens no meu log de erros do apache:

ldap_create
ldap_url_parse_ext(ldaps://localhost)
ldap_bind_s
ldap_simple_bind_s
ldap_sasl_bind_s
ldap_sasl_bind
ldap_send_initial_request
ldap_new_connection 1 1 0
ldap_int_open_connection
ldap_connect_to_host: TCP localhost:636
ldap_new_socket: 20
ldap_prepare_socket: 20
ldap_connect_to_host: Trying 127.0.0.1:636
ldap_pvt_connect: fd: 20 tm: -1 async: 0
TLS: peer cert untrusted or revoked (0x42)
TLS: can't connect: (unknown error code).
ldap_err2string

Portanto, é obviamente um problema de certificado. Eu acho que a biblioteca php ldap, por algum motivo, não encontra / usa meu ldap.conf (que está localizado em /usr/local/etc/openldap ) e, portanto, não usa o TLS_CACERT fornecido lá.
Eu tentei fazer o symlinking /usr/local/etc/openldap/ldap.conf to /etc/openldap/ldap.conf , que normalmente é o local padrão. Isso infelizmente não funcionou também.

Atualizar Consegui fazê-lo funcionar colocando

putenv('LDAPTLS_CACERT=/path/to/my/root.ca');

dentro do meu script. Isso prova que o php não usa meu ldap.conf . Seria uma solução razoável colocar essa variável de ambiente na minha configuração do phpldapadmin?

Outras ferramentas do cliente LDAP não php, como ldapsearch , funcionam perfeitamente.

Alguém tem uma idéia do que poderia fazer com que a biblioteca cliente ldap do php não encontre / use meu ldap.conf ?

Configuração do Sistema

slapd.conf

cat /usr/local/etc/openldap/slapd.conf

include         /usr/local/etc/openldap/schema/core.schema
include         /usr/local/etc/openldap/schema/cosine.schema
include         /usr/local/etc/openldap/schema/inetorgperson.schema

pidfile         /var/run/slapd/slapd.pid
argsfile        /var/run/slapd/slapd.args

# self-compiled to enable SHA2 password hash support
modulepath /usr/local/lib
moduleload pw-sha2.so

database        bdb
suffix          "dc=domain,dc=tld"
rootdn          "cn=root,dc=domain,dc=tld"
cachesize       2000

# Use this command to generate a SHA512 hash:
# slappasswd -o module-path=/usr/local/lib -o module-load=pw-sha2.so -h "{SSHA512}"
rootpw          {SSHA512}...

directory       /var/ldap
mode 0600
# Indices to maintain
index   objectClass     eq
index   cn              pres,eq

###############################################################################
# Logging stuff
###############################################################################
loglevel      488

###############################################################################
# TLS stuff
###############################################################################

TLSCipherSuite        ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS
TLSCertificateFile    path to certificate file
TLSCertificateKeyFile path to key file
TLSCACertificateFile  path to CA certificate file
TLSVerifyClient       never

###############################################################################
# LDAP security stuff
###############################################################################

password-hash {SSHA512}
security update_tls=256 ssf=256
require authc bind

###############################################################################
# ACLs
###############################################################################

# enable users to change their own password. Everyone else can only use it for auth
#access to * by *
access to attrs=userPassword
       by self write
       by * auth

parâmetros de inicialização do slapd

ps aux | grep slapd
ldap      4801  0.0  0.0  73612  7924 ?        Ssl  07:19   0:00 /usr/local/bin/slapd -h ldaps://127.0.0.1:636 -g ldap -u ldap -f /usr/local/etc/openldap/slapd.conf

ldap.conf

cat /usr/local/etc/openldap/ldap.conf

BASE    dc=domain,dc=tld
URI     ldaps://127.0.0.1:636

#TLS_REQCERT     never
TLS_CACERT      path to CA certificate file

phpldapadmin config.php (todos os comentários foram removidos)

<?php
  $config->custom->debug['level'] = 255;
  $config->custom->debug['syslog'] = true;
$config->custom->appearance['friendly_attrs'] = array(
    'facsimileTelephoneNumber' => 'Fax',
    'gid'                      => 'Group',
    'mail'                     => 'Email',
    'telephoneNumber'          => 'Telephone',
    'uid'                      => 'User Name',
    'userPassword'             => 'Password'
);
   $config->custom->modify_member['attr'] = 'dn';


$servers = new Datastore();
$servers->newServer('ldap_pla');
$servers->setValue('server','name','domain.tld LDAP server');
/* according to documentation port must be provided in URI and server->port
 * must be 0 when using ldaps
 */
$servers->setValue('server','host','ldaps://127.0.0.1:636');
$servers->setValue('server','port',0);
$servers->setValue('server','base',array('dc=domain,dc=tld'));
$servers->setValue('login','auth_type','session');
$servers->setValue('login','bind_id','cn=root,dc=domain,dc=tld');
/* no need to enable this, if ldap is running on port 636 with ldaps:// */
$servers->setValue('server','tls',false);
$servers->setValue('login','anon_bind',false);
?>

Conteúdo do banco de dados LDAP (apenas começando;))

slapcat

dn: dc=domain,dc=tld
dc: domain
objectClass: dcObject
objectClass: organizationalUnit
structuralObjectClass: organizationalUnit
entryUUID: c2dc8e83-77a6-47ca-b245-f74636aca48f
creatorsName: cn=root,dc=domain,dc=tld
createTimestamp: 20140928123911Z
ou: domain.tld
entryCSN: 20140929080227.350590Z#000000#000#000000
modifiersName: cn=root,dc=domain,dc=tld
modifyTimestamp: 20140929080227Z

O que eu tentei

Para garantir que isso não seja um problema de configuração SSL, invoquei:

openssl s_client -connect localhost:636 -CAfile /path/to/CA_certificate.file -verify 5 

CONNECTED(00000003)
depth=2 C = IL, O = StartCom Ltd., OU = Secure Digital Certificate Signing, CN = StartCom Certification Authority
verify return:1
depth=1 C = IL, O = StartCom Ltd., OU = Secure Digital Certificate Signing, CN = StartCom Class 1 Primary Intermediate Server CA
verify return:1
depth=0 description = BNw48VehLnkei38O, C = DE, CN = domain.tld, emailAddress = [email protected]
verify return:1
---
Certificate chain
 0 s:/description=<stripped>/C=DE/CN=domain.tld/[email protected]
   i:/C=IL/O=StartCom Ltd./OU=Secure Digital Certificate Signing/CN=StartCom Class 1 Primary Intermediate Server CA
 1 s:/C=IL/O=StartCom Ltd./OU=Secure Digital Certificate Signing/CN=StartCom Class 1 Primary Intermediate Server CA
   i:/C=IL/O=StartCom Ltd./OU=Secure Digital Certificate Signing/CN=StartCom Certification Authority
 2 s:/C=IL/O=StartCom Ltd./OU=Secure Digital Certificate Signing/CN=StartCom Certification Authority
   i:/C=IL/O=StartCom Ltd./OU=Secure Digital Certificate Signing/CN=StartCom Certification Authority
---
Server certificate
-----BEGIN CERTIFICATE-----
<stripped>
-----END CERTIFICATE-----
subject=/description=BNw48VehLnkei38O/C=DE/CN=domain.tld/[email protected]
issuer=/C=IL/O=StartCom Ltd./OU=Secure Digital Certificate Signing/CN=StartCom Class 1 Primary Intermediate Server CA
---
No client certificate CA names sent
---
SSL handshake has read 5739 bytes and written 891 bytes
---
New, TLSv1/SSLv3, Cipher is AES256-GCM-SHA384
Server public key is 4096 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
SSL-Session:
    Protocol  : TLSv1.2
    Cipher    : AES256-GCM-SHA384
    Session-ID: <stripped>
    Session-ID-ctx: 
    Master-Key: <stripped>
    Key-Arg   : None
    PSK identity: None
    PSK identity hint: None
    SRP username: None
    TLS session ticket lifetime hint: 300 (seconds)
    TLS session ticket:
    <stripped>

    Start Time: 1412055431
    Timeout   : 300 (sec)
    Verify return code: 0 (ok)

O ldapsearch funciona perfeitamente:

su www-data -c 'ldapsearch -H "ldaps://localhost" -b "dc=domain,dc=tld" -s base "dc=domain,dc=tld" -D "cn=root,dc=domain,dc=tld" -w"<stripped>" -v -d256'
ldap_initialize( ldaps://localhost:636/??base )
filter: dc=domain,dc=tld
requesting: All userApplication attributes
# extended LDIF
#
# LDAPv3
# base <dc=domain,dc=tld> with scope baseObject
# filter: dc=domain,dc=tld
# requesting: ALL
#

# search result
search: 2
result: 0 Success

# numResponses: 1

Versões

Estas são as versões dos pacotes de software relevantes que uso:

OpenLDAP (auto-compilado)

slapd -V
@(#) $OpenLDAP: slapd 2.4.39 (Sep 28 2014 22:28:35)

PHP

php --version
PHP 5.4.4-14+deb7u14 (cli) (built: Aug 21 2014 08:36:44)

Apache

apache2 -v
Server version: Apache/2.2.22 (Debian)
Server built:   Jul 24 2014 15:34:00

phpldapadmin (do SID)

cat /usr/share/phpldapadmin/VERSION
RELEASE-1.2.2

Desculpe por essa longa pergunta. Espero que alguém possa me ajudar, porque estou sem idéias. Muito obrigado por qualquer ajuda antecipadamente!

    
por Chris 30.09.2014 / 08:13

1 resposta

0

Ok, consegui resolvê-lo.
Eu precisava de um link simbólico de /usr/local/etc/openlad/ldap.conf para /etc/ldap/ldap.conf

    
por 01.10.2014 / 10:26

Tags