diff options
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libcrypto/format-pem.pl | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/src/lib/libcrypto/format-pem.pl b/src/lib/libcrypto/format-pem.pl index 556178eb30..6134d656b7 100644 --- a/src/lib/libcrypto/format-pem.pl +++ b/src/lib/libcrypto/format-pem.pl | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | #!/usr/bin/perl | 1 | #!/usr/bin/perl |
| 2 | # $OpenBSD: format-pem.pl,v 1.2 2018/03/21 15:23:53 sthen Exp $ | 2 | # $OpenBSD: format-pem.pl,v 1.3 2018/12/16 11:56:53 sthen Exp $ |
| 3 | # | 3 | # |
| 4 | # Copyright (c) 2016 Stuart Henderson <sthen@openbsd.org> | 4 | # Copyright (c) 2016 Stuart Henderson <sthen@openbsd.org> |
| 5 | # | 5 | # |
| @@ -46,9 +46,6 @@ while(<>) { | |||
| 46 | my $subj = `openssl x509 -in $t -noout -subject`; | 46 | my $subj = `openssl x509 -in $t -noout -subject`; |
| 47 | $subj =~ s/^subject= (.*)\n/$1/; | 47 | $subj =~ s/^subject= (.*)\n/$1/; |
| 48 | 48 | ||
| 49 | print STDERR "'$subj' not self-signed" | ||
| 50 | if ($issuer ne $subj); | ||
| 51 | |||
| 52 | my $o = `openssl x509 -in $t -noout -nameopt sep_multiline,use_quote,esc_msb -subject`; | 49 | my $o = `openssl x509 -in $t -noout -nameopt sep_multiline,use_quote,esc_msb -subject`; |
| 53 | if ($o =~ /O=/) { | 50 | if ($o =~ /O=/) { |
| 54 | $o =~ s/.*O=([^\n]*).*/$1/sm; | 51 | $o =~ s/.*O=([^\n]*).*/$1/sm; |
| @@ -56,6 +53,18 @@ while(<>) { | |||
| 56 | $o = $subj; | 53 | $o = $subj; |
| 57 | } | 54 | } |
| 58 | 55 | ||
| 56 | if (defined $ca{$o}{$subj}) { | ||
| 57 | print STDERR "ERROR: '$subj': duplicate\n"; | ||
| 58 | $ca{$o}{$subj}{'valid'} = 0; | ||
| 59 | } | ||
| 60 | |||
| 61 | $ca{$o}{$subj}{'valid'} = 1; | ||
| 62 | |||
| 63 | if ($issuer ne $subj) { | ||
| 64 | print STDERR "ERROR: '$subj' not self-signed"; | ||
| 65 | $ca{$o}{$subj}{'valid'} = 0; | ||
| 66 | } | ||
| 67 | |||
| 59 | if (eval {require Date::Parse;1;}) { | 68 | if (eval {require Date::Parse;1;}) { |
| 60 | my $startdate = `openssl x509 -in $t -startdate -noout`; | 69 | my $startdate = `openssl x509 -in $t -startdate -noout`; |
| 61 | my $enddate = `openssl x509 -in $t -enddate -noout`; | 70 | my $enddate = `openssl x509 -in $t -enddate -noout`; |
| @@ -65,12 +74,14 @@ while(<>) { | |||
| 65 | my $endtime = str2time($enddate); | 74 | my $endtime = str2time($enddate); |
| 66 | 75 | ||
| 67 | if ($starttime > time) { | 76 | if ($starttime > time) { |
| 68 | print STDERR "'$subj' not valid yet\n" | 77 | print STDERR "ERROR: '$subj' not valid yet\n"; |
| 78 | $ca{$o}{$subj}{'valid'} = 0; | ||
| 69 | } | 79 | } |
| 70 | if ($endtime < time) { | 80 | if ($endtime < time) { |
| 71 | print STDERR "'$subj' expired on $startdate\n" | 81 | print STDERR "ERROR: '$subj' expired on $startdate\n"; |
| 82 | $ca{$o}{$subj}{'valid'} = 0; | ||
| 72 | } elsif ($endtime < time + 86400 * 365 * 2) { | 83 | } elsif ($endtime < time + 86400 * 365 * 2) { |
| 73 | print STDERR "'$subj' expires on $enddate\n" | 84 | print STDERR "WARNING: '$subj' expires on $enddate\n"; |
| 74 | } | 85 | } |
| 75 | } | 86 | } |
| 76 | 87 | ||
| @@ -78,8 +89,10 @@ while(<>) { | |||
| 78 | $info .= qx/openssl x509 -in $t -fingerprint -sha256 -noout/; | 89 | $info .= qx/openssl x509 -in $t -fingerprint -sha256 -noout/; |
| 79 | my $cert = qx/openssl x509 -in $t/; | 90 | my $cert = qx/openssl x509 -in $t/; |
| 80 | 91 | ||
| 81 | if (defined $ca{$o}{$subj}) { | 92 | my $verify = qx/openssl verify -CAfile $t $t 2>&1/; |
| 82 | print STDERR "'$subj': duplicate\n"; | 93 | if (not $verify =~ /^$t: OK$/) { |
| 94 | print STDERR "ERROR: '$subj' cannot be verified with libressl\n---\n$verify---\n"; | ||
| 95 | $ca{$o}{$subj}{'valid'} = 0; | ||
| 83 | } | 96 | } |
| 84 | 97 | ||
| 85 | $ca{$o}{$subj}{'subj'} = $subj; | 98 | $ca{$o}{$subj}{'subj'} = $subj; |
| @@ -92,13 +105,16 @@ while(<>) { | |||
| 92 | } | 105 | } |
| 93 | 106 | ||
| 94 | close $tmp; | 107 | close $tmp; |
| 108 | chomp $rcsid; | ||
| 95 | print $rcsid; | 109 | print $rcsid; |
| 96 | foreach my $o (sort{lc($a) cmp lc($b)} keys %ca) { | 110 | foreach my $o (sort{lc($a) cmp lc($b)} keys %ca) { |
| 97 | print "\n### $o\n\n"; | 111 | print "\n### $o\n\n"; |
| 98 | foreach my $subj (sort{lc($a) cmp lc($b)} keys %{ $ca{$o} }) { | 112 | foreach my $subj (sort{lc($a) cmp lc($b)} keys %{ $ca{$o} }) { |
| 99 | print "=== $subj\n"; | 113 | if ($ca{$o}{$subj}{'valid'} == 1) { |
| 100 | print $ca{$o}{$subj}{'info'}; | 114 | print "=== $subj\n"; |
| 101 | print $ca{$o}{$subj}{'cert'}; | 115 | print $ca{$o}{$subj}{'info'}; |
| 116 | print $ca{$o}{$subj}{'cert'}; | ||
| 117 | } | ||
| 102 | } | 118 | } |
| 103 | } | 119 | } |
| 104 | 120 | ||
