line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Amazon::S3::Signature::V4; |
2
|
|
|
|
|
|
|
# ABSTRACT: V4 signatures |
3
|
|
|
|
|
|
|
$Net::Amazon::S3::Signature::V4::VERSION = '0.99'; |
4
|
99
|
|
|
99
|
|
762
|
use Moose; |
|
99
|
|
|
|
|
273
|
|
|
99
|
|
|
|
|
754
|
|
5
|
|
|
|
|
|
|
|
6
|
99
|
|
|
99
|
|
724320
|
use Net::Amazon::S3::Signature::V4Implementation; |
|
99
|
|
|
|
|
376
|
|
|
99
|
|
|
|
|
3785
|
|
7
|
99
|
|
|
99
|
|
907
|
use Digest::SHA; |
|
99
|
|
|
|
|
271
|
|
|
99
|
|
|
|
|
3966
|
|
8
|
99
|
|
|
99
|
|
713
|
use Ref::Util; |
|
99
|
|
|
|
|
274
|
|
|
99
|
|
|
|
|
3408
|
|
9
|
|
|
|
|
|
|
|
10
|
99
|
|
|
99
|
|
678
|
use Net::Amazon::S3::Constants; |
|
99
|
|
|
|
|
283
|
|
|
99
|
|
|
|
|
2322
|
|
11
|
99
|
|
|
99
|
|
627
|
use Net::Amazon::S3::Signature::V2; |
|
99
|
|
|
|
|
277
|
|
|
99
|
|
|
|
|
2388
|
|
12
|
|
|
|
|
|
|
|
13
|
99
|
|
|
99
|
|
651
|
use namespace::clean; |
|
99
|
|
|
|
|
262
|
|
|
99
|
|
|
|
|
1151
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
extends 'Net::Amazon::S3::Signature'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub enforce_use_virtual_host { |
18
|
2
|
|
|
2
|
0
|
60
|
1; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub redirect_handler { |
22
|
0
|
|
|
0
|
0
|
0
|
my ($self, $http_request, $response, $ua, $h) = @_; |
23
|
|
|
|
|
|
|
|
24
|
0
|
0
|
|
|
|
0
|
my $region = $response->header(Net::Amazon::S3::Constants->HEADER_BUCKET_REGION) or return; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# change the bucket region in request |
27
|
0
|
|
|
|
|
0
|
my $request = $response->request; |
28
|
0
|
|
|
|
|
0
|
$request->uri( $response->header( 'location' ) ); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# sign the request again |
31
|
0
|
|
|
|
|
0
|
$request->headers->remove_header('Authorization'); |
32
|
0
|
|
|
|
|
0
|
$request->headers->remove_header(Net::Amazon::S3::Constants->HEADER_DATE); |
33
|
0
|
|
|
|
|
0
|
$http_request->_sign_request( $request, $region ); |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
0
|
return $request; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub _sign { |
39
|
7
|
|
|
7
|
|
24
|
my ($self, $region) = @_; |
40
|
|
|
|
|
|
|
|
41
|
7
|
|
33
|
|
|
211
|
return Net::Amazon::S3::Signature::V4Implementation->new( |
42
|
|
|
|
|
|
|
$self->http_request->s3->aws_access_key_id, |
43
|
|
|
|
|
|
|
$self->http_request->s3->aws_secret_access_key, |
44
|
|
|
|
|
|
|
$region || $self->http_request->region, |
45
|
|
|
|
|
|
|
's3', |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub _host_to_region_host { |
50
|
7
|
|
|
7
|
|
18
|
my ($self, $sign, $request) = @_; |
51
|
|
|
|
|
|
|
|
52
|
7
|
|
|
|
|
25
|
my $host = $request->uri->host; |
53
|
7
|
100
|
|
|
|
638
|
return if $sign->{endpoint} eq 'us-east-1'; |
54
|
6
|
100
|
|
|
|
38
|
return unless $host =~ s/(?<=\bs3)(?=\.amazonaws\.com$)/"-" . $sign->{endpoint}/e; |
|
4
|
|
|
|
|
35
|
|
55
|
|
|
|
|
|
|
|
56
|
4
|
|
|
|
|
17
|
$request->uri->host( $host ); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub sign_request { |
60
|
1
|
|
|
1
|
1
|
852
|
my ($self, $request, $region) = @_; |
61
|
|
|
|
|
|
|
|
62
|
1
|
|
|
|
|
11
|
my $sha = Digest::SHA->new( '256' ); |
63
|
1
|
50
|
|
|
|
27
|
if (Ref::Util::is_coderef( my $coderef = $request->content )) { |
64
|
0
|
|
|
|
|
0
|
while (length (my $snippet = $coderef->())) { |
65
|
0
|
|
|
|
|
0
|
$sha->add ($snippet); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
0
|
$request->header( $Net::Amazon::S3::Signature::V4Implementation::X_AMZ_CONTENT_SHA256 => $sha->hexdigest ); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
1
|
|
|
|
|
29
|
$self->_append_authorization_headers ($request); |
72
|
|
|
|
|
|
|
|
73
|
1
|
|
|
|
|
164
|
my $sign = $self->_sign( $region ); |
74
|
1
|
|
|
|
|
5
|
$self->_host_to_region_host( $sign, $request ); |
75
|
1
|
|
|
|
|
6
|
$sign->sign( $request ); |
76
|
|
|
|
|
|
|
|
77
|
1
|
|
|
|
|
32
|
return $request; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub sign_uri { |
81
|
6
|
|
|
6
|
1
|
17
|
my ($self, $request, $expires_at) = @_; |
82
|
|
|
|
|
|
|
|
83
|
6
|
|
|
|
|
30
|
$self->_append_authorization_query_params ($request); |
84
|
|
|
|
|
|
|
|
85
|
6
|
|
|
|
|
17
|
my $sign = $self->_sign; |
86
|
6
|
|
|
|
|
24
|
$self->_host_to_region_host( $sign, $request ); |
87
|
|
|
|
|
|
|
|
88
|
6
|
|
|
|
|
378
|
return $sign->sign_uri( $request->uri, $expires_at - time, $request->method ); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
1; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
__END__ |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=pod |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=encoding UTF-8 |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 NAME |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Net::Amazon::S3::Signature::V4 - V4 signatures |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 VERSION |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
version 0.99 |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 AUTHOR |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Branislav Zahradník <barney@cpan.org> |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
This software is copyright (c) 2021 by Amazon Digital Services, Leon Brocard, Brad Fitzpatrick, Pedro Figueiredo, Rusty Conover, Branislav Zahradník. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
116
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=cut |