1 | #!/usr/bin/env perl |
---|
2 | |
---|
3 | my $cert = ""; |
---|
4 | my $seenbegin = 0; |
---|
5 | my $count = 0; |
---|
6 | |
---|
7 | if (@ARGV != 1) { |
---|
8 | printf "Usage: $0 <output-prefix>" |
---|
9 | } |
---|
10 | |
---|
11 | while (<STDIN>) { |
---|
12 | if ($_ =~ /^-----BEGIN CERTIFICATE-----$/) { |
---|
13 | $seenbegin = 1; |
---|
14 | } |
---|
15 | |
---|
16 | if ($seenbegin) { |
---|
17 | $cert .= $_; |
---|
18 | } |
---|
19 | |
---|
20 | if ($_ =~ /^-----END CERTIFICATE-----$/) { |
---|
21 | my $file = $ARGV[0] . "-" . sprintf("%03d", $count) . ".pem"; |
---|
22 | |
---|
23 | open OUT, ">$file"; |
---|
24 | $certinfo = `echo "$cert" | openssl x509 -subject -fingerprint -dates -noout`; |
---|
25 | print OUT $certinfo; |
---|
26 | print OUT $cert; |
---|
27 | close OUT; |
---|
28 | |
---|
29 | $cert = ""; |
---|
30 | |
---|
31 | print "$file\n"; |
---|
32 | |
---|
33 | $seenbegin = 0; |
---|
34 | $count++; |
---|
35 | } |
---|
36 | } |
---|