3
# Copyright (C) 2007, 2009 Free Software Foundation
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# generate-cacerts.pl generates a gkeytool keystore named 'cacerts'
16
# from OpenSSL's certificate bundle.
18
# First extract each of OpenSSL's bundled certificates into its own
20
chomp($file=@ARGV[0]);
21
$file = "/etc/pki/tls/cert.pem" unless $file ne "";
28
foreach $cert (@certs)
30
if ($cert eq "-----BEGIN CERTIFICATE-----\n")
32
if ($writing_cert != 0)
34
die "$file is malformed.";
37
# Numbering each file guarantees that cert aliases will be
39
$pem_file_name = "$pem_file_number$cert_alias.pem";
41
open(PEM, ">$pem_file_name");
44
elsif ($cert eq "-----END CERTIFICATE-----\n")
50
elsif ($cert =~ /Issuer: /)
52
# Generate an alias using the OU and CN attributes of the
53
# Issuer field if both are present, otherwise use only the CN
54
# attribute. The Issuer field must have either the OU or the
60
# Remove other occurrences of OU=.
62
# Remove CN= if there were not other occurrences of OU=.
65
elsif ($cert =~ /CN=/)
75
if ($writing_cert == 1)
82
# Check that the correct number of .pem files were produced.
84
if (@pem_files != $pem_file_number)
86
die "Number of .pem files produced does not match".
87
" number of certs read from $file.";
90
# Now store each cert in the 'cacerts' file using gkeytool.
91
$certs_written_count = 0;
92
foreach $pem_file (@pem_files)
94
system "yes | gkeytool@gcc_suffix@ -import -alias `basename $pem_file .pem`".
95
" -keystore cacerts -storepass '' -file $pem_file".
98
$certs_written_count++;
101
# Check that the correct number of certs were added to the keystore.
102
if ($certs_written_count != $pem_file_number)
104
die "Number of certs added to keystore does not match".
105
" number of certs read from $file.";