Saturday, February 8, 2014

REST::Client and invalid TLS certificates

A couple of days ago I had the need to consume data from a REST application to complete a test automation job that I was creating.
While I could do it by simple using curl in a shell, the response was also in JSON, which I would need to process anyway, so I decided to do it with a Perl script using REST::Client and JSON::XS.
Since I was working in a development environment, the TLS certificates were self-signed and thus, not valid.
Looking for an option with REST::Client Pod I was disappointed to find nothing. That should be an easy enough thing to do.
REST::Client is built over LWP::UserAgent, so after some researching I found an option with it that does the job:

my $client = REST::Client->new();
$client->getUseragent()->ssl_opts( verify_hostname => 0 ); 

Simple enough. Also a shame to find nothing about it in Google (well, at least until now :-) ).