From bf26fd7c03c68702e1871aafaace3aab9497cb5a Mon Sep 17 00:00:00 2001 From: Thomas Hooge Date: Mon, 8 Jun 2020 10:05:06 +0200 Subject: [PATCH] Fixed certificate serial detection --- lib/OpenSSL.pm | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/OpenSSL.pm b/lib/OpenSSL.pm index f388b92..9f56c10 100644 --- a/lib/OpenSSL.pm +++ b/lib/OpenSSL.pm @@ -557,6 +557,8 @@ sub parsecert { my $tmp = {}; my (@lines, $dn, $i, $c, $v, $k, $cmd, $crl, $time, $t, $ext, $ret, $pid); + my($rdfh, $wtfh); + $time = time(); $force && delete($self->{'CACHE'}->{$file}); @@ -632,6 +634,21 @@ sub parsecert { } } + # no serial yet? get it now the direct way + if(!defined $tmp->{'SERIAL'}){ + $cmd = "$self->{'bin'} x509 -noout -serial -in $file"; + $ext = "$cmd\n\n"; + $pid = open3($wtfh, $rdfh, $rdfh, $cmd); + while(<$rdfh>){ + $ext .= $_; + ($k, $v) = split(/=/); + $tmp->{'SERIAL'} = $v if($k =~ /serial/i); + chomp($tmp->{'SERIAL'}); + } + waitpid($pid, 0); + $ret = $? >> 8; + } + # parse subject DN $dn = HELPERS::parse_dn($tmp->{'DN'}); foreach(keys(%$dn)) { @@ -646,7 +663,6 @@ sub parsecert { # get fingerprint $cmd = "$self->{'bin'} x509 -noout -fingerprint -md5 -in $file"; - my($rdfh, $wtfh); $ext = "$cmd\n\n"; $pid = open3($wtfh, $rdfh, $rdfh, $cmd); while(<$rdfh>){ @@ -1059,6 +1075,9 @@ sub _set_expired { close IN; + # Format of OpenSSl index db + # E|R|VExpiry[RevocationDate]SerialunknownSubjectDN + open(OUT, ">$index") || do { my $t = sprintf(_("Can't write index %s: %s"), $index, $!); GUI::HELPERS::print_warning($t);