line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::SSL::AutoCA; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
22411
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
230
|
|
4
|
1
|
|
|
1
|
|
8
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
855
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
Net::SSL::AutoCA - Provides a automated method for locating CA bundle file/directory. |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 VERSION |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Version 0.0.0 |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '0.0.0'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 SYNOPSIS |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
use Net::SSL::AutoCA; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $autoca = Net::SSL::AutoCA->new(); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
if( defined( $autoca->{CAfile} ) || defined( $autoca->{CApath} ) ){ |
26
|
|
|
|
|
|
|
if( defined( $autoca->{CAfile} ) ){ |
27
|
|
|
|
|
|
|
print 'CA file: '.$autoca->{CAfile}."\n"; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
if( defined( $autoca->{CApath} ) ){ |
31
|
|
|
|
|
|
|
print 'CA path: '.$autoca->{CApath}."\n"; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
#as it currently stands, this will always be true if |
34
|
|
|
|
|
|
|
#$autoca->{CApath} is defined, unless done via a |
35
|
|
|
|
|
|
|
#enviromental variable |
36
|
|
|
|
|
|
|
if( $autoca->{checkCRL} ){ |
37
|
|
|
|
|
|
|
print "Check CRL\n"; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 METHODS |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head2 new |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head3 args hash |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head4 methods |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
This is the methods it should us. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
The value taken is a camma seperated list. The |
54
|
|
|
|
|
|
|
default value is 'path,env'. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
The supported values listed below |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
env |
59
|
|
|
|
|
|
|
path |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head4 userssl |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
If set to 1, '~/.sslca' will be check. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
This requires $ENV{USER} to be defined. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head4 prefix |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
This allows adds a addiontal prefix to check instead of |
70
|
|
|
|
|
|
|
just '/usr' and '/usr/local'. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head4 prefixByEnv |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
If set to 1, it will populate the prefix info |
75
|
|
|
|
|
|
|
via $ENV{'Net::SSL::AutoCA-prefix'}. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=cut |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub new{ |
80
|
0
|
|
|
0
|
1
|
|
my %args; |
81
|
0
|
0
|
|
|
|
|
if (defined( $_[1] )) { |
82
|
0
|
|
|
|
|
|
%args=%{$_[1]}; |
|
0
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
my $self={error=>undef, CAfile=>undef, CApath=>undef, checkCRL=>undef}; |
86
|
0
|
|
|
|
|
|
bless $self; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
#get the methods to use |
89
|
0
|
0
|
|
|
|
|
if (defined( $args{methods} )) { |
90
|
0
|
|
|
|
|
|
$self->{methods}=$args{methods}; |
91
|
|
|
|
|
|
|
}else { |
92
|
0
|
|
|
|
|
|
$self->{methods}='path,env'; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
#gets the prefix to use, if needed |
96
|
0
|
0
|
|
|
|
|
if (defined( $args{prefix} )) { |
97
|
0
|
|
|
|
|
|
$self->{prefix}=$args{prefix}; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
#set the prefix by env variable |
101
|
0
|
0
|
|
|
|
|
if ( defined( $args{prefixByEnv} ) ) { |
102
|
0
|
|
|
|
|
|
$self->{prefixByEnv}=$args{prefixByEnv}; |
103
|
|
|
|
|
|
|
}else { |
104
|
0
|
|
|
|
|
|
$self->{prefixByEnv}=1; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
#get the prefix by env if needed |
108
|
0
|
0
|
|
|
|
|
if ($self->{prefixByEnv}) { |
109
|
0
|
0
|
|
|
|
|
if (defined( $ENV{'Net::SSL::AutoCA-prefix'} )) { |
110
|
0
|
|
|
|
|
|
$self->{prefix}=$ENV{'Net::SSL::AutoCA-prefix'}; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
#runs through the methodes and finds one to use |
115
|
0
|
|
|
|
|
|
my @split=split(/,/, $self->{methods}); #splits them apart at every ',' |
116
|
0
|
|
|
|
|
|
my $splitInt=0; |
117
|
0
|
|
|
|
|
|
while (defined($split[$splitInt])){ |
118
|
|
|
|
|
|
|
#handles it via the env method |
119
|
0
|
0
|
|
|
|
|
if ($split[$splitInt] eq "path") { |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
0
|
|
|
|
|
|
$splitInt++; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
0
|
|
|
|
|
|
$self->byPath; |
127
|
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
|
return $self; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head2 clear |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
This clears the selections. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
my $autoca->clear; |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=cut |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub clear{ |
140
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
141
|
|
|
|
|
|
|
|
142
|
0
|
|
|
|
|
|
$self->{CAfile}=undef; |
143
|
0
|
|
|
|
|
|
$self->{CApath}=undef; |
144
|
0
|
|
|
|
|
|
$self->{checkCRL}=undef; |
145
|
|
|
|
|
|
|
|
146
|
0
|
|
|
|
|
|
return 1; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head2 byPath |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
This fetches it by the path. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head3 args hash |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head4 userssl |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
If set to 1, '~/.sslca/' and '~/.sslca.bundle' will |
158
|
|
|
|
|
|
|
be check. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
This requires $ENV{USER} to be defined. |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head3 PATH ORDER |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head4 dir |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
~/.sslca/ |
167
|
|
|
|
|
|
|
/etc/ssl/ca/ |
168
|
|
|
|
|
|
|
/usr/local/etc/ssl/ca/ |
169
|
|
|
|
|
|
|
$prefix/etc/ssl/ca/ |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head4 file |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
~/.sslca.bundle |
174
|
|
|
|
|
|
|
/etc/ssl/ca.bundle |
175
|
|
|
|
|
|
|
/usr/local/etc/ssl/ca.bundle |
176
|
|
|
|
|
|
|
/usr/share/certs/ca-root-nss.crt |
177
|
|
|
|
|
|
|
/usr/local/share/certs/ca-root-nss.crt |
178
|
|
|
|
|
|
|
$prefix/etc/ssl/ca.bundle |
179
|
|
|
|
|
|
|
$prefix/share/certs/ca-root-nss.crt |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
my $returned=$autoca->byPath({userssl=>1}); |
182
|
|
|
|
|
|
|
if($returned){ |
183
|
|
|
|
|
|
|
print "Nothing matched. |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=cut |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
sub byPath{ |
189
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
190
|
0
|
|
|
|
|
|
my %args; |
191
|
0
|
0
|
|
|
|
|
if (defined( $_[1] )) { |
192
|
0
|
|
|
|
|
|
%args=%{$_[1]}; |
|
0
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
|
195
|
0
|
|
|
|
|
|
my @dircheck; |
196
|
|
|
|
|
|
|
my @filecheck; |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
#prepents the user stuff first. |
199
|
0
|
0
|
|
|
|
|
if ($args{userssl}) { |
200
|
0
|
0
|
|
|
|
|
if (defined( $ENV{USER} )) { |
201
|
|
|
|
|
|
|
|
202
|
0
|
|
|
|
|
|
my ($name,$passwd,$uid,$gid, |
203
|
|
|
|
|
|
|
$quota,$comment,$gcos,$dir,$shell,$expire)=getpwnam($ENV{USER}); |
204
|
|
|
|
|
|
|
|
205
|
0
|
|
|
|
|
|
push(@dircheck, $dir.'/.sslca'); |
206
|
0
|
|
|
|
|
|
push(@filecheck, $dir.'/.sslca.bundle'); |
207
|
|
|
|
|
|
|
} |
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
|
210
|
0
|
|
|
|
|
|
my @dircheck2=( |
211
|
|
|
|
|
|
|
'/etc/ssl/ca/', |
212
|
|
|
|
|
|
|
'/usr/local/etc/ssl/ca/', |
213
|
|
|
|
|
|
|
); |
214
|
0
|
|
|
|
|
|
my @filecheck2=( |
215
|
|
|
|
|
|
|
'/etc/ssl/ca.bundle', |
216
|
|
|
|
|
|
|
'/usr/local/etc/ssl/ca.bundle', |
217
|
|
|
|
|
|
|
'/usr/share/certs/ca-root-nss.crt', |
218
|
|
|
|
|
|
|
'/usr/local/share/certs/ca-root-nss.crt', |
219
|
|
|
|
|
|
|
); |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
#append the prefix stuff if needed |
222
|
0
|
0
|
|
|
|
|
if (defined( $self->{prefix} )) { |
223
|
0
|
|
|
|
|
|
push(@dircheck, $self->{prefix}.'/etc/ssl/ca/'); |
224
|
0
|
|
|
|
|
|
push(@filecheck, $self->{prefix}.'/etc/ssl/ca.bundle'); |
225
|
0
|
|
|
|
|
|
push(@filecheck, $self->{prefix}.'/share/certs/ca-root-nss.crt'); |
226
|
|
|
|
|
|
|
} |
227
|
|
|
|
|
|
|
|
228
|
0
|
|
|
|
|
|
push(@dircheck, @dircheck2); |
229
|
0
|
|
|
|
|
|
push(@filecheck, @filecheck2); |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
#run through each one for directories |
232
|
0
|
|
|
|
|
|
my $int=0; |
233
|
0
|
|
|
|
|
|
my $matched=undef; |
234
|
0
|
|
|
|
|
|
while (defined( $dircheck[$int] )){ |
235
|
0
|
0
|
|
|
|
|
if (-d $dircheck[$int]) { |
236
|
0
|
|
|
|
|
|
$self->{CApath}=$dircheck[$int]; |
237
|
0
|
|
|
|
|
|
$self->{checkCRL}=1; |
238
|
0
|
|
|
|
|
|
$matched=1; |
239
|
|
|
|
|
|
|
} |
240
|
|
|
|
|
|
|
|
241
|
0
|
|
|
|
|
|
$int++; |
242
|
|
|
|
|
|
|
} |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
#run through each one for files |
245
|
0
|
|
|
|
|
|
$int=0; |
246
|
0
|
|
|
|
|
|
$matched=undef; |
247
|
0
|
|
|
|
|
|
while (defined($filecheck[$int])){ |
248
|
0
|
0
|
|
|
|
|
if (-f $filecheck[$int]) { |
249
|
0
|
|
|
|
|
|
$self->{CAfile}=$filecheck[$int]; |
250
|
0
|
|
|
|
|
|
$matched=1; |
251
|
|
|
|
|
|
|
} |
252
|
|
|
|
|
|
|
|
253
|
0
|
|
|
|
|
|
$int++; |
254
|
|
|
|
|
|
|
} |
255
|
|
|
|
|
|
|
|
256
|
0
|
|
|
|
|
|
return $matched; |
257
|
|
|
|
|
|
|
} |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
=head2 byEnv |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
This fetches it via a enviromental variables. |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
Net::LDAP::AutoCA-CAfile |
264
|
|
|
|
|
|
|
Net::LDAP::AutoCA-CApath |
265
|
|
|
|
|
|
|
Net::LDAP::AutoCA-checkCRL |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
=cut |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
sub byEnv{ |
270
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
271
|
|
|
|
|
|
|
|
272
|
0
|
|
|
|
|
|
my $matched=undef; |
273
|
|
|
|
|
|
|
|
274
|
0
|
0
|
|
|
|
|
if (defined($ENV{'Net::LDAP::AutoCA-CAfile'})) { |
275
|
0
|
|
|
|
|
|
$self->{CAfile}=$ENV{'Net::LDAP::AutoCA-CAfile'}; |
276
|
0
|
|
|
|
|
|
$matched=1; |
277
|
|
|
|
|
|
|
} |
278
|
|
|
|
|
|
|
|
279
|
0
|
0
|
|
|
|
|
if (defined($ENV{'Net::LDAP::AutoCA-CApath'})) { |
280
|
0
|
|
|
|
|
|
$self->{CApath}=$ENV{'Net::LDAP::AutoCA-CApath'}; |
281
|
0
|
|
|
|
|
|
$matched=1; |
282
|
|
|
|
|
|
|
} |
283
|
|
|
|
|
|
|
|
284
|
0
|
0
|
|
|
|
|
if (defined($ENV{'Net::LDAP::AutoCA-checkCRL'})) { |
285
|
0
|
|
|
|
|
|
$self->{checkCRL}=$ENV{'Net::LDAP::AutoCA-checkCRL'}; |
286
|
|
|
|
|
|
|
} |
287
|
|
|
|
|
|
|
|
288
|
0
|
|
|
|
|
|
return $matched; |
289
|
|
|
|
|
|
|
} |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
=head1 AUTHOR |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
Zane C. Bowers, C<< >> |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
=head1 BUGS |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
298
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
299
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
=head1 SUPPORT |
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
307
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
perldoc Net::SSL::AutoCA |
309
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
You can also look for information at: |
312
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
=over 4 |
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
L |
318
|
|
|
|
|
|
|
|
319
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
320
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
L |
322
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
=item * CPAN Ratings |
324
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
L |
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
=item * Search CPAN |
328
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
L |
330
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
=back |
332
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
|
334
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
335
|
|
|
|
|
|
|
|
336
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
338
|
|
|
|
|
|
|
|
339
|
|
|
|
|
|
|
Copyright 2009 Zane C. Bowers, all rights reserved. |
340
|
|
|
|
|
|
|
|
341
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
342
|
|
|
|
|
|
|
under the same terms as Perl itself. |
343
|
|
|
|
|
|
|
|
344
|
|
|
|
|
|
|
|
345
|
|
|
|
|
|
|
=cut |
346
|
|
|
|
|
|
|
|
347
|
|
|
|
|
|
|
1; # End of Net::SSL::AutoCA |