]>
Raphaël G. Git Repositories - acme/blob - acmecert
   3 # This program is free software: you can redistribute it and/or modify 
   4 # it under the terms of the GNU General Public License as published by 
   5 # the Free Software Foundation, either version 3 of the License, or 
   6 # (at your option) any later version. 
   8 # This program is distributed in the hope that it will be useful, 
   9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 
  10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
  11 # GNU General Public License for more details. 
  13 # You should have received a copy of the GNU General Public License 
  14 # along with this program.  If not, see <http://www.gnu.org/licenses/>. 
  16 # Copyright (C) 2016 - 2017 Raphaël Gertz <acme@rapsys.eu> 
  23 use filetest 
qw(access); 
  26 use File
::stat qw(stat); 
  27 use File
::Slurp 
qw(read_file); 
  28 use JSON 
qw(decode_json); 
  32 use POSIX 
qw(EXIT_SUCCESS EXIT_FAILURE); 
  40 # Init config file name 
  41 my $configFilename = '/etc/acme/config'; 
  46 # Strip and enable debug 
  47 @ARGV = map { if ($_ eq '-d') { $debug = 1; (); } else { $_; } } @ARGV; 
  49 # Strip and enable debug 
  50 for (my $i = 0; $i <= $#ARGV; $i++) { 
  52         if ($ARGV[$i] =~ /^(?:(\-c|\-\-config)(?:=(.+))?)$/) { 
  53                 if (defined($2) && -f 
$2) { 
  57                 # Extract next parameter 
  58                 } elsif(defined($ARGV[$i+1]) && $ARGV[$i+1] =~ /^(.+)$/ && -f 
$1) { 
  64                         print 'Config parameter without valid file name'."\n"; 
  72         #XXX: use eval to workaround a fatal in decode_json 
  75                 (-f 
$configFilename) && 
  77                 ($config = read_file
($configFilename)) && 
  79                 ($config = decode_json
($config)) && 
  81                 defined($config->{certificates
}) && 
  83                 scalar($config->{certificates
}) && 
  85                 defined($config->{thumbprint
}) && 
  86                 # Check certificates array 
  87                 ! scalar map {unless(defined($_->{cert
}) && defined($_->{key
}) && defined($_->{mail
}) && defined($_->{domain
}) && defined($_->{domains
})) {1;} else {();}} @{$config->{certificates
}} 
  90         print 'Config file '.$configFilename.' is not readable or invalid'."\n"; 
  94 # Deal with specified domains 
  95 if (scalar(@ARGV) > 0) { 
  96         # Check that domains are present in config 
  97         foreach my $domain (@ARGV) { 
  99                 foreach my $certificate (@{$config->{certificates
}}) { 
 100                         if ($certificate->{domain
} eq $domain) { 
 101                                 push(@domains, $certificate); 
 106                         print 'Domain '.$domain.' not found in config file '.$configFilename."\n"; 
 112         # Populate domains array with available ones 
 113         foreach my $certificate (@{$config->{certificates
}}) { 
 114                 push(@domains, $certificate); 
 119 if (scalar(@domains) < 1) { 
 120         print "Usage: $0 [-(c|-config)[=/etc/acme/config]] [example.com] [...]\n"; 
 124 # Deal with each domain 
 125 foreach my $domain (@domains) { 
 127         my $acme = Acme-
>new($debug, $domain, {thumbprint 
=> $config->{thumbprint
}, pending 
=> $config->{pending
}, term 
=> $config->{term
}}); 
 129         # Prepare environement 
 132         # Generate required keys