Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi I have 2 problems which are as listed below:
1.In the first instance i have to check whether the HTTPS
service is running on a remote machine or not.The
following is the code snippet for it:
use LWP::UserAgent; my ($strHttpURL)='https://machinename; $ua = LWP::UserAgent->new; $req = HTTP::Request->new(GET =>$strHttpURL); $res = $ua->request($req); if ($res->is_success) { print ("$strHttpURL connected successfully"); return $TRUE; } else{ print "$strHttpURL not connected"); }
I have secured the https://machinename link. However, the
problem is though i am able to run the above code from
windows, it does not succeed in unix.Also, the
operation succeeds in unix when i try to access any 'http' service.
Is the problem related to some certificate mismatch.

2.The second problem is on the similar lines,here i have to
check whether the LDAPS server is running or not.In
windows i am able to check both the LDP and LDAPS
services. However, in UNIX the LDAP code works fine but
LDAPS again is not able to connect properly.The
following is the code snippet for LDAPS:

use Net::LDAPS; use Net::LDAP; $ldaps = Net::LDAPS->new( $strLDAPIpAdd,port =>$strLDAPPort,onerror=>u +ndef); if ($ldaps==undef) { print("Ip Address of LDAP server over SSL is not correct"); return $ERROR; } $mesg = $ldaps->bind(); if ($mesg->code==0) { print ("LDAP over SSL with ip $strLDAPIpAdd connected successfully!"); $mesg=$ldaps->unbind; } else{ print("LDAP over SSL with ip $strLDAPIpAdd not connected..."); $mesg=$ldaps->unbind; }
I think both the above problems are related.Pls help.
Regds

Replies are listed 'Best First'.
Re: Checking HTTPS and LDAPS thru UNIX
by zengargoyle (Deacon) on Dec 13, 2003 at 10:53 UTC

    take a look at the perldoc for the modules and try to follow their examples.

    my $ldap = Net::LDAPS->new( 'hostname' ) or die "$@";

    then you might get an error message that tells you what's wrong with your code.

    and it is a bit deep in the docs, but you can try this:

    my $ldap = Net::LDAPS->new( 'hostname', verify => 'none' ) or die "$@";

    or even

    my $ldap = Net::LDAP->new( 'myhost.example.com', version => 3 ); my $mesg = $ldap->start_tls( verify => 'require', clientcert => 'mycert.pem', clientkey => 'mykey.pem', decryptkey => sub { 'secret'; }, capath => '/usr/local/cacerts/' );

    the other possibility is that the UNIX system is missing IO::Socket::SSL and/or the openssl libraries that these modules use. getting error messages will help you find out what's happening.

      Zengargoyles last comment was my first idea, so I would look there first as it absolutely will be the problem if you don't have the libs on the Unix box.
      The two libs on win32 are libeay32.dll and ssleay32.dll on Unix I think they are libcrypto.a and libssl.a ( asuming OpenSSL). I would imagine that just looking for the openssl directory would key you into a place to look right away. If they are there... just verify they are in your path.
      JamesNC