line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Amazon::Signature; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
18527
|
use strict; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
30
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
28
|
|
5
|
1
|
|
|
1
|
|
397
|
use Spiffy -Base; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
field 'Service'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use URI::Escape; |
9
|
|
|
|
|
|
|
use DateTime; |
10
|
|
|
|
|
|
|
use Digest::HMAC_SHA1 qw(hmac_sha1); |
11
|
|
|
|
|
|
|
use MIME::Base64; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 NAME |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Net::Amazon::Signature |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 VERSION |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Version 0.03 |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=cut |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
our $VERSION = 0.03; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 SYNOPSIS |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
use Net::Amazon::Signature; |
28
|
|
|
|
|
|
|
my $sig_maker = Net::Amazon::Signature->new(Service => AWSServiceName); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my ($signature, $timestamp) = $sig_maker->create({ |
31
|
|
|
|
|
|
|
Operation => 'GetInfo', |
32
|
|
|
|
|
|
|
SecretAccessKey => 'Your Secret Key Here', |
33
|
|
|
|
|
|
|
uri_escape => 1 |
34
|
|
|
|
|
|
|
}); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# go ahead and make your SOAP or REST call now... |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 DESCRIPTION |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
This module creates the encrypted signature needed to login to Amazon's Mechanical Turk and Alexa web services and any other web services that Amazon might make in the future that require an encrypted signature, assuming they follow the same convention. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=cut |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 METHODS |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head2 new |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
creates a new Net::Amazon::Signature object |
51
|
|
|
|
|
|
|
Takes in a hashref with key Service |
52
|
|
|
|
|
|
|
Example |
53
|
|
|
|
|
|
|
my $foo = Net::Amazon::Signature->new({Service => 'AWSMechanicalTurkRequester'}); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=cut |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head2 create |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Creates the signature. The method takes in a hashref with two required values: |
60
|
|
|
|
|
|
|
* SecretAccessKey - the secret access key that Amazon has assigned to you. |
61
|
|
|
|
|
|
|
* Operation - the name of the operation to perform. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Returns an array with the signature and the timestamp used in creating the authenticated request. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=cut |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub create |
68
|
|
|
|
|
|
|
{ |
69
|
|
|
|
|
|
|
my $args = shift; |
70
|
|
|
|
|
|
|
die "need SecretAccessKey" if !$args->{SecretAccessKey}; |
71
|
|
|
|
|
|
|
die "need Operation" if !$args->{Operation}; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
my $timestamp = DateTime->now() . 'Z'; |
74
|
|
|
|
|
|
|
my $operation = $args->{Operation}; |
75
|
|
|
|
|
|
|
my $sig = $self->Service().$operation.$timestamp; |
76
|
|
|
|
|
|
|
my $digest =$self->_make_signature($sig,$args->{SecretAccessKey}); |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
if (defined $args->{uri_escape}) |
79
|
|
|
|
|
|
|
{ |
80
|
|
|
|
|
|
|
$digest = uri_escape($digest); |
81
|
|
|
|
|
|
|
$timestamp = uri_escape($timestamp); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
return ($digest, $timestamp); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head2 _make_signature |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
makes the encoded signature give an unencoded string and a hashing key (the secret access id). |
89
|
|
|
|
|
|
|
You do not need to call this function directly. Call create_signature instead. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=cut |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub _make_signature |
94
|
|
|
|
|
|
|
{ |
95
|
|
|
|
|
|
|
my ($sig,$key) = @_; |
96
|
|
|
|
|
|
|
my $hmac = hmac_sha1(@_); |
97
|
|
|
|
|
|
|
my $digest = encode_base64($hmac); |
98
|
|
|
|
|
|
|
chomp $digest; |
99
|
|
|
|
|
|
|
return $digest; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 AUTHOR |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Rachel Richard, C<< >> |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 BUGS |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
109
|
|
|
|
|
|
|
C, or through the web interface at |
110
|
|
|
|
|
|
|
L. |
111
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress on |
112
|
|
|
|
|
|
|
your bug as I make changes. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 SUPPORT |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
perldoc Net::Amazon::Signature |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
You can also look for information at: |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=over 4 |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
L |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=item * CPAN Ratings |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
L |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
L |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=item * Search CPAN |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
L |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=back |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Copyright 2005 Rachel Richard, all rights reserved. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
149
|
|
|
|
|
|
|
under the same terms as Perl itself. |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=cut |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
1; |