enh(protocol/x509): add ipv6 support for subjectAltNames (#2749)

This commit is contained in:
qgarnier 2021-04-29 15:26:46 +02:00 committed by GitHub
parent 2512ad1d8b
commit 7e308b0248
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 4 deletions

View File

@ -23,6 +23,7 @@ package apps::protocols::x509::custom::file;
use strict;
use warnings;
use centreon::plugins::http;
use Socket;
use Net::SSLeay 1.42;
use DateTime;
@ -130,7 +131,7 @@ sub read_certificate {
for (my $i = 0; $i < $#subject_alt_names; $i += 2) {
my ($type, $name) = ($subject_alt_names[$i], $subject_alt_names[$i + 1]);
if ($type == &Net::SSLeay::GEN_IPADD) {
$name = inet_ntoa($name);
$name = Socket::inet_ntop(length($name) > 4 ? Socket::AF_INET6 : Socket::AF_INET, $name);
}
$cert_infos->{alt_subjects} .= $append . $name;
$append = ', ';

View File

@ -25,6 +25,7 @@ use warnings;
use centreon::plugins::http;
use Net::SSLeay 1.42;
use DateTime;
use Socket;
sub new {
my ($class, %options) = @_;
@ -119,7 +120,7 @@ sub pem_type {
for (my $i = 0; $i < $#subject_alt_names; $i += 2) {
my ($type, $name) = ($subject_alt_names[$i], $subject_alt_names[$i + 1]);
if ($type == &Net::SSLeay::GEN_IPADD) {
$name = inet_ntoa($name);
$name = Socket::inet_ntop(length($name) > 4 ? Socket::AF_INET6 : Socket::AF_INET, $name);
}
$cert_infos->{alt_subjects} .= $append . $name;
$append = ', ';
@ -145,7 +146,7 @@ sub socket_type {
for (my $i = 0; $i < $#subject_alt_names; $i += 2) {
my ($type, $name) = ($subject_alt_names[$i], $subject_alt_names[$i + 1]);
if ($type == &Net::SSLeay::GEN_IPADD) {
$name = inet_ntoa($name);
$name = Socket::inet_ntop(length($name) > 4 ? Socket::AF_INET6 : Socket::AF_INET, $name);
}
$cert_infos->{alt_subjects} .= $append . $name;
$append = ', ';

View File

@ -217,7 +217,7 @@ sub get_certificate_informations {
for (my $i = 0; $i < $#subject_alt_names; $i += 2) {
my ($type, $name) = ($subject_alt_names[$i], $subject_alt_names[$i + 1]);
if ($type == GEN_IPADD) {
$name = inet_ntoa($name);
$name = Socket::inet_ntop(length($name) > 4 ? Socket::AF_INET6 : Socket::AF_INET, $name);
}
$cert_infos->{alt_subjects} .= $append . $name;
$append = ', ';