| 1 | package HTTP::Message::Signature; | ||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||
| 3 | # ABSTRACT: Verify HTTP Message Signatures (RFC 9421) | ||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use v5.24; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use Carp qw( carp croak ); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use Crypt::PK::Ed25519; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use Crypt::PK::RSA; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 11 | 4 | ▶ | use Hash::Ordered; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 12 | 4 | ▶ | use HTTP::Message 6.41; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 13 | 4 | ▶ | use HTTP::Request; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 14 | 4 | ▶ | use HTTP::StructuredField v0.0.5; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 15 | 4 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 16 | 4 | ▶ | use JSON qw( decode_json ); # used by CryptX | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 17 | 4 | ▶ | use List::Util 1.29 qw( first max pairmap ); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 18 | 4 | ▶ | use MIME::Base64 qw( decode_base64 ); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 19 | 4 | ▶ | use PerlX::Maybe qw( maybe ); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 20 | 4 | ▶ | use Ref::Util qw( is_blessed_ref is_plain_hashref ); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 21 | 4 | ▶ | use String::Util qw( trim unquote ); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 22 | 4 | ▶ | use Syntax::Keyword::Match; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 23 | 4 | ▶ | use Types::Common qw( Bool HashRef InstanceOf NonEmptyStr PositiveInt ); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 24 | 4 | ▶ | use Types::URI qw( Uri ); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 25 | 4 | ▶ | use URI; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||
| 27 | # RECOMMEND PREREQ: Ref::Util::XS | ||||||||||||||||||||||||||||||||||||||
| 28 | # RECOMMEND PREREQ: Type::Tiny::XS | ||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||
| 30 | 4 | ▶ | use experimental qw( lexical_subs signatures ); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||
| 32 | 4 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||
| 34 | 4 | our $VERSION = 'v0.1.2'; | |||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||
| 38 | 4 | has message => ( | |||||||||||||||||||||||||||||||||||||
| 39 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||
| 40 | isa => InstanceOf [qw/ HTTP::Message Plack::Request /], | ||||||||||||||||||||||||||||||||||||||
| 41 | required => 1, | ||||||||||||||||||||||||||||||||||||||
| 42 | handles => [qw/ as_string headers /], | ||||||||||||||||||||||||||||||||||||||
| 43 | ); | ||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||
| 46 | has is_request => ( | ||||||||||||||||||||||||||||||||||||||
| 47 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||
| 48 | isa => Bool, | ||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | builder => sub($self) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Subroutine
_build_is_request: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||
| 50 | 0 | my $message = $self->message; | |||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | return $message->isa("HTTP::Request") || $message->isa("Plack::Request"); | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
$message->isa('HTTP::Request') || $message->isa('Plack::Request')
$message->isa('HTTP::Request') || $message->isa('Plack::Request')
MC/DC0%0/2
$message->isa('HTTP::Request') || $message->isa('Plack::Request')
$message->isa('HTTP::Request')
$message->isa('Plack::Request')
MC/DC0%0/2
$message->isa('HTTP::Request') || $message->isa('Plack::Request')
$message->isa('HTTP::Request')
$message->isa('Plack::Request')
Truth table0%0/3
A || B
A= $message->isa('HTTP::Request')B= $message->isa('Plack::Request')
Truth table0%0/3
A || B
A= $message->isa('HTTP::Request')B= $message->isa('Plack::Request')
| |||||||||||||||||||||||||||||||||||||||
| 52 | }, | ||||||||||||||||||||||||||||||||||||||
| 53 | 4 | init_arg => undef, | |||||||||||||||||||||||||||||||||||||
| 54 | ); | ||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||
| 57 | has is_response => ( | ||||||||||||||||||||||||||||||||||||||
| 58 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||
| 59 | isa => Bool, | ||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | builder => sub($self) { $self->message->isa("HTTP::Response") }, | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_is_response: not called CC=1 SCAR=1.2
Subroutine
__ANON__: called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||
| 61 | 4 | init_arg => undef, | |||||||||||||||||||||||||||||||||||||
| 62 | ); | ||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||
| 65 | 4 | has request => ( | |||||||||||||||||||||||||||||||||||||
| 66 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||
| 67 | isa => InstanceOf [qw/ HTTP::Request Plack::Request /], | ||||||||||||||||||||||||||||||||||||||
| 68 | predicate => 1, | ||||||||||||||||||||||||||||||||||||||
| 69 | ); | ||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||
| 72 | has user_agent => ( | ||||||||||||||||||||||||||||||||||||||
| 73 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||
| 74 | isa => InstanceOf ['LWP::UserAgent'], | ||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | builder => sub($self) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_user_agent: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 76 | 0 | return LWP::UserAgent->new( max_size => 8192, timeout => 10 ); | |||||||||||||||||||||||||||||||||||||
| 77 | }, | ||||||||||||||||||||||||||||||||||||||
| 78 | 4 | ); | |||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||
| 81 | has signature_agent => ( | ||||||||||||||||||||||||||||||||||||||
| 82 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||
| 83 | isa => NonEmptyStr, | ||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | coerce => sub($uri) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | if (is_blessed_ref($uri) && $uri->isa("URI")) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
Ref::Util::XS::is_blessed_ref($uri) and $uri->isa("URI")
MC/DC0%0/2
Ref::Util::XS::is_blessed_ref($uri) and $uri->isa("URI")
Ref::Util::XS::is_blessed_ref($uri)
$uri->isa("URI")
Truth table0%0/3
A and B
A= Ref::Util::XS::is_blessed_ref($uri)B= $uri->isa("URI")
| |||||||||||||||||||||||||||||||||||||||
| 86 | 0 | return $uri->scheme . "://" . $uri->authority; | |||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||
| 88 | 0 | return "$uri"; | |||||||||||||||||||||||||||||||||||||
| 89 | }, | ||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | builder => sub($self) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_signature_agent: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | my $agent = join(",", $self->headers->header("signature-agent") // "" ); | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->headers->header("signature-agent") // ""
MC/DC0%0/1
$self->headers->header("signature-agent") // ""
$self->headers->header("signature-agent")
Truth table0%0/2
A
A= $self->headers->header("signature-agent")
| |||||||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | if ( !$agent && $self->is_response ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $agent and $self->is_response
MC/DC0%0/2
not $agent and $self->is_response
not $agent
$self->is_response
Truth table0%0/3
not(A) and B
A= not $agentB= $self->is_response
| |||||||||||||||||||||||||||||||||||||||
| 93 | 0 | return $self->request->uri; | |||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | if ( $agent =~ /\A [a-z\*][a-z0-1_\-\.\*]* = /ax ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | my ($key) = $self->headers->header("signature-agent-key") || $self->signature_labels; | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->headers->header('signature-agent-key') || $self->signature_labels
MC/DC0%0/2
$self->headers->header('signature-agent-key') || $self->signature_labels
$self->headers->header('signature-agent-key')
$self->signature_labels
Truth table0%0/3
A || B
A= $self->headers->header('signature-agent-key')B= $self->signature_labels
| |||||||||||||||||||||||||||||||||||||||
| 97 | 0 | my $agents = HTTP::StructuredField->parse_dictionary( $agent ); | |||||||||||||||||||||||||||||||||||||
| 98 | 0 | $agent = $agents->get( unquote($key) )->value; | |||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||
| 100 | 0 | return $agent; | |||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||
| 102 | 4 | ); | |||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||
| 105 | has signature_agent_uri => ( | ||||||||||||||||||||||||||||||||||||||
| 106 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||
| 107 | isa => Uri, | ||||||||||||||||||||||||||||||||||||||
| 108 | coerce => 1, | ||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | builder => sub($self) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||
| 110 | 0 | my $uri = URI->new( unquote( $self->signature_agent ) ); | |||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | carp "signature-agent header contains a full URL" if $uri->path && $uri->path ne "/"; | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$uri->path and $uri->path ne "/"
MC/DC0%0/2
$uri->path and $uri->path ne "/"
$uri->path
$uri->path ne "/"
Truth table0%0/3
A and B
A= $uri->pathB= $uri->path ne "/"
| |||||||||||||||||||||||||||||||||||||||
| 112 | 0 | $uri->path("/.well-known/http-message-signatures-directory"); | |||||||||||||||||||||||||||||||||||||
| 113 | 0 | return $uri; | |||||||||||||||||||||||||||||||||||||
| 114 | }, | ||||||||||||||||||||||||||||||||||||||
| 115 | 4 | ); | |||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||
| 118 | has signature_input => ( | ||||||||||||||||||||||||||||||||||||||
| 119 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||
| 120 | isa => InstanceOf ['Hash::Ordered'], | ||||||||||||||||||||||||||||||||||||||
| 121 | 11 | ▶ | builder => sub($self) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 122 | 11 | my @input = $self->headers->header("signature-input"); | |||||||||||||||||||||||||||||||||||||
| 123 | 11 | return HTTP::StructuredField->parse_dictionary( join( ',', @input ) ); | |||||||||||||||||||||||||||||||||||||
| 124 | }, | ||||||||||||||||||||||||||||||||||||||
| 125 | 4 | handles => { | |||||||||||||||||||||||||||||||||||||
| 126 | signature_labels => 'keys', | ||||||||||||||||||||||||||||||||||||||
| 127 | }, | ||||||||||||||||||||||||||||||||||||||
| 128 | ); | ||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||
| 131 | has signature_header => ( | ||||||||||||||||||||||||||||||||||||||
| 132 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||
| 133 | isa => InstanceOf ['Hash::Ordered'], | ||||||||||||||||||||||||||||||||||||||
| 134 | 8 | ▶ | builder => sub($self) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_signature_header: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 135 | 8 | my @input = $self->headers->header("signature"); | |||||||||||||||||||||||||||||||||||||
| 136 | 8 | return HTTP::StructuredField->parse_dictionary( join( ',', @input ) ); | |||||||||||||||||||||||||||||||||||||
| 137 | }, | ||||||||||||||||||||||||||||||||||||||
| 138 | 4 | ); | |||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||
| 141 | has public_keys_json => ( | ||||||||||||||||||||||||||||||||||||||
| 142 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||
| 143 | isa => NonEmptyStr, | ||||||||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | builder => sub($self) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_public_keys_json: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||
| 146 | 0 | state $types = { map { $_ => 1 } qw[ application/http-message-signatures-directory+json application/json ] }; | |||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||
| 148 | 0 | my $uri = $self->signature_agent_uri; | |||||||||||||||||||||||||||||||||||||
| 149 | 0 | ▶ | croak "agent_uri should be an https URL" unless $uri->scheme eq "https"; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||
| 151 | 0 | my $req = HTTP::Request->new( | |||||||||||||||||||||||||||||||||||||
| 152 | GET => $uri, | ||||||||||||||||||||||||||||||||||||||
| 153 | [ | ||||||||||||||||||||||||||||||||||||||
| 154 | Accept => join( ",", keys $types->%* ), | ||||||||||||||||||||||||||||||||||||||
| 155 | 'User-Agent' => sprintf( 'Perl-%s-%s', __PACKAGE__, $VERSION ), | ||||||||||||||||||||||||||||||||||||||
| 156 | ] | ||||||||||||||||||||||||||||||||||||||
| 157 | ); | ||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||
| 159 | 0 | my $res = $self->user_agent->request($req); | |||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | if ( $res->is_success && $types->{ $res->content_type } ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$res->is_success and $$types{$res->content_type}
MC/DC0%0/2
$res->is_success and $$types{$res->content_type}
$res->is_success
$$types{$res->content_type}
Truth table0%0/3
A and B
A= $res->is_successB= $$types{$res->content_type}
| |||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||
| 163 | 0 | ▶ | if ( $self->verify_public_keys ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | if ( $res->header("Signature-Input") && $res->header("Signature") ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$res->header("Signature-Input") and $res->header("Signature")
MC/DC0%0/2
$res->header("Signature-Input") and $res->header("Signature")
$res->header("Signature-Input")
$res->header("Signature")
Truth table0%0/3
A and B
A= $res->header("Signature-Input")B= $res->header("Signature")
| |||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||
| 167 | 0 | my $check = __PACKAGE__->new( | |||||||||||||||||||||||||||||||||||||
| 168 | request => $req, | ||||||||||||||||||||||||||||||||||||||
| 169 | response => $res, | ||||||||||||||||||||||||||||||||||||||
| 170 | require_tag => "http-message-signatures-directory", | ||||||||||||||||||||||||||||||||||||||
| 171 | public_keys_json => $res->decoded_content, | ||||||||||||||||||||||||||||||||||||||
| 172 | ); | ||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||
| 174 | 0 | ▶ | $check->verify or croak "signatures-directory was not signed"; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||
| 177 | else { | ||||||||||||||||||||||||||||||||||||||
| 178 | 0 | carp "signatures-directory response was unsigned"; | |||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||
| 183 | 0 | $res->max_body_size( $self->max_public_keys_json_size ); | |||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||
| 185 | 0 | return $res->decoded_content; | |||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||
| 188 | 0 | croak "error retrieving ${uri}"; | |||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||
| 190 | 4 | ); | |||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||
| 193 | 4 | has max_public_keys_json_size => ( | |||||||||||||||||||||||||||||||||||||
| 194 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||
| 195 | isa => PositiveInt, | ||||||||||||||||||||||||||||||||||||||
| 196 | default => 16384, | ||||||||||||||||||||||||||||||||||||||
| 197 | ); | ||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||
| 200 | 4 | has verify_public_keys => ( | |||||||||||||||||||||||||||||||||||||
| 201 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||
| 202 | isa => Bool, | ||||||||||||||||||||||||||||||||||||||
| 203 | default => 0, | ||||||||||||||||||||||||||||||||||||||
| 204 | ); | ||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||
| 207 | has public_keys => ( | ||||||||||||||||||||||||||||||||||||||
| 208 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||
| 209 | isa => HashRef, # TODO make strict validation optional | ||||||||||||||||||||||||||||||||||||||
| 210 | 2 | ▶ | builder => sub($self) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_public_keys: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 211 | 2 | my $pks = decode_json( $self->public_keys_json ); | |||||||||||||||||||||||||||||||||||||
| 212 | 2 | my $max = $self->max_keys; | |||||||||||||||||||||||||||||||||||||
| 213 | 2 | ▶ | if ( defined $pks->{keys}[$max] ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 214 | 1 | splice( $pks->{keys}->@*, $max ); | |||||||||||||||||||||||||||||||||||||
| 215 | 1 | carp "public_keys truncated to the first ${max} keys"; | |||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||
| 217 | 2 | return $pks; | |||||||||||||||||||||||||||||||||||||
| 218 | }, | ||||||||||||||||||||||||||||||||||||||
| 219 | 4 | ); | |||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||
| 223 | 4 | has max_keys => ( | |||||||||||||||||||||||||||||||||||||
| 224 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||
| 225 | isa => PositiveInt, | ||||||||||||||||||||||||||||||||||||||
| 226 | default => 100, | ||||||||||||||||||||||||||||||||||||||
| 227 | ); | ||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||
| 230 | 4 | has require_tag => ( | |||||||||||||||||||||||||||||||||||||
| 231 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||
| 232 | isa => NonEmptyStr, | ||||||||||||||||||||||||||||||||||||||
| 233 | predicate => 1, | ||||||||||||||||||||||||||||||||||||||
| 234 | ); | ||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||
| 237 | 12 | ▶ | sub is_expired( $self, $label = undef ) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
is_expired: called CC=4 SCAR=15.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 238 | 12 | ▶ | my $input = $self->_get_input_from_label( $label // $self->_get_default_label ); | ||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$label // $self->_get_default_label
MC/DC0%0/2
$label // $self->_get_default_label
$label
$self->_get_default_label
Truth table33%1/3
A // B
A= $labelB= $self->_get_default_label
| |||||||||||||||||||||||||||||||||||||||
| 239 | 12 | ▶ | my $expires = $input->params->get("expires") or return undef; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 240 | 12 | return time > $expires->value; | |||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||
| 244 | 8 | ▶ | sub verify( $self, $options = undef ) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
verify: called CC=22 SCAR=34.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||
| 246 | 8 | ▶ | $options //= {}; | ||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$options //= {}
MC/DC0%0/1
$options //= {}
$options
Truth table50%1/2
A
A= $options
| |||||||||||||||||||||||||||||||||||||||
| 247 | 8 | ▶ | $options = { label => $options } unless is_plain_hashref($options); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||
| 249 | 8 | ▶ | my $label = $options->{label} //= $self->_get_default_label; | ||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$options->{"label"} //= $self->_get_default_label
MC/DC0%0/2
$options->{"label"} //= $self->_get_default_label
$options->{"label"}
$self->_get_default_label
Truth table33%1/3
A //= B
A= $options->{"label"}B= $self->_get_default_label
| |||||||||||||||||||||||||||||||||||||||
| 250 | 8 | my $input = $self->_get_input_from_label($label); | |||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||
| 252 | 8 | ▶ | if ( $options->{check_expires} //= 1 ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$options->{"check_expires"} //= 1
MC/DC0%0/1
$options->{"check_expires"} //= 1
$options->{"check_expires"}
Truth table50%1/2
A
A= $options->{"check_expires"}
| |||||||||||||||||||||||||||||||||||||||
| 253 | 4 | ▶ | croak "signature is expired" if $self->is_expired; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||
| 256 | 8 | ▶ | if ( $options->{check_created} //= 1 ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$options->{"check_created"} //= 1
MC/DC0%0/1
$options->{"check_created"} //= 1
$options->{"check_created"}
Truth table50%1/2
A
A= $options->{"check_created"}
| |||||||||||||||||||||||||||||||||||||||
| 257 | 8 | my $created = $input->params->get("created"); | |||||||||||||||||||||||||||||||||||||
| 258 | 8 | ▶ | croak "signature is postdated" if $created && $created->value > time; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$created and $created->value > time
MC/DC0%0/2
$created and $created->value > time
$created
$created->value > time
Truth table33%1/3
A and B
A= $createdB= $created->value > time
| |||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||
| 261 | 8 | ▶ | if ( $self->has_require_tag ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 262 | 8 | my $check = $input->params->get("tag"); | |||||||||||||||||||||||||||||||||||||
| 263 | 8 | my $tag = $self->require_tag; | |||||||||||||||||||||||||||||||||||||
| 264 | 8 | ▶ | croak "tag is not '${tag}'" unless $check && $check->value eq $tag; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$check and $check->value eq $tag
MC/DC0%0/2
$check and $check->value eq $tag
$check
$check->value eq $tag
Truth table33%1/3
A and B
A= $checkB= $check->value eq $tag
| |||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||
| 267 | 8 | ▶ | my $keyid = $input->params->get("keyid") or croak "no keyid was found in the signature-input"; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 268 | 8 | my $kid = unquote( $keyid->value ); | |||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||
| 270 | 8 | state $algs = { | |||||||||||||||||||||||||||||||||||||
| 271 | "ed25519" => { class => "Crypt::PK::Ed25519", key => { kty => "OKP", crv => "Ed25519" } }, | ||||||||||||||||||||||||||||||||||||||
| 272 | "rsa-pss-sha512" => { class => "Crypt::PK::RSA", key => { kty => "RSA", alg => "PS512" }, hash => [qw/ SHA512 pss 64 /] }, | ||||||||||||||||||||||||||||||||||||||
| 273 | }; | ||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||
| 275 | 8 | ▶ | my $alg = eval { $input->params->get("alg")->value } or croak "missing alg parameter"; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 276 | 8 | ▶ | my $meta = $algs->{ $alg } or croak "unsupported algorithm"; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||
| 278 | 8 | ▶ | my $key = first { $_->{kid} eq $kid } $self->public_keys->{keys}->@* | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 279 | 8 | ▶ | or croak "keyid '${kid}' was not found in the public keys"; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||
| 281 | # TODO: add support for looking up keys from a cache based on agent URL and key id, and alg | ||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||
| 283 | 8 | for my $field ( keys $meta->{key}->%* ) { | |||||||||||||||||||||||||||||||||||||
| 284 | 16 | ▶ | $key->{$field} eq $meta->{key}{$field} or croak "keyid ${kid} is incompatible with ${alg}"; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||
| 287 | 8 | my $class = $meta->{class}; | |||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||
| 289 | 8 | ▶ | my @params = $meta->{hash} ? $meta->{hash}->@* : (); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||
| 291 | 8 | my $pk = $class->new($key); | |||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||
| 293 | 8 | my $sig = $self->signature_header->get($label)->value; | |||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||
| 295 | 8 | my $base = $self->_generate_signature_base($options); | |||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||
| 297 | 8 | return $pk->verify_message( $sig, $base, @params ); | |||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||
| 300 | 20 | ▶ | sub _get_default_label($self) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_default_label: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||
| 301 | 20 | my ($label) = $self->signature_labels; | |||||||||||||||||||||||||||||||||||||
| 302 | 20 | ▶ | croak "no labels found" unless defined $label; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 303 | 20 | return $label; | |||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||
| 306 | 31 | ▶ | sub _get_input_from_label( $self, $label ) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_input_from_label: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||||||
| 307 | 31 | ▶ | my $input = $self->signature_input->get($label) or croak "signature-input label ${label} was not found"; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 308 | 31 | return $input; | |||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||
| 311 | 11 | ▶ | sub _generate_signature_base( $self, $options ) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_generate_signature_base: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||
| 313 | 11 | my $label = $options->{label}; | |||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||
| 315 | 11 | my @buffer; | |||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||
| 317 | 11 | my $seen = Hash::Ordered->new; | |||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||
| 319 | 28 | ▶ | my sub _process_header_field( $field, $value ) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_process_header_field: called CC=3 SCAR=11.4
| |||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||
| 321 | # TODO serialize line as per "component-identifier ABNF rule" | ||||||||||||||||||||||||||||||||||||||
| 322 | # TODO canonicalize the field value | ||||||||||||||||||||||||||||||||||||||
| 323 | 28 | ▶ | my $line = sprintf( '%s: %s', lc($field), $value // "" ); | ||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$value // ""
MC/DC0%0/1
$value // ""
$value
Truth table50%1/2
A
A= $value
| |||||||||||||||||||||||||||||||||||||||
| 324 | 28 | ▶ | croak "component has already been added to the sginature base" if $seen->exists( lc $field ); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 325 | 28 | $seen->set( lc $field => 1 ); | |||||||||||||||||||||||||||||||||||||
| 326 | 28 | push @buffer, $line; | |||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||
| 329 | 11 | my $input = $self->_get_input_from_label($label); | |||||||||||||||||||||||||||||||||||||
| 330 | 11 | ▶ | croak "label ${label} is not a list" unless $input->is_inner_list; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||
| 332 | 11 | for my $field ( $input->value->@* ) { | |||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||
| 334 | 17 | my $name = unquote($field->value, braces => 1 ); | |||||||||||||||||||||||||||||||||||||
| 335 | 17 | ▶ | if ( substr($name, 0, 1) eq '@' ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 336 | 11 | _process_header_field( $self->_get_derived_field( $field, $options ) ); | |||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||
| 338 | else { | ||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||
| 340 | 6 | my $header = $self->headers->header($name); | |||||||||||||||||||||||||||||||||||||
| 341 | 6 | ▶ | if ($field->has_params) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||
| 343 | 2 | my ($key) = $field->params->get("key")->value; | |||||||||||||||||||||||||||||||||||||
| 344 | 2 | my $dict = HTTP::StructuredField->parse_dictionary($header); | |||||||||||||||||||||||||||||||||||||
| 345 | 2 | my $param = $dict->get($key); | |||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||
| 347 | # TODO: improve quoting | ||||||||||||||||||||||||||||||||||||||
| 348 | 2 | _process_header_field( "\"${name}\";key=\"${key}\"" => sprintf('"%s"', $param->value ) ); | |||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||
| 351 | else { | ||||||||||||||||||||||||||||||||||||||
| 352 | 4 | _process_header_field( "\"${name}\"" => $header ); | |||||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||
| 358 | 11 | my $header = $self->headers->header("signature-input"); | |||||||||||||||||||||||||||||||||||||
| 359 | 11 | ▶ | croak "unexpected signature-input" unless substr( $header, 0, length($label) + 1 ) eq "${label}="; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 360 | 11 | my $params = substr( $header, length($label) + 1 ); | |||||||||||||||||||||||||||||||||||||
| 361 | 11 | _process_header_field( '"@signature-params"' => $params ); | |||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||
| 363 | 11 | return join( "\n", @buffer ); | |||||||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||
| 366 | 11 | ▶ | sub _get_derived_field( $self, $field, $options ) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_derived_field: called CC=5 SCAR=22.1
| |||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||
| 368 | 11 | my $name = $field->value; | |||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||
| 370 | # Note: HTTP::Message has uri_canonical but Plack::Request does not. | ||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||
| 372 | state $handlers = { | ||||||||||||||||||||||||||||||||||||||
| 373 | 0 | ▶ | '@status' => sub( $message, $, $ ) { $message->code }, | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 374 | 0 | ▶ | '@method' => sub( $message, $, $ ) { $message->method }, | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 375 | 0 | ▶ | '@target-uri' => sub( $message, $, $ ) { $message->uri }, | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 376 | 11 | ▶ | '@authority' => sub( $message, $, $ ) { $message->uri->authority }, | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 377 | 0 | ▶ | '@scheme' => sub( $message, $, $ ) { $message->uri->scheme }, | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 378 | 0 | ▶ | '@path' => sub( $message, $, $ ) { $message->uri->path }, | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 379 | 0 | ▶ | '@query' => sub( $message, $, $ ) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||
| 380 | 0 | my $query = $message->uri->query; | |||||||||||||||||||||||||||||||||||||
| 381 | 0 | ▶ | if ( defined $query ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 382 | 0 | return '?' . $query; | |||||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||||
| 384 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||
| 385 | }, | ||||||||||||||||||||||||||||||||||||||
| 386 | 0 | ▶ | '@query-param' => sub( $message, $, $params ) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||
| 387 | 0 | ▶ | if ( my ($key) = $params->keys ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 388 | # Note: RFC 9421 Sec 2.2.8 says named parameters with multiple values must not be included | ||||||||||||||||||||||||||||||||||||||
| 389 | 0 | my @values = $message->uri->query_param($key); | |||||||||||||||||||||||||||||||||||||
| 390 | 0 | ▶ | croak "multipe query-param values for '${key}'" if @values > 1; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 391 | 0 | return $values[0]; | |||||||||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||||||
| 394 | 11 | }; | |||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||
| 396 | 11 | ▶ | croak "unsupported field ${name}" unless exists $handlers->{$name}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||
| 398 | 11 | my $quoted = "\"${name}\""; | |||||||||||||||||||||||||||||||||||||
| 399 | 11 | my $message = $self->message; | |||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||
| 401 | 11 | my ($param, @extra) = $field->params->keys; | |||||||||||||||||||||||||||||||||||||
| 402 | 11 | ▶ | if ( defined $param ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 403 | 1 | ▶ | croak "extra parameters in field ${name}" if @extra; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 404 | 1 | $quoted .= ";" . unquote($param); | |||||||||||||||||||||||||||||||||||||
| 405 | 1 | ▶ | if ( $param eq "req" ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 406 | 1 | $message = $self->request; | |||||||||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||
| 410 | 11 | return ( maybe $quoted => $handlers->{$name}->( $message, $options, $field->params ) ); | |||||||||||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||
| 414 | 13 | ▶ | sub BUILDARGS( $, @args ) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILDARGS: called CC=6 SCAR=18.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||
| 416 | 13 | ▶ | my %args = @args == 1 && is_plain_hashref( $args[0] ) ? $args[0]->%* : @args; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@args == 1 and Ref::Util::XS::is_plain_hashref($args[0])
MC/DC0%0/2
@args == 1 and Ref::Util::XS::is_plain_hashref($args[0])
@args == 1
Ref::Util::XS::is_plain_hashref($args[0])
Truth table33%1/3
A and B
A= @args == 1B= Ref::Util::XS::is_plain_hashref($args[0])
| |||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||
| 418 | 13 | ▶ | if (my $res = $args{response}) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 419 | 1 | $args{message} = $res; | |||||||||||||||||||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||||||||||||||||||
| 421 | elsif (my $req = $args{request}) { | ||||||||||||||||||||||||||||||||||||||
| 422 | 8 | $args{message} = $req; | |||||||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||
| 425 | 13 | my $message = $args{message}; | |||||||||||||||||||||||||||||||||||||
| 426 | 13 | ▶ | if ( is_plain_hashref($message) ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 427 | 1 | require Plack::Request; | |||||||||||||||||||||||||||||||||||||
| 428 | 1 | $args{message} = Plack::Request->new($message); | |||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||
| 432 | 13 | return \%args; | |||||||||||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||
| 436 | 4 | 1; | |||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||
| 438 | __END__ | ||||||||||||||||||||||||||||||||||||||