Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

How to convert curl authentication method to perl

by newperldeveloper (Novice)
on Feb 28, 2020 at 16:46 UTC ( #11113549=perlquestion: print w/replies, xml ) Need Help??

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

I have a curl command curl --cert ~/Desktop/file.pfx:secret_key --cert-type P12 https://example.com/token The above will return a a json object. How would I go about achieving the same results in perls. I've tried using
use LWP::UserAgent qw(); require LWP::Protocol::https; my $ua = LWP::UserAgent->new; $ua->ssl_opts( SSL_ca_file => '/Downloads/file.pfx', ); my $test = $ua->post('https://example.com/gettoken');
This returns a 500 error.

Replies are listed 'Best First'.
Re: How to convert curl authentication method to perl (client certificate)
by hippo (Chancellor) on Feb 28, 2020 at 16:53 UTC

    SSL_ca_file is for specifying the CA cert file. You want instead to specify your Client cert file and key. Take a look at the SSL_cert_file section of https://metacpan.org/pod/IO::Socket::SSL for some examples and try taking it from there.

      Here is what I have so far and the error I have encountered.
      my $client = IO::Socket::SSL->new( # where to connect PeerHost => "example/gettoken", PeerPort => "https" SSL_cert_file => $cert_file, # typical CA file on BSD SSL_passwd_cb => sub {"secret_key"}, ) or die "failed connect or ssl handshake: $!,$SSL_ERROR"; # send and receive over SSL connection print $client "GET / HTTP/1.0\r\n\r\n"; print <$client>;
      The above code give an error failed connect or ssl handshake: Invalid argument,IO::Socket::IP configuration failed When I comment out peerhost and port I nothing happens. Not sure what to do next. When I print dumper is outputs $VAR1 = bless( \*Symbol::GEN0, 'IO::Socket::SSL' ); Any help is greatly appreciated.
        PeerHost => "example/gettoken"

        This does not look right. PeerHost should be a hostname, not some URL or whatever you think example/gettoken is.

Re: How to convert curl authentication method to perl
by Corion (Pope) on Feb 28, 2020 at 16:52 UTC

    If the code you show is supposed to be what the Curl command does, you have an inconsistency there. You are trying two different files:

    ~/Desktop/file.pfx

    is very different from

    /Downloads/file.pfx

    If the :secret_key in your Curl command means that the file is password protected, you will have to look at how IO::Socket::SSL or Net::SSLeay handle this, depending on which backend your code uses. For IO::Socket::SSL, see the SSL_passwd_cb callback.

      Fixed that error after uploading. Still get same results. I will check out IO::Socket and NET::SSLeay. Thanks

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2020-07-06 05:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?