Merge pull request #94 from Shini31/https

Add key and root cert files options
This commit is contained in:
qgarnier 2015-07-16 14:19:09 +02:00
commit 8f8eab6884
5 changed files with 67 additions and 21 deletions

View File

@ -48,7 +48,7 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$self->{version} = '1.1'; $self->{version} = '1.2';
$options{options}->add_options(arguments => $options{options}->add_options(arguments =>
{ {
"hostname:s" => { name => 'hostname' }, "hostname:s" => { name => 'hostname' },
@ -64,6 +64,8 @@ sub new {
"timeout:s" => { name => 'timeout', default => '3' }, "timeout:s" => { name => 'timeout', default => '3' },
"ssl:s" => { name => 'ssl', }, "ssl:s" => { name => 'ssl', },
"cert-file:s" => { name => 'cert_file' }, "cert-file:s" => { name => 'cert_file' },
"key-file:s" => { name => 'key_file' },
"cacert-file:s" => { name => 'cacert_file' },
"cert-pwd:s" => { name => 'cert_pwd' }, "cert-pwd:s" => { name => 'cert_pwd' },
"cert-pkcs12" => { name => 'cert_pkcs12' }, "cert-pkcs12" => { name => 'cert_pkcs12' },
}); });
@ -175,6 +177,14 @@ Specify SSL version (example : 'sslv3', 'tlsv1'...)
Specify certificate to send to the webserver Specify certificate to send to the webserver
=item B<--key-file>
Specify key to send to the webserver
=item B<--cacert-file>
Specify root certificate to send to the webserver
=item B<--cert-pwd> =item B<--cert-pwd>
Specify certificate's password Specify certificate's password

View File

@ -51,7 +51,7 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$self->{version} = '1.1'; $self->{version} = '1.2';
$options{options}->add_options(arguments => $options{options}->add_options(arguments =>
{ {
"data:s" => { name => 'data' }, "data:s" => { name => 'data' },
@ -70,6 +70,8 @@ sub new {
"timeout:s" => { name => 'timeout', default => 10 }, "timeout:s" => { name => 'timeout', default => 10 },
"ssl:s" => { name => 'ssl', }, "ssl:s" => { name => 'ssl', },
"cert-file:s" => { name => 'cert_file' }, "cert-file:s" => { name => 'cert_file' },
"key-file:s" => { name => 'key_file' },
"cacert-file:s" => { name => 'cacert_file' },
"cert-pwd:s" => { name => 'cert_pwd' }, "cert-pwd:s" => { name => 'cert_pwd' },
"cert-pkcs12" => { name => 'cert_pkcs12' }, "cert-pkcs12" => { name => 'cert_pkcs12' },
@ -454,6 +456,14 @@ Specify SSL version (example : 'sslv3', 'tlsv1'...)
Specify certificate to send to the webserver Specify certificate to send to the webserver
=item B<--key-file>
Specify key to send to the webserver
=item B<--cacert-file>
Specify root certificate to send to the webserver
=item B<--cert-pwd> =item B<--cert-pwd>
Specify certificate's password Specify certificate's password

View File

@ -53,22 +53,24 @@ sub new {
$self->{version} = '1.1'; $self->{version} = '1.1';
$options{options}->add_options(arguments => $options{options}->add_options(arguments =>
{ {
"hostname:s" => { name => 'hostname' }, "hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port', }, "port:s" => { name => 'port', },
"proto:s" => { name => 'proto', default => "http" }, "proto:s" => { name => 'proto', default => "http" },
"urlpath:s" => { name => 'url_path', default => "/" }, "urlpath:s" => { name => 'url_path', default => "/" },
"credentials" => { name => 'credentials' }, "credentials" => { name => 'credentials' },
"ntlm" => { name => 'ntlm' }, "ntlm" => { name => 'ntlm' },
"username:s" => { name => 'username' }, "username:s" => { name => 'username' },
"password:s" => { name => 'password' }, "password:s" => { name => 'password' },
"proxyurl:s" => { name => 'proxyurl' }, "proxyurl:s" => { name => 'proxyurl' },
"warning:s" => { name => 'warning' }, "warning:s" => { name => 'warning' },
"critical:s" => { name => 'critical' }, "critical:s" => { name => 'critical' },
"timeout:s" => { name => 'timeout', default => '3' }, "timeout:s" => { name => 'timeout', default => '3' },
"ssl:s" => { name => 'ssl', }, "ssl:s" => { name => 'ssl' },
"cert-file:s" => { name => 'cert_file' }, "cert-file:s" => { name => 'cert_file' },
"cert-pwd:s" => { name => 'cert_pwd' }, "key-file:s" => { name => 'key_file' },
"cert-pkcs12" => { name => 'cert_pkcs12' }, "cacert-file:s" => { name => 'cacert_file' },
"cert-pwd:s" => { name => 'cert_pwd' },
"cert-pkcs12" => { name => 'cert_pkcs12' },
}); });
return $self; return $self;
} }
@ -199,6 +201,14 @@ Threshold critical in seconds (Webpage response time)
Specify certificate to send to the webserver Specify certificate to send to the webserver
=item B<--key-file>
Specify key to send to the webserver
=item B<--cacert-file>
Specify root certificate to send to the webserver
=item B<--cert-pwd> =item B<--cert-pwd>
Specify certificate's password Specify certificate's password

View File

@ -50,7 +50,7 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$self->{version} = '1.1'; $self->{version} = '1.2';
$options{options}->add_options(arguments => $options{options}->add_options(arguments =>
{ {
"service-soap:s" => { name => 'service_soap' }, "service-soap:s" => { name => 'service_soap' },
@ -69,6 +69,8 @@ sub new {
"timeout:s" => { name => 'timeout', default => 10 }, "timeout:s" => { name => 'timeout', default => 10 },
"ssl:s" => { name => 'ssl', }, "ssl:s" => { name => 'ssl', },
"cert-file:s" => { name => 'cert_file' }, "cert-file:s" => { name => 'cert_file' },
"key-file:s" => { name => 'key_file' },
"cacert-file:s" => { name => 'cacert_file' },
"cert-pwd:s" => { name => 'cert_pwd' }, "cert-pwd:s" => { name => 'cert_pwd' },
"cert-pkcs12" => { name => 'cert_pkcs12' }, "cert-pkcs12" => { name => 'cert_pkcs12' },
@ -449,6 +451,14 @@ Specify SSL version (example : 'sslv3', 'tlsv1'...)
Specify certificate to send to the webserver Specify certificate to send to the webserver
=item B<--key-file>
Specify key to send to the webserver
=item B<--cacert-file>
Specify root certificate to send to the webserver
=item B<--cert-pwd> =item B<--cert-pwd>
Specify certificate's password Specify certificate's password

View File

@ -133,8 +133,14 @@ sub connect {
} }
if (defined($self->{option_results}->{cert_file}) && !defined($self->{option_results}->{cert_pkcs12})) { if (defined($self->{option_results}->{cert_file}) && !defined($self->{option_results}->{cert_pkcs12})) {
eval "use Net::SSL"; die $@ if $@; use IO::Socket::SSL;
$ENV{HTTPS_CERT_FILE} = $self->{option_results}->{cert_file}; my $context = new IO::Socket::SSL::SSL_Context(
SSL_use_cert => 1,
SSL_cert_file => $self->{option_results}->{cert_file},
$self->{option_results}->{key_file} ? ( SSL_key_file => $self->{option_results}->{key_file} ):(),
$self->{option_results}->{cacert_file} ? ( SSL_ca_file => $self->{option_results}->{cacert_file} ):(),
);
IO::Socket::SSL::set_default_context($context);
} }
$response = $ua->request($req); $response = $ua->request($req);