2012-05-15 114 views
3

我無法獲得以下代碼,無法工作,並且在此處卡住了。我正在嘗試在POST請求期間使用證書執行客戶端身份驗證。我只對將客戶端證書發送給服務器感興趣,並且不需要檢查服務器證書。

使用證書的Perl ssl客戶端認證

這裏是試圖複製curl命令:

捲曲--cacert caCertificate.pem --cert clientCerticate.pem -d 「串」 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

參見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', 
); 

我還沒有測試過這段代碼。