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

I am stumped on how to use the Net::SSLeay module.
use Net::SSLeay qw(get_https post_https sslcat make_headers make_form) +; my $api_page='api.mysite.com'; my $mime_type='application/json'; my $cert_key='mykey'; my $cert_file='/accounts/perl_user/file.pfx'; my ($page, $response, %reply_headers) = post_https($api_page, 443, '/a +pi/v1/token',
I am getting a cert error given without key at lib/Net/SSLeay.pm autosplit into blib/lib/auto/Net/SSLeay/https_cat.al How do I pass the key?

Replies are listed 'Best First'.
Re: using Net SSLeay to send Client Certificate connect to remote host
by haukex (Archbishop) on Mar 03, 2020 at 13:32 UTC

    Typically, one would use a different HTTP client module, such as HTTP::Tiny - see the "SSL Support" section in its documentation. Its SSL options are from IO::Socket::SSL.

Re: using Net SSLeay to send Client Certificate connect to remote host
by hippo (Archbishop) on Mar 03, 2020 at 13:49 UTC

    Like haukex I wouldn't use such a low-level module by default. Here is an example using LWP::UserAgent and a known, public endpoint. Perhaps you can start from here and then modify to your needs?

    #!/usr/bin/env perl use strict; use warnings; use LWP::UserAgent; use Data::Dumper; my $url = 'https://server.cryptomix.com/secure/'; my $keyfile = 'foo.key'; my $certfile = 'foo.cert'; my $ua = LWP::UserAgent->new ( ssl_opts => { SSL_cert_file => $certfile, SSL_key_file => $keyfile } ); my $res = $ua->get ($url); print $res->status_line; print $res->decoded_content;

    This assumes that you have the RSA key in foo.key and the PEM client cert in foo.cert. You'll get lots of info back from that server.

      Thanks this worked. I had this before but I was using IO::Socket module it should have worked but I will look into this a little more. I do not have a key file so I had to use
      my $ua = LWP::UserAgent->new ( ssl_opts => { SSL_cert_file => $certfile, SSL_passwd_cb => sub {$my_key}, } );
      I am new to perl and don't have to touch it often. Thanks
      Thanks I will give this a shot. I tried this earlier but it did not work. I kept getting errors. I will do a post here to show results.