From 7e308b02488f2fed9b077d04ffea080af5756c10 Mon Sep 17 00:00:00 2001 From: qgarnier Date: Thu, 29 Apr 2021 15:26:46 +0200 Subject: [PATCH] enh(protocol/x509): add ipv6 support for subjectAltNames (#2749) --- apps/protocols/x509/custom/file.pm | 3 ++- apps/protocols/x509/custom/https.pm | 5 +++-- apps/protocols/x509/custom/tcp.pm | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/apps/protocols/x509/custom/file.pm b/apps/protocols/x509/custom/file.pm index 163fa285e..6c4c4f870 100644 --- a/apps/protocols/x509/custom/file.pm +++ b/apps/protocols/x509/custom/file.pm @@ -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 = ', '; diff --git a/apps/protocols/x509/custom/https.pm b/apps/protocols/x509/custom/https.pm index 11d629cce..ca38f7d1c 100644 --- a/apps/protocols/x509/custom/https.pm +++ b/apps/protocols/x509/custom/https.pm @@ -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 = ', '; diff --git a/apps/protocols/x509/custom/tcp.pm b/apps/protocols/x509/custom/tcp.pm index 798fb57d9..c7bd10cb2 100644 --- a/apps/protocols/x509/custom/tcp.pm +++ b/apps/protocols/x509/custom/tcp.pm @@ -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 = ', ';