CrlPublish.pm untested

filter: Statementstmt 0.0% 0 / 63 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 22 MC/DCmcdc 0.0% 0 / 14 Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 123 CC 5 SCAR 19.5
CC
5
Cov
0%
_publishOneCrl
20.0
loadConfiguration
6.0
publishCrl
2.0
CRAP 7.0
1 package EJBCA::CrlPublish;
2 use warnings;
3 use strict;
4 #
5 # crlpublish
6 #
7 # Copyright (C) 2014, Kevin Cody-Little <kcody@cpan.org>
8 #
9 # Portions derived from crlpublisher.sh, original copyright follows:
10 #
11 # Copyright (C) 2011, Branko Majic <branko@majic.rs>
12 #
13 # This program is free software: you can redistribute it and/or modify
14 # it under the terms of the GNU General Public License as published by
15 # the Free Software Foundation, either version 3 of the License, or
16 # (at your option) any later version.
17 #
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
22 #
23 # You should have received a copy of the GNU General Public License
24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #
26 ###############################################################################
27  
28 =head1 NAME
29  
30 EJBCA::CrlPublish
31  
32 =head1 SYNOPSIS
33  
34 High level API for publishing new CRLs.
35  
36 Exports: &publishCrl &processQueue
37  
38 =cut
39  
40  
41 ###############################################################################
42 # Global Configuration
43  
44 my $globalOldConfig = '/etc/crlpublisher';
45 my $invokeOldConfig = $ENV{HOME} . '/.crlpublisher';
46 my $globalNewConfig = '/etc/crlpublish';
47 my $invokeNewConfig = $ENV{HOME} . '/.crlpublish';
48  
49  
50 ###############################################################################
51 # Library Dependencies
52  
53 use EJBCA::CrlPublish::Config;
54 use EJBCA::CrlPublish::CrlInfo;
55 use EJBCA::CrlPublish::Logging;
56 use EJBCA::CrlPublish::Method;
57 use EJBCA::CrlPublish::Target;
58  
59 our $VERSION = '0.60';
60  
61 use base 'Exporter';
62 our @EXPORT = qw( publishCrl processQueue );
63  
64  
65 ###############################################################################
66 # Configuration Loader
67  
68 sub loadConfiguration() {
69 my $rc = 1;
70  
71 $rc &&= EJBCA::CrlPublish::Config->importAllFiles( $globalNewConfig );
72 $rc &&= EJBCA::CrlPublish::Config->importAllFiles( $globalOldConfig );
73 $rc &&= EJBCA::CrlPublish::Config->importAllFiles( $invokeNewConfig );
74 $rc &&= EJBCA::CrlPublish::Config->importAllFiles( $invokeOldConfig );
75  
76 unless ( $rc ) {
77 msgError "Configuration errors detected. Aborting.";
78 }
79  
80 return $rc;
81 }
82  
83  
84 ###############################################################################
85 # CRL Handler
86  
87 sub _publishOneCrl($) {
88 my $crlFile = shift;
89  
90 my $crlInfo = EJBCA::CrlPublish::CrlInfo->new( $crlFile );
91  
92 unless ( $crlInfo ) {
93 msgError "Unable to parse CRL. Aborting.";
94 return 0;
95 }
96  
97 my @targets = EJBCA::CrlPublish::Target->find( $crlInfo );
98  
99 unless ( scalar( @targets ) ) {
100 msgError "Could not find any publishing targets. Aborting.";
101 return 0;
102 }
103  
104 my $rc = 1;
105 foreach my $target ( @targets ) {
106 msgDebug "Publishing to target ", $target->remoteHost;
107 # TODO: implement asynchronous queueing
108 $rc &&= EJBCA::CrlPublish::Method->execute( $target );
109 }
110  
111 if ( $rc ) {
112 msgDebug "Publishing succeeded.";
113 }
114  
115 else {
116 msgError "Publishing failed.";
117 }
118  
119 return $rc;
120 }
121  
122 =head1 CRL PUBLISHING FUNCTION
123  
124 =head2 publishCrl( $crlFile );
125  
126 =head2 publishCrl( @crlFiles );
127  
128 Publishes the given CRL file, which must be a readable plain file, and
129 must be a valid certificate revocation list in PEM or DER format.
130  
131 Supplying a list of crlFile names is supported, but only recommended when
132 asynchronous publishing is in use. Otherwise, the caller will not be able to
133 tell which CRL might have failed, and will have to republish them all.
134  
135 Returns true if all supplied crlFiles were published or queued successfully,
136 and returns false if any single crlFile failed to publish or enqueue.
137  
138 =cut
139  
140 sub publishCrl(@) {
141  
142 loadConfiguration()
143 or return 0;
144  
145 my $rc = 1;
146 while ( my $crlFile = shift ) {
147 $rc &&= _publishOneCrl( $crlFile );
148 }
149  
150 return $rc;
151 }
152  
153  
154 ###############################################################################
155 # Cron Despooler
156  
157 =head1 QUEUE FLUSH FUNCTION
158  
159 =head2 processQueue();
160  
161 Examines the local spool directory and attempts to push any pending CRL
162 updates to their destinations. Upon failure, the CRL will remain in the queue
163 for another attempt.
164  
165 By default, the queue directory is in /var/spool/crlpublish.
166  
167 =cut
168  
169 sub processQueue() {
170  
171 loadConfiguration()
172 or return 0;
173  
174 # my $dir = $cfg->spooldirectory
175 # or die "Asynchronous publishing is not configured.\n";
176  
177 # look through spooldirectory; push then remove
178  
179 return 0;
180 }
181  
182  
183 ###############################################################################
184  
185 =head1 AUTHOR
186  
187 Kevin Cody-Little <kcody@cpan.org>
188  
189 =cut
190  
191  
192 ###############################################################################
193 ####################################### EOF ###################################
194 ###############################################################################
195 1;