| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package OAuth::Lite::SignatureMethod::RSA_SHA1; |
|
2
|
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
1792
|
use strict; |
|
|
3
|
|
|
|
|
7
|
|
|
|
3
|
|
|
|
|
112
|
|
|
4
|
3
|
|
|
3
|
|
18
|
use warnings; |
|
|
3
|
|
|
|
|
4
|
|
|
|
3
|
|
|
|
|
103
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
16
|
use base 'OAuth::Lite::SignatureMethod'; |
|
|
3
|
|
|
|
|
10
|
|
|
|
3
|
|
|
|
|
751
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
7019
|
use Crypt::OpenSSL::RSA; |
|
|
3
|
|
|
|
|
20450
|
|
|
|
3
|
|
|
|
|
73
|
|
|
9
|
3
|
|
|
3
|
|
1356
|
use Digest::SHA (); |
|
|
3
|
|
|
|
|
5616
|
|
|
|
3
|
|
|
|
|
66
|
|
|
10
|
3
|
|
|
3
|
|
970
|
use MIME::Base64 (); |
|
|
3
|
|
|
|
|
822
|
|
|
|
3
|
|
|
|
|
1295
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
__PACKAGE__->method_name('RSA-SHA1'); |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 NAME |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
OAuth::Lite::SignatureMethod::RSA_SHA1 - RSA_SHA1 signature method class; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# Consumer side |
|
21
|
|
|
|
|
|
|
my $signer = OAuth::Lite::SignatureMethod::RSA_SHA1->new( |
|
22
|
|
|
|
|
|
|
consumer_secret => $rsa_private_key, |
|
23
|
|
|
|
|
|
|
); |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $signature = $signer->sign($base_string); |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# Service Provider side |
|
28
|
|
|
|
|
|
|
my $verifier = OAuth::Lite::SignatureMethod::RSA_SHA1->new( |
|
29
|
|
|
|
|
|
|
consumer_secret => $rsa_public_key, |
|
30
|
|
|
|
|
|
|
); |
|
31
|
|
|
|
|
|
|
unless ($verifier->verify($base_string, $signature)) { |
|
32
|
|
|
|
|
|
|
say "Signature is invalid!"; |
|
33
|
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
RSA_SHA1 signature method class. |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 PRIVATE KEY AND PUBLIC KEY |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
RSA needs two keys that called public key and private key. |
|
42
|
|
|
|
|
|
|
If you runs OAuth consumer application and want to use this RSA_SHA1 method |
|
43
|
|
|
|
|
|
|
for signature on OAuth protocol, you have to prepare these keys. |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
To generate them in Perl, here is an example. |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
my $rsa = Crypt::OpenSSL::RSA->generate_key(1024); |
|
48
|
|
|
|
|
|
|
my $public_key = $rsa->get_public_key_string(); |
|
49
|
|
|
|
|
|
|
my $private_key = $rsa->get_private_key_string(); |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
And prior to use OAuth protocol with a service provider, |
|
52
|
|
|
|
|
|
|
you have to register public key onto the service provider. |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 METHODS |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head2 method_name |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
Class method. Returns this method's name. |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
say OAuth::Lite::SignatureMethod::RSA_SHA1->method_name; |
|
61
|
|
|
|
|
|
|
# RSA_SHA1 |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head2 build_body_hash |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
say OAuth::Lite::SignatureMethod::RSA_SHA1->build_body_hash($content); |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=cut |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub build_body_hash { |
|
70
|
1
|
|
|
1
|
1
|
857
|
my ( $class, $content ) = @_; |
|
71
|
1
|
|
|
|
|
37
|
my $hash = MIME::Base64::encode_base64(Digest::SHA::sha1($content)); |
|
72
|
1
|
|
|
|
|
6
|
$hash =~ s/\n//g; |
|
73
|
1
|
|
|
|
|
5
|
return $hash; |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head2 new(%params) |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
On the consumer side, you should pass RSA private key for consumer_secret, |
|
79
|
|
|
|
|
|
|
But for service provider to verify signature, pass RSA public key that |
|
80
|
|
|
|
|
|
|
consumer register on service provider beforehand. |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head3 parameters |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=over 4 |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=item consumer_secret |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=back |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
my $signer = OAuth::Lite::SignatureMethod::RSA_SHA1->new( |
|
91
|
|
|
|
|
|
|
consumer_secret => $rsa_private_key, |
|
92
|
|
|
|
|
|
|
); |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
my $verifier = OAuth::Lite::SignatureMethod::RSA_SHA1->new( |
|
95
|
|
|
|
|
|
|
consumer_secret => $rsa_public_key, |
|
96
|
|
|
|
|
|
|
); |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head2 sign($base_string) |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Generate signature from base string. |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
my $signature = $method->sign($base_string); |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=cut |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub sign { |
|
107
|
1
|
|
|
1
|
1
|
7
|
my ($self, $base_string) = @_; |
|
108
|
1
|
|
|
|
|
11
|
my $private_key_pem = $self->{consumer_secret}; |
|
109
|
1
|
|
|
|
|
170
|
my $private_key = Crypt::OpenSSL::RSA->new_private_key($private_key_pem); |
|
110
|
1
|
|
|
|
|
1115
|
my $signature = MIME::Base64::encode_base64($private_key->sign($base_string)); |
|
111
|
1
|
|
|
|
|
4
|
chomp $signature; |
|
112
|
1
|
|
|
|
|
15
|
$signature; |
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head2 verify($base_string, $signature) |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Verify signature with base string. |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
my $signature_is_valid = $method->verify($base_string, $signature); |
|
120
|
|
|
|
|
|
|
unless ($signature_is_valid) { |
|
121
|
|
|
|
|
|
|
say "Signature is invalid!"; |
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=cut |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub verify { |
|
127
|
2
|
|
|
2
|
1
|
18
|
my ($self, $base_string, $signature) = @_; |
|
128
|
2
|
|
|
|
|
6
|
my $public_key_pem = $self->{consumer_secret}; |
|
129
|
2
|
|
|
|
|
61
|
my $public_key = Crypt::OpenSSL::RSA->new_public_key($public_key_pem); |
|
130
|
2
|
|
|
|
|
1051
|
return $public_key->verify($base_string, MIME::Base64::decode_base64($signature)); |
|
131
|
|
|
|
|
|
|
} |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 AUTHOR |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Lyo Kato, C |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
|
140
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.8.6 or, |
|
141
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=cut |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
1; |