| 1 | package Net::Amazon::S3::Signature::V4; | ||||||||||||||||||||
| 2 | # ABSTRACT: V4 signatures | ||||||||||||||||||||
| 3 | 99 | $Net::Amazon::S3::Signature::V4::VERSION = '0.992'; | |||||||||||||||||||
| 4 | 99 | ▶ | use Moose; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 99 | ▶ | use Net::Amazon::S3::Signature::V4Implementation; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 99 | ▶ | use Digest::SHA; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 99 | ▶ | use Ref::Util; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 99 | ▶ | use Net::Amazon::S3::Constants; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 99 | ▶ | use Net::Amazon::S3::Signature::V2; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 99 | ▶ | use namespace::clean; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 99 | extends 'Net::Amazon::S3::Signature'; | |||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | 2 | ▶ | sub enforce_use_virtual_host { | ||||||||||||||||||
|
Subroutine
enforce_use_virtual_host: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 18 | 2 | 1; | |||||||||||||||||||
| 19 | } | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 0 | ▶ | sub redirect_handler { | ||||||||||||||||||
|
Subroutine
redirect_handler: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 22 | 0 | my ($self, $http_request, $response, $ua, $h) = @_; | |||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 0 | ▶ | my $region = $response->header(Net::Amazon::S3::Constants->HEADER_BUCKET_REGION) or return; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | # change the bucket region in request | ||||||||||||||||||||
| 27 | 0 | my $request = $response->request; | |||||||||||||||||||
| 28 | 0 | $request->uri( $response->header( 'location' ) ); | |||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | # sign the request again | ||||||||||||||||||||
| 31 | 0 | $request->headers->remove_header('Authorization'); | |||||||||||||||||||
| 32 | 0 | $request->headers->remove_header(Net::Amazon::S3::Constants->HEADER_DATE); | |||||||||||||||||||
| 33 | 0 | $http_request->_sign_request( $request, $region ); | |||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 0 | return $request; | |||||||||||||||||||
| 36 | } | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 7 | ▶ | sub _sign { | ||||||||||||||||||
|
Subroutine
_sign: called CC=2 SCAR=8.1
| |||||||||||||||||||||
| 39 | 7 | my ($self, $region) = @_; | |||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 7 | ▶ | return Net::Amazon::S3::Signature::V4Implementation->new( | ||||||||||||||||||
|
Condition33%1/3
$region || $self->http_request->region
MC/DC0%0/2
$region || $self->http_request->region
$region
$self->http_request->region
Truth table33%1/3
A || B
A= $regionB= $self->http_request->region
| |||||||||||||||||||||
| 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 | 7 | ▶ | sub _host_to_region_host { | ||||||||||||||||||
|
Subroutine
_host_to_region_host: called CC=3 SCAR=11.0
| |||||||||||||||||||||
| 50 | 7 | my ($self, $sign, $request) = @_; | |||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 7 | my $host = $request->uri->host; | |||||||||||||||||||
| 53 | 7 | ▶ | return if $sign->{endpoint} eq 'us-east-1'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 54 | 6 | ▶ | return unless $host =~ s/(?<=\bs3)(?=\.amazonaws\.com$)/"-" . $sign->{endpoint}/e; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 4 | $request->uri->host( $host ); | |||||||||||||||||||
| 57 | } | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | 1 | ▶ | sub sign_request { | ||||||||||||||||||
|
Subroutine
sign_request: called CC=3 SCAR=12.7
Pod
documented
| |||||||||||||||||||||
| 60 | 1 | my ($self, $request, $region) = @_; | |||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | 1 | my $sha = Digest::SHA->new( '256' ); | |||||||||||||||||||
| 63 | 1 | ▶ | if (Ref::Util::is_coderef( my $coderef = $request->content )) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 64 | 0 | ▶ | while (length (my $snippet = $coderef->())) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 65 | 0 | $sha->add ($snippet); | |||||||||||||||||||
| 66 | } | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | 0 | $request->header( $Net::Amazon::S3::Signature::V4Implementation::X_AMZ_CONTENT_SHA256 => $sha->hexdigest ); | |||||||||||||||||||
| 69 | } | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | 1 | $self->_append_authorization_headers ($request); | |||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | 1 | my $sign = $self->_sign( $region ); | |||||||||||||||||||
| 74 | 1 | $self->_host_to_region_host( $sign, $request ); | |||||||||||||||||||
| 75 | 1 | $sign->sign( $request ); | |||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | 1 | return $request; | |||||||||||||||||||
| 78 | } | ||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | 6 | ▶ | sub sign_uri { | ||||||||||||||||||
|
Subroutine
sign_uri: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 81 | 6 | my ($self, $request, $expires_at) = @_; | |||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | 6 | $self->_append_authorization_query_params ($request); | |||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | 6 | my $sign = $self->_sign; | |||||||||||||||||||
| 86 | 6 | $self->_host_to_region_host( $sign, $request ); | |||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | 6 | return $sign->sign_uri( $request->uri, $expires_at - time, $request->method ); | |||||||||||||||||||
| 89 | } | ||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | 99 | 1; | |||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | __END__ | ||||||||||||||||||||