| 1 | package AWS::Signature::V4::Credentials; | ||||||||||||||||||||||||||||
| 2 | 9 | ▶ | use v5.24; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 9 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 9 | ▶ | use AWS::Signature::V4::Error qw< fail shown >; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 9 | ▶ | use Digest::SHA qw< hmac_sha256 hmac_sha256_hex >; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 9 | ▶ | use experimental qw< signatures >; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 9 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | # The credentials-based variant (AWS4-HMAC-SHA256). The options are the ones | ||||||||||||||||||||||||||||
| 10 | # of the "credentials" option of AWS::Signature::V4. | ||||||||||||||||||||||||||||
| 11 | 9 | has [qw< access_key_id secret_access_key session_token >] => (is => 'ro'); | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 38 | ▶ | sub BUILD ($self, $args) { | ||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 14 | 38 | ▶ | if (my ($name) = sort(grep { !m{\A(?:access_key_id|secret_access_key|session_token)\z} } keys $args->%*)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 15 | 1 | fail 400, 'unknown option "' . shown($name) . '" in credentials'; | |||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||
| 17 | 37 | for my $name (qw< access_key_id secret_access_key >) { | |||||||||||||||||||||||||||
| 18 | 72 | my $value = $self->$name; # empty is like missing, AWS would refuse it | |||||||||||||||||||||||||||
| 19 | 72 | ▶ | defined $value && length $value or fail 400, "missing credentials/$name"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $value and length $value
MC/DC100%2/2
defined $value and length $value
defined $value
length $value
Truth table100%3/3
A and B
A= defined $valueB= length $value
| |||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | 32 | return; | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | # ---- what AWS::Signature::V4 wants from a variant -------------------------- | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 462 | ▶ | sub algorithm ($self) { 'AWS4-HMAC-SHA256' } | ||||||||||||||||||||||||||
|
Subroutine
algorithm: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | # identifies who signs, in the Credential part of the authorization | ||||||||||||||||||||||||||||
| 29 | 231 | ▶ | sub credential_id ($self) { $self->access_key_id } | ||||||||||||||||||||||||||
|
Subroutine
credential_id: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | # the key derived from the secret, for a scope like "20150830/us-east-1/iam/aws4_request" | ||||||||||||||||||||||||||||
| 32 | 332 | ▶ | sub signing_key ($self, $scope) { | ||||||||||||||||||||||||||
|
Subroutine
signing_key: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 33 | 332 | my ($date, $region, $service, $terminator) = split m{/}, $scope, 4; | |||||||||||||||||||||||||||
| 34 | 332 | my $key = 'AWS4' . $self->secret_access_key; | |||||||||||||||||||||||||||
| 35 | 332 | $key = hmac_sha256($_, $key) for $date, $region, $service, $terminator; | |||||||||||||||||||||||||||
| 36 | 332 | return $key; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | # hex signature of the string to sign | ||||||||||||||||||||||||||||
| 40 | 230 | ▶ | sub signature ($self, $scope, $string_to_sign) { | ||||||||||||||||||||||||||
|
Subroutine
signature: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 41 | 230 | return hmac_sha256_hex($string_to_sign, $self->signing_key($scope)); | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | # what goes with the request besides the signature, as (name => value) pairs | ||||||||||||||||||||||||||||
| 45 | 242 | ▶ | sub extra_fields ($self) { | ||||||||||||||||||||||||||
|
Subroutine
extra_fields: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 46 | 242 | my $token = $self->session_token; # empty, e.g. from an empty variable: none | |||||||||||||||||||||||||||
| 47 | 242 | ▶ | return defined $token && length $token ? ('X-Amz-Security-Token' => $token) : (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $token and length $token
MC/DC100%2/2
defined $token and length $token
defined $token
length $token
Truth table100%3/3
A and B
A= defined $tokenB= length $token
| |||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | # signed chunks need the derived key | ||||||||||||||||||||||||||||
| 51 | 103 | ▶ | sub can_sign_chunks ($self) { 1 } | ||||||||||||||||||||||||||
|
Subroutine
can_sign_chunks: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 9 | 1; | |||||||||||||||||||||||||||