« blib/lib/Google/Auth/ExternalAccountCredentials/Pluggable.pm
↑ Summary
blib/lib/Google/Auth/ImpersonatedServiceAccountCredentials.pm »
| 1 | package Google::Auth::IDTokens::Verifier; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use JSON::MaybeXS; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use MIME::Base64 qw(decode_base64); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use Scalar::Util qw(looks_like_number); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 3 | my %ALLOWED_JWT_ALGS = ( | |||||||||||||||||||||||||||||||||||||||||
| 12 | RS256 => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 13 | ES256 => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 14 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 3 | my %ALG_TO_KTY = ( | |||||||||||||||||||||||||||||||||||||||||
| 17 | RS256 => 'RSA', | ||||||||||||||||||||||||||||||||||||||||||
| 18 | ES256 => 'EC', | ||||||||||||||||||||||||||||||||||||||||||
| 19 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 17 | ▶ | sub _is_finite_number { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_finite_number: called CC=4 SCAR=14.2
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 17 | my ($val) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 23 | 17 | ▶ | return 0 if !defined $val || ref($val); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $val or ref $val
MC/DC50%1/2
not defined $val or ref $val
not defined $val
ref $val
Truth table66%2/3
not(A) or B
A= not defined $valB= ref $val
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 16 | ▶ | return $val =~ /\A-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?\z/ ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||
| 26 | 3 | ▶ | use Google::Auth; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 3 | ▶ | use Google::Auth::IDTokens::KeySources; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 3 | has key_source => ( | |||||||||||||||||||||||||||||||||||||||||
| 30 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 31 | required => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 32 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 3 | has aud => ( | |||||||||||||||||||||||||||||||||||||||||
| 35 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 36 | required => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 3 | has azp => ( | |||||||||||||||||||||||||||||||||||||||||
| 40 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 41 | required => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 42 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 3 | has iss => ( | |||||||||||||||||||||||||||||||||||||||||
| 45 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 46 | required => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 38 | ▶ | sub _decode_base64url { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_decode_base64url: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 38 | my ($s) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 51 | 38 | $s =~ tr{-_}{+/}; | |||||||||||||||||||||||||||||||||||||||||
| 52 | 38 | my $padding = length($s) % 4; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 38 | ▶ | if ($padding) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 30 | $s .= '=' x (4 - $padding); | |||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 38 | return MIME::Base64::decode_base64($s); | |||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 13 | ▶ | sub verify { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
verify: called CC=45 SCAR=42.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 13 | my ($self, $token, %options) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 13 | ▶ | $self = ref $self ? $self : $self->new(); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | 13 | ▶ | my $key_source = $options{key_source} // $self->key_source; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$options{"key_source"} // $self->key_source
MC/DC0%0/2
$options{"key_source"} // $self->key_source
$options{"key_source"}
$self->key_source
Truth table66%2/3
A // B
A= $options{"key_source"}B= $self->key_source
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 13 | ▶ | my $aud = $options{aud} // $self->aud; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$options{"aud"} // $self->aud
MC/DC0%0/2
$options{"aud"} // $self->aud
$options{"aud"}
$self->aud
Truth table66%2/3
A // B
A= $options{"aud"}B= $self->aud
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 13 | ▶ | my $azp = $options{azp} // $self->azp; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$options{"azp"} // $self->azp
MC/DC100%2/2
$options{"azp"} // $self->azp
$options{"azp"}
$self->azp
Truth table100%3/3
A // B
A= $options{"azp"}B= $self->azp
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | 13 | ▶ | my $iss = $options{iss} // $self->iss; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$options{"iss"} // $self->iss
MC/DC0%0/2
$options{"iss"} // $self->iss
$options{"iss"}
$self->iss
Truth table66%2/3
A // B
A= $options{"iss"}B= $self->iss
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 13 | ▶ | my $clock_skew = $options{clock_skew} // 300; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$options{"clock_skew"} // 300
MC/DC0%0/1
$options{"clock_skew"} // 300
$options{"clock_skew"}
Truth table50%1/2
A
A= $options{"clock_skew"}
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 13 | ▶ | die 'KeySourceError: No key source provided' unless defined $key_source; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 13 | my @parts = split /\./, $token; | |||||||||||||||||||||||||||||||||||||||||
| 73 | 13 | ▶ | if (@parts != 3) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | die 'VerificationError: Invalid JWT format'; | |||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 13 | my ($header_b64, $payload_b64, $signature_b64) = @parts; | |||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 13 | my $coder = JSON::MaybeXS->new->utf8->allow_nonref; | |||||||||||||||||||||||||||||||||||||||||
| 79 | 13 | my $header = eval { $coder->decode(_decode_base64url($header_b64)) }; | |||||||||||||||||||||||||||||||||||||||||
| 80 | 13 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | die 'VerificationError: Failed to parse JWT header: ' . $@; | |||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 13 | my $payload = eval { $coder->decode(_decode_base64url($payload_b64)) }; | |||||||||||||||||||||||||||||||||||||||||
| 84 | 13 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | die 'VerificationError: Failed to parse JWT payload: ' . $@; | |||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 13 | my $alg = $header->{alg}; | |||||||||||||||||||||||||||||||||||||||||
| 89 | 13 | ▶ | if (!defined $alg || !$ALLOWED_JWT_ALGS{$alg}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $alg and $ALLOWED_JWT_ALGS{$alg}
MC/DC50%1/2
defined $alg and $ALLOWED_JWT_ALGS{$alg}
defined $alg
$ALLOWED_JWT_ALGS{$alg}
Truth table66%2/3
A and B
A= defined $algB= $ALLOWED_JWT_ALGS{$alg}
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 1 | die 'VerificationError: Unsupported or missing alg claim in JWT header'; | |||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 12 | my $kid = $header->{kid}; | |||||||||||||||||||||||||||||||||||||||||
| 94 | 12 | ▶ | die 'VerificationError: Missing kid claim in JWT header' unless defined $kid; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 12 | my $signature = _decode_base64url($signature_b64); | |||||||||||||||||||||||||||||||||||||||||
| 97 | 12 | my $message = $header_b64 . '.' . $payload_b64; | |||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 12 | my $payload_verified; | |||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 17 | ▶ | my $verify_with_keys = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=12 SCAR=28.3
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 17 | my ($keys_ref) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 103 | 17 | foreach my $key (@$keys_ref) { | |||||||||||||||||||||||||||||||||||||||||
| 104 | 32 | ▶ | if ($key->id eq $kid) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 14 | ▶ | if ( defined $key->algorithm | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $key->algorithm and length $key->algorithm and $key->algorithm ne $alg
defined $key->algorithm and length $key->algorithm
MC/DC0%0/3
defined $key->algorithm and length $key->algorithm and $key->algorithm ne $alg
defined $key->algorithm
length $key->algorithm
$key->algorithm ne $alg
Truth table25%1/4
A and B and C
A= defined $key->algorithmB= length $key->algorithmC= $key->algorithm ne $alg
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | && length $key->algorithm | ||||||||||||||||||||||||||||||||||||||||||
| 107 | && $key->algorithm ne $alg) | ||||||||||||||||||||||||||||||||||||||||||
| 108 | { | ||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 14 | ▶ | if ( $key->can('key_type') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$key->can("key_type") and defined $key->key_type and length $key->key_type
$key->can("key_type") and defined $key->key_type
MC/DC33%1/3
$key->can("key_type") and defined $key->key_type and length $key->key_type
$key->can("key_type")
defined $key->key_type
length $key->key_type
Truth table50%2/4
A and B and C
A= $key->can("key_type")B= defined $key->key_typeC= length $key->key_type
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | && defined $key->key_type | ||||||||||||||||||||||||||||||||||||||||||
| 113 | && length $key->key_type) | ||||||||||||||||||||||||||||||||||||||||||
| 114 | { | ||||||||||||||||||||||||||||||||||||||||||
| 115 | 13 | my $expected_kty = $ALG_TO_KTY{$alg}; | |||||||||||||||||||||||||||||||||||||||||
| 116 | 13 | ▶ | if (defined $expected_kty && $key->key_type ne $expected_kty) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $expected_kty and $key->key_type ne $expected_kty
MC/DC0%0/2
defined $expected_kty and $key->key_type ne $expected_kty
defined $expected_kty
$key->key_type ne $expected_kty
Truth table33%1/3
A and B
A= defined $expected_ktyB= $key->key_type ne $expected_kty
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 120 | 14 | ▶ | if (Google::Auth::verify_signature($key->key, $message, $signature)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 10 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||
| 125 | 7 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 126 | 12 | }; | |||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 12 | my $keys_ref = $key_source->current_keys; | |||||||||||||||||||||||||||||||||||||||||
| 129 | 12 | ▶ | if ($verify_with_keys->($keys_ref)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 7 | $payload_verified = 1; | |||||||||||||||||||||||||||||||||||||||||
| 131 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 132 | 5 | my $refreshed_keys_ref = $key_source->refresh_keys; | |||||||||||||||||||||||||||||||||||||||||
| 133 | 5 | ▶ | if ($verify_with_keys->($refreshed_keys_ref)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | 3 | $payload_verified = 1; | |||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | 12 | ▶ | unless ($payload_verified) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | 2 | die 'SignatureError: Token signature verification failed'; | |||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | 10 | ▶ | my $now = $options{time_now} // time(); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$options{"time_now"} // time
MC/DC0%0/1
$options{"time_now"} // time
$options{"time_now"}
Truth table50%1/2
A
A= $options{"time_now"}
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | 10 | ▶ | if (!_is_finite_number($payload->{exp})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | 1 | die 'VerificationError: Missing or invalid exp claim'; | |||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||
| 146 | 9 | ▶ | if ($payload->{exp} < $now - $clock_skew) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | 2 | die 'ExpiredTokenError: Token signature is expired'; | |||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||
| 149 | 7 | ▶ | if (exists $payload->{nbf}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | if (!_is_finite_number($payload->{nbf}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not _is_finite_number($payload->{"nbf"}) or $payload->{"nbf"} > $now + $clock_skew
MC/DC0%0/2
not _is_finite_number($payload->{"nbf"}) or $payload->{"nbf"} > $now + $clock_skew
not _is_finite_number($payload->{"nbf"})
$payload->{"nbf"} > $now + $clock_skew
Truth table0%0/3
not(A) or B
A= not _is_finite_number($payload->{"nbf"})B= $payload->{"nbf"} > $now + $clock_skew
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | || $payload->{nbf} > $now + $clock_skew) | ||||||||||||||||||||||||||||||||||||||||||
| 152 | { | ||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | die 'VerificationError: Token not yet valid'; | |||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||
| 156 | 7 | ▶ | if (exists $payload->{iat}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | 7 | ▶ | if (!_is_finite_number($payload->{iat}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not _is_finite_number($payload->{"iat"}) or $payload->{"iat"} > $now + $clock_skew
MC/DC0%0/2
not _is_finite_number($payload->{"iat"}) or $payload->{"iat"} > $now + $clock_skew
not _is_finite_number($payload->{"iat"})
$payload->{"iat"} > $now + $clock_skew
Truth table33%1/3
not(A) or B
A= not _is_finite_number($payload->{"iat"})B= $payload->{"iat"} > $now + $clock_skew
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | || $payload->{iat} > $now + $clock_skew) | ||||||||||||||||||||||||||||||||||||||||||
| 159 | { | ||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | die 'VerificationError: Token issued in the future'; | |||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | 7 | ▶ | $payload->{azp} ||= $payload->{cid} if exists $payload->{cid}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$payload->{"azp"} ||= $payload->{"cid"}
MC/DC0%0/2
$payload->{"azp"} ||= $payload->{"cid"}
$payload->{"azp"}
$payload->{"cid"}
Truth table0%0/3
A ||= B
A= $payload->{"azp"}B= $payload->{"cid"}
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | 7 | ▶ | if (defined $aud) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 7 | ▶ | my @expected_auds = ref $aud eq 'ARRAY' ? @$aud : ($aud); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | 7 | my $token_aud = $payload->{aud}; | |||||||||||||||||||||||||||||||||||||||||
| 169 | 7 | ▶ | my @token_auds = ref $token_aud eq 'ARRAY' ? @$token_aud : ($token_aud); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||
| 171 | 7 | my %expected_map = map { $_ => 1 } @expected_auds; | |||||||||||||||||||||||||||||||||||||||||
| 172 | 7 | my $aud_match = 0; | |||||||||||||||||||||||||||||||||||||||||
| 173 | 7 | foreach my $t_aud (@token_auds) { | |||||||||||||||||||||||||||||||||||||||||
| 174 | 7 | ▶ | if (exists $expected_map{$t_aud}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | 6 | $aud_match = 1; | |||||||||||||||||||||||||||||||||||||||||
| 176 | 6 | last; | |||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||
| 179 | 7 | ▶ | unless ($aud_match) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | 1 | die 'AudienceMismatchError: Token aud mismatch: ' . | |||||||||||||||||||||||||||||||||||||||||
| 181 | join(', ', @token_auds); | ||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | 6 | ▶ | if (defined $azp) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | 5 | ▶ | my @expected_azps = ref $azp eq 'ARRAY' ? @$azp : ($azp); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | 5 | my $token_azp = $payload->{azp}; | |||||||||||||||||||||||||||||||||||||||||
| 188 | 5 | ▶ | my @token_azps = ref $token_azp eq 'ARRAY' ? @$token_azp : ($token_azp); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||
| 190 | 5 | my %expected_map = map { $_ => 1 } @expected_azps; | |||||||||||||||||||||||||||||||||||||||||
| 191 | 5 | my $azp_match = 0; | |||||||||||||||||||||||||||||||||||||||||
| 192 | 5 | foreach my $t_azp (@token_azps) { | |||||||||||||||||||||||||||||||||||||||||
| 193 | 5 | ▶ | if (exists $expected_map{$t_azp}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | 4 | $azp_match = 1; | |||||||||||||||||||||||||||||||||||||||||
| 195 | 4 | last; | |||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||
| 198 | 5 | ▶ | unless ($azp_match) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | 1 | ▶ | die 'AuthorizedPartyMismatchError: Token azp mismatch: ' . | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$token_azp // ""
MC/DC0%0/1
$token_azp // ""
$token_azp
Truth table50%1/2
A
A= $token_azp
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | ($token_azp // ''); | ||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||
| 204 | 5 | ▶ | if (defined $iss) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | 5 | ▶ | my @expected_isss = ref $iss eq 'ARRAY' ? @$iss : ($iss); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 206 | 5 | my $token_iss = $payload->{iss}; | |||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||
| 208 | 5 | my %expected_map = map { $_ => 1 } @expected_isss; | |||||||||||||||||||||||||||||||||||||||||
| 209 | 5 | ▶ | unless (exists $expected_map{$token_iss}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 210 | 1 | ▶ | die 'IssuerMismatchError: Token iss mismatch: ' . ($token_iss // ''); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$token_iss // ""
MC/DC0%0/1
$token_iss // ""
$token_iss
Truth table50%1/2
A
A= $token_iss
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||
| 214 | 4 | return $payload; | |||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | 3 | my $_oidc_verifier; | |||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | 3 | ▶ | sub verify_oidc { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
verify_oidc: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | 3 | my ($class, $token, %options) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||
| 222 | 3 | ▶ | $_oidc_verifier //= Google::Auth::IDTokens::Verifier->new( | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$_oidc_verifier //= "Google::Auth::IDTokens::Verifier"->new("key_source", "Google::Auth::IDTokens::JwkHttpKeySource"->new({"uri", "https://www.googleapis.com/oauth2/v3/certs"}), "iss", ["accounts.google.com", "https://accounts.google.com"])
MC/DC0%0/2
$_oidc_verifier //= "Google::Auth::IDTokens::Verifier"->new("key_source", "Google::Auth::IDTokens::JwkHttpKeySource"->new({"uri", "https://www.googleapis.com/oauth2/v3/certs"}), "iss", ["accounts.google.com", "https://accounts.google.com"])
$_oidc_verifier
"Google::Auth::IDTokens::Verifier"->new("key_source", "Google::Auth::IDTokens::JwkHttpKeySource"->new({"uri", "https://www.googleapis.com/oauth2/v3/certs"}), "iss", ["accounts.google.com", "https://accounts.google.com"])
Truth table66%2/3
A //= B
A= $_oidc_verifierB= "Google::Auth::IDTokens::Verifier"->new("key_source", "Google::Auth::IDTokens::JwkHttpKeySource"->new({"uri", "https://www.googleapis.com/oauth2/v3/certs"}), "iss", ["accounts.google.com", "https://accounts.google.com"])
| |||||||||||||||||||||||||||||||||||||||||||
| 223 | key_source => Google::Auth::IDTokens::JwkHttpKeySource->new({ | ||||||||||||||||||||||||||||||||||||||||||
| 224 | uri => 'https://www.googleapis.com/oauth2/v3/certs' | ||||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||
| 226 | ), | ||||||||||||||||||||||||||||||||||||||||||
| 227 | iss => ['accounts.google.com', 'https://accounts.google.com']); | ||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | 3 | return $_oidc_verifier->verify($token, %options); | |||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||
| 232 | my $_iap_verifier; | ||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | 3 | ▶ | sub verify_iap { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
verify_iap: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 235 | 3 | my ($class, $token, %options) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | 3 | ▶ | $_iap_verifier //= Google::Auth::IDTokens::Verifier->new( | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$_iap_verifier //= "Google::Auth::IDTokens::Verifier"->new("key_source", "Google::Auth::IDTokens::JwkHttpKeySource"->new({"uri", "https://www.googleapis.com/iap/verify/public_key-jwk"}), "iss", "https://cloud.google.com/iap")
MC/DC0%0/2
$_iap_verifier //= "Google::Auth::IDTokens::Verifier"->new("key_source", "Google::Auth::IDTokens::JwkHttpKeySource"->new({"uri", "https://www.googleapis.com/iap/verify/public_key-jwk"}), "iss", "https://cloud.google.com/iap")
$_iap_verifier
"Google::Auth::IDTokens::Verifier"->new("key_source", "Google::Auth::IDTokens::JwkHttpKeySource"->new({"uri", "https://www.googleapis.com/iap/verify/public_key-jwk"}), "iss", "https://cloud.google.com/iap")
Truth table66%2/3
A //= B
A= $_iap_verifierB= "Google::Auth::IDTokens::Verifier"->new("key_source", "Google::Auth::IDTokens::JwkHttpKeySource"->new({"uri", "https://www.googleapis.com/iap/verify/public_key-jwk"}), "iss", "https://cloud.google.com/iap")
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | key_source => Google::Auth::IDTokens::JwkHttpKeySource->new({ | ||||||||||||||||||||||||||||||||||||||||||
| 239 | uri => 'https://www.googleapis.com/iap/verify/public_key-jwk' | ||||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||
| 241 | ), | ||||||||||||||||||||||||||||||||||||||||||
| 242 | iss => 'https://cloud.google.com/iap' | ||||||||||||||||||||||||||||||||||||||||||
| 243 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | 3 | return $_iap_verifier->verify($token, %options); | |||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||
| 248 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | __END__ | ||||||||||||||||||||||||||||||||||||||||||