| 1 | # Copyrights 2012-2016 by [Mark Overmeer]. | ||||||||||||||||||||||||||||
| 2 | # For other contributors see ChangeLog. | ||||||||||||||||||||||||||||
| 3 | # See the manual pages for details on the licensing terms. | ||||||||||||||||||||||||||||
| 4 | # Pod stripped from pm file by OODoc 2.02. | ||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | package XML::Compile::WSS::Signature; | ||||||||||||||||||||||||||||
| 9 | 5 | ▶ | use vars '$VERSION'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 5 | $VERSION = '2.02'; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 5 | ▶ | use base 'XML::Compile::WSS'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 5 | ▶ | use Log::Report 'xml-compile-wss-sig'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 5 | ▶ | use XML::Compile::WSS::Util qw/:wss11 :wsm10 :dsig :xtp10/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 5 | ▶ | use XML::Compile::WSS::SecToken (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 5 | ▶ | use XML::Compile::WSS::Sign (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 5 | ▶ | use XML::Compile::WSS::KeyInfo (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 5 | ▶ | use XML::Compile::WSS::SignedInfo (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 5 | ▶ | use XML::Compile::C14N::Util qw/:c14n/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 5 | ▶ | use XML::Compile::C14N (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 5 | ▶ | use Digest (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 5 | ▶ | use XML::LibXML (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 5 | ▶ | use File::Basename qw/dirname/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | 5 | ▶ | use File::Glob qw/bsd_glob/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | 5 | ▶ | use Scalar::Util qw/blessed/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 5 | my %prefixes = | |||||||||||||||||||||||||||
| 32 | ( # ds=DSIG_NS already registered in ::WSS | ||||||||||||||||||||||||||||
| 33 | dsig11 => DSIG11_NS | ||||||||||||||||||||||||||||
| 34 | , dsp => DSP_NS | ||||||||||||||||||||||||||||
| 35 | , dsigm => DSIG_MORE_NS | ||||||||||||||||||||||||||||
| 36 | , xenc => XENC_NS | ||||||||||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | #use Data::Dumper; | ||||||||||||||||||||||||||||
| 40 | #$Data::Dumper::Indent = 1; | ||||||||||||||||||||||||||||
| 41 | #$Data::Dumper::Quotekeys = 0; | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | sub init($) | ||||||||||||||||||||||||||||
| 45 | 4 | ▶ | { my ($self, $args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=14 SCAR=31.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 46 | 4 | ▶ | my $wss_v = $args->{wss_version} ||= '1.1'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$args->{"wss_version"} ||= "1.1"
MC/DC0%0/1
$args->{"wss_version"} ||= "1.1"
$args->{"wss_version"}
Truth table50%1/2
A
A= $args->{"wss_version"}
| |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 4 | $self->SUPER::init($args); | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 4 | ▶ | my $signer = delete $args->{signer} || {}; | ||||||||||||||||||||||||||
|
Condition100%2/2
delete $args->{'signer'} || {}
MC/DC100%1/1
delete $args->{'signer'} || {}
delete $args->{'signer'}
Truth table100%2/2
A
A= delete $args->{'signer'}
| |||||||||||||||||||||||||||||
| 51 | 4 | ▶ | blessed $signer || ref $signer | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($signer) or ref $signer
MC/DC50%1/2
builtin::blessed($signer) or ref $signer
builtin::blessed($signer)
ref $signer
Truth table66%2/3
A or B
A= builtin::blessed($signer)B= ref $signer
| |||||||||||||||||||||||||||||
| 52 | or $signer = +{ sign_method => $signer }; # pre 2.00 | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 4 | ▶ | $signer->{private_key} ||= delete $args->{private_key}; # pre 2.00 | ||||||||||||||||||||||||||
|
Condition66%2/3
$signer->{"private_key"} ||= delete $args->{"private_key"}
MC/DC50%1/2
$signer->{"private_key"} ||= delete $args->{"private_key"}
$signer->{"private_key"}
delete $args->{"private_key"}
Truth table66%2/3
A ||= B
A= $signer->{"private_key"}B= delete $args->{"private_key"}
| |||||||||||||||||||||||||||||
| 55 | $self->{XCWS_signer} = | ||||||||||||||||||||||||||||
| 56 | 4 | XML::Compile::WSS::Sign->fromConfig(%$signer, wss => $self); | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 4 | ▶ | my $si = delete $args->{signed_info} || {}; | ||||||||||||||||||||||||||
|
Condition50%1/2
delete $args->{'signed_info'} || {}
MC/DC0%0/1
delete $args->{'signed_info'} || {}
delete $args->{'signed_info'}
Truth table50%1/2
A
A= delete $args->{'signed_info'}
| |||||||||||||||||||||||||||||
| 59 | $si->{$_} ||= delete $args->{$_} | ||||||||||||||||||||||||||||
| 60 | 4 | ▶ | for qw/digest_method cannon_method prefix_list/; # pre 2.00 | ||||||||||||||||||||||||||
|
Condition66%2/3
$si->{$_} ||= delete $args->{$_}
MC/DC50%1/2
$si->{$_} ||= delete $args->{$_}
$si->{$_}
delete $args->{$_}
Truth table66%2/3
A ||= B
A= $si->{$_}B= delete $args->{$_}
| |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | $self->{XCWS_siginfo} = | ||||||||||||||||||||||||||||
| 63 | 4 | XML::Compile::WSS::SignedInfo->fromConfig(%$si, wss => $self); | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 4 | ▶ | my $ki = delete $args->{key_info} || {}; | ||||||||||||||||||||||||||
|
Condition50%1/2
delete $args->{'key_info'} || {}
MC/DC0%0/1
delete $args->{'key_info'} || {}
delete $args->{'key_info'}
Truth table50%1/2
A
A= delete $args->{'key_info'}
| |||||||||||||||||||||||||||||
| 66 | 4 | ▶ | $ki->{publish_token} ||= delete $args->{publish_token}; # pre 2.00 | ||||||||||||||||||||||||||
|
Condition33%1/3
$ki->{"publish_token"} ||= delete $args->{"publish_token"}
MC/DC0%0/2
$ki->{"publish_token"} ||= delete $args->{"publish_token"}
$ki->{"publish_token"}
delete $args->{"publish_token"}
Truth table33%1/3
A ||= B
A= $ki->{"publish_token"}B= delete $args->{"publish_token"}
| |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | $self->{XCWS_keyinfo} = | ||||||||||||||||||||||||||||
| 69 | 4 | XML::Compile::WSS::KeyInfo->fromConfig(%$ki, wss => $self); | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 4 | ▶ | if(my $subsig = delete $args->{signature}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 0 | ▶ | { $subsig->{sign_types} ||= [ 'wsse:SignatureType' ]; | ||||||||||||||||||||||||||
|
Condition0%0/2
$subsig->{"sign_types"} ||= ["wsse:SignatureType"]
MC/DC0%0/1
$subsig->{"sign_types"} ||= ["wsse:SignatureType"]
$subsig->{"sign_types"}
Truth table0%0/2
A
A= $subsig->{"sign_types"}
| |||||||||||||||||||||||||||||
| 73 | 0 | ▶ | $subsig->{sign_put} ||= $args->{sign_put}; | ||||||||||||||||||||||||||
|
Condition0%0/3
$subsig->{"sign_put"} ||= $args->{"sign_put"}
MC/DC0%0/2
$subsig->{"sign_put"} ||= $args->{"sign_put"}
$subsig->{"sign_put"}
$args->{"sign_put"}
Truth table0%0/3
A ||= B
A= $subsig->{"sign_put"}B= $args->{"sign_put"}
| |||||||||||||||||||||||||||||
| 74 | 0 | $self->{XCWS_subsig} = (ref $self) | |||||||||||||||||||||||||||
| 75 | ->new(wss_version => $wss_v, schema => $self->schema, %$subsig); | ||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 4 | $self->{XCWS_token} = $args->{token}; | |||||||||||||||||||||||||||
| 79 | 4 | $self->{XCWS_config} = $args; # the left-overs are for me | |||||||||||||||||||||||||||
| 80 | 4 | $self; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | #----------------------------- | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 4 | ▶ | sub keyInfo() {shift->{XCWS_keyinfo}} | ||||||||||||||||||||||||||
|
Subroutine
keyInfo: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 87 | 4 | ▶ | sub signedInfo() {shift->{XCWS_siginfo}} | ||||||||||||||||||||||||||
|
Subroutine
signedInfo: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 88 | 2 | ▶ | sub signer() {shift->{XCWS_signer}} | ||||||||||||||||||||||||||
|
Subroutine
signer: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | #----------------------------- | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 4 | ▶ | sub token() {shift->{XCWS_token}} | ||||||||||||||||||||||||||
|
Subroutine
token: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 94 | 0 | ▶ | sub remoteToken() {shift->{XCWS_rem_token}} | ||||||||||||||||||||||||||
|
Subroutine
remoteToken: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | #----------------------------- | ||||||||||||||||||||||||||||
| 97 | #### HELPERS | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | sub prepareReading($) | ||||||||||||||||||||||||||||
| 100 | 2 | ▶ | { my ($self, $schema) = @_; | ||||||||||||||||||||||||||
|
Subroutine
prepareReading: called CC=5 SCAR=16.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 101 | 2 | $self->SUPER::prepareReading($schema); | |||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 2 | my $config = $self->{XCWS_config}; | |||||||||||||||||||||||||||
| 104 | 2 | ▶ | if(my $r = $config->{remote_token}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | 0 | { $self->{XCWS_rem_token} = XML::Compile::WSS::SecToken->fromConfig($r); | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 2 | my (@elems_to_check, $container, @signature_elems); | |||||||||||||||||||||||||||
| 109 | $schema->addHook | ||||||||||||||||||||||||||||
| 110 | ( action => 'READER' | ||||||||||||||||||||||||||||
| 111 | , type => ($config->{sign_types} or panic) | ||||||||||||||||||||||||||||
| 112 | , before => sub { | ||||||||||||||||||||||||||||
| 113 | 1 | ▶ | my ($node, $path) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 114 | 1 | push @elems_to_check, $node; | |||||||||||||||||||||||||||
| 115 | 1 | $node; | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | 2 | ▶ | ); | ||||||||||||||||||||||||||
|
Condition33%1/3
$config->{'sign_types'} || &panic()
MC/DC0%0/2
$config->{'sign_types'} || &panic()
$config->{'sign_types'}
&panic()
Truth table33%1/3
A || B
A= $config->{'sign_types'}B= &panic()
| |||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | # we need the unparsed node to canonicalize and check | ||||||||||||||||||||||||||||
| 120 | 2 | $schema->addHook | |||||||||||||||||||||||||||
| 121 | ( action => 'READER' | ||||||||||||||||||||||||||||
| 122 | , type => 'ds:SignedInfoType' | ||||||||||||||||||||||||||||
| 123 | , after => 'XML_NODE' | ||||||||||||||||||||||||||||
| 124 | ); | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | # collect the elements to check, while decoding them | ||||||||||||||||||||||||||||
| 127 | 2 | ▶ | my $sign_put = $config->{sign_put} or panic; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | $schema->addHook | ||||||||||||||||||||||||||||
| 129 | ( action => 'READER' | ||||||||||||||||||||||||||||
| 130 | , type => $sign_put | ||||||||||||||||||||||||||||
| 131 | , after => sub { | ||||||||||||||||||||||||||||
| 132 | 1 | ▶ | my ($xml, $data, $path) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 133 | #warn "Located signature at $path"; | ||||||||||||||||||||||||||||
| 134 | push @signature_elems, $data->{ds_Signature} | ||||||||||||||||||||||||||||
| 135 | 1 | ▶ | if $data->{ds_Signature}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | 1 | $container = $data; | |||||||||||||||||||||||||||
| 137 | 1 | $data; | |||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | 2 | ); | |||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 2 | my $check_signature = $self->checker; | |||||||||||||||||||||||||||
| 142 | 2 | ▶ | my $sign_when = $config->{sign_when} || $sign_put; | ||||||||||||||||||||||||||
|
Condition66%2/3
$config->{'sign_when'} || $sign_put
MC/DC0%0/2
$config->{'sign_when'} || $sign_put
$config->{'sign_when'}
$sign_put
Truth table66%2/3
A || B
A= $config->{'sign_when'}B= $sign_put
| |||||||||||||||||||||||||||||
| 143 | $schema->addHook | ||||||||||||||||||||||||||||
| 144 | ( action => 'READER' | ||||||||||||||||||||||||||||
| 145 | , type => $sign_when | ||||||||||||||||||||||||||||
| 146 | , after => sub { | ||||||||||||||||||||||||||||
| 147 | 1 | ▶ | my ($xml, $data, $path) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 148 | #warn "Checking signatures when at $path"; | ||||||||||||||||||||||||||||
| 149 | @signature_elems | ||||||||||||||||||||||||||||
| 150 | 1 | ▶ | or error __x"signature element not found in answer"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | # We can leave the checking via exceptions, so have to reset | ||||||||||||||||||||||||||||
| 153 | # the counters for the next message first. | ||||||||||||||||||||||||||||
| 154 | 1 | my @e = @elems_to_check; @elems_to_check = (); | |||||||||||||||||||||||||||
| 155 | 1 | my @s = @signature_elems; @signature_elems = (); | |||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 1 | $check_signature->($container, $_, \@e) for @s; | |||||||||||||||||||||||||||
| 158 | 1 | $data; | |||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||
| 160 | 2 | ); | |||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 2 | $self; | |||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | # The checker routines throw an exception on error | ||||||||||||||||||||||||||||
| 166 | sub checker($@) | ||||||||||||||||||||||||||||
| 167 | 2 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
checker: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 168 | 2 | my $config = $self->{XCWS_config}; | |||||||||||||||||||||||||||
| 169 | 2 | my %args = (%$config, @_); | |||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | 2 | my $si = $self->signedInfo; | |||||||||||||||||||||||||||
| 172 | 2 | my $si_checker = $si->checker($self, %args); | |||||||||||||||||||||||||||
| 173 | 2 | my $get_tokens = $self->keyInfo->getTokens($self, %args); | |||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | sub { | ||||||||||||||||||||||||||||
| 176 | 1 | ▶ | my ($container, $sig, $elems) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 177 | 1 | my $ki = $sig->{ds_KeyInfo}; | |||||||||||||||||||||||||||
| 178 | 1 | ▶ | my @tokens = $ki ? $get_tokens->($ki, $container, $sig->{Id}) : (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | # Hey, you try to get tokens up in the hierachy in a recursive | ||||||||||||||||||||||||||||
| 181 | # nested program yourself! | ||||||||||||||||||||||||||||
| 182 | 1 | $ki->{__TOKENS} = \@tokens; | |||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | ### check the signed-info content | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | 1 | my $info = $sig->{ds_SignedInfo}; | |||||||||||||||||||||||||||
| 187 | 1 | $si_checker->($info, $elems, \@tokens); | |||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | ### Check the signature of the whole block | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | 1 | my $canon = $info->{ds_CanonicalizationMethod}; | |||||||||||||||||||||||||||
| 192 | 1 | my $preflist = $canon->{c14n_InclusiveNamespaces}{PrefixList}; # || []; | |||||||||||||||||||||||||||
| 193 | 1 | my $canonic = $si->_get_canonic($canon->{Algorithm}, $preflist); | |||||||||||||||||||||||||||
| 194 | 1 | my $sigvalue = $sig->{ds_SignatureValue}{_}; | |||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | my $signer = XML::Compile::WSS::Sign->new | ||||||||||||||||||||||||||||
| 197 | ( sign_method => $info->{ds_SignatureMethod}{Algorithm} | ||||||||||||||||||||||||||||
| 198 | 1 | , public_key => $tokens[0] | |||||||||||||||||||||||||||
| 199 | ); | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | 1 | ▶ | $signer->checker->($canonic->($info->{_XML_NODE}), $sigvalue) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 202 | or error __x"received signature value is incorrect"; | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | 2 | }; | |||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | sub builder(%) | ||||||||||||||||||||||||||||
| 208 | 2 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
builder: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 209 | 2 | my $config = $self->{XCWS_config}; | |||||||||||||||||||||||||||
| 210 | 2 | my %args = (%$config, @_); | |||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | 2 | my $signer = $self->signer; | |||||||||||||||||||||||||||
| 213 | 2 | my $signmeth = $signer->signMethod; | |||||||||||||||||||||||||||
| 214 | 2 | my $sign = $signer->builder($self, %args); | |||||||||||||||||||||||||||
| 215 | 2 | my $signedinfo = $self->signedInfo->builder($self, %args); | |||||||||||||||||||||||||||
| 216 | 2 | my $keylink = $self->keyInfo->builder($self, %args); | |||||||||||||||||||||||||||
| 217 | 2 | my $token = $self->token; | |||||||||||||||||||||||||||
| 218 | 2 | ▶ | my $tokenw = $token->isa('XML::Compile::WSS::SecToken::EncrKey') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 219 | ? $token->builder($self, %args) : undef; | ||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | 2 | my $sigw = $self->schema->writer('ds:Signature'); | |||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | # sign the signature! | ||||||||||||||||||||||||||||
| 224 | 2 | my $subsign; | |||||||||||||||||||||||||||
| 225 | 2 | ▶ | if(my $subsig = $self->{XCWS_subsig}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 226 | 0 | { $subsign = $subsig->builder; | |||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | 2 | my $unique = time; | |||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | sub { | ||||||||||||||||||||||||||||
| 232 | 1 | ▶ | my ($doc, $elems, $sec_node) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||
| 233 | 1 | my ($sinfo, $si_canond) = $signedinfo->($doc, $elems, $signmeth); | |||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | 1 | ▶ | $sec_node->appendChild($tokenw->($doc, $sec_node)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 236 | if $tokenw; | ||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | 1 | my $signature = $sign->($si_canond); | |||||||||||||||||||||||||||
| 239 | 1 | my %sig = | |||||||||||||||||||||||||||
| 240 | ( ds_SignedInfo => $sinfo | ||||||||||||||||||||||||||||
| 241 | , ds_SignatureValue => {_ => $signature} | ||||||||||||||||||||||||||||
| 242 | , ds_KeyInfo => $keylink->($doc, $token, $sec_node) | ||||||||||||||||||||||||||||
| 243 | , Id => 'SIG-'.$unique++ | ||||||||||||||||||||||||||||
| 244 | ); | ||||||||||||||||||||||||||||
| 245 | 1 | my $signode = $sigw->($doc, \%sig); | |||||||||||||||||||||||||||
| 246 | 1 | $sec_node->appendChild($signode); | |||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | 1 | ▶ | $subsign->($doc, [$signode], $sec_node) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 249 | if $subsign; | ||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | 1 | $sec_node; | |||||||||||||||||||||||||||
| 252 | 2 | }; | |||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | sub prepareWriting($) | ||||||||||||||||||||||||||||
| 256 | 2 | ▶ | { my ($self, $schema) = @_; | ||||||||||||||||||||||||||
|
Subroutine
prepareWriting: called CC=7 SCAR=20.7
Pod
undocumented
| |||||||||||||||||||||||||||||
| 257 | 2 | $self->SUPER::prepareWriting($schema); | |||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | 2 | ▶ | $self->token | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 260 | or error __x"creating signatures needs a token"; | ||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | 2 | my $config = $self->{XCWS_config}; | |||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||
| 264 | 2 | my @elems_to_sign; | |||||||||||||||||||||||||||
| 265 | 2 | ▶ | my $sign_types = $config->{sign_types} or panic; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 266 | 2 | ▶ | my @sign_types = ref $sign_types eq 'ARRAY' ? @$sign_types : $sign_types; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | $schema->addHook | ||||||||||||||||||||||||||||
| 269 | ( action => 'WRITER' | ||||||||||||||||||||||||||||
| 270 | , type => \@sign_types | ||||||||||||||||||||||||||||
| 271 | , after => sub { | ||||||||||||||||||||||||||||
| 272 | 1 | ▶ | my ($doc, $xml, $path, $val, $type) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=18.7
| |||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | # Not all schemas demand an explicit Id on the signed element, so | ||||||||||||||||||||||||||||
| 275 | # we may need to force one. | ||||||||||||||||||||||||||||
| 276 | 1 | ▶ | my $has = $xml->getAttributeNS(WSU_10, 'Id') | ||||||||||||||||||||||||||
|
Condition33%1/3
$xml->getAttributeNS('http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd', 'Id') || $xml->getAttribute('wsu:Id')
MC/DC0%0/2
$xml->getAttributeNS('http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd', 'Id') || $xml->getAttribute('wsu:Id')
$xml->getAttributeNS('http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd', 'Id')
$xml->getAttribute('wsu:Id')
Truth table33%1/3
A || B
A= $xml->getAttributeNS('http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd', 'Id')B= $xml->getAttribute('wsu:Id')
| |||||||||||||||||||||||||||||
| 277 | || $xml->getAttribute('wsu:Id'); | ||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||
| 279 | 1 | my $wsuid = $val->{wsu_Id}; | |||||||||||||||||||||||||||
| 280 | 1 | ▶ | if($has) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 281 | 0 | ▶ | { error __x"element {type} wants two wsu:Id's: {one} and {two}" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 282 | , type => $type, one => $wsuid, two => $has | ||||||||||||||||||||||||||||
| 283 | if $has ne $wsuid; | ||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||
| 285 | else | ||||||||||||||||||||||||||||
| 286 | 1 | { $xml->setNamespace(WSU_10, wsu => 0); | |||||||||||||||||||||||||||
| 287 | 1 | ▶ | $xml->setAttributeNS(WSU_10, Id => $wsuid || 'node-'.($xml+0)); | ||||||||||||||||||||||||||
|
Condition50%1/2
$wsuid || 'node-' . ($xml + 0)
MC/DC0%0/1
$wsuid || 'node-' . ($xml + 0)
$wsuid
Truth table50%1/2
A
A= $wsuid
| |||||||||||||||||||||||||||||
| 288 | # Above two lines do add a xmlns:wsu per Id. | ||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||
| 291 | 1 | push @elems_to_sign, $xml; | |||||||||||||||||||||||||||
| 292 | 1 | $xml; | |||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||
| 294 | 2 | ); | |||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||
| 296 | 2 | ▶ | my $sign_put = $config->{sign_put} or panic; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 297 | 2 | ▶ | my $sign_when = $config->{sign_when} || $sign_put; | ||||||||||||||||||||||||||
|
Condition66%2/3
$config->{'sign_when'} || $sign_put
MC/DC0%0/2
$config->{'sign_when'} || $sign_put
$config->{'sign_when'}
$sign_put
Truth table66%2/3
A || B
A= $config->{'sign_when'}B= $sign_put
| |||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||
| 299 | 2 | my $enveloped = grep $sign_put eq $_, @sign_types; | |||||||||||||||||||||||||||
| 300 | 2 | ▶ | if($enveloped) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 301 | { # The Signature element is required in the enveloped element, | ||||||||||||||||||||||||||||
| 302 | # but can only be created after the element has been produced. This | ||||||||||||||||||||||||||||
| 303 | # is a chicken-egg situation. Gladly, XML::Compile does not check | ||||||||||||||||||||||||||||
| 304 | # the kind of node which get's produced, so we can put in an empty | ||||||||||||||||||||||||||||
| 305 | # text-node which gets ignored. | ||||||||||||||||||||||||||||
| 306 | $schema->addHook | ||||||||||||||||||||||||||||
| 307 | ( action => 'WRITER', type => 'ds:SignatureType' | ||||||||||||||||||||||||||||
| 308 | 0 | ▶ | , replace => sub { $_[0]->createTextNode('') } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 309 | 0 | ); | |||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||
| 312 | 2 | my $add_signature = $self->builder(enveloped => $enveloped); | |||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | 2 | my $container; | |||||||||||||||||||||||||||
| 315 | $schema->addHook | ||||||||||||||||||||||||||||
| 316 | ( action => 'WRITER' | ||||||||||||||||||||||||||||
| 317 | , type => $sign_put | ||||||||||||||||||||||||||||
| 318 | , after => sub { | ||||||||||||||||||||||||||||
| 319 | 1 | ▶ | my ($doc, $xml) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 320 | #warn "Located signature container"; | ||||||||||||||||||||||||||||
| 321 | # $schema->prefixFor(WSU_10); | ||||||||||||||||||||||||||||
| 322 | 1 | $container = $xml; | |||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||
| 324 | 2 | ); | |||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||
| 326 | $schema->addHook | ||||||||||||||||||||||||||||
| 327 | ( action => 'WRITER' | ||||||||||||||||||||||||||||
| 328 | , type => $sign_when | ||||||||||||||||||||||||||||
| 329 | , after => sub { | ||||||||||||||||||||||||||||
| 330 | 1 | ▶ | my ($doc, $xml) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 331 | #warn "Creating signature"; | ||||||||||||||||||||||||||||
| 332 | 1 | $add_signature->($doc, \@elems_to_sign, $container); | |||||||||||||||||||||||||||
| 333 | 1 | @elems_to_sign = (); | |||||||||||||||||||||||||||
| 334 | 1 | $xml; | |||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||
| 336 | 2 | ); | |||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||
| 338 | 2 | $self; | |||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||
| 341 | sub loadSchemas($$) | ||||||||||||||||||||||||||||
| 342 | 4 | ▶ | { my ($self, $schema, $version) = @_; | ||||||||||||||||||||||||||
|
Subroutine
loadSchemas: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 343 | 4 | ▶ | return if $schema->{XCWS_sig_loaded}++; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||
| 345 | 4 | $self->SUPER::loadSchemas($schema, $version); | |||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||
| 347 | 4 | my $xsddir = dirname __FILE__; | |||||||||||||||||||||||||||
| 348 | 4 | trace "loading wss-dsig schemas from $xsddir/(dsig|encr)/*.xsd"; | |||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||
| 350 | 4 | my @xsds = | |||||||||||||||||||||||||||
| 351 | ( bsd_glob("$xsddir/dsig/*.xsd") | ||||||||||||||||||||||||||||
| 352 | , bsd_glob("$xsddir/encr/*.xsd") | ||||||||||||||||||||||||||||
| 353 | ); | ||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||
| 355 | 4 | $schema->addPrefixes(\%prefixes); | |||||||||||||||||||||||||||
| 356 | 4 | my $prefixes = join ',', sort keys %prefixes; | |||||||||||||||||||||||||||
| 357 | 4 | $schema->addKeyRewrite("PREFIXED($prefixes)"); | |||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||
| 359 | 4 | $schema->importDefinitions(\@xsds); | |||||||||||||||||||||||||||
| 360 | 4 | $schema; | |||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||
| 363 | 5 | 1; | |||||||||||||||||||||||||||