Probleme mit sichere Bindung zu Active Directory mit PHP
Scheine ich unfähig zu sein, um php zu benutzen, um sichere Bindung zu Active Directory. Unverschlüsselte verbindungen funktionieren. Mit anderen clients sind in der Lage, sicher zu binden, z.B. den Anschluss mit LDAPAdmin über SSL. Was ist hier das problem? Gibt es einige LDAP-SSL-Modul, das mir fehlt? Wie sicher binden an den server mit php?
Bemerkte ich aus phpinfo()
dass LOCKE hat die Unterstützung für ldap - /ldaps - was ist ein gutes Beispiel, die Verwendung dieser, um eine sichere Bindung in php? Ist das eine praktikable Lösung?
phpinfo();
ldap
LDAP Support enabled
RCS Version $Id: ldap.c 293036 2010-01-03 09:23:27Z sebastian $
Total Links 0/unlimited
API Version 3001
Vendor Name OpenLDAP
Vendor Version 20421
SASL Support Enabled
Versucht hat, eine Bindung an ein Active Directory server mit PHP Version 5.3.2-1ubuntu4.7 von Ubuntu 10.04 repo
$username = 'user';
$password = 'passwd';
$account_suffix = '@example.com';
$hostnameSSL = 'ldaps://ldap.example.com:636';
$hostnameTLS = 'ldap.example.com';
$portTLS = 389;
ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, 7);
//Attempting fix from http://www.php.net/manual/en/ref.ldap.php#77553
putenv('LDAPTLS_REQCERT=never');
####################
# SSL bind attempt #
####################
//Attempting syntax from http://www.php.net/manual/en/function.ldap-bind.php#101445
$con = ldap_connect($hostnameSSL);
if (!is_resource($con)) trigger_error("Unable to connect to $hostnameSSL",E_USER_WARNING);
//Options from http://www.php.net/manual/en/ref.ldap.php#73191
if (!ldap_set_option($con, LDAP_OPT_PROTOCOL_VERSION, 3))
{
trigger_error("Failed to set LDAP Protocol version to 3, TLS not supported",E_USER_WARNING);
}
ldap_set_option($con, LDAP_OPT_REFERRALS, 0);
if (ldap_bind($con,$username . $account_suffix, $password)) die('All went well using SSL');
ldap_close($con);
####################
# TLS bind attempt #
####################
$con = ldap_connect($hostnameTLS,$portTLS);
ldap_set_option($con, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($con, LDAP_OPT_REFERRALS, 0);
$encrypted = (ldap_start_tls($con));
if ($encrypted) ldap_bind($con,$username . $account_suffix, $password); //Unecrypted works, but don't want logins sent in cleartext
ldap_close($con);
#####################
# SASL bind attempt #
#####################
$con = ldap_connect($hostnameTLS,$portTLS);
ldap_set_option($con, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($con, LDAP_OPT_REFERRALS, 0);
ldap_sasl_bind($con, NULL, $password, 'DIGEST-MD5', NULL, $username. $account_suffix);
ldap_close($con);
Alle der oben genannten ausfällt. Fehler aus der log:
ldap_create
ldap_url_parse_ext(ldaps://ldap.example.com:636)
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 ldap.example.com:636
ldap_new_socket: 27
ldap_prepare_socket: 27
ldap_connect_to_host: Trying 1.1.1.1:636
ldap_pvt_connect: fd: 27 tm: -1 async: 0
ldap_open_defconn: successful
ldap_send_server_request
ldap_result ld 0x215380c0 msgid 1
wait4msg ld 0x215380c0 msgid 1 (infinite timeout)
wait4msg continue ld 0x215380c0 msgid 1 all 1
** ld 0x215380c0 Connections:
* host: ldap.example.com port: 636 (default)
refcnt: 2 status: Connected
last used: Thu Mar 10 11:15:53 2011
** ld 0x215380c0 Outstanding Requests:
* msgid 1, origid 1, status InProgress
outstanding referrals 0, parent count 0
ld 0x215380c0 request count 1 (abandoned 0)
** ld 0x215380c0 Response Queue:
Empty
ld 0x215380c0 response count 0
ldap_chkResponseList ld 0x215380c0 msgid 1 all 1
ldap_chkResponseList returns ld 0x215380c0 NULL
ldap_int_select
read1msg: ld 0x215380c0 msgid 1 all 1
ldap_err2string
[Thu Mar 10 11:15:53 2011] [error] [client ::1] PHP Warning: ldap_bind() [<a href='function.ldap-bind'>function.ldap-bind</a>]: Unable to bind to server: Can't contact LDAP server in /..test.php on line 28
[Thu Mar 10 11:15:53 2011] [error] [client ::1] PHP Stack trace:
[Thu Mar 10 11:15:53 2011] [error] [client ::1] PHP 1. {main}() /..test.php:0
[Thu Mar 10 11:15:53 2011] [error] [client ::1] PHP 2. ldap_bind() /..test.php:28
ldap_free_request (origid 1, msgid 1)
ldap_free_connection 1 1
ldap_free_connection: actually freed
ldap_create
ldap_err2string
[Thu Mar 10 11:15:53 2011] [error] [client ::1] PHP Warning: ldap_start_tls() [<a href='function.ldap-start-tls'>function.ldap-start-tls</a>]: Unable to start TLS: Not Supported in /..test.php on line 37
[Thu Mar 10 11:15:53 2011] [error] [client ::1] PHP Stack trace:
[Thu Mar 10 11:15:53 2011] [error] [client ::1] PHP 1. {main}() /..test.php:0
[Thu Mar 10 11:15:53 2011] [error] [client ::1] PHP 2. ldap_start_tls() /..test.php:37
ldap_create
ldap_sasl_interactive_bind_s: user selected: DIGEST-MD5
ldap_err2string
[Thu Mar 10 11:15:53 2011] [error] [client ::1] PHP Warning: ldap_sasl_bind() [<a href='function.ldap-sasl-bind'>function.ldap-sasl-bind</a>]: Unable to bind to server: Not Supported in /..test.php on line 47
[Thu Mar 10 11:15:53 2011] [error] [client ::1] PHP Stack trace:
[Thu Mar 10 11:15:53 2011] [error] [client ::1] PHP 1. {main}() /..test.php:0
[Thu Mar 10 11:15:53 2011] [error] [client ::1] PHP 2. ldap_sasl_bind() /..test.php:47
Blick auf ssl Antwort:
>> openssl s_client -connect my.example.com:636 -prexit
(...)
SSL handshake has read 5732 bytes and written 443 bytes
---
New, TLSv1/SSLv3, Cipher is RC4-MD5
Server public key is 2048 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
SSL-Session:
Protocol : TLSv1
Cipher : RC4-MD5
Session-ID: 111111111111111111111111
Session-ID-ctx:
Master-Key: AAAAAAAAAAAAAAAAAAAAA
Key-Arg : None
Start Time: 1299071105
Timeout : 300 (sec)
Verify return code: 20 (unable to get local issuer certificate)
Ergebnisse von 'strace php test.php' :
write(2, " refcnt: 2 status: Connected\n", 31 refcnt: 2 status: Connected
) = 31
write(2, " last used: Tue Mar 15 10:59:19"..., 39 last used: Tue Mar 15 10:59:19 2011
) = 39
write(2, "\n", 1
) = 1
write(2, "** ld 0x954e0b8 Outstanding Requ"..., 38** ld 0x954e0b8 Outstanding Requests:
) = 38
write(2, " * msgid 1, origid 1, status In"..., 41 * msgid 1, origid 1, status InProgress
) = 41
write(2, " outstanding referrals 0, pare"..., 43 outstanding referrals 0, parent count 0
) = 43
write(2, " ld 0x954e0b8 request count 1 ("..., 45 ld 0x954e0b8 request count 1 (abandoned 0)
) = 45
write(2, "** ld 0x954e0b8 Response Queue:\n", 32** ld 0x954e0b8 Response Queue:
) = 32
write(2, " Empty\n", 9 Empty
) = 9
write(2, " ld 0x954e0b8 response count 0\n", 32 ld 0x954e0b8 response count 0
) = 32
write(2, "ldap_chkResponseList ld 0x954e0b"..., 48ldap_chkResponseList ld 0x954e0b8 msgid 1 all 1
) = 48
write(2, "ldap_chkResponseList returns ld "..., 47ldap_chkResponseList returns ld 0x954e0b8 NULL
) = 47
write(2, "ldap_int_select\n", 16ldap_int_select
) = 16
poll([{fd=3, events=POLLIN|POLLPRI|POLLERR|POLLHUP}], 1, -1) = 1 ([{fd=3, revents=POLLIN}])
write(2, "read1msg: ld 0x954e0b8 msgid 1 a"..., 37read1msg: ld 0x954e0b8 msgid 1 all 1
) = 37
read(3, "", 8) = 0
write(2, "ldap_err2string\n", 16ldap_err2string
) = 16
write(2, "PHP Warning: ldap_bind(): Unabl"..., 158PHP Warning: ldap_bind(): Unable to bind to server: Can't contact LDAP server in
Und ich habe auch den /etc/ldap.conf fix mit "TLS_REQCERT never" - auch wenn dieses Update ist für eine andere Fehler gibt, die eine ziemlich eindeutige Fehlermeldung.
Es hilft etwas, weil ich versuchte, führen Sie es auf einem anderen Rechner, gegen den gleichen ldap-server und SSL-Bindung gearbeitet. Dies war eine centos-5-server mit php 5.2. Die debug-Ausgabe auch ein paar TLS-Zeilen, die fehlen auf der ubuntu-setup. Was den Fehler auf ubuntu ist, noch entzieht sich mir
Ich habe versucht, ein upgrade auf 10.10, die Schiffe der PHP-Version => 5.3.3-1ubuntu9.3 - ich bekomme immer noch die excact gleichen Ergebnis wie oben beschrieben.
Ihre Frage war, die die meisten nützliche Handbuch über das gesamte internet! Sie machte meinen Tag. Eine Sache könnte jedoch geändert werden. putenv('LDAPTLS_REQCERT=nie'); hatte überhaupt keine Wirkung auf sasl auf meinem windows-Rechner.
InformationsquelleAutor Jon Skarpeteig | 2011-03-10
Du musst angemeldet sein, um einen Kommentar abzugeben.
Hast du unter dem Kommentar auf der PHP.net Seite über fehlende Berechtigungen auf einige cert-store, der dies tut:
http://de3.php.net/manual/en/function.ldap-connect.php
Also vielleicht ist das ja Ihr Problem auch. Wenn nicht, sollten Sie geben entweder strace oder wireshark versuchen zu fangen die syscalls und Netzwerk-übertragungen und herauszufinden, was schief geht. Einer der beiden wird es zeigen, klar.
InformationsquelleAutor schlenk
dies ist, wie ich es mache:
hast, aktivieren Sie das Zertifikat? ich weiß, es war ein problem, wenn die certifiacte wird abgelehnt. Bearbeiten Sie die "/etc/ldap/ldap.conf" und fügen Sie "TLS_REQCERT never"
jedoch, für mich es funktioniert mit ldap und ldaps:
InformationsquelleAutor JMW
War ich endlich in der Lage, die Dinge in der Arbeit auf meinem Windows-Computer durch das Lesen der folgenden PHP-bug-thread:
http://bugs.php.net/bug.php?id=48866
Leider, das ist Windows spezifisch, aber es hat mich zumindest in die richtige Richtung geht jetzt in meinen Tests (ich weiß, sollte es funktionieren von PHP jetzt auf meinem web-server...so lange wie ich ldap.conf richtig konfiguriert). Unter Windows mit PHP 5.3, die ich brauchte, zum hinzufügen von ldap.conf-Datei in den root von meinem Laufwerk C: (andere Beispiele, die ich gesehen hatte online hatte Sie in C:\openldap\sysconf was nicht funktioniert).
TLS funktioniert immer noch nicht genau, (es gibt mir ein "unable to start tls: can 'T contact LDAP server" - Meldung), aber SSL nicht erscheint, um zu arbeiten, und ich war in der Lage, ein Kennwort zu aktualisieren, die für ein Konto in meinem test-Skript.
Ich vermute, dass die ldap.conf-Datei muss nur eingerichtet werden, ähnlich wie auf meinem web-server und sollte ich hoffentlich in der Geschäfts (ich bin nur nicht sicher, ob der eine, der schon da ist, die ich brauche zu ändern oder wenn ich brauche eine zusätzliche). Ich werde sehen, ob ich kann berichten, dass vor.
Auf Windows verwenden, sollten Sie auch in der Lage sein zu tun: putenv('LDAPTLS_REQCERT=nie'); anstelle von ldap.conf beheben. Ich war auch in der Lage, um es arbeiten auf CentOS -, so vermute ich einen bug in apache/ldap/php gebaut für Ubuntu irgendwo..
InformationsquelleAutor Omar Ramos
Als mein code ist in Ordnung arbeiten mit CentOS, schließe ich, dass das problem nicht die Programmierung spezifischer. Ich habe nicht in der Lage gewesen, um es läuft in meine Ubuntu-Umgebung als der noch, aber ich nehme an, dies ist ein Fehler in meiner server-software.
InformationsquelleAutor Jon Skarpeteig
Enthält Ihre Active Directory LDAPS aktiviert? Wenn dem so ist, Holen Sie sich die Vertrauenswürdigen Root-CA-Schlüssels in dem vertrauenswürdigen Schlüsselspeicher.
InformationsquelleAutor geoffc