使用证书的Perl ssl客户端身份验证

时间:2012-05-15 15:02:22

标签: perl

我无法使用以下代码并且遇到困难。我正在尝试在POST请求期间使用证书执行客户端身份验证。我只对将客户端证书发送到服务器并且不需要检查服务器证书感兴趣。

以下是尝试复制的cUrl命令:

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

我在Perl脚本中不断收到以下错误: ssl握手失败

我想我有两个问题:对于CRT7和KEY8变量,我应该指出什么?这是使用客户端证书身份验证发送POST请求的最佳方式吗?

!/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";

1 个答案:

答案 0 :(得分:1)

请参阅LWP::UserAgentIO::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',
);

我还没有测试过这段代码。