Q:

Perl UserAgent won't connect to TLS1.2 server

Perl version is = v5.12.4
LWP::UserAgent->VERSION = 6.03

   #.... 
   # Setup HTTP request
   my $req = HTTP::Request->new();
   $req->method($cmd);
   $req->uri($uri);
   $req->header('content-type' => 'application/json');
   $req->header('Accept' => 'application/json');

   # Setup the call
   my $ua = LWP::UserAgent->new(ssl_opts => { verify_hostname => 0,
                                              SSL_version => 'tlsv12' });
   $ua->timeout(60);

   # Do the call
   my $resp = $ua->request($req);
   # ....

The http code is always 500 and I get the error message - 

"Can't connect to 10.0.0.1:443".

I have tried various SSL_versions string tlsv12, tslv1.2, TSLv1, TLSv12, TLS, etc. to no avail. I know the server expects TLS 1.2. Same HTTP call through curl works fine. 
Additional Debug output..
Perl -MIO::Socket::SSL=debug4  powervc_cli.pl -O
DEBUG: .../IO/Socket/SSL.pm:193: set domain to 2
DEBUG: .../IO/Socket/SSL.pm:1545: new ctx 140528264056208
DEBUG: .../IO/Socket/SSL.pm:334: socket not yet connected
DEBUG: .../IO/Socket/SSL.pm:336: socket connected
DEBUG: .../IO/Socket/SSL.pm:349: ssl handshake not started
DEBUG: .../IO/Socket/SSL.pm:379: set socket to non-blocking to enforce timeout=60
DEBUG: .../IO/Socket/SSL.pm:392: Net::SSLeay::connect -> -1
DEBUG: .../IO/Socket/SSL.pm:402: ssl handshake in progress
DEBUG: .../IO/Socket/SSL.pm:412: waiting for fd to become ready: SSL wants a read first
DEBUG: .../IO/Socket/SSL.pm:432: socket ready, retrying connect
DEBUG: .../IO/Socket/SSL.pm:392: Net::SSLeay::connect -> 0
DEBUG: .../IO/Socket/SSL.pm:440: connection failed - connect returned 0
DEBUG: .../IO/Socket/SSL.pm:1276: SSL connect attempt failed because of handshake problemserror:00000000:lib(0):func(0):reason(0)

DEBUG: .../IO/Socket/SSL.pm:1276: IO::Socket::INET6 configuration failederror:00000000:lib(0):func(0):reason(0)

DEBUG: .../IO/Socket/SSL.pm:1582: free ctx 140528264056208 open=140528264056208
DEBUG: .../IO/Socket/SSL.pm:1590: OK free ctx 140528264056208

Please help! -Eddie

A:

DEBUG: .../IO/Socket/SSL.pm:392: Net::SSLeay::connect -> 0
DEBUG: .../IO/Socket/SSL.pm:440: connection failed - connect returned 0
DEBUG: .../IO/Socket/SSL.pm:1276: SSL connect attempt failed because of handshake problemserror:00000000:lib(0):func(0):reason(0)

This looks like the server did not like what the client sent as the SSL handshake and thus the server closed the connection. Why the server did this is not clear but you might find error messages on the server side. 

Same HTTP call through curl works fine.

If this is really a HTTP call (i.e. no HTTPS) you do with curl than your problem is that the server expects HTTP w/o SSL but your code with LWP uses HTTP with SSL (HTTPS). But if a HTTPS call with curl succeeds then you can debug the problem by making packet captures of the successful call with curl and the unsuccessful with LWP and compare the handshakes. 

I have tried various SSL_versions string tlsv12, tslv1.2, TSLv1, TLSv12, TLS, etc. to no avail.

With current versions of IO::Socket::SSL it will accept TLSv12 and TLSv1_2 for TLS 1.2 and TLSv1 for TLS 1.*, case does not matter. Specifying only "TLS" will cause IO::Socket::SSL to croak. Older versions of IO::Socket::SSL (before version 1.70 from 2012) simply ignored invalid settings. See also the documentation which describes the settings.

