blib/lib/Crypt/X509/CRL.pm

filter: Statementstmt 28.9% 86 / 297 Branchbran 14.0% 14 / 100 Conditioncond 66.6% 4 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 40.0% 16 / 40 Podpod 100% 30 / 30 totaltotal 31.8% 152 / 477 CC 64 SCAR 41.8
CC
64
Cov
26%
IDPs
240.0
revocation_list
182.0
_AuthorityKeyIdentifier
42.0
CRAP 65.7
↑ Summary
1 package Crypt::X509::CRL;
2
3 3 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Convert::ASN1 qw(:io :debug);
Subroutine BEGIN: called CC=1 SCAR=0.0
8
9 3 require Exporter;
10
11 3 our @ISA = qw(Exporter);
12 3 our %EXPORT_TAGS = ( 'all' => [qw()] );
13 3 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
14 3 our @EXPORT = qw( error new this_update next_update );
15 3 our $VERSION = '0.4';
16
17 3 my $parser = undef;
18 3 my $asn = undef;
19 3 my $error = undef;
20
21 3 my %oid2enchash= (
22 '1.2.840.113549.1.1.1' => {'enc' => 'RSA'},
23 '1.2.840.113549.1.1.2' => {'enc' => 'RSA', 'hash' => 'MD2'},
24 '1.2.840.113549.1.1.3' => {'enc' => 'RSA', 'hash' => 'MD4'},
25 '1.2.840.113549.1.1.4' => {'enc' => 'RSA', 'hash' => 'MD5'},
26 '1.2.840.113549.1.1.5' => {'enc' => 'RSA', 'hash' => 'SHA1'},
27 '1.2.840.113549.1.1.6' => {'enc' => 'OAEP'}
28 );
29
30 3 my %oid2attr = (
31 "2.5.4.3" => "CN",
32 "2.5.4.6" => "C",
33 "2.5.4.7" => "l",
34 "2.5.4.8" => "S",
35 "2.5.4.10" => "O",
36 "2.5.4.11" => "OU",
37 "1.2.840.113549.1.9.1" => "E",
38 "0.9.2342.19200300.100.1.1" => "UID",
39 "0.9.2342.19200300.100.1.25" => "DC"
40 );
41
42
43
44
45 3 ▶sub new {
Subroutine new: called CC=3 SCAR=11.0
Pod documented
46 3 my ( $class , %args ) = @_;
47
48 3 ▶ if ( !defined ( $parser ) || $parser->error ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $parser or $parser->error) 2 1 3
Condition66%2/3
not defined $parser or $parser->error
l!l&&r!l&&!r
201
MC/DC50%1/2
not defined $parser or $parser->error
not defined $parser $parser->error
Truth table66%2/3
not(A) or B
A= not defined $parserB= $parser->error
ABresult
1X1
011
000
49 2 $parser = _init();
50 }
51
52 3 my $self = $parser->decode( $args{'crl'} );
53
54 3 $self->{'_error'} = $parser->error;
55 3 bless ( $self , $class );
56
57 3 return $self;
58 }
59
60
61 3 ▶sub error {
Subroutine error: called CC=1 SCAR=0.0
Pod documented
62 3 my $self = shift;
63 3 return $self->{'_error'};
64 }
65
66
67 0 ▶sub version {
Subroutine version: not called CC=2 SCAR=17.9
Pod documented
68 0 my $self = shift;
69
70 0 ▶ return undef if not exists $self->{'tbsCertList'}{'version'};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"tbsCertList"}{"version"} 0 0 0
71
72 0 return $self->{'tbsCertList'}{'version'};
73 }
74
75
76 0 ▶sub version_string {
Subroutine version_string: not called CC=5 SCAR=34.0
Pod documented
77 0 my $self = shift;
78
79 0 ▶ return undef if not exists $self->{'tbsCertList'}{'version'};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"tbsCertList"}{"version"} 0 0 0
80
81 0 my $v = $self->{'tbsCertList'}{'version'};
82 0 ▶ return "v1" if $v == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $v == 0 0 0 0
83 0 ▶ return "v2" if $v == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $v == 1 0 0 0
84 0 ▶ return "v3" if $v == 2;
Branch: 1 branch
BranchTrueFalseTotal
if $v == 2 0 0 0
85 }
86
87
88 1 ▶sub this_update {
Subroutine this_update: called CC=3 SCAR=15.1
Pod documented
89 1 my $self = shift;
90 1 ▶ if ( exists $self->{'tbsCertList'}{'thisUpdate'}{'utcTime'} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $self->{'tbsCertList'}{'thisUpdate'}{'utcTime'}) { } 1 0 1
elsif (exists $self->{'tbsCertList'}{'thisUpdate'}{'generalTime'}) { } 0 0 0
91 1 return $self->{'tbsCertList'}{'thisUpdate'}{'utcTime'};
92 } elsif ( exists $self->{'tbsCertList'}{'thisUpdate'}{'generalTime'} ) {
93 0 return $self->{'tbsCertList'}{'thisUpdate'}{'generalTime'};
94 } else {
95 0 return undef;
96 }
97 }
98
99
100 1 ▶sub next_update {
Subroutine next_update: called CC=3 SCAR=15.1
Pod documented
101 1 my $self = shift;
102 1 ▶ if ( exists $self->{'tbsCertList'}{'nextUpdate'}{'utcTime'} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $self->{'tbsCertList'}{'nextUpdate'}{'utcTime'}) { } 1 0 1
elsif ($self->{'tbsCertList'}{'nextUpdate'}{'generalTime'}) { } 0 0 0
103 1 return $self->{'tbsCertList'}{'nextUpdate'}{'utcTime'};
104 } elsif ( $self->{'tbsCertList'}{'nextUpdate'}{'generalTime'} ) {
105 0 return $self->{'tbsCertList'}{'nextUpdate'}{'generalTime'};
106 } else {
107 0 return undef;
108 }
109 }
110
111
112 0 ▶sub signature {
Subroutine signature: not called CC=1 SCAR=6.9
Pod documented
113 0 my $self = shift;
114 0 return $self->{'signatureValue'}[0];
115 }
116
117
118 1 ▶sub signature_length {
Subroutine signature_length: called CC=1 SCAR=0.0
Pod documented
119 1 my $self = shift;
120 1 return $self->{'signatureValue'}[1];
121 }
122
123
124 1 ▶sub signature_algorithm {
Subroutine signature_algorithm: called CC=1 SCAR=0.0
Pod documented
125 1 my $self = shift;
126 1 return $self->{'tbsCertList'}{'signature'}{'algorithm'};
127 }
128
129
130 1 ▶sub SigEncAlg {
Subroutine SigEncAlg: called CC=1 SCAR=0.0
Pod documented
131 1 my $self = shift;
132 1 return $oid2enchash{ $self->{'tbsCertList'}{'signature'}->{'algorithm'} }->{'enc'};
133 }
134
135 1 ▶sub SigHashAlg {
Subroutine SigHashAlg: called CC=1 SCAR=0.0
Pod documented
136 1 my $self = shift;
137 1 return $oid2enchash{ $self->{'tbsCertList'}{'signature'}->{'algorithm'} }->{'hash'};
138 }
139
140
141 #########################################################################
142 # accessors - issuer
143 #########################################################################
144
145 1 ▶sub Issuer {
Subroutine Issuer: called CC=3 SCAR=11.0
Pod documented
146 1 my $self = shift;
147 1 my ( $i , $type );
148 1 my $issuerdn = $self->{'tbsCertList'}->{'issuer'}->{'rdnSequence'};
149
150 1 $self->{'tbsCertList'}->{'issuer'}->{'dn'} = [];
151
152 1 my $issuedn = $self->{'tbsCertList'}->{'issuer'}->{'dn'};
153
154 1 for my $issue ( @{ $issuerdn } ) {
155 5 $i = @{ $issue }[0];
156 5 ▶ if ( $oid2attr{ $i->{'type'} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($oid2attr{$i->{'type'}}) { } 5 0 5
157 5 $type = $oid2attr{ $i->{'type'} };
158 } else {
159 0 $type = $i->{'type'};
160 }
161 5 my @key = keys ( %{ $i->{'value'} } );
162 5 push @{ $issuedn } , $type . "=" . $i->{'value'}->{ $key[0] };
163 }
164 1 return $issuedn;
165 }
166
167 0 ▶sub _issuer_part {
Subroutine _issuer_part: not called CC=3 SCAR=24.8
168 0 my $self = shift;
169 0 my $oid = shift;
170 0 my $issuerrdn = $self->{'tbsCertList'}->{'issuer'}->{'rdnSequence'};
171 0 for my $issue ( @{ $issuerrdn } ) {
172 0 my $i = @{ $issue }[0];
173 0 ▶ if ( $i->{'type'} eq $oid ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i->{"type"} eq $oid) 0 0 0
174 0 my @key = keys ( %{ $i->{'value'} } );
175 0 return $i->{'value'}->{ $key[0] };
176 }
177 }
178 0 return undef;
179 }
180
181
182 0 ▶sub issuer_cn {
Subroutine issuer_cn: not called CC=1 SCAR=6.9
Pod documented
183 0 my $self = shift;
184 0 return _issuer_part( $self , '2.5.4.3' );
185 }
186
187
188
189 0 ▶sub issuer_country {
Subroutine issuer_country: not called CC=1 SCAR=6.9
Pod documented
190 0 my $self = shift;
191 0 return _issuer_part( $self , '2.5.4.6' );
192 }
193
194
195 0 ▶sub issuer_state {
Subroutine issuer_state: not called CC=1 SCAR=6.9
Pod documented
196 0 my $self = shift;
197 0 return _issuer_part( $self , '2.5.4.8' );
198 }
199
200
201 0 ▶sub issuer_locality {
Subroutine issuer_locality: not called CC=1 SCAR=6.9
Pod documented
202 0 my $self = shift;
203 0 return _issuer_part( $self , '2.5.4.7' );
204 }
205
206
207 0 ▶sub issuer_org {
Subroutine issuer_org: not called CC=1 SCAR=6.9
Pod documented
208 0 my $self = shift;
209 0 return _issuer_part( $self , '2.5.4.10' );
210 }
211
212
213 0 ▶sub issuer_email {
Subroutine issuer_email: not called CC=1 SCAR=6.9
Pod documented
214 0 my $self = shift;
215 0 return _issuer_part( $self , '1.2.840.113549.1.9.1' );
216 }
217
218
219 #########################################################################
220 #
221 # ------- EXTENSIONS -------
222 #
223 # valid RFC 3280 extensions:
224 # Authority Key Identifier (implemented)
225 # CRL Number (implemented)
226 # Issuing Distribution Point (implemented)
227 # Issuer Alternative Name
228 # Delta CRL Indicator
229 # Freshest CRL (a.k.a. Delta CRL Distribution Point)
230 #
231 #########################################################################
232
233
234 0 ▶sub key_identifier {
Subroutine key_identifier: not called CC=2 SCAR=17.9
Pod documented
235 0 my $self = shift;
236 0 ▶ if ( defined $self->_AuthorityKeyIdentifier ) { return ( $self->_AuthorityKeyIdentifier )->{keyIdentifier}; }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->_AuthorityKeyIdentifier) 0 0 0
237 0 return undef;
238 }
239
240 # _AuthorityKeyIdentifier
241 0 ▶sub _AuthorityKeyIdentifier {
Subroutine _AuthorityKeyIdentifier: not called CC=6 SCAR=37.4
242 0 my $self = shift;
243 0 my $extensions = $self->{'tbsCertList'}->{'crlExtensions'};
244
245 0 ▶ if ( not defined $extensions ) { return undef; } # no extensions in certificate
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $extensions) 0 0 0
246
247 0 ▶ if ( defined $self->{'tbsCertList'}{'AuthorityKeyIdentifier'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"tbsCertList"}{"AuthorityKeyIdentifier"}) 0 0 0
248 0 return ( $self->{'tbsCertList'}{'AuthorityKeyIdentifier'} );
249 }
250
251 0 for my $extension ( @{ $extensions } ) {
252 0 ▶ if ( $extension->{'extnID'} eq '2.5.29.35' ) { # OID for AuthorityKeyIdentifier
Branch: 1 branch
BranchTrueFalseTotal
if ($extension->{"extnID"} eq "2.5.29.35") 0 0 0
253 0 my $parser = _init('AuthorityKeyIdentifier');
254 0 $self->{'tbsCertList'}{'AuthorityKeyIdentifier'} = $parser->decode( $extension->{'extnValue'} );
255 0 ▶ if ( $parser->error ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parser->error) 0 0 0
256 0 $self->{"_error"} = $parser->error;
257 0 return undef;
258 }
259 0 return $self->{'tbsCertList'}{'AuthorityKeyIdentifier'};
260 }
261 }
262 0 return undef;
263 }
264
265
266 0 ▶sub authorityCertIssuer {
Subroutine authorityCertIssuer: not called CC=4 SCAR=30.0
Pod documented
267 0 my $self = shift;
268 0 my ( $i , $type );
269 0 my $rdn = _AuthorityKeyIdentifier( $self );
270 0 ▶ if ( not defined ( $rdn ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $rdn) { } 0 0 0
271 0 return (undef); # we do not have that extension
272 } else {
273 0 $rdn = $rdn->{'authorityCertIssuer'}[0]->{'directoryName'};
274 }
275 0 $rdn->{'dn'} = [];
276 0 my $dn = $rdn->{'dn'};
277 0 $rdn = $rdn->{'rdnSequence'};
278 0 for my $r ( @{ $rdn } ) {
279 0 $i = @{ $r }[0];
280 0 ▶ if ( $oid2attr{ $i->{'type'} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($oid2attr{$i->{'type'}}) { } 0 0 0
281 0 $type = $oid2attr{ $i->{'type'} };
282 } else {
283 0 $type = $i->{'type'};
284 }
285 0 my @key = keys ( %{ $i->{'value'} } );
286 0 push @{ $dn } , $type . "=" . $i->{'value'}->{ $key[0] };
287 }
288 0 return $dn;
289 }
290
291 0 ▶sub _authcert_part {
Subroutine _authcert_part: not called CC=4 SCAR=30.0
292 0 my $self = shift;
293 0 my $oid = shift;
294 0 my $rdn = _AuthorityKeyIdentifier( $self );
295 0 ▶ if ( not defined ( $rdn ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $rdn) { } 0 0 0
296 0 return (undef); # we do not have that extension
297 } else {
298 0 $rdn = $rdn->{'authorityCertIssuer'}[0]->{'directoryName'}->{'rdnSequence'};
299 }
300 0 for my $r ( @{ $rdn } ) {
301 0 my $i = @{ $r }[0];
302 0 ▶ if ( $i->{'type'} eq $oid ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i->{"type"} eq $oid) 0 0 0
303 0 my @key = keys ( %{ $i->{'value'} } );
304 0 return $i->{'value'}->{ $key[0] };
305 }
306 }
307 0 return undef;
308 }
309
310
311 0 ▶sub authority_serial {
Subroutine authority_serial: not called CC=1 SCAR=6.9
Pod documented
312 0 my $self = shift;
313 0 return ( $self->_AuthorityKeyIdentifier )->{authorityCertSerialNumber};
314 }
315
316
317 0 ▶sub authority_cn {
Subroutine authority_cn: not called CC=1 SCAR=6.9
Pod documented
318 0 my $self = shift;
319 0 return _authcert_part( $self , '2.5.4.3' );
320 }
321
322
323 0 ▶sub authority_country {
Subroutine authority_country: not called CC=1 SCAR=6.9
Pod documented
324 0 my $self = shift;
325 0 return _authcert_part( $self , '2.5.4.6' );
326 }
327
328
329 0 ▶sub authority_state {
Subroutine authority_state: not called CC=1 SCAR=6.9
Pod documented
330 0 my $self = shift;
331 0 return _authcert_part( $self , '2.5.4.8' );
332
333 }
334
335
336 0 ▶sub authority_locality {
Subroutine authority_locality: not called CC=1 SCAR=6.9
Pod documented
337 0 my $self = shift;
338 0 return _authcert_part( $self , '2.5.4.7' );
339 }
340
341
342 0 ▶sub authority_org {
Subroutine authority_org: not called CC=1 SCAR=6.9
Pod documented
343 0 my $self = shift;
344 0 return _authcert_part( $self , '2.5.4.10' );
345 }
346
347
348 0 ▶sub authority_email {
Subroutine authority_email: not called CC=1 SCAR=6.9
Pod documented
349 0 my $self = shift;
350 0 return _authcert_part( $self , '1.2.840.113549.1.9.1' );
351 }
352
353
354 # crl_number (another extension)
355 1 ▶sub crl_number {
Subroutine crl_number: called CC=6 SCAR=19.7
Pod documented
356 1 my $self = shift;
357 1 my $extension;
358 1 my $extensions = $self->{'tbsCertList'}->{'crlExtensions'};
359
360 1 ▶ if ( defined $self->{'tbsCertList'}{'cRLNumber'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"tbsCertList"}{"cRLNumber"}) 0 1 1
361 0 return ( $self->{'tbsCertList'}{'cRLNumber'} );
362 }
363
364 0 ▶ if ( not defined $extensions ) { return undef; } # no extensions in certificate
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $extensions) 0 1 1
365
366 1 for $extension ( @{ $extensions } ) {
367 2 ▶ if ( $extension->{'extnID'} eq '2.5.29.20' ) { # OID for CRLNumber
Branch: 1 branch
BranchTrueFalseTotal
if ($extension->{"extnID"} eq "2.5.29.20") 1 1 2
368 1 my $parser = _init('cRLNumber'); # get a parser for this
369 1 $self->{'tbsCertList'}{'cRLNumber'} = $parser->decode( $extension->{'extnValue'} ); # decode the value
370 1 ▶ if ( $parser->error ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parser->error) 0 1 1
371 0 $self->{"_error"} = $parser->error;
372 0 return undef;
373 }
374 1 return $self->{'tbsCertList'}{'cRLNumber'};
375 }
376 }
377 0 return undef;
378 }
379
380
381 # IDPs
382 0 ▶sub IDPs {
Subroutine IDPs: not called CC=15 SCAR=54.8
Pod documented
383 0 my $self = shift;
384 0 my $extension;
385 0 my $extensions = $self->{'tbsCertList'}->{'crlExtensions'};
386
387 0 ▶ if ( defined $self->{'tbsCertList'}{'idp'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"tbsCertList"}{"idp"}) 0 0 0
388 0 return ( $self->{'tbsCertList'}{'idp'} );
389 }
390
391 0 ▶ if ( not defined $extensions ) { return undef; } # no extensions in certificate
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $extensions) 0 0 0
392
393 0 for $extension ( @{ $extensions } ) {
394 0 ▶ if ( $extension->{'extnID'} eq '2.5.29.28' ) { # OID for issuingDistributionPoint
Branch: 1 branch
BranchTrueFalseTotal
if ($extension->{"extnID"} eq "2.5.29.28") 0 0 0
395 0 my $parser = _init('issuingDistributionPoint'); # get a parser for this
396 0 my $idps = $parser->decode( $extension->{'extnValue'} ); # decode the value
397 0 ▶ if ( $parser->error ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parser->error) 0 0 0
398 0 $self->{"_error"} = $parser->error;
399 0 return undef;
400 }
401
402 # set the critical flag
403 0 ▶ if ( exists $extension->{'critical'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $extension->{'critical'}) { } 0 0 0
404 0 $self->{'tbsCertList'}{'idp'}{'critical'} = $extension->{'critical'};
405 } else {
406 0 $self->{'tbsCertList'}{'idp'}{'critical'} = 0;
407 }
408
409 # set the onlyContainsUserCerts flag
410 0 ▶ if ( exists $idps->{'onlyContainsUserCerts'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $idps->{'onlyContainsUserCerts'}) { } 0 0 0
411 0 $self->{'tbsCertList'}{'idp'}{'onlyUserCerts'} = $idps->{'onlyContainsUserCerts'};
412 } else {
413 0 $self->{'tbsCertList'}{'idp'}{'onlyUserCerts'} = 0;
414 }
415
416 # set the onlyContainsCACerts flag
417 0 ▶ if ( exists $idps->{'onlyContainsCACerts'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $idps->{'onlyContainsCACerts'}) { } 0 0 0
418 0 $self->{'tbsCertList'}{'idp'}{'onlyCaCerts'} = $idps->{'onlyContainsCACerts'};
419 } else {
420 0 $self->{'tbsCertList'}{'idp'}{'onlyCaCerts'} = 0;
421 }
422
423 # set the onlyContainsAttributeCerts flag
424 0 ▶ if ( exists $idps->{'onlyContainsAttributeCerts'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $idps->{'onlyContainsAttributeCerts'}) { } 0 0 0
425 0 $self->{'tbsCertList'}{'idp'}{'onlyAttribCerts'} = $idps->{'onlyContainsAttributeCerts'}
426 } else {
427 0 $self->{'tbsCertList'}{'idp'}{'onlyAttribCerts'} = 0;
428 }
429
430 # set the indirectCRL flag
431 0 ▶ if ( exists $idps->{'indirectCRL'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $idps->{'indirectCRL'}) { } 0 0 0
432 0 $self->{'tbsCertList'}{'idp'}{'indirectCRL'} = $idps->{'indirectCRL'}
433 } else {
434 0 $self->{'tbsCertList'}{'idp'}{'indirectCRL'} = 0
435 }
436
437 # set the defaults for directory_addr and url
438 0 $self->{'tbsCertList'}{'idp'}{'directory_addr'} = undef;
439 0 $self->{'tbsCertList'}{'idp'}{'url'} = undef;
440
441 # set the directory_addr and/or URL values
442 0 for my $each_fullName ( @{ $idps->{'distributionPoint'}->{'fullName'} } ) { # this loops through multiple "fullName" values
443 0 ▶ if ( exists $each_fullName->{directoryName} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $each_fullName->{'directoryName'}) { } 0 0 0
elsif (exists $each_fullName->{'uniformResourceIdentifier'}) { } 0 0 0
444 # found a rdnSequence
445 $self->{'tbsCertList'}{'idp'}{'directory_addr'} =
446 0 join( ', ' , reverse @{ _IDP_rdn( $each_fullName->{directoryName}->{rdnSequence} ) } );
447 } elsif ( exists $each_fullName->{uniformResourceIdentifier} ) {
448 # found a URI
449 0 $self->{'tbsCertList'}{'idp'}{'url'} = $each_fullName->{uniformResourceIdentifier};
450 } else {
451 # found some other type of IDP value
452 # return undef;
453 }
454 }
455
456 # set the reason flags BIT STRING
457 0 ▶ if ( exists $idps->{'onlySomeReasons'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $idps->{'onlySomeReasons'}) { } 0 0 0
458 0 $self->{'tbsCertList'}{'idp'}{'reasonFlags'} = $idps->{'onlySomeReasons'};
459 } else {
460 0 $self->{'tbsCertList'}{'idp'}{'reasonFlags'} = undef;
461 }
462
463 0 return $self->{'tbsCertList'}{'idp'};
464 }
465 }
466 0 return undef;
467 }
468
469 # internal function for parsing the rdn sequence parts
470 0 ▶sub _IDP_rdn {
Subroutine _IDP_rdn: not called CC=3 SCAR=24.8
471 0 my $crl_rdn = shift; # this should be the passed in 'rdnSequence' array
472 0 my ( $i ,$type );
473 0 my $crl_dn = [];
474 0 for my $part ( @{$crl_rdn} ) {
475 0 $i = @{$part}[0];
476 0 ▶ if ( $oid2attr{ $i->{'type'} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($oid2attr{$i->{'type'}}) { } 0 0 0
477 0 $type = $oid2attr{ $i->{'type'} };
478 } else {
479 0 $type = $i->{'type'};
480 }
481 0 my @key = keys ( %{ $i->{'value'} } );
482 0 push @{ $crl_dn } , $type . "=" . $i->{'value'}->{ $key[0] };
483 }
484 0 return $crl_dn;
485 }
486
487 #########################################################################
488 #
489 # ------- CRL ENTRY EXTENSIONS -------
490 #
491 # valid RFC 3280 CRL Entry Extensions:
492 # Reason Code
493 # Hold Instruction Code
494 # Invalidity Date
495 # Certificate Issuer
496 #
497 #########################################################################
498
499
500 # revocation_list
501 0 ▶sub revocation_list {
Subroutine revocation_list: not called CC=13 SCAR=52.0
Pod documented
502 0 my $self = shift;
503 0 my @crl_reason = qw(unspecified keyCompromise cACompromise affiliationChanged superseded
504 cessationOfOperation certificateHold removeFromCRL privilegeWithdrawn
505 aACompromise);
506 0 my %hold_codes = (
507 '1.2.840.10040.2.1' => 'holdinstruction-none',
508 '1.2.840.10040.2.2' => 'holdinstruction-callissuer',
509 '1.2.840.10040.2.3' => 'holdinstruction-reject',
510 );
511
512 0 ▶ if ( defined $self->{'tbsCertList'}{'rl'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"tbsCertList"}{"rl"}) 0 0 0
513 0 return ( $self->{'tbsCertList'}{'rl'} );
514 }
515
516 0 my $rls = $self->{'tbsCertList'}->{'revokedCertificates'};
517 0 ▶ if ( not defined $rls ) { # no revoked certs in this CRL
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $rls) 0 0 0
518 0 $self->{'tbsCertList'}{'rl'} = undef;
519 0 return $self->{'tbsCertList'}{'rl'};
520 }
521
522 0 for my $rl ( @{ $rls } ) {
523 # the below assignment of 'utcTime' is based on the RFC of dates through the
524 # year 2049, after which the RFC calls for dates to be listed as
525 # 'GeneralizedTime' or in the ASN1 below for Time as 'generalTime'.
526 0 ▶ if ( exists $rl->{'revocationDate'}{'utcTime'} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $rl->{'revocationDate'}{'utcTime'}) { } 0 0 0
elsif (exists $rl->{'revocationDate'}{'generalTime'}) { } 0 0 0
527 $self->{'tbsCertList'}{'rl'}{ $rl->{'userCertificate'} }{'revocationDate'} =
528 0 $rl->{'revocationDate'}{'utcTime'};
529 } elsif ( exists $rl->{'revocationDate'}{'generalTime'} ) {
530 $self->{'tbsCertList'}{'rl'}{ $rl->{'userCertificate'} }{'revocationDate'} =
531 0 $rl->{'revocationDate'}{'generalTime'};
532 } else {
533 0 $self->{'tbsCertList'}{'rl'}{ $rl->{'userCertificate'} }{'revocationDate'} = undef;
534 }
535
536 0 for my $extension ( @{ $rl->{'crlEntryExtensions'} } ) {
537 0 ▶ if ( $extension->{'extnID'} eq '2.5.29.21' ) { # OID for crlReason
Branch: 3 branches
BranchTrueFalseTotal
if ($extension->{'extnID'} eq '2.5.29.21') { } 0 0 0
elsif ($extension->{'extnID'} eq '2.5.29.24') { } 0 0 0
elsif ($extension->{'extnID'} eq '2.5.29.23') { } 0 0 0
538 0 my $parser = _init('CRLReason'); # get a parser for this
539 0 my $reason = $parser->decode( $extension->{'extnValue'} ); # decode the value
540 0 ▶ if ( $parser->error ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parser->error) 0 0 0
541 0 $self->{"_error"} = $parser->error;
542 0 return undef;
543 }
544 0 $self->{'tbsCertList'}{'rl'}{ $rl->{'userCertificate'} }{'crlReason'} =
545 $crl_reason[ $reason ];
546
547 } elsif ( $extension->{'extnID'} eq '2.5.29.24' ) { # OID for invalidityDate
548 0 my $parser = _init('invalidityDate');
549 0 my $invalid_date = $parser->decode( $extension->{'extnValue'} );
550 0 ▶ if ( $parser->error ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parser->error) 0 0 0
551 0 $self->{"_error"} = $parser->error;
552 0 return undef;
553 }
554 0 $self->{'tbsCertList'}{'rl'}{ $rl->{'userCertificate'} }{'invalidityDate'} =
555 $invalid_date;
556
557 } elsif ( $extension->{'extnID'} eq '2.5.29.23' ) { # OID for holdInstructionCode
558 0 my $parser = _init('holdInstructionCode');
559 0 my $hold_code = $parser->decode( $extension->{'extnValue'} );
560 0 ▶ if ( $parser->error ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parser->error) 0 0 0
561 0 $self->{"_error"} = $parser->error;
562 0 return undef;
563 }
564 $self->{'tbsCertList'}{'rl'}{ $rl->{'userCertificate'} }{'holdInstructionCode'} =
565 0 $hold_codes{ $hold_code };
566
567 } else {
568 # unimplemented OID(s) found
569 $self->{'tbsCertList'}{'rl'}{ $rl->{'userCertificate'} }{ $extension->{'extnID'} } =
570 0 $extension->{'extnValue'};
571 }
572 }
573 }
574 0 return $self->{'tbsCertList'}{'rl'};
575 }
576
577
578 #######################################################################
579 # internal function
580 #######################################################################
581
582 # _init is the initialzation function and is also used for subsequent
583 # decoding of the inner parts of the object.
584 3 ▶sub _init {
Subroutine _init: called CC=4 SCAR=13.9
585 3 my $what = shift;
586 3 ▶ if ( ( not defined $what ) or ( '' eq $what ) ) { $what = 'CertificateList' }
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $what or "" eq $what) 2 1 3
Condition66%2/3
not defined $what or "" eq $what
l!l&&r!l&&!r
201
MC/DC50%1/2
not defined $what or "" eq $what
not defined $what "" eq $what
Truth table66%2/3
not(A) or B
A= not defined $whatB= "" eq $what
ABresult
1X1
011
000
587 3 ▶ if ( not defined $asn) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $asn) 2 1 3
588 2 $asn = Convert::ASN1->new;
589 2 $asn->prepare(<<ASN1);
590 -- ASN.1 from RFC 3280 and X509 (April 2002)
591 -- Adapted for use with Convert::ASN1
592
593
594 -- attribute data types --
595
596 Attribute ::= SEQUENCE {
597 type AttributeType,
598 values SET OF AttributeValue
599 -- at least one value is required --
600 }
601
602 AttributeType ::= OBJECT IDENTIFIER
603
604 AttributeValue ::= DirectoryString --ANY
605
606 AttributeTypeAndValue ::= SEQUENCE {
607 type AttributeType,
608 value AttributeValue
609 }
610
611
612 -- naming data types --
613
614 Name ::= CHOICE { -- only one possibility for now
615 rdnSequence RDNSequence
616 }
617
618 RDNSequence ::= SEQUENCE OF RelativeDistinguishedName
619
620 RelativeDistinguishedName ::=
621 SET OF AttributeTypeAndValue --SET SIZE (1 .. MAX) OF
622
623
624 -- Directory string type --
625
626 DirectoryString ::= CHOICE {
627 teletexString TeletexString, --(SIZE (1..MAX)),
628 printableString PrintableString, --(SIZE (1..MAX)),
629 bmpString BMPString, --(SIZE (1..MAX)),
630 universalString UniversalString, --(SIZE (1..MAX)),
631 utf8String UTF8String, --(SIZE (1..MAX)),
632 ia5String IA5String, --added for EmailAddress,
633 integer INTEGER
634 }
635
636
637 -- CRL specific structures begin here
638
639 CertificateList ::= SEQUENCE {
640 tbsCertList TBSCertList,
641 signatureAlgorithm AlgorithmIdentifier,
642 signatureValue BIT STRING
643 }
644
645
646 TBSCertList ::= SEQUENCE {
647 version Version OPTIONAL, -- if present, MUST be v2
648 signature AlgorithmIdentifier,
649 issuer Name,
650 thisUpdate Time,
651 nextUpdate Time OPTIONAL,
652
653 revokedCertificates RevokedCertificates OPTIONAL,
654 crlExtensions [0] EXPLICIT Extensions OPTIONAL
655 }
656
657 RevokedCertificates ::= SEQUENCE OF RevokedCerts
658
659 RevokedCerts ::= SEQUENCE {
660 userCertificate CertificateSerialNumber,
661 revocationDate Time,
662 crlEntryExtensions Extensions OPTIONAL
663 }
664
665 -- Version, Time, CertificateSerialNumber, and Extensions
666 -- are all defined in the ASN.1 in section 4.1
667
668 -- AlgorithmIdentifier is defined in section 4.1.1.2
669
670 Version ::= INTEGER --{ v1(0), v2(1), v3(2) }
671
672 CertificateSerialNumber ::= INTEGER
673
674 AlgorithmIdentifier ::= SEQUENCE {
675 algorithm OBJECT IDENTIFIER,
676 parameters ANY
677 }
678
679
680 Name ::= CHOICE { -- only one possibility for now
681 rdnSequence RDNSequence
682 }
683
684
685 Time ::= CHOICE {
686 utcTime UTCTime,
687 generalTime GeneralizedTime
688 }
689
690 --extensions
691
692 Extensions ::= SEQUENCE OF Extension --SIZE (1..MAX) OF Extension
693
694 Extension ::= SEQUENCE {
695 extnID OBJECT IDENTIFIER,
696 critical BOOLEAN OPTIONAL, --DEFAULT FALSE,
697 extnValue OCTET STRING
698 }
699
700 AuthorityKeyIdentifier ::= SEQUENCE {
701 keyIdentifier [0] KeyIdentifier OPTIONAL,
702 authorityCertIssuer [1] GeneralNames OPTIONAL,
703 authorityCertSerialNumber [2] CertificateSerialNumber OPTIONAL }
704 -- authorityCertIssuer and authorityCertSerialNumber shall both
705 -- be present or both be absent
706
707 KeyIdentifier ::= OCTET STRING
708
709 GeneralNames ::= SEQUENCE OF GeneralName
710
711 GeneralName ::= CHOICE {
712 otherName [0] AnotherName,
713 rfc822Name [1] IA5String,
714 dNSName [2] IA5String,
715 x400Address [3] ANY, --ORAddress,
716 directoryName [4] Name,
717 ediPartyName [5] EDIPartyName,
718 uniformResourceIdentifier [6] IA5String,
719 iPAddress [7] OCTET STRING,
720 registeredID [8] OBJECT IDENTIFIER }
721
722 -- AnotherName replaces OTHER-NAME ::= TYPE-IDENTIFIER, as
723 -- TYPE-IDENTIFIER is not supported in the 88 ASN.1 syntax
724
725 AnotherName ::= SEQUENCE {
726 type OBJECT IDENTIFIER,
727 value [0] EXPLICIT ANY } --DEFINED BY type-id }
728
729 EDIPartyName ::= SEQUENCE {
730 nameAssigner [0] DirectoryString OPTIONAL,
731 partyName [1] DirectoryString }
732
733 -- id-ce-issuingDistributionPoint OBJECT IDENTIFIER ::= { id-ce 28 }
734
735 issuingDistributionPoint ::= SEQUENCE {
736 distributionPoint [0] DistributionPointName OPTIONAL,
737 onlyContainsUserCerts [1] BOOLEAN OPTIONAL, --DEFAULT FALSE,
738 onlyContainsCACerts [2] BOOLEAN OPTIONAL, --DEFAULT FALSE,
739 onlySomeReasons [3] ReasonFlags OPTIONAL,
740 indirectCRL [4] BOOLEAN OPTIONAL, --DEFAULT FALSE,
741 onlyContainsAttributeCerts [5] BOOLEAN OPTIONAL --DEFAULT FALSE
742 }
743
744 DistributionPointName ::= CHOICE {
745 fullName [0] GeneralNames,
746 nameRelativeToCRLIssuer [1] RelativeDistinguishedName }
747
748 ReasonFlags ::= BIT STRING --{
749 -- unused (0),
750 -- keyCompromise (1),
751 -- cACompromise (2),
752 -- affiliationChanged (3),
753 -- superseded (4),
754 -- cessationOfOperation (5),
755 -- certificateHold (6),
756 -- privilegeWithdrawn (7),
757 -- aACompromise (8) }
758
759 -- id-ce-cRLNumber OBJECT IDENTIFIER ::= { id-ce 20 }
760
761 cRLNumber ::= INTEGER --(0..MAX)
762
763 -- id-ce-cRLReason OBJECT IDENTIFIER ::= { id-ce 21 }
764
765 -- reasonCode ::= { CRLReason }
766
767 CRLReason ::= ENUMERATED {
768 unspecified (0),
769 keyCompromise (1),
770 cACompromise (2),
771 affiliationChanged (3),
772 superseded (4),
773 cessationOfOperation (5),
774 certificateHold (6),
775 removeFromCRL (8),
776 privilegeWithdrawn (9),
777 aACompromise (10) }
778
779 -- id-ce-holdInstructionCode OBJECT IDENTIFIER ::= { id-ce 23 }
780
781 holdInstructionCode ::= OBJECT IDENTIFIER
782
783 -- holdInstruction OBJECT IDENTIFIER ::=
784 -- { iso(1) member-body(2) us(840) x9-57(10040) 2 }
785 --
786 -- id-holdinstruction-none OBJECT IDENTIFIER ::= {holdInstruction 1}
787 -- id-holdinstruction-callissuer
788 -- OBJECT IDENTIFIER ::= {holdInstruction 2}
789 -- id-holdinstruction-reject OBJECT IDENTIFIER ::= {holdInstruction 3}
790
791 -- id-ce-invalidityDate OBJECT IDENTIFIER ::= { id-ce 24 }
792
793 invalidityDate ::= GeneralizedTime
794
795 -- id-ce-certificateIssuer OBJECT IDENTIFIER ::= { id-ce 29 }
796
797 certificateIssuer ::= GeneralNames
798
799 ASN1
800 }
801 3 my $self = $asn->find( $what );
802 3 return $self;
803 }
804
805
806
807 3 1;
808
809 __DATA__
↑ Summary