line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OAuth::Lite::SignatureMethod::HMAC_SHA1; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
1829
|
use strict; |
|
6
|
|
|
|
|
844
|
|
|
6
|
|
|
|
|
213
|
|
4
|
6
|
|
|
6
|
|
25
|
use warnings; |
|
6
|
|
|
|
|
61
|
|
|
6
|
|
|
|
|
172
|
|
5
|
|
|
|
|
|
|
|
6
|
6
|
|
|
6
|
|
23
|
use base 'OAuth::Lite::SignatureMethod'; |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
2167
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
__PACKAGE__->method_name('HMAC-SHA1'); |
9
|
|
|
|
|
|
|
|
10
|
6
|
|
|
6
|
|
3969
|
use Digest::SHA; |
|
6
|
|
|
|
|
19935
|
|
|
6
|
|
|
|
|
334
|
|
11
|
6
|
|
|
6
|
|
3665
|
use MIME::Base64; |
|
6
|
|
|
|
|
3673
|
|
|
6
|
|
|
|
|
1161
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 NAME |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
OAuth::Lite::SignatureMethod::HMAC_SHA1 - HMAC_SHA1 signature method class; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 SYNOPSIS |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# Consumer side |
20
|
|
|
|
|
|
|
my $method = OAuth::Lite::SignatureMethod::HMAC_SHA1->new( |
21
|
|
|
|
|
|
|
consumer_secret => 'foo', |
22
|
|
|
|
|
|
|
token_secret => 'bar', |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $signature = $method->sign($base_string); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# Service Provider side |
28
|
|
|
|
|
|
|
my $method = OAuth::Lite::SignatureMethod::HMAC_SHA1->new( |
29
|
|
|
|
|
|
|
consumer_secret => 'foo', |
30
|
|
|
|
|
|
|
token_secret => 'bar', |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
unless ($method->verify($base_string, $signature)) { |
33
|
|
|
|
|
|
|
say "Signature is invalid!"; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 DESCRIPTION |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
HMAC_SHA1 signature method class. |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 METHODS |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head2 method_name |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Class method. Returns this method's name. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
say OAuth::Lite::SignatureMethod::HMAC_SHA1->method_name; |
47
|
|
|
|
|
|
|
# HMAC_SHA1 |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head2 build_body_hash |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
say OAuth::Lite::SignatureMethod::HMAC_SHA1->build_body_hash($content); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=cut |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub build_body_hash { |
56
|
1
|
|
|
1
|
1
|
956
|
my ( $class, $content ) = @_; |
57
|
1
|
|
|
|
|
65
|
my $hash = MIME::Base64::encode_base64(Digest::SHA::sha1($content)); |
58
|
1
|
|
|
|
|
8
|
$hash =~ s/\n//g; |
59
|
1
|
|
|
|
|
6
|
return $hash; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head2 new(%params) |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head3 parameters |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=over 4 |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=item consumer_secret |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=item token_secret |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=back |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
my $method = OAuth::Lite::SignatureMethod::HMAC_SHA1->new( |
75
|
|
|
|
|
|
|
consumer_secret => $consumer_secret, |
76
|
|
|
|
|
|
|
token_secret => $bar, |
77
|
|
|
|
|
|
|
); |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head2 sign($base_string) |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Generate signature from base string. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
my $signature = $method->sign($base_string); |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=cut |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub sign { |
88
|
21
|
|
|
21
|
1
|
44
|
my ($self, $base_string) = @_; |
89
|
21
|
|
|
|
|
75
|
my $key = $self->secrets_as_key(); |
90
|
21
|
|
|
|
|
827
|
my $sign = MIME::Base64::encode_base64(Digest::SHA::hmac_sha1($base_string, $key)); |
91
|
21
|
|
|
|
|
48
|
chomp $sign; |
92
|
21
|
|
|
|
|
83
|
$sign; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head2 verify($base_string, $signature) |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Verify signature with base string. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
my $signature_is_valid = $method->verify($base_string, $signature); |
100
|
|
|
|
|
|
|
unless ($signature_is_valid) { |
101
|
|
|
|
|
|
|
say "Signature is invalid!"; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 AUTHOR |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Lyo Kato, C |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
111
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.8.6 or, |
112
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=cut |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
1; |