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.98'; |
4
|
96
|
|
|
96
|
|
761
|
use Moose; |
|
96
|
|
|
|
|
241
|
|
|
96
|
|
|
|
|
773
|
|
5
|
|
|
|
|
|
|
|
6
|
96
|
|
|
96
|
|
720353
|
use Net::Amazon::S3::Signature::V4Implementation; |
|
96
|
|
|
|
|
349
|
|
|
96
|
|
|
|
|
3892
|
|
7
|
96
|
|
|
96
|
|
884
|
use Digest::SHA; |
|
96
|
|
|
|
|
273
|
|
|
96
|
|
|
|
|
4245
|
|
8
|
96
|
|
|
96
|
|
637
|
use Ref::Util; |
|
96
|
|
|
|
|
260
|
|
|
96
|
|
|
|
|
3338
|
|
9
|
|
|
|
|
|
|
|
10
|
96
|
|
|
96
|
|
654
|
use Net::Amazon::S3::Constants; |
|
96
|
|
|
|
|
246
|
|
|
96
|
|
|
|
|
2966
|
|
11
|
96
|
|
|
96
|
|
629
|
use Net::Amazon::S3::Signature::V2; |
|
96
|
|
|
|
|
244
|
|
|
96
|
|
|
|
|
2404
|
|
12
|
|
|
|
|
|
|
|
13
|
96
|
|
|
96
|
|
581
|
use namespace::clean; |
|
96
|
|
|
|
|
268
|
|
|
96
|
|
|
|
|
1146
|
|
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
|
|
20
|
my ($self, $region) = @_; |
40
|
|
|
|
|
|
|
|
41
|
7
|
|
33
|
|
|
204
|
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
|
|
19
|
my ($self, $sign, $request) = @_; |
51
|
|
|
|
|
|
|
|
52
|
7
|
|
|
|
|
32
|
my $host = $request->uri->host; |
53
|
7
|
100
|
|
|
|
714
|
return if $sign->{endpoint} eq 'us-east-1'; |
54
|
6
|
100
|
|
|
|
39
|
return unless $host =~ s/(?<=\bs3)(?=\.amazonaws\.com$)/"-" . $sign->{endpoint}/e; |
|
4
|
|
|
|
|
21
|
|
55
|
|
|
|
|
|
|
|
56
|
4
|
|
|
|
|
14
|
$request->uri->host( $host ); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub sign_request { |
60
|
1
|
|
|
1
|
1
|
1045
|
my ($self, $request, $region) = @_; |
61
|
|
|
|
|
|
|
|
62
|
1
|
|
|
|
|
15
|
my $sha = Digest::SHA->new( '256' ); |
63
|
1
|
50
|
|
|
|
34
|
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
|
|
|
|
|
30
|
$self->_append_authorization_headers ($request); |
72
|
|
|
|
|
|
|
|
73
|
1
|
|
|
|
|
7
|
my $sign = $self->_sign( $region ); |
74
|
1
|
|
|
|
|
7
|
$self->_host_to_region_host( $sign, $request ); |
75
|
1
|
|
|
|
|
6
|
$sign->sign( $request ); |
76
|
|
|
|
|
|
|
|
77
|
1
|
|
|
|
|
23
|
return $request; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub sign_uri { |
81
|
6
|
|
|
6
|
1
|
18
|
my ($self, $request, $expires_at) = @_; |
82
|
|
|
|
|
|
|
|
83
|
6
|
|
|
|
|
47
|
$self->_append_authorization_query_params ($request); |
84
|
|
|
|
|
|
|
|
85
|
6
|
|
|
|
|
18
|
my $sign = $self->_sign; |
86
|
6
|
|
|
|
|
26
|
$self->_host_to_region_host( $sign, $request ); |
87
|
|
|
|
|
|
|
|
88
|
6
|
|
|
|
|
392
|
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.98 |
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 |