【问题标题】:Perl ssl client auth using certificate使用证书的 Perl ssl 客户端身份验证
【发布时间】:2012-05-16 03:58:31
【问题描述】:

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

这是尝试复制的 cUrl 命令:

curl --cacert caCertificate.pem --cert clientCertificate.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";

【问题讨论】:

    标签: perl


    【解决方案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',
    );
    

    我没有测试过这段代码。

    【讨论】:

      猜你喜欢
      • 2015-07-29
      • 1970-01-01
      • 1970-01-01
      • 2014-04-04
      • 2021-02-11
      • 2011-05-24
      • 1970-01-01
      • 2011-04-09
      • 2013-10-07
      相关资源
      最近更新 更多