| Line 29... |
Line 29... |
| 29 |
my $serverCertDir; # where to put the server certs
|
29 |
my $serverCertDir; # where to put the server certs
|
| 30 |
my $certDays; # number of days a Server certificate is valid for, not used here
|
30 |
my $certDays; # number of days a Server certificate is valid for, not used here
|
| 31 |
my $caDays; # number of days a CA is good for
|
31 |
my $caDays; # number of days a CA is good for
|
| 32 |
|
32 |
|
| 33 |
die "Config File $config not found\n" unless -f $config;
|
33 |
die "Config File $config not found\n" unless -f $config;
|
| 34 |
die "openssl config file $sslConfig not found\n" unless -f $sslConfig;
|
34 |
#die "openssl config file $sslConfig not found\n" unless -f $sslConfig;
|
| 35 |
|
35 |
|
| 36 |
# load the config file
|
36 |
# load the config file
|
| 37 |
eval `cat $config`;
|
37 |
eval `cat $config`;
|
| 38 |
|
38 |
|
| 39 |
my $targetDir = '/etc/certificates/';
|
39 |
my $targetDir = '/etc/certificates/';
|
| Line 47... |
Line 47... |
| 47 |
my @temp;
|
47 |
my @temp;
|
| 48 |
if ( $certname ) {
|
48 |
if ( $certname ) {
|
| 49 |
die "Can not find $certname ending in .crt or .key\n" unless -f "$serverCertDir$certname.crt" && -f "$serverCertDir$certname.key";
|
49 |
die "Can not find $certname ending in .crt or .key\n" unless -f "$serverCertDir$certname.crt" && -f "$serverCertDir$certname.key";
|
| 50 |
push @temp, "$serverCertDir$certname";
|
50 |
push @temp, "$serverCertDir$certname";
|
| 51 |
} else {
|
51 |
} else {
|
| - |
|
52 |
$certname = $hostname;
|
| 52 |
opendir my $dh, $serverCertDir or die "Can not find cert directory $certDir: $!\n";
|
53 |
opendir my $dh, $serverCertDir or die "Can not find cert directory $serverCertDir: $!\n";
|
| 53 |
# get all matching cert files
|
54 |
# get all matching cert files
|
| 54 |
my @temp = grep { /^$certname.*\.crt/ } readdir( $dh );
|
55 |
@temp = map{ $serverCertDir . $_ } grep { /^$certname.*\.crt/ } readdir( $dh );
|
| 55 |
closedir $dh;
|
56 |
closedir $dh;
|
| 56 |
for ( my $i = 0; $i < @temp; $i++ ) {
|
57 |
for ( my $i = 0; $i < @temp; $i++ ) {
|
| 57 |
$temp[$i] =~ s/crt$//;
|
58 |
$temp[$i] =~ s/\.crt$//;
|
| 58 |
}
|
59 |
}
|
| 59 |
}
|
60 |
}
|
| 60 |
|
61 |
|
| 61 |
# make pem, create a list of all files to copy
|
62 |
# make pem, create a list of all files to copy
|
| 62 |
my $filesToCopy;
|
63 |
my $filesToCopy;
|
| 63 |
foreach my $file ( @temp ) {
|
64 |
foreach my $file ( @temp ) {
|
| 64 |
die "Can not find $key file $file\n" unless -e "$file\.key";
|
65 |
die "Can not find key file $file.key\n" unless -e "$file\.key";
|
| 65 |
`cat $file.crt $file.key > $file.pem`;
|
66 |
`cat $file.crt $file.key > $file.pem`;
|
| 66 |
$filesToCopy .= "$file.crt";
|
- |
|
| 67 |
$filesToCopy .= "$file.key";
|
- |
|
| 68 |
$filesToCopy .= "$file.pem";
|
67 |
$filesToCopy .= "$file.crt $file.key $file.pem ";
|
| 69 |
}
|
68 |
}
|
| 70 |
|
69 |
|
| 71 |
# ensure target directory exists on $hostname
|
70 |
# ensure target directory exists on $hostname
|
| 72 |
`ssh $hostname 'mkdir -p /etc/certificates`;
|
71 |
`ssh $hostname 'mkdir -p /etc/certificates'`;
|
| 73 |
# copy the files
|
72 |
# copy the files
|
| 74 |
`scp $filesToCopy $hostname:$targetDir`;
|
73 |
`scp $filesToCopy $hostname:$targetDir`;
|
| 75 |
# set permissions and reload services
|
74 |
# set permissions and reload services
|
| 76 |
`ssh $hostname '$remoteCommand'`;
|
75 |
`ssh $hostname '$remoteCommand'`;
|
| 77 |
|
76 |
|