Perl ssl client certificate using certificate

I was having trouble getting the following code to work when I got stuck. I am trying to do client-side authentication using a certificate during a POST request. I am interested in sending the client certificate to the server and do not need to check the server certificate.

Here is the cUrl command that is trying to replicate:

curl --cacert caCertificate.pem --cert clientCerticate.pem -d "string" https: //xx.xx.xx.xx: 8443 / postRf

I continue to receive the following error in my Perl script: ssl handshake failed

Probably I have there are two questions: what should I point to variables CRT7 and KEY8? and is this the best way to send a POST request using client authentication?

!/usr/bin/perl
use warnings;
use strict;
use Net::SSLeay qw(post_https);


my $$hostIp = "xx.xx.xx.xx" 
my $hostPort = "8443" 
my $postCommand = "/postRf/string";
my $http_method = 'plain/text';
my $path_to_crt7 = 'pathToCert.pem';
my $path_to_key8 = 'pathToKey.pem';

my ($page, $response, %reply_headers) =
        post_https($hostIp, $hostPort, $postCommand, '',
        $http_method, $path_to_crt7, $path_to_key8
);

print $page . "\n";
print $response . "\n";
+3
source share
1 answer

See LWP :: UserAgent and IO :: Socket :: SSL .

use strictures;
use LWP::UserAgent qw();
require LWP::Protocol::https;

my $ua = LWP::UserAgent->new;
$ua->ssl_opts(
    SSL_ca_file   => 'caCertificate.pem',
    SSL_cert_file => 'clientCerticate.pem',
);
$ua->post(
    'https://xx.xx.xx.xx:8443/postRf',
    Content => 'string',
);

I have not tested this code.

+1
source

All Articles