Search code examples
perlssllwp-useragent

Perl LWP::UserAgent SSL/TLS Inconsistent Certificate Error Message Issue


I seem to have an odd difference in LWP::UserAgent on Ubuntu and CentOS.

On Ubuntu (14.04.1 with LWP::UserAgent 6.05), if I try to connect to a domain with a self-signed certificate, I get this error message with a 500 error code:

"Can't connect to my.test-domain.com:443 (certificate verify failed)"

That's good. I can see exactly what's wrong - a certificate issue. But on CentOS 7 (also with LWP::UserAgent 6.05) I just get this:

"Can't connect to my.test-domain.com:443".

That's less informative, and as such gives me a problem! Does anyone know how I can kick LWP on CentOS to get the "certificate verify failed" message? Here is the script I test with:

#!/usr/bin/perl -w
use strict;
use LWP::UserAgent;
my $url='https://my.test-domain.com/';
my $browser= LWP::UserAgent->new();
my $tryHEAD=$browser->head($url);
my $responseCode=$tryHEAD->code();
if($tryHEAD->code()==200  ) {    print "OK\n"; }
else {    print $tryHEAD->code().' '.$tryHEAD->message()."\n"; }

Solution

  • It seems related to the version of IO::Socket::IP (which is automatically used by IO::Socket::SSL). Without IO::Socket::IP or with version 0.31 (and probably later) it works as intended while with version 0.25 (Ubuntu 14.04) it does not. This is probably related to changes in the handling of connect in version 0.30,0.31.