Beefy Boxes and Bandwidth Generously Provided by pair Networks BBQ
P is for Practical
 
PerlMonks  

LWP_SSL_Verify_mode option

by packetstormer (Monk)
on Oct 30, 2013 at 11:52 UTC ( #1060341=perlquestion: print w/ replies, xml ) Need Help??
packetstormer has asked for the wisdom of the Perl Monks concerning the following question:

Hello!

I have a script that calls an HTTPS site. The SSL cert is self signed and I would like the script to accept it regardless. I can do this when calling LWP::UserAgent->new or by using $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME}=0;. I know this isn't the best idea but it gets around the warnings.

My question is: Is there a way to invoke this option when not calling LWP::UserAgent directly? In the script, I also call Frontier::Client which in turns calls LWP::UserAgent. However, the global $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME}=0; I have set is ignored and the error appears on STDOUT.
Does anyone know how to pass this option to a method which in turns call the LWP::Agent new method?

Comment on LWP_SSL_Verify_mode option
Select or Download Code
Re: LWP_SSL_Verify_mode option
by daxim (Chaplain) on Oct 30, 2013 at 12:22 UTC
    Adapted from my answer at How to ignore 'Certificate Verify Failed' error in perl?:
    use IO::Socket::SSL qw(); use LWP::UserAgent qw(); my $ua = LWP::UserAgent->new(ssl_opts => { SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE, verify_hostname => 0, # this key is likely going to be removed in +future LWP >6.04 });
    Then set the ua attribute on the Frontier::Client instance.
Re: LWP_SSL_Verify_mode option
by packetstormer (Monk) on Oct 30, 2013 at 12:43 UTC
    Then set the ua attribute on the Frontier::Client instance.

    This is the part I am having trouble with. Frontier::Client doesn't seem to allow me to do this!?

      This is the part I am having trouble with. Frontier::Client doesn't seem to allow me to do this!?

      Use the Source, Luke, look inside

      $self->{'ua'} = LWP::UserAgent->new; $self->{'ua'}->proxy('http', $self->{'proxy'}) if(defined $self->{'proxy'}); $self->{'rq'} = HTTP::Request->new (POST => $self->{'url'}); $self->{'rq'}->header('Content-Type' => 'text/xml');
Re: LWP_SSL_Verify_mode option
by Khen1950fx (Canon) on Oct 31, 2013 at 04:33 UTC
    First, I've never actually used Frontier::Client. Second, if I was inclined to use it, I would probably go with something like this:
    #!/usr/bin/perl -l use strict; use warnings; use LWP::UserAgent; use Frontier::Client; use Data::Dumper::Concise; my $ua = LWP::UserAgent->new( ssl_opts => { verify_hostname => 0 }, protocols_allowed => ['https'], ); my $req = HTTP::Request->new( GET => 'https://pause.perl.org', ); my $res = $ua->request($req); print $res->code; my $server = Frontier::Client->new( url => 'https://pause.perl.org', encoding => 'ISO-8859-1', debug => 1, ); my $date_time = $server->call('date_time'); print Dumper( $date_time );
    I was was just trying to make it work, so feel free to add to or subtract from ssl_opts. Good luck:-).

      First, I've never actually used Frontier::Client. Second, if I was inclined to use it, I would probably go with something like this:

      Double request? Smart!

Re: LWP_SSL_Verify_mode option
by natxo (Sexton) on Nov 01, 2013 at 11:32 UTC
    you could also write a wrapper shell script with that environment variable (envvar) in it. You then start the perl scripts from that wrapper shell script.

    Or you could add your envvar to your profile, then all the processes you start would inherit it (not ideal if you want to verify the certificates, but if you don't care ...).

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1060341]
Approved by ww
Front-paged by toolic
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (9)
As of 2014-04-20 22:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (488 votes), past polls