line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Crypt::Perl::X509::Extensions; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
716
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
62
|
|
4
|
3
|
|
|
3
|
|
19
|
use warnings; |
|
3
|
|
|
|
|
33
|
|
|
3
|
|
|
|
|
91
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=encoding utf-8 |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Crypt::Perl::X509::Extensions - extensions list for X.509 certificates |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 SYNOPSIS |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
#Each object passed should be an instance of a subclass of |
15
|
|
|
|
|
|
|
#Crypt::Perl::X509::Extension |
16
|
|
|
|
|
|
|
my $exreq = Crypt::Perl::X509::Extensions->new( @EXTN_OBJS ); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
#...or: |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my $exreq = Crypt::Perl::X509::Extensions->new( |
21
|
|
|
|
|
|
|
[ $extn_type1 => @args1 ], |
22
|
|
|
|
|
|
|
[ $extn_type2 => @args2 ], |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
#...for example: |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $exreq = Crypt::Perl::X509::Extensions->new( |
28
|
|
|
|
|
|
|
[ 'subjectAltName', |
29
|
|
|
|
|
|
|
[ dNSName => 'foo.com' ], |
30
|
|
|
|
|
|
|
[ dNSName => 'haha.tld' ], |
31
|
|
|
|
|
|
|
], |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 DESCRIPTION |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
Instances of this class represent the list of extensions in an X.509 (SSL) |
37
|
|
|
|
|
|
|
certificate. |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
You probably don’t need to |
40
|
|
|
|
|
|
|
instantiate this class directly; instead, you can instantiate it |
41
|
|
|
|
|
|
|
implicitly by listing out arguments to |
42
|
|
|
|
|
|
|
L’s constructor. See that module’s |
43
|
|
|
|
|
|
|
L for an example. |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Look in the L distribution’s |
46
|
|
|
|
|
|
|
C namespace for supported extensions. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=cut |
49
|
|
|
|
|
|
|
|
50
|
3
|
|
|
3
|
|
22
|
use Try::Tiny; |
|
3
|
|
|
|
|
13
|
|
|
3
|
|
|
|
|
127
|
|
51
|
|
|
|
|
|
|
|
52
|
3
|
|
|
3
|
|
12
|
use Module::Load (); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
60
|
|
53
|
|
|
|
|
|
|
|
54
|
3
|
|
|
3
|
|
27
|
use Crypt::Perl::ASN1 (); |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
57
|
|
55
|
|
|
|
|
|
|
|
56
|
3
|
|
|
|
|
16
|
use parent qw( |
57
|
|
|
|
|
|
|
Crypt::Perl::ASN1::Encodee |
58
|
3
|
|
|
3
|
|
12
|
); |
|
3
|
|
|
|
|
3
|
|
59
|
|
|
|
|
|
|
|
60
|
3
|
|
|
3
|
|
152
|
use constant OID => '1.2.840.113549.1.9.14'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
218
|
|
61
|
|
|
|
|
|
|
|
62
|
3
|
|
|
3
|
|
21
|
use constant ASN1 => <
|
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
1335
|
|
63
|
|
|
|
|
|
|
Extension ::= SEQUENCE { |
64
|
|
|
|
|
|
|
extnID OBJECT IDENTIFIER, |
65
|
|
|
|
|
|
|
critical BOOLEAN OPTIONAL, |
66
|
|
|
|
|
|
|
extnValue OCTET STRING |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
Extensions ::= SEQUENCE OF Extension |
70
|
|
|
|
|
|
|
END |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
my $EXT_BASE = 'Crypt::Perl::X509::Extension'; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub new { |
75
|
17
|
|
|
17
|
0
|
1025
|
my ($class, @extensions) = @_; |
76
|
|
|
|
|
|
|
|
77
|
17
|
50
|
|
|
|
88
|
if (!@extensions) { |
78
|
0
|
|
|
|
|
0
|
die Crypt::Perl::X::create('Generic', "Empty “extensions”!"); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
17
|
|
|
|
|
113
|
for my $ext (@extensions) { |
82
|
137
|
100
|
|
137
|
|
610
|
if (!try { $ext->isa($EXT_BASE) }) { |
|
137
|
|
|
|
|
4685
|
|
83
|
136
|
100
|
|
|
|
1751
|
if ( 'HASH' eq ref $ext ) { |
|
|
50
|
|
|
|
|
|
84
|
1
|
50
|
|
1
|
|
5
|
if ( !try { $ext->{'extension'}->isa($EXT_BASE) }) { |
|
1
|
|
|
|
|
31
|
|
85
|
0
|
0
|
|
|
|
0
|
if ( 'ARRAY' ne ref $ext->{'extension'} ) { |
86
|
0
|
|
|
|
|
0
|
die Crypt::Perl::X::create('Generic', "“extension” in HASH reference must be ARRAY reference or instance of $EXT_BASE, not “$ext”!"); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
elsif ( 'ARRAY' ne ref $ext ) { |
91
|
0
|
|
|
|
|
0
|
die Crypt::Perl::X::create('Generic', "Extension must be HASH reference, ARRAY reference, or instance of $EXT_BASE, not “$ext”!"); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
17
|
|
|
|
|
138
|
return bless \@extensions, $class; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub _new_parse_arrayref { |
100
|
135
|
|
|
135
|
|
286
|
my ($ext) = @_; |
101
|
135
|
|
|
|
|
359
|
my $module = $ext->[0]; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# For the acmeValdation-v1 extension … |
104
|
135
|
|
|
|
|
304
|
$module =~ tr<-><_>; |
105
|
|
|
|
|
|
|
|
106
|
135
|
|
|
|
|
355
|
my $class = "Crypt::Perl::X509::Extension::$module"; |
107
|
135
|
|
|
|
|
556
|
Module::Load::load($class); |
108
|
135
|
|
|
|
|
10197
|
return $class->new( @{$ext}[ 1 .. $#$ext ] ); |
|
135
|
|
|
|
|
2449
|
|
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub _encode_params { |
112
|
17
|
|
|
17
|
|
46
|
my ($self) = @_; |
113
|
|
|
|
|
|
|
|
114
|
17
|
|
|
|
|
37
|
my @exts_asn1; |
115
|
|
|
|
|
|
|
|
116
|
17
|
|
|
|
|
102
|
for my $ext ( @$self ) { |
117
|
137
|
|
|
|
|
20841
|
my ($critical, $real_ext); |
118
|
137
|
100
|
|
|
|
499
|
if ('HASH' eq ref $ext) { |
119
|
1
|
|
|
|
|
3
|
($critical, $real_ext) = @{$ext}{ qw(critical extension) }; |
|
1
|
|
|
|
|
3
|
|
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
else { |
122
|
136
|
|
|
|
|
256
|
$real_ext = $ext; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
137
|
100
|
|
|
|
469
|
if ('ARRAY' eq ref $real_ext) { |
126
|
135
|
|
|
|
|
370
|
$real_ext = _new_parse_arrayref($real_ext); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
137
|
100
|
|
|
|
494
|
if (!defined $critical) { |
130
|
136
|
|
|
|
|
917
|
$critical = $real_ext->can('CRITICAL'); |
131
|
136
|
|
100
|
|
|
655
|
$critical &&= $critical->(); |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
137
|
100
|
|
|
|
1185
|
push @exts_asn1, { |
135
|
|
|
|
|
|
|
extnID => $real_ext->OID(), |
136
|
|
|
|
|
|
|
($critical ? (critical => Crypt::Perl::ASN1->ASN_BOOLEAN()) : ()), |
137
|
|
|
|
|
|
|
extnValue => $real_ext->encode(), |
138
|
|
|
|
|
|
|
}, |
139
|
|
|
|
|
|
|
}; |
140
|
|
|
|
|
|
|
|
141
|
17
|
|
|
|
|
1548
|
return \@exts_asn1; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
1; |