logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: Apache on Windows 7 - Windows LDAP and SSL
Author
MikeM-2468



Joined: 19 Oct 2012
Posts: 12

PostPosted: Fri 19 Oct '12 20:44    Post subject: Apache on Windows 7 - Windows LDAP and SSL Reply with quote

I have Apache 2.2.17 running on Windows 7. I'm using PHP to query a Windows 2008 LDAP server. Everything works ok until I try to use LDAPS. Many of the resources I can find refer to a ldap.conf file and the certificates being the main problem. I don't have an ldap.conf file anywhere, so I put all of the relevant lines in the httpd.conf.

One of the things I'm not sure on is the certificate I'm getting from the 2008 AD server. I haven't found any tutorial that covers it with an implementation in Apache on Windows. Many tutorials cover using LDAP to authenticate to the site, but I need to use it for queries. I used the procedure at http://social.technet.microsoft.com/wiki/contents/articles/2980.ldap-over-ssl-ldaps-certificate.aspx#CustomServerAuthCert to get the certificate installed and exported. But I don't know a way to confirm that it's using the cert I think it is for LDAPS. All LDAPS tests work (LDP.EXE from Windows).

Here is my test script:
Code:

$LDAPUserDomain = "@domain.com";
$LDAPUser = "user";
$LDAPUserPassword = "password";
$LDAPHost = "ldaps://ldap.domain.com";
$connect = ldap_connect($LDAPHost) or die("Could not connect to LDAP");
ldap_set_option($connect, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($connect, LDAP_OPT_REFERRALS, 0);
ldap_bind($connect,$LDAPUser.$LDAPUserDomain,$LDAPUserPassword) or die(ldap_error($connect) . ' (' . ldap_errno($connect) . ')');


Here is what I've added to my httpd.conf (Also tried adding LDAPTrustedGlobalCert with the CA cert):
Code:

LDAPTrustedClientCert CA_BASE64 "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/conf/ssl/LDAPoverSSL.cer"
LDAPVerifyServerCert Off


When I run the test script, I get "Can't contact LDAP server (-1)". The ldap_connect works ok, but the ldap_bind does not. If I change the ldap host in the script to ldap instead of ldaps, it works. I've seen references to splitting the cert into a key file but I get errors when I try to run the commands.
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7355
Location: Germany, Next to Hamburg

PostPosted: Mon 22 Oct '12 11:25    Post subject: Reply with quote

We have there some topic about PHP and ldaps.

if you still have a question please ask again!

http://www.apachelounge.com/viewtopic.php?t=3547
http://www.apachelounge.com/viewtopic.php?p=7884
http://www.apachelounge.com/viewtopic.php?p=19858
Back to top
MikeM-2468



Joined: 19 Oct 2012
Posts: 12

PostPosted: Mon 22 Oct '12 13:13    Post subject: Reply with quote

I had already reviewed those and they don't address my specific question.
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7355
Location: Germany, Next to Hamburg

PostPosted: Mon 22 Oct '12 15:08    Post subject: Re: Apache on Windows 7 - Windows LDAP and SSL Reply with quote

MikeM-2468 wrote:
I've seen references to splitting the cert into a key file but I get errors when I try to run the commands.


Example?

by the way, you forget to specify the needed port in ldap_connect. You connect over the default port which is not SSL
Back to top
MikeM-2468



Joined: 19 Oct 2012
Posts: 12

PostPosted: Mon 22 Oct '12 15:46    Post subject: Reply with quote

I'm searching for the example.

I had tried specifying the port previously but that didn't change anything.
Back to top
MikeM-2468



Joined: 19 Oct 2012
Posts: 12

PostPosted: Mon 22 Oct '12 16:08    Post subject: Reply with quote

No luck finding the example. I guess we should forget I mentioned it. Sounds like it wasn't standard procedure anyway.
Back to top
MikeM-2468



Joined: 19 Oct 2012
Posts: 12

PostPosted: Mon 22 Oct '12 16:44    Post subject: Reply with quote

If LDAPVerifyServerCert Off is set, shouldn't it just work whether the certificate is setup correctly or not?

I have this set in httpd.conf. Is that the correct place?
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7355
Location: Germany, Next to Hamburg

PostPosted: Mon 22 Oct '12 17:04    Post subject: Reply with quote

Ya, paste it into the httpd.conf very end
Back to top
MikeM-2468



Joined: 19 Oct 2012
Posts: 12

PostPosted: Mon 22 Oct '12 17:06    Post subject: Reply with quote

OK, so that's not the problem. Why else would it fail if LDAPVerifyServerCert Off is set?
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7355
Location: Germany, Next to Hamburg

PostPosted: Mon 22 Oct '12 17:46    Post subject: Reply with quote

This is what I would do. Set the error_reporting in PHP to max. Run the relevant script part on the command line to see if apache if the issue or my code itself. Plus a heavy use of print_r() to see what is going on.
Back to top
MikeM-2468



Joined: 19 Oct 2012
Posts: 12

PostPosted: Mon 22 Oct '12 17:56    Post subject: Reply with quote

The only error in the log is "PHP Warning: ldap_bind(): Unable to bind to server: Can't contact LDAP server"

The output from the bind command is "Can't contact LDAP server (-1)"

The ldap_connect command runs without error.
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7355
Location: Germany, Next to Hamburg

PostPosted: Tue 23 Oct '12 10:26    Post subject: Reply with quote

On the manual I found that it is a security feature from PHP... http://de3.php.net/ldap_bind search for SSL in the user comments.
Back to top
MikeM-2468



Joined: 19 Oct 2012
Posts: 12

PostPosted: Tue 23 Oct '12 13:16    Post subject: Reply with quote

That goes back to my original question about ldap.conf. I don't have one of those or know where to put it.
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7355
Location: Germany, Next to Hamburg

PostPosted: Tue 23 Oct '12 14:04    Post subject: Reply with quote

You have that file if you use OpenLDAP instead of M$ AD. I haven't figured out why what fails with PHP. But I think it is about the certificate.
Back to top
MikeM-2468



Joined: 19 Oct 2012
Posts: 12

PostPosted: Tue 23 Oct '12 14:08    Post subject: Reply with quote

Looks like I got this working. Your last link helped me find other resources.

I created a ldap.conf in C:\openldap\sysconf containing the following:
Code:

TLS_REQCERT never
TLSCACertificateFile "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/conf/ssl/CA.pem"

Without both lines it doesn't work.

It must be the openldap client that needs this, because I'm hitting an AD LDAP server.

These links were helpful
http://www.freebsd.org/doc/en/articles/ldap-auth/article.html
https://bugs.php.net/bug.php?id=48866
http://stackoverflow.com/questions/10534724/do-i-need-ldap-conf-when-i-connect-to-active-directory-using-php
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7355
Location: Germany, Next to Hamburg

PostPosted: Tue 23 Oct '12 23:16    Post subject: Reply with quote

MikeM-2468 wrote:

It must be the openldap client that needs this, because I'm hitting an AD LDAP server.


The compiled in LDAP client in PHP or an external resource you use?
So you just created those folders in C: and the ldap.conf?
Back to top
MikeM-2468



Joined: 19 Oct 2012
Posts: 12

PostPosted: Wed 24 Oct '12 14:08    Post subject: Reply with quote

It must be the client compiled into PHP. There is no other client.

Yes, I just created the folder and file.
Back to top
MikeM-2468



Joined: 19 Oct 2012
Posts: 12

PostPosted: Wed 24 Oct '12 15:21    Post subject: Reply with quote

But....

Using "TLS_REQCERT never" allows it to work, but it won't work for modify commands. Looks like I still have a certificate issue because I think the client needs to accept the cert, not ignore it for the modify commands to work.
Back to top
MikeM-2468



Joined: 19 Oct 2012
Posts: 12

PostPosted: Wed 24 Oct '12 18:13    Post subject: Reply with quote

I fixed the certificate issue, but still can't use the modify commands. I get "Server is unwilling to perform". I get similar error when using ldp.exe to run the same request. Maybe I have a syntax/formatting issue. I think Apache is ok.
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7355
Location: Germany, Next to Hamburg

PostPosted: Wed 24 Oct '12 22:14    Post subject: Reply with quote

There can be a lot of reasons for that issue.
php ldap Server is unwilling to perform
Back to top


Reply to topic   Topic: Apache on Windows 7 - Windows LDAP and SSL View previous topic :: View next topic
Post new topic   Forum Index -> Apache