line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OpenID::Lite::Message; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
4828
|
use URI; |
|
3
|
|
|
|
|
16110
|
|
|
3
|
|
|
|
|
85
|
|
4
|
3
|
|
|
3
|
|
23
|
use URI::Escape (); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
40
|
|
5
|
3
|
|
|
3
|
|
13871
|
use Storable (); |
|
3
|
|
|
|
|
17836
|
|
|
3
|
|
|
|
|
114
|
|
6
|
3
|
|
|
3
|
|
3908
|
use List::MoreUtils qw(any); |
|
3
|
|
|
|
|
3589
|
|
|
3
|
|
|
|
|
284
|
|
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
3342
|
use OpenID::Lite::Constants::Namespace qw(SIGNON_1_0 SIGNON_1_1 SPEC_2_0); |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
364
|
|
9
|
3
|
|
|
3
|
|
2648
|
use OpenID::Lite::Message::Decoder; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
30
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my $REQUEST_DECODER = OpenID::Lite::Message::Decoder->new; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
2
|
|
|
2
|
0
|
34
|
my ( $class, %params ) = @_; |
15
|
2
|
|
|
|
|
21
|
my $self = bless { |
16
|
|
|
|
|
|
|
_params => {}, |
17
|
|
|
|
|
|
|
_extension_params => {}, |
18
|
|
|
|
|
|
|
_extra_params => {}, |
19
|
|
|
|
|
|
|
_extension_namespaces => {}, |
20
|
|
|
|
|
|
|
}, $class; |
21
|
2
|
|
|
|
|
10
|
return $self; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub copy { |
25
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
26
|
0
|
|
|
|
|
0
|
my $class = ref $self; |
27
|
0
|
|
|
|
|
0
|
my $copied = Storable::dclone($self); |
28
|
0
|
|
|
|
|
0
|
return bless $copied, $class; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub register_extension_namespace { |
32
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $ext_name, $ext_ns ) = @_; |
33
|
0
|
|
|
|
|
0
|
$self->{_extension_namespaces}{$ext_name} = $ext_ns; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub get { |
37
|
21
|
|
|
21
|
0
|
30
|
my ( $self, $key ) = @_; |
38
|
21
|
50
|
|
|
|
44
|
if ($key =~ /^([^.]+)\.([^.]+)$/) { |
39
|
0
|
|
|
|
|
0
|
my $ext_name = $1; |
40
|
0
|
|
|
|
|
0
|
my $ext_key = $2; |
41
|
0
|
0
|
|
|
|
0
|
if ( $ext_name eq 'ns' ) { |
42
|
0
|
0
|
|
|
|
0
|
return exists $self->{_extension_namespaces}{$ext_key} |
43
|
|
|
|
|
|
|
? $self->{_extension_namespaces}{$ext_key} |
44
|
|
|
|
|
|
|
: undef;; |
45
|
|
|
|
|
|
|
} else { |
46
|
0
|
|
|
|
|
0
|
return $self->get_extension($ext_name, $ext_key); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
} else { |
49
|
21
|
50
|
|
|
|
87
|
return exists $self->{_params}{$key} |
50
|
|
|
|
|
|
|
? $self->{_params}{$key} |
51
|
|
|
|
|
|
|
: undef; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub get_ns_alias { |
56
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $ns ) = @_; |
57
|
0
|
|
|
|
|
0
|
for my $alias ( keys %{ $self->{_extension_namespaces} } ) { |
|
0
|
|
|
|
|
0
|
|
58
|
0
|
0
|
|
|
|
0
|
return $alias if $ns eq $self->{_extension_namespaces}{$alias}; |
59
|
|
|
|
|
|
|
} |
60
|
0
|
|
|
|
|
0
|
return; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub has_key { |
64
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $key ) = @_; |
65
|
0
|
|
|
|
|
0
|
return exists $self->{_params}{$key}; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub get_extension { |
69
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $ext_name, $key ) = @_; |
70
|
0
|
0
|
0
|
|
|
0
|
return ( exists $self->{_extension_params}{$ext_name} |
71
|
|
|
|
|
|
|
&& exists $self->{_extension_params}{$ext_name}{$key} ) |
72
|
|
|
|
|
|
|
? $self->{_extension_params}{$ext_name}{$key} |
73
|
|
|
|
|
|
|
: undef; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub get_extra { |
77
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $key ) = @_; |
78
|
0
|
0
|
|
|
|
0
|
return exists $self->{_extra_params}{$key} |
79
|
|
|
|
|
|
|
? $self->{_extra_params}{$key} |
80
|
|
|
|
|
|
|
: undef; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub get_keys { |
84
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
85
|
0
|
|
|
|
|
0
|
my @keys = keys %{ $self->{_params} }; |
|
0
|
|
|
|
|
0
|
|
86
|
0
|
|
|
|
|
0
|
return \@keys; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub get_extension_keys { |
90
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
91
|
0
|
|
|
|
|
0
|
my $alias = shift; |
92
|
0
|
|
|
|
|
0
|
my @keys = keys %{ $self->{_extension_params}{$alias} }; |
|
0
|
|
|
|
|
0
|
|
93
|
0
|
|
|
|
|
0
|
return \@keys; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub get_extension_args { |
97
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
98
|
0
|
|
|
|
|
0
|
my $alias = shift; |
99
|
0
|
0
|
|
|
|
0
|
return unless exists $self->{_extension_params}{$alias}; |
100
|
0
|
|
|
|
|
0
|
return $self->{_extension_params}{$alias}; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub get_extra_keys { |
104
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
105
|
0
|
|
|
|
|
0
|
my @keys = keys %{ $self->{_extra_params} }; |
|
0
|
|
|
|
|
0
|
|
106
|
0
|
|
|
|
|
0
|
return \@keys; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub set { |
110
|
8
|
|
|
8
|
0
|
33
|
my ( $self, $key, $value ) = @_; |
111
|
8
|
50
|
33
|
|
|
50
|
return unless ( defined $key && defined $value ); |
112
|
8
|
50
|
|
|
|
26
|
if ($key =~ /^([^.]+)\.([^.]+)$/) { |
113
|
0
|
|
|
|
|
0
|
my $ext_name = $1; |
114
|
0
|
|
|
|
|
0
|
my $ext_key = $2; |
115
|
0
|
0
|
|
|
|
0
|
if ($ext_name eq 'ns') { |
116
|
0
|
|
|
|
|
0
|
$self->register_extension_namespace($ext_key, $value); |
117
|
|
|
|
|
|
|
} else { |
118
|
0
|
|
|
|
|
0
|
$self->set_extension($ext_name, $ext_key, $value); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
} else { |
121
|
8
|
|
|
|
|
38
|
$self->{_params}{$key} = $value; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub set_extension { |
126
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $ext_name, $key, $value ) = @_; |
127
|
0
|
|
|
|
|
0
|
$self->{_extension_params}{$ext_name}{$key} = $value; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub set_extra { |
131
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $key, $value ) = @_; |
132
|
0
|
0
|
0
|
|
|
0
|
if ( defined $key && defined $value ) { |
133
|
0
|
0
|
|
|
|
0
|
if (ref $value eq 'ARRAY') { |
134
|
0
|
0
|
|
|
|
0
|
$self->{_extra_params}{$key} = @$value > 1 ? $value : $value->[0]; |
135
|
|
|
|
|
|
|
} else { |
136
|
0
|
|
|
|
|
0
|
$self->{_extra_params}{$key} = $value |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub from_key_value { |
143
|
0
|
|
|
0
|
0
|
0
|
my ( $class, $body ) = @_; |
144
|
0
|
|
|
|
|
0
|
my $params = $class->new; |
145
|
0
|
|
|
|
|
0
|
for my $line ( split /\n/, $body ) { |
146
|
0
|
|
|
|
|
0
|
my ($key, $value) = split /:/, $line, 2; |
147
|
0
|
|
|
|
|
0
|
$params->set( $key, $value ); |
148
|
|
|
|
|
|
|
} |
149
|
0
|
|
|
|
|
0
|
return $params; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub from_request { |
153
|
0
|
|
|
0
|
0
|
0
|
my ( $class, $request ) = @_; |
154
|
0
|
|
|
|
|
0
|
return $REQUEST_DECODER->decode($request); |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub to_key_value { |
158
|
1
|
|
|
1
|
0
|
6
|
my $self = shift; |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
#$self->set( ns => SIGNON_1_0 ) unless $self->get('ns'); |
161
|
1
|
|
|
|
|
25
|
return join( |
162
|
|
|
|
|
|
|
"\n", |
163
|
|
|
|
|
|
|
map( sprintf( q{%s:%s}, $_, $self->{_params}{$_} ), |
164
|
1
|
|
|
|
|
3
|
sort keys %{ $self->{_params} } ) |
165
|
|
|
|
|
|
|
)."\n"; |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
sub to_post_body { |
169
|
1
|
|
|
1
|
0
|
3
|
my $self = shift; |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
#$self->set( ns => SIGNON_1_0 ) unless $self->get('ns'); |
172
|
1
|
|
|
|
|
6
|
my $params = $self->to_hash; |
173
|
1
|
|
|
|
|
12
|
return join( |
174
|
|
|
|
|
|
|
"&", |
175
|
|
|
|
|
|
|
map( sprintf( q{%s=%s}, |
176
|
|
|
|
|
|
|
URI::Escape::uri_escape_utf8($_), |
177
|
|
|
|
|
|
|
URI::Escape::uri_escape_utf8( $params->{$_} ) ), |
178
|
1
|
|
|
|
|
3
|
sort keys %{ $params } ) |
179
|
|
|
|
|
|
|
); |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
sub to_url { |
183
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $uri ) = @_; |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
#$self->set( ns => SIGNON_1_0 ) unless $self->get('ns'); |
186
|
0
|
0
|
|
|
|
0
|
$uri = URI->new($uri) unless ref $uri eq 'URI'; |
187
|
0
|
|
|
|
|
0
|
$uri->query_form( %{ $self->to_hash } ); |
|
0
|
|
|
|
|
0
|
|
188
|
0
|
|
|
|
|
0
|
return $uri; |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
sub to_hash { |
192
|
1
|
|
|
1
|
0
|
2
|
my $self = shift; |
193
|
2
|
|
|
|
|
14
|
my %params = map { ( sprintf( q{openid.%s}, $_ ), $self->{_params}{$_} ) } |
|
1
|
|
|
|
|
5
|
|
194
|
1
|
|
|
|
|
3
|
keys %{ $self->{_params} }; |
195
|
1
|
|
|
|
|
3
|
for my $ext_name ( keys %{ $self->{_extension_namespaces} } ) { |
|
1
|
|
|
|
|
6
|
|
196
|
0
|
|
|
|
|
0
|
my $key = sprintf( q{openid.ns.%s}, $ext_name ); |
197
|
0
|
|
|
|
|
0
|
my $value = $self->{_extension_namespaces}{$ext_name}; |
198
|
0
|
|
|
|
|
0
|
$params{$key} = $value; |
199
|
|
|
|
|
|
|
} |
200
|
1
|
|
|
|
|
3
|
for my $ext_name ( keys %{ $self->{_extension_params} } ) { |
|
1
|
|
|
|
|
5
|
|
201
|
0
|
|
|
|
|
0
|
my $ext_hash = $self->{_extension_params}{$ext_name}; |
202
|
0
|
|
|
|
|
0
|
for my $ext_key ( keys %$ext_hash ) { |
203
|
0
|
|
|
|
|
0
|
my $key = sprintf( q{openid.%s.%s}, $ext_name, $ext_key ); |
204
|
0
|
|
|
|
|
0
|
my $value = $ext_hash->{$ext_key}; |
205
|
0
|
|
|
|
|
0
|
$params{$key} = $value; |
206
|
|
|
|
|
|
|
} |
207
|
|
|
|
|
|
|
} |
208
|
1
|
|
|
|
|
2
|
for my $key ( keys %{ $self->{_extra_params} } ) { |
|
1
|
|
|
|
|
9
|
|
209
|
0
|
|
|
|
|
0
|
$params{$key} = $self->{_extra_params}{$key}; |
210
|
|
|
|
|
|
|
} |
211
|
1
|
|
|
|
|
5
|
return \%params; |
212
|
|
|
|
|
|
|
} |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
sub set_signed { |
215
|
1
|
|
|
1
|
0
|
6
|
my $self = shift; |
216
|
1
|
|
|
|
|
2
|
my @keys = grep { $_ ne q{sig} } keys %{ $self->{_params} }; |
|
3
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
5
|
|
217
|
1
|
|
|
|
|
3
|
for my $ext_name ( keys %{ $self->{_extension_namespaces} } ) { |
|
1
|
|
|
|
|
4
|
|
218
|
0
|
|
|
|
|
0
|
push(@keys, sprintf(q{ns.%s}, $ext_name)); |
219
|
0
|
|
|
|
|
0
|
for my $ext_key ( keys %{ $self->{_extension_params}{$ext_name} } ) { |
|
0
|
|
|
|
|
0
|
|
220
|
0
|
|
|
|
|
0
|
push(@keys, sprintf(q{%s.%s},$ext_name, $ext_key)); |
221
|
|
|
|
|
|
|
} |
222
|
|
|
|
|
|
|
} |
223
|
1
|
|
|
|
|
12
|
@keys = grep { $self->get($_) } @keys; |
|
3
|
|
|
|
|
8
|
|
224
|
1
|
|
|
|
|
2
|
push(@keys, q{signed}); |
225
|
1
|
|
|
|
|
10
|
$self->set( signed => join(',', sort @keys)); |
226
|
|
|
|
|
|
|
} |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
sub is_openid1 { |
229
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
230
|
0
|
|
|
|
|
|
my $ns = $self->get('ns'); |
231
|
0
|
|
0
|
0
|
|
|
return ( !$ns || any { $ns eq $_ } ( SIGNON_1_1, SIGNON_1_0 ) ); |
|
0
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
sub is_openid2 { |
235
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
236
|
0
|
|
|
|
|
|
my $ns = $self->get('ns'); |
237
|
0
|
|
0
|
|
|
|
return ( $ns && $ns eq SPEC_2_0 ); |
238
|
|
|
|
|
|
|
} |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
1; |