| 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.1'; | |||||||||||||||||||||||||||||||||||||
| 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 | 1 | ▶ | builder => sub($self) { $self->message->isa("HTTP::Response") }, | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 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
__ANON__: 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
__ANON__: not called CC=6 SCAR=37.4
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: 1 branch
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
__ANON__: 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 | 16 | ▶ | sub is_expired($self) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
is_expired: called CC=2 SCAR=9.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 238 | 16 | ▶ | my $expires = $self->signature_input->get("expires") or return undef; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 239 | 0 | return time > $expires->value; | |||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||
| 243 | 8 | ▶ | sub verify( $self, $options = undef ) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
verify: called CC=24 SCAR=36.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||
| 245 | 8 | ▶ | $options //= {}; | ||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$options //= {}
MC/DC0%0/1
$options //= {}
$options
Truth table50%1/2
A
A= $options
| |||||||||||||||||||||||||||||||||||||||
| 246 | 8 | ▶ | $options = { label => $options } unless is_plain_hashref($options); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||
| 248 | 8 | my $label = $options->{label}; | |||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||
| 250 | 8 | ▶ | unless (defined $label) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 251 | 8 | ($label) = $self->signature_labels; | |||||||||||||||||||||||||||||||||||||
| 252 | 8 | ▶ | $options->{label} //= $label; | ||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$options->{"label"} //= $label
MC/DC0%0/2
$options->{"label"} //= $label
$options->{"label"}
$label
Truth table33%1/3
A //= B
A= $options->{"label"}B= $label
| |||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||
| 255 | 8 | ▶ | my $input = $self->signature_input->get($label) or croak "signature-input label ${label} was not found"; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||
| 257 | 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"}
| |||||||||||||||||||||||||||||||||||||||
| 258 | 8 | ▶ | croak "signature is expired" if $self->is_expired; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||
| 261 | 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"}
| |||||||||||||||||||||||||||||||||||||||
| 262 | 8 | my $created = $self->signature_input->get("created"); | |||||||||||||||||||||||||||||||||||||
| 263 | 8 | ▶ | croak "signature is postdated" if $created && $created > time; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$created and $created > time
MC/DC0%0/2
$created and $created > time
$created
$created > time
Truth table33%1/3
A and B
A= $createdB= $created > time
| |||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||
| 266 | 8 | ▶ | if ( $self->has_require_tag ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 267 | 8 | my $check = $input->params->get("tag"); | |||||||||||||||||||||||||||||||||||||
| 268 | 8 | my $tag = $self->require_tag; | |||||||||||||||||||||||||||||||||||||
| 269 | 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
| |||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||
| 272 | 8 | ▶ | my $keyid = $input->params->get("keyid") or croak "no keyid was found in the signature-input"; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 273 | 8 | my $kid = unquote( $keyid->value ); | |||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||
| 275 | 8 | state $algs = { | |||||||||||||||||||||||||||||||||||||
| 276 | "ed25519" => { class => "Crypt::PK::Ed25519", key => { kty => "OKP", crv => "Ed25519" } }, | ||||||||||||||||||||||||||||||||||||||
| 277 | "rsa-pss-sha512" => { class => "Crypt::PK::RSA", key => { kty => "RSA", alg => "PS512" }, hash => [qw/ SHA512 pss 64 /] }, | ||||||||||||||||||||||||||||||||||||||
| 278 | }; | ||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||
| 280 | 8 | ▶ | my $alg = eval { $input->params->get("alg")->value } or croak "missing alg parameter"; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 281 | 8 | ▶ | my $meta = $algs->{ $alg } or croak "unsupported algorithm"; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||
| 283 | 8 | ▶ | my $key = first { $_->{kid} eq $kid } $self->public_keys->{keys}->@* | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 284 | 8 | ▶ | or croak "keyid '${kid}' was not found in the public keys"; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||
| 286 | # TODO: add support for looking up keys from a cache based on agent URL and key id, and alg | ||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||
| 288 | 8 | for my $field ( keys $meta->{key}->%* ) { | |||||||||||||||||||||||||||||||||||||
| 289 | 16 | ▶ | $key->{$field} eq $meta->{key}{$field} or croak "keyid ${kid} is incompatible with ${alg}"; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||
| 292 | 8 | my $class = $meta->{class}; | |||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||
| 294 | 8 | ▶ | my @params = $meta->{hash} ? $meta->{hash}->@* : (); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||
| 296 | 8 | my $pk = $class->new($key); | |||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||
| 298 | 8 | my $sig = $self->signature_header->get($label)->value; | |||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||
| 300 | 8 | my $base = $self->_generate_signature_base($options); | |||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||
| 302 | 8 | return $pk->verify_message( $sig, $base, @params ); | |||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||
| 305 | 11 | ▶ | sub _generate_signature_base( $self, $options ) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_generate_signature_base: called CC=7 SCAR=19.6
| |||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||
| 307 | 11 | my $label = $options->{label}; | |||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||
| 309 | 11 | my @buffer; | |||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||
| 311 | 11 | my $seen = Hash::Ordered->new; | |||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||
| 313 | 28 | ▶ | my sub _process_header_field( $field, $value ) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_process_header_field: called CC=3 SCAR=11.4
| |||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||
| 315 | # TODO serialize line as per "component-identifier ABNF rule" | ||||||||||||||||||||||||||||||||||||||
| 316 | # TODO canonicalize the field value | ||||||||||||||||||||||||||||||||||||||
| 317 | 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
| |||||||||||||||||||||||||||||||||||||||
| 318 | 28 | ▶ | croak "component has already been added to the sginature base" if $seen->exists( lc $field ); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 319 | 28 | $seen->set( lc $field => 1 ); | |||||||||||||||||||||||||||||||||||||
| 320 | 28 | push @buffer, $line; | |||||||||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||
| 323 | 11 | ▶ | my $input = $self->signature_input->get($label) or croak "signature-input label ${label} was not found"; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 324 | 11 | ▶ | croak "label ${label} is not a list" unless $input->is_inner_list; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||
| 326 | 11 | for my $field ( $input->value->@* ) { | |||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||
| 328 | 17 | my $name = unquote($field->value, braces => 1 ); | |||||||||||||||||||||||||||||||||||||
| 329 | 17 | ▶ | if ( substr($name, 0, 1) eq '@' ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 330 | 11 | _process_header_field( $self->_get_derived_field( $field, $options ) ); | |||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||
| 332 | else { | ||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||
| 334 | 6 | my $header = $self->headers->header($name); | |||||||||||||||||||||||||||||||||||||
| 335 | 6 | ▶ | if ($field->has_params) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||
| 337 | 2 | my ($key) = $field->params->get("key")->value; | |||||||||||||||||||||||||||||||||||||
| 338 | 2 | my $dict = HTTP::StructuredField->parse_dictionary($header); | |||||||||||||||||||||||||||||||||||||
| 339 | 2 | my $param = $dict->get($key); | |||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||
| 341 | # TODO: improve quoting | ||||||||||||||||||||||||||||||||||||||
| 342 | 2 | _process_header_field( "\"${name}\";key=\"${key}\"" => sprintf('"%s"', $param->value ) ); | |||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||||||||
| 345 | else { | ||||||||||||||||||||||||||||||||||||||
| 346 | 4 | _process_header_field( "\"${name}\"" => $header ); | |||||||||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||
| 352 | 11 | my $header = $self->headers->header("signature-input"); | |||||||||||||||||||||||||||||||||||||
| 353 | 11 | ▶ | croak "unexpected signature-input" unless substr( $header, 0, length($label) + 1 ) eq "${label}="; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 354 | 11 | my $params = substr( $header, length($label) + 1 ); | |||||||||||||||||||||||||||||||||||||
| 355 | 11 | _process_header_field( '"@signature-params"' => $params ); | |||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||
| 357 | 11 | return join( "\n", @buffer ); | |||||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||
| 360 | 11 | ▶ | sub _get_derived_field( $self, $field, $options ) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_derived_field: called CC=5 SCAR=22.1
| |||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||
| 362 | 11 | my $name = $field->value; | |||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||
| 364 | # Note: HTTP::Message has uri_canonical but Plack::Request does not. | ||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||
| 366 | state $handlers = { | ||||||||||||||||||||||||||||||||||||||
| 367 | 0 | ▶ | '@status' => sub( $message, $, $ ) { $message->code }, | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 368 | 0 | ▶ | '@method' => sub( $message, $, $ ) { $message->method }, | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 369 | 0 | ▶ | '@target-uri' => sub( $message, $, $ ) { $message->uri }, | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 370 | 11 | ▶ | '@authority' => sub( $message, $, $ ) { $message->uri->authority }, | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 371 | 0 | ▶ | '@scheme' => sub( $message, $, $ ) { $message->uri->scheme }, | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 372 | 0 | ▶ | '@path' => sub( $message, $, $ ) { $message->uri->path }, | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 373 | 0 | ▶ | '@query' => sub( $message, $, $ ) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||
| 374 | 0 | my $query = $message->uri->query; | |||||||||||||||||||||||||||||||||||||
| 375 | 0 | ▶ | if ( defined $query ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 376 | 0 | return '?' . $query; | |||||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||||
| 378 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||
| 379 | }, | ||||||||||||||||||||||||||||||||||||||
| 380 | 0 | ▶ | '@query-param' => sub( $message, $, $params ) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||
| 381 | 0 | ▶ | if ( my ($key) = $params->keys ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 382 | # Note: RFC 9421 Sec 2.2.8 says named parameters with multiple values must not be included | ||||||||||||||||||||||||||||||||||||||
| 383 | 0 | my @values = $message->uri->query_param($key); | |||||||||||||||||||||||||||||||||||||
| 384 | 0 | ▶ | croak "multipe query-param values for '${key}'" if @values > 1; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 385 | 0 | return $values[0]; | |||||||||||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||||||||||||
| 388 | 11 | }; | |||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||
| 390 | 11 | ▶ | croak "unsupported field ${name}" unless exists $handlers->{$name}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||
| 392 | 11 | my $quoted = "\"${name}\""; | |||||||||||||||||||||||||||||||||||||
| 393 | 11 | my $message = $self->message; | |||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||
| 395 | 11 | my ($param, @extra) = $field->params->keys; | |||||||||||||||||||||||||||||||||||||
| 396 | 11 | ▶ | if ( defined $param ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 397 | 1 | ▶ | croak "extra parameters in field ${name}" if @extra; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 398 | 1 | $quoted .= ";" . unquote($param); | |||||||||||||||||||||||||||||||||||||
| 399 | 1 | ▶ | if ( $param eq "req" ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 400 | 1 | $message = $self->request; | |||||||||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||
| 404 | 11 | return ( maybe $quoted => $handlers->{$name}->( $message, $options, $field->params ) ); | |||||||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||
| 408 | 13 | ▶ | sub BUILDARGS( $, @args ) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILDARGS: called CC=6 SCAR=18.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||
| 410 | 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])
| |||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||
| 412 | 13 | ▶ | if (my $res = $args{response}) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 413 | 1 | $args{message} = $res; | |||||||||||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||||||||||||
| 415 | elsif (my $req = $args{request}) { | ||||||||||||||||||||||||||||||||||||||
| 416 | 8 | $args{message} = $req; | |||||||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||
| 419 | 13 | my $message = $args{message}; | |||||||||||||||||||||||||||||||||||||
| 420 | 13 | ▶ | if ( is_plain_hashref($message) ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 421 | 1 | require Plack::Request; | |||||||||||||||||||||||||||||||||||||
| 422 | 1 | $args{message} = Plack::Request->new($message); | |||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||
| 426 | 13 | return \%args; | |||||||||||||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||
| 430 | 4 | 1; | |||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||
| 432 | __END__ | ||||||||||||||||||||||||||||||||||||||