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

I wonder if anyone has ever implemented bi-directional TLS communication with a server? My code sends SOAP requests via "normal" HTTP just fine, but I have never done HTTPS with both sides exchanging credentials. Code excerpts/samples or a reference to documentation would be very much appreciated. Thank you in advance.

Replies are listed 'Best First'.
Re: Bi-directional TLS with LWP
by zwon (Abbot) on Nov 24, 2009 at 23:43 UTC

    Could you tell a bit more about your problem? What have you tried already? What do you mean by HTTPS with both sides exchanging credentials? Do you mean SSL authentication or what? Have a look onto IO::Socket::SSL.

    Update: oh, I missed LWP in subject. You should install Crypt::SSLeay in order to enable TLS support in LWP.

      Here's what I tried:
      use warnings; use strict; use LWP; use HTTP::Message; # For TLS connection use LWP::Protocol::https; use Crypt::SSLeay; # TLS stuff $ENV{HTTPS_DEBUG} = 1; $ENV{HTTPS_VERSION} = 3; $ENV{'HTTPS_CERT_FILE'} = '/opt/CT/certs/EHR_ICA.ihe.net.pem'; $ENV{'HTTPS_KEY_FILE'} = '/opt/CT/requests/EHR_ICA.ihe.net.pem'; my $req = HTTP::Request->new(POST => $self->{'endpoint'}); # ...
      I installed the certificate and passkey files, but when I run my script, here is what I get:
      $ perl -w xds_qry.pl Enter PEM pass phrase: SSL_connect:before/connect initialization SSL_connect:SSLv3 write client hello A SSL_connect:failed in SSLv3 read server hello A Enter PEM pass phrase: SSL_connect:before/connect initialization SSL_connect:SSLv2 write client hello A SSL_connect:failed in SSLv2 read server hello A syntax error at line 1, column 0, byte 0: 500 SSL negotiation failed: ^ at /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/XML/Par +ser.pm line 187
      It seems strange to me that the passkey prompt comes up in the first place. I tried a few options, but they didn't work.

        There's no need in

        # For TLS connection use LWP::Protocol::https; use Crypt::SSLeay;
        LWP should use them automatically. Also $ENV{HTTPS_VERSION} = 3 should allow only SSLv3, try $ENV{HTTPS_VERSION} = 23 if you want TLS.