SAML2/Protocol/Assertion.pm

filter: Statementstmt 96.7% 353 / 365 Branchbran 76.3% 145 / 190 Conditioncond 78.0% 57 / 73 MC/DCmcdc 46.5% 20 / 43 Subroutinesub 94.6% 53 / 56 Podpod 100% 17 / 17 totaltotal 86.6% 645 / 744 CC 126 SCAR 25.2
CC
126
Cov
88%
new_from_xml
37.6
_trusted_signature_refs
17.3
_get_trusted_assertion
12.4
CRAP 12.4
↑ Summary SAML2/Object/Response.pm »
1 package Net::SAML2::Protocol::Assertion;
2 33 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 33 our $VERSION = '0.89'; # VERSION
5  
6 33 ▶use MooseX::Types::DateTime qw/ DateTime /;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 33 ▶use MooseX::Types::Common::String qw/ NonEmptySimpleStr /;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 33 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 33 ▶use DateTime::HiRes;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 33 ▶use DateTime::Format::XSD;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 33 ▶use Net::SAML2::XML::Util qw/ no_comments /;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 33 ▶use Net::SAML2::XML::Sig;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 33 ▶use XML::Enc;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 33 ▶use XML::LibXML::XPathContext;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 33 ▶use Crypt::OpenSSL::X509;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 33 ▶use Crypt::OpenSSL::Verify;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 33 ▶use List::Util qw(first);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 33 ▶use URN::OASIS::SAML2 qw(STATUS_SUCCESS);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 33 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 33 ▶use Net::SAML2::Types qw(XsdID);
Subroutine BEGIN: called CC=1 SCAR=0.0
21 33 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 33 with 'Net::SAML2::Role::ProtocolMessage';
24 33 with 'Net::SAML2::Role::VerifyXML';
25 33 with 'Net::SAML2::Role::XMLCertificate';
26  
27 # ABSTRACT: SAML2 assertion object
28  
29  
30 33 has 'attributes' => (isa => 'HashRef[ArrayRef]', is => 'ro', required => 1);
31 33 has 'audience' => (isa => NonEmptySimpleStr, is => 'ro', required => 1);
32 33 has 'not_after' => (isa => DateTime, is => 'ro', required => 1);
33 33 has 'not_before' => (isa => DateTime, is => 'ro', required => 1);
34 33 has 'session' => (isa => 'Str', is => 'ro', required => 1);
35 33 has 'in_response_to' => (isa => 'Str', is => 'ro', required => 1);
36 33 has 'response_status' => (isa => 'Str', is => 'ro', required => 1);
37 33 has 'response_substatus' => (isa => 'Str', is => 'ro');
38 33 has 'cacert' => (isa => 'Str', is => 'ro', required => 0);
39 33 has 'cert_text' => (isa => 'Str', is => 'ro', required => 0);
40 33 has 'xpath' => (isa => 'XML::LibXML::XPathContext', is => 'ro', required => 1);
41 33 has 'nameid_object' => (
42 isa => 'XML::LibXML::Element',
43 is => 'ro',
44 required => 0,
45 init_arg => 'nameid',
46 predicate => 'has_nameid',
47 );
48 33 has 'authnstatement_object' => (
49 isa => 'XML::LibXML::Element',
50 is => 'ro',
51 required => 0,
52 init_arg => 'authnstatement',
53 predicate => 'has_authnstatement',
54 );
55 33 has 'insecure_trust_embedded_cert' => (
56 isa => 'Bool',
57 is => 'ro',
58 default => 0,
59 );
60  
61  
62  
63 # BUILDARGS
64  
65 34 ▶around BUILDARGS => sub {
Subroutine __ANON__: called CC=4 SCAR=14.2
66 34 my $orig = shift;
67 34 my $self = shift;
68  
69 34 my %params = @_;
70 34 ▶ unless ($params{cacert}
Branch: 1 branch
BranchTrueFalseTotal
unless ($params{"cacert"} or $params{"cert_text"} or $params{"insecure_trust_embedded_cert"}) 0 34 34
Condition83%5/6
$params{"cacert"} or $params{"cert_text"} or $params{"insecure_trust_embedded_cert"}
l!l&&r!l&&!r
20140
$params{"cacert"} or $params{"cert_text"}
l!l&&r!l&&!r
15514
MC/DC0%0/3
$params{"cacert"} or $params{"cert_text"} or $params{"insecure_trust_embedded_cert"}
$params{"cacert"} $params{"cert_text"} $params{"insecure_trust_embedded_cert"}
Truth table75%3/4
A or B or C
A= $params{"cacert"}B= $params{"cert_text"}C= $params{"insecure_trust_embedded_cert"}
ABCresult
1XX1
01X1
0011
0000
71 || $params{cert_text}
72 || $params{insecure_trust_embedded_cert}) {
73 0 croak(
74 "'cacert' or 'cert_text' is required to verify assertion signatures. "
75 . "Without a trusted certificate the verifier accepts any "
76 . "KeyInfo-embedded certificate. To explicitly disable this check "
77 . "(test/dev only), pass insecure_trust_embedded_cert => 1 to "
78 . "new_from_xml()."
79 );
80 }
81  
82 34 return $self->$orig(%params);
83 33 };
84  
85 81 ▶sub _assert_saml_value {
Subroutine _assert_saml_value: called CC=5 SCAR=16.1
86 81 my ($self, $xpath, $needle, $haystack, $ctx) = @_;
87  
88 81 ▶ my $found = $ctx
Branch: 1 branch
BranchTrueFalseTotal
$ctx ? : 32 49 81
89 ? $xpath->findvalue($haystack, $ctx)
90 : $xpath->findvalue($haystack); # findvalue WILL concat multiple values iirc
91 81 ▶ die "assert_saml_value: Unable to get a value for ($haystack)" unless defined $found;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $found 0 81 81
92 81 ▶ return $found unless defined $needle;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $needle 77 4 81
93  
94 4 ▶ if ($needle ne $found) {
Branch: 1 branch
BranchTrueFalseTotal
if ($needle ne $found) 2 2 4
95 2 die "assert_saml_value: ($needle) does not match ($found) in ($haystack)";
96 }
97 2 return $found;
98 }
99  
100 46 ▶sub _get_actual_destination {
Subroutine _get_actual_destination: called CC=1 SCAR=0.0
101 46 my ($class, $destination, $xpath) = @_;
102  
103 46 return $class->_assert_saml_value($xpath, $destination,
104 '/samlp:Response/@Destination | /samlp:ArtifactResponse/@Destination');
105 }
106  
107 35 ▶sub _get_not_before {
Subroutine _get_not_before: called CC=4 SCAR=14.6
108 35 my ($class, $xpath, $ctx) = @_;
109  
110 35 my $not_before;
111 35 ▶ my $value = $ctx
Branch: 1 branch
BranchTrueFalseTotal
$ctx ? : 32 3 35
112 ? $xpath->findvalue('saml:Conditions/@NotBefore', $ctx)
113 : $xpath->findvalue('//samlp:Response/saml:Assertion/saml:Conditions/@NotBefore');
114 35 ▶ $value //= $xpath->findvalue('//saml:Conditions/@NotBefore');
Condition33%1/3
$value //= $xpath->findvalue("//saml:Conditions/\@NotBefore")
l!l&&r!l&&!r
3500
MC/DC0%0/2
$value //= $xpath->findvalue("//saml:Conditions/\@NotBefore")
$value $xpath->findvalue("//saml:Conditions/\@NotBefore")
Truth table33%1/3
A //= B
A= $valueB= $xpath->findvalue("//saml:Conditions/\@NotBefore")
ABresult
1X1
011
000
115  
116 35 ▶ if ($value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value) { } 35 0 35
117 35 $not_before = DateTime::Format::XSD->parse_datetime($value);
118 }
119 else {
120 0 $not_before = DateTime::HiRes->now();
121 }
122 35 return $not_before;
123 }
124  
125 35 ▶sub _get_not_after {
Subroutine _get_not_after: called CC=4 SCAR=14.6
126 35 my ($class, $xpath, $ctx) = @_;
127  
128 35 my $not_after;
129 35 ▶ my $value = $ctx
Branch: 1 branch
BranchTrueFalseTotal
$ctx ? : 32 3 35
130 ? $xpath->findvalue('saml:Conditions/@NotOnOrAfter', $ctx)
131 : $xpath->findvalue('//samlp:Response/saml:Assertion/saml:Conditions/@NotOnOrAfter');
132 35 ▶ $value //= $xpath->findvalue('//saml:Conditions/@NotOnOrAfter');
Condition33%1/3
$value //= $xpath->findvalue("//saml:Conditions/\@NotOnOrAfter")
l!l&&r!l&&!r
3500
MC/DC0%0/2
$value //= $xpath->findvalue("//saml:Conditions/\@NotOnOrAfter")
$value $xpath->findvalue("//saml:Conditions/\@NotOnOrAfter")
Truth table33%1/3
A //= B
A= $valueB= $xpath->findvalue("//saml:Conditions/\@NotOnOrAfter")
ABresult
1X1
011
000
133 35 ▶ if ($value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value) { } 35 0 35
134 35 $not_after = DateTime::Format::XSD->parse_datetime($value);
135 }
136 else {
137 0 $not_after = DateTime->from_epoch(epoch => time() + 1000);
138 }
139 35 return $not_after;
140 }
141  
142 35 ▶sub _get_nameid {
Subroutine _get_nameid: called CC=5 SCAR=16.1
143 35 my ($class, $xpath, $ctx) = @_;
144  
145 35 my $nameid;
146 35 ▶ my $nameid_nodes = $ctx
Branch: 1 branch
BranchTrueFalseTotal
$ctx ? : 32 3 35
147 ? $xpath->findnodes('saml:Subject/saml:NameID', $ctx)
148 : $xpath->findnodes('/samlp:Response/saml:Assertion/saml:Subject/saml:NameID');
149  
150 35 ▶ if ($nameid_nodes->size) {
Branch: 2 branches
BranchTrueFalseTotal
if ($nameid_nodes->size) { } 32 3 35
elsif (not $ctx) { } 1 2 3
151 32 $nameid = $nameid_nodes->get_node(1);
152 }
153 elsif (!$ctx) {
154 1 my $global = $xpath->findnodes('//saml:Subject/saml:NameID');
155 1 ▶ $nameid = $global->get_node(1) if $global->size;
Branch: 1 branch
BranchTrueFalseTotal
if $global->size 1 0 1
156 }
157 35 return $nameid;
158 }
159  
160 35 ▶sub _get_authnstatement {
Subroutine _get_authnstatement: called CC=3 SCAR=11.0
161 35 my ($class, $xpath, $ctx) = @_;
162  
163 35 my $authnstatement;
164 35 ▶ my $authn_nodes = $ctx
Branch: 1 branch
BranchTrueFalseTotal
$ctx ? : 32 3 35
165 ? $xpath->findnodes('saml:AuthnStatement', $ctx)
166 : $xpath->findnodes('/samlp:Response/saml:Assertion/saml:AuthnStatement');
167  
168 35 ▶ if ($authn_nodes->size) {
Branch: 1 branch
BranchTrueFalseTotal
if ($authn_nodes->size) 34 1 35
169 34 $authnstatement = $authn_nodes->get_node(1);
170 }
171 35 return $authnstatement;
172 }
173  
174 35 ▶sub _get_actual_issuer {
Subroutine _get_actual_issuer: called CC=2 SCAR=6.9
175 35 my ($class, $issuer, $xpath, $ctx) = @_;
176  
177 35 ▶ return $ctx
Branch: 1 branch
BranchTrueFalseTotal
$ctx ? : 32 3 35
178 ? $class->_assert_saml_value($xpath, $issuer, 'saml:Issuer', $ctx)
179 : $class->_assert_saml_value($xpath, $issuer, '//saml:Assertion/saml:Issuer');
180 }
181  
182 34 ▶sub _get_id {
Subroutine _get_id: called CC=2 SCAR=6.9
183 34 my $class = shift;
184 34 my $xpath = shift;
185 34 my $assertion_node = shift;
186  
187 34 ▶ return $xpath->findvalue('//saml:Assertion/@ID') unless $assertion_node;
Branch: 1 branch
BranchTrueFalseTotal
unless $assertion_node 3 31 34
188 31 return $assertion_node->getAttribute('ID');
189 }
190  
191 34 ▶sub _get_audience {
Subroutine _get_audience: called CC=2 SCAR=6.9
192 34 my $class = shift;
193 34 my $xpath = shift;
194 34 my $assertion_node = shift;
195  
196 34 ▶ return $xpath->findvalue('//saml:Conditions/saml:AudienceRestriction/saml:Audience') unless $assertion_node;
Branch: 1 branch
BranchTrueFalseTotal
unless $assertion_node 3 31 34
197 31 return $xpath->findvalue('saml:Conditions/saml:AudienceRestriction/saml:Audience', $assertion_node);
198 }
199  
200 34 ▶sub _get_session {
Subroutine _get_session: called CC=2 SCAR=6.9
201 34 my $class = shift;
202 34 my $xpath = shift;
203 34 my $assertion_node = shift;
204  
205 34 ▶ return $xpath->findvalue('//saml:AuthnStatement/@SessionIndex') unless $assertion_node;
Branch: 1 branch
BranchTrueFalseTotal
unless $assertion_node 3 31 34
206 31 return $xpath->findvalue('saml:AuthnStatement/@SessionIndex', $assertion_node);
207 }
208  
209 34 ▶sub _get_in_response_to {
Subroutine _get_in_response_to: called CC=2 SCAR=6.9
210 34 my $class = shift;
211 34 my $xpath = shift;
212 34 my $assertion_node = shift;
213  
214 34 ▶ return $xpath->findvalue(
Branch: 1 branch
BranchTrueFalseTotal
unless $assertion_node 3 31 34
215 '//saml:Subject/saml:SubjectConfirmation/saml:SubjectConfirmationData/@InResponseTo'
216 ) unless $assertion_node;
217  
218 31 return $xpath->findvalue(
219 'saml:Subject/saml:SubjectConfirmation/saml:SubjectConfirmationData/@InResponseTo',
220 $assertion_node);
221 }
222  
223 35 ▶sub _get_trusted_assertion {
Subroutine _get_trusted_assertion: called CC=11 SCAR=25.2
224 35 my $class = shift;
225 35 my $xpath = shift;
226 35 my ($candidate_refs) = @_;
227  
228 35 my $assertion_node;
229 35 for my $sign_id_ref (@$candidate_refs) {
230 32 ▶ next unless (defined $sign_id_ref && XsdID->check($sign_id_ref));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $sign_id_ref and XsdID()->check($sign_id_ref) 0 32 32
Condition33%1/3
defined $sign_id_ref and XsdID()->check($sign_id_ref)
!ll&&!rl&&r
0032
MC/DC0%0/2
defined $sign_id_ref and XsdID()->check($sign_id_ref)
defined $sign_id_ref XsdID()->check($sign_id_ref)
Truth table33%1/3
A and B
A= defined $sign_id_refB= XsdID()->check($sign_id_ref)
ABresult
0X0
100
111
231 32 my $candidates = $xpath->findnodes("//*[\@ID='$sign_id_ref']");
232 32 ▶ croak("XSW guard: signed Reference URI '$sign_id_ref' is ambiguous "
Branch: 1 branch
BranchTrueFalseTotal
if $candidates->size > 1 0 32 32
233 . "(matched " . $candidates->size . " elements)")
234 if $candidates->size > 1;
235 32 my $root = $candidates->get_node(1);
236 32 ▶ next unless $root;
Branch: 1 branch
BranchTrueFalseTotal
unless $root 0 32 32
237  
238 32 ▶ my $ln = $root->localname // '';
Condition50%1/2
$root->localname // ""
l!l
320
MC/DC0%0/1
$root->localname // ""
$root->localname
Truth table50%1/2
A
A= $root->localname
Aresult
11
00
239 32 ▶ my $ns = $root->namespaceURI // '';
Condition50%1/2
$root->namespaceURI // ""
l!l
320
MC/DC0%0/1
$root->namespaceURI // ""
$root->namespaceURI
Truth table50%1/2
A
A= $root->namespaceURI
Aresult
11
00
240 32 ▶ if ($ln eq 'Assertion'
Branch: 1 branch
BranchTrueFalseTotal
if ($ln eq "Assertion" and $ns eq "urn:oasis:names:tc:SAML:2.0:assertion") 30 2 32
Condition66%2/3
$ln eq "Assertion" and $ns eq "urn:oasis:names:tc:SAML:2.0:assertion"
!ll&&!rl&&r
2030
MC/DC50%1/2
$ln eq "Assertion" and $ns eq "urn:oasis:names:tc:SAML:2.0:assertion"
$ln eq "Assertion" $ns eq "urn:oasis:names:tc:SAML:2.0:assertion"
Truth table66%2/3
A and B
A= $ln eq "Assertion"B= $ns eq "urn:oasis:names:tc:SAML:2.0:assertion"
ABresult
0X0
100
111
241 && $ns eq 'urn:oasis:names:tc:SAML:2.0:assertion') {
242 30 $assertion_node = $root;
243 30 last;
244 }
245 2 my $asns = $xpath->findnodes('.//saml:Assertion', $root);
246 2 ▶ if ($asns->size) {
Branch: 1 branch
BranchTrueFalseTotal
if ($asns->size) 2 0 2
247 2 $assertion_node = $asns->get_node(1);
248 2 last;
249 }
250 }
251 35 return $assertion_node;
252 }
253  
254 35 ▶sub _trusted_signature_refs {
Subroutine _trusted_signature_refs: called CC=17 SCAR=28.5
255 35 my ($class, $xpath, $cacert, $cert_text) = @_;
256  
257 35 ▶ return unless $cacert || $cert_text;
Branch: 1 branch
BranchTrueFalseTotal
unless $cacert or $cert_text 15 20 35
Condition100%3/3
$cacert or $cert_text
l!l&&r!l&&!r
15515
MC/DC100%2/2
$cacert or $cert_text
$cacert $cert_text
Truth table100%3/3
A or B
A= $cacertB= $cert_text
ABresult
1X1
011
000
258  
259 20 ▶ my $ca = $cacert
Branch: 1 branch
BranchTrueFalseTotal
$cacert ? : 15 5 20
260 ? Crypt::OpenSSL::Verify->new($cacert, { strict_certs => 0 })
261 : undef;
262  
263 20 my @trusted_refs;
264 20 for my $sig ($xpath->findnodes('//dsig:Signature')) {
265 29 my @verify_with;
266  
267 29 ▶ if ($cert_text) {
Branch: 2 branches
BranchTrueFalseTotal
if ($cert_text) { } 8 21 29
elsif ($ca) { } 21 0 21
268 8 push @verify_with, $cert_text; # pinned: KeyInfo is never consulted
269 }
270 elsif ($ca) {
271 21 my $pem = $class->get_pem_from_keynode($sig);
272 21 ▶ my $cert_obj = try { Crypt::OpenSSL::X509->new_from_string($pem) };
Subroutine __ANON__: called CC=1 SCAR=0.0
273 push @verify_with, $pem
274 21 ▶ if $cert_obj && try { $ca->verify($cert_obj) };
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if $cert_obj and &try(sub { $ca->verify($cert_obj); } ) 20 1 21
Condition66%2/3
$cert_obj and &try(sub { $ca->verify($cert_obj); } )
!ll&&!rl&&r
0120
MC/DC50%1/2
$cert_obj and &try(sub { $ca->verify($cert_obj); } )
$cert_obj &try(sub { $ca->verify($cert_obj); } )
Truth table66%2/3
A and B
A= $cert_objB= &try(sub { $ca->verify($cert_obj); } )
ABresult
0X0
100
111
275 }
276  
277 29 ▶ next unless @verify_with;
Branch: 1 branch
BranchTrueFalseTotal
unless @verify_with 1 28 29
278  
279 28 my $ref = $xpath->findvalue(
280 './dsig:SignedInfo/dsig:Reference/@URI', $sig);
281 28 ▶ next unless defined $ref;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ref 0 28 28
282 28 $ref =~ s/^#//;
283  
284 28 ▶ next unless XsdID->check($ref);
Branch: 1 branch
BranchTrueFalseTotal
unless XsdID()->check($ref) 0 28 28
285  
286 28 my $resolved = $xpath->findnodes("//*[\@ID='$ref']");
287  
288 # A trusted signature whose Reference URI resolves to more than
289 # one element is an active XSW1 (duplicate-ID) attack - fail closed.
290 28 ▶ die("XSW guard: trusted signature Reference URI '$ref' is "
Branch: 1 branch
BranchTrueFalseTotal
if $resolved->size > 1 0 28 28
291 . "ambiguous (matched " . $resolved->size . " elements)")
292 if $resolved->size > 1;
293  
294 28 ▶ next unless $resolved->size == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless $resolved->size == 1 0 28 28
295 28 my $node = $resolved->get_node(1);
296  
297 28 my $genuine;
298 28 for my $pem (@verify_with) {
299 28 ▶ $genuine = try {
Subroutine __ANON__: called CC=1 SCAR=0.0
300 28 Net::SAML2::XML::Sig->new({
301 cert_text => $pem,
302 no_xml_declaration => 1,
303 })->verify($node->toString);
304 28 };
305 28 ▶ last if $genuine;
Branch: 1 branch
BranchTrueFalseTotal
if $genuine 24 4 28
306 }
307 28 ▶ next unless $genuine;
Branch: 1 branch
BranchTrueFalseTotal
unless $genuine 4 24 28
308  
309 24 push @trusted_refs, $ref;
310 }
311  
312 20 return @trusted_refs;
313 }
314  
315 38 ▶sub _verify_encrypted_assertion {
Subroutine _verify_encrypted_assertion: called CC=11 SCAR=24.0
316 38 my $self = shift;
317 38 my $xml = shift;
318 38 my $cacert = shift;
319 38 my $key_file = shift;
320 38 my $key_name = shift;
321 38 my $insecure_trust_embedded_cert = shift;
322 38 my $cert_text = shift;
323 38 my $require_signed_assertion = shift;
324  
325 38 ▶ unless ($cacert || $cert_text || $insecure_trust_embedded_cert) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($cacert or $cert_text or $insecure_trust_embedded_cert) 2 36 38
Condition100%6/6
$cacert or $cert_text or $insecure_trust_embedded_cert
l!l&&r!l&&!r
21152
$cacert or $cert_text
l!l&&r!l&&!r
16517
MC/DC100%3/3
$cacert or $cert_text or $insecure_trust_embedded_cert
$cacert $cert_text $insecure_trust_embedded_cert
Truth table100%4/4
A or B or C
A= $cacertB= $cert_textC= $insecure_trust_embedded_cert
ABCresult
1XX1
01X1
0011
0000
326 2 croak(
327 "'cacert' or 'cert_text' is required to verify assertion signatures. "
328 . "Without a trusted certificate the verifier accepts any "
329 . "KeyInfo-embedded certificate. To explicitly disable this check "
330 . "(test/dev only), pass insecure_trust_embedded_cert => 1 to "
331 . "new_from_xml()."
332 );
333 }
334  
335 36 my $xpath = XML::LibXML::XPathContext->new($xml);
336 36 $xpath->registerNs('saml', 'urn:oasis:names:tc:SAML:2.0:assertion');
337 36 $xpath->registerNs('samlp', 'urn:oasis:names:tc:SAML:2.0:protocol');
338 36 $xpath->registerNs('dsig', 'http://www.w3.org/2000/09/xmldsig#');
339 36 $xpath->registerNs('xenc', 'http://www.w3.org/2001/04/xmlenc#');
340  
341 36 ▶ return $xml unless $xpath->exists('//saml:EncryptedAssertion');
Branch: 1 branch
BranchTrueFalseTotal
unless $xpath->exists("//saml:EncryptedAssertion") 31 5 36
342  
343 5 ▶ croak "Encrypted Assertions require key_file" if !defined $key_file;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $key_file 0 5 5
344  
345 5 $xml = $self->_decrypt(
346 $xml,
347 key_file => $key_file,
348 key_name => $key_name,
349 );
350 5 $xpath->setContextNode($xml);
351  
352 5 my $assert_nodes = $xpath->findnodes('//saml:Assertion');
353 5 ▶ return $xml unless $assert_nodes->size;
Branch: 1 branch
BranchTrueFalseTotal
unless $assert_nodes->size 0 5 5
354 5 my $assert = $assert_nodes->get_node(1);
355  
356 5 ▶ unless ($xpath->exists('dsig:Signature', $assert)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($xpath->exists("dsig:Signature", $assert)) 2 3 5
357 2 ▶ return $xml unless $require_signed_assertion;
Branch: 1 branch
BranchTrueFalseTotal
unless $require_signed_assertion 1 1 2
358 1 croak(
359 "Decrypted assertion has no signature. Set require_signed_assertion => 0 "
360 . "to accept unsigned encrypted assertions (not recommended)."
361 );
362 }
363  
364 $self->verify_xml(
365 3 ▶ $assert->toString(),
Branch: 2 branches
BranchTrueFalseTotal
$cert_text ? : 0 3 3
$cacert ? : 2 1 3
366 no_xml_declaration => 1,
367 $cert_text ? (cert_text => $cert_text) : (),
368 $cacert ? (cacert => $cacert) : (),
369 );
370  
371 3 return $xml;
372 }
373  
374 46 ▶sub new_from_xml {
Subroutine new_from_xml: called CC=35 SCAR=36.3
Pod documented
375 46 my($class, %args) = @_;
376  
377 46 my $key_file = $args{key_file};
378 46 my $cacert = delete $args{cacert};
379 46 my $cert_text = delete $args{cert_text};
380 46 my $issuer = delete $args{issuer};
381 46 my $destination = delete $args{destination};
382 46 ▶ my $insecure_trust_embedded_cert = delete $args{insecure_trust_embedded_cert} // 0;
Condition100%2/2
delete $args{"insecure_trust_embedded_cert"} // 0
l!l
1828
MC/DC100%1/1
delete $args{"insecure_trust_embedded_cert"} // 0
delete $args{"insecure_trust_embedded_cert"}
Truth table100%2/2
A
A= delete $args{"insecure_trust_embedded_cert"}
Aresult
11
00
383 46 ▶ my $require_signed_assertion = delete $args{require_signed_assertion} // 0;
Condition100%2/2
delete $args{"require_signed_assertion"} // 0
l!l
244
MC/DC100%1/1
delete $args{"require_signed_assertion"} // 0
delete $args{"require_signed_assertion"}
Truth table100%2/2
A
A= delete $args{"require_signed_assertion"}
Aresult
11
00
384  
385 46 my $xpath = XML::LibXML::XPathContext->new();
386 46 $xpath->registerNs('saml', 'urn:oasis:names:tc:SAML:2.0:assertion');
387 46 $xpath->registerNs('samlp', 'urn:oasis:names:tc:SAML:2.0:protocol');
388 46 $xpath->registerNs('dsig', 'http://www.w3.org/2000/09/xmldsig#');
389 46 $xpath->registerNs('xenc', 'http://www.w3.org/2001/04/xmlenc#');
390  
391 46 my $xml = no_comments($args{xml});
392 46 $xpath->setContextNode($xml);
393  
394 46 ▶ my $trust_anchor = $cacert || $cert_text;
Condition100%3/3
$cacert || $cert_text
l!l&&r!l&&!r
181018
MC/DC100%2/2
$cacert || $cert_text
$cacert $cert_text
Truth table100%3/3
A || B
A= $cacertB= $cert_text
ABresult
1X1
011
000
395  
396 46 my $actual_destination = $class->_get_actual_destination($destination, $xpath);
397 45 ▶ if ($trust_anchor && $xpath->findnodes('//dsig:Signature')->size > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($trust_anchor and $xpath->findnodes("//dsig:Signature")->size > 0) 26 19 45
Condition100%3/3
$trust_anchor and $xpath->findnodes("//dsig:Signature")->size > 0
!ll&&!rl&&r
17226
MC/DC100%2/2
$trust_anchor and $xpath->findnodes("//dsig:Signature")->size > 0
$trust_anchor $xpath->findnodes("//dsig:Signature")->size > 0
Truth table100%3/3
A and B
A= $trust_anchorB= $xpath->findnodes("//dsig:Signature")->size > 0
ABresult
0X0
100
111
398 26 ▶ my $verifier = Net::SAML2::XML::Sig->new({
Branch: 1 branch
BranchTrueFalseTotal
$cert_text ? : 11 15 26
399 x509 => 1,
400 $cert_text ? (cert_text => $cert_text) : (),
401 no_xml_declaration => 1,
402 });
403  
404 26 ▶ my $ok = try {
Subroutine __ANON__: called CC=1 SCAR=0.0
405 26 $verifier->verify($xml->toString)
406 0 ▶ } catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
407 0 croak("XML signature verification failed in new_from_xml ($_)");
408 26 };
409 # XML::Sig can croak or return 0 in event that the signature fails
410 26 ▶ croak("XML signature verification failed in new_from_xml")
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 7 19 26
411 unless $ok;
412 }
413  
414 $xml = $class->_verify_encrypted_assertion(
415 $xml,
416 $cacert,
417 $key_file,
418 $args{key_name},
419 38 $insecure_trust_embedded_cert,
420 $cert_text,
421 $require_signed_assertion,
422 );
423  
424 my $dec = $class->_decrypt(
425 $xml,
426 key_file => $key_file,
427 key_name => $args{key_name}
428 35 );
429 35 $xpath->setContextNode($dec);
430  
431 my @trusted_refs
432 35 = $class->_trusted_signature_refs($xpath, $cacert, $cert_text);
433 35 my $sig_count = $xpath->findnodes('//dsig:Signature')->size;
434 35 ▶ if ($trust_anchor && $sig_count > 0 && !@trusted_refs) {
Branch: 1 branch
BranchTrueFalseTotal
if ($trust_anchor and $sig_count > 0 and not @trusted_refs) 0 35 35
Condition83%5/6
$trust_anchor and $sig_count > 0 and not @trusted_refs
!ll&&!rl&&r
16190
$trust_anchor and $sig_count > 0
!ll&&!rl&&r
15119
MC/DC0%0/3
$trust_anchor and $sig_count > 0 and not @trusted_refs
$trust_anchor $sig_count > 0 not @trusted_refs
Truth table75%3/4
A and B and not(C)
A= $trust_anchorB= $sig_count > 0C= not @trusted_refs
ABCresult
0XX0
10X0
1100
1111
435 0 ▶ croak(
Branch: 1 branch
BranchTrueFalseTotal
$cacert ? : 0 0 0
436 "No <dsig:Signature> in the document validates against the "
437 . "configured " . ($cacert ? 'cacert' : 'cert_text')
438 . ". Refusing to extract assertion content."
439 );
440 }
441  
442 35 my @candidate_refs;
443 35 ▶ if (@trusted_refs) {
Branch: 1 branch
BranchTrueFalseTotal
if (@trusted_refs) { } 19 16 35
444 19 @candidate_refs = @trusted_refs;
445 }
446 else {
447 16 ▶ croak("No trusted signature found in the assertion. Pass "
Branch: 1 branch
BranchTrueFalseTotal
unless $insecure_trust_embedded_cert 0 16 16
448 . "insecure_trust_embedded_cert => 1 to new_from_xml() to trust "
449 . "embedded certificates (dev/test only).")
450 unless $insecure_trust_embedded_cert;
451  
452 16 my $ids = $xpath->findnodes('//saml:Assertion/@ID');
453 16 ▶ if ($ids->size == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ids->size == 1) 13 3 16
454 13 (my $ref = $ids->get_node(1)->value) =~ s/^#//;
455 13 ▶ @candidate_refs = ($ref) if length $ref;
Branch: 1 branch
BranchTrueFalseTotal
if length $ref 13 0 13
456 }
457 }
458  
459 35 my $assertion_node = $class->_get_trusted_assertion($xpath, \@candidate_refs);
460  
461 35 ▶ if ($trust_anchor && $sig_count > 0 && !$assertion_node) {
Branch: 1 branch
BranchTrueFalseTotal
if ($trust_anchor and $sig_count > 0 and not $assertion_node) 0 35 35
Condition83%5/6
$trust_anchor and $sig_count > 0 and not $assertion_node
!ll&&!rl&&r
16190
$trust_anchor and $sig_count > 0
!ll&&!rl&&r
15119
MC/DC0%0/3
$trust_anchor and $sig_count > 0 and not $assertion_node
$trust_anchor $sig_count > 0 not $assertion_node
Truth table75%3/4
A and B and not(C)
A= $trust_anchorB= $sig_count > 0C= not $assertion_node
ABCresult
0XX0
10X0
1100
1111
462 0 croak(
463 "XSW guard: no trusted signature anchors a <saml:Assertion>. "
464 . "Refusing to extract assertion content via document order."
465 );
466 }
467  
468 35 ▶ if (defined $destination && $assertion_node) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $destination and $assertion_node) 1 34 35
Condition66%2/3
defined $destination and $assertion_node
!ll&&!rl&&r
3401
MC/DC50%1/2
defined $destination and $assertion_node
defined $destination $assertion_node
Truth table66%2/3
A and B
A= defined $destinationB= $assertion_node
ABresult
0X0
100
111
469 1 my $recipient = $xpath->findvalue(
470 'saml:Subject/saml:SubjectConfirmation/saml:SubjectConfirmationData/@Recipient',
471 $assertion_node,
472 );
473 1 ▶ if (($recipient // '') ne $destination) {
Branch: 1 branch
BranchTrueFalseTotal
if (($recipient // "") ne $destination) 0 1 1
Condition50%1/2
$recipient // ""
l!l
10
MC/DC0%0/1
$recipient // ""
$recipient
Truth table50%1/2
A
A= $recipient
Aresult
11
00
474 0 croak(sprintf(
475 "Assertion SubjectConfirmationData/Recipient (%s) does "
476 . "not match expected destination (%s)",
477 $recipient, $destination,
478 ));
479 }
480 }
481  
482 35 ▶ die "Net::SAML2: no Assertion found in response\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $assertion_node or $xpath->exists("//saml:Assertion") 0 35 35
Condition66%2/3
$assertion_node or $xpath->exists("//saml:Assertion")
l!l&&r!l&&!r
3230
MC/DC0%0/2
$assertion_node or $xpath->exists("//saml:Assertion")
$assertion_node $xpath->exists("//saml:Assertion")
Truth table66%2/3
A or B
A= $assertion_nodeB= $xpath->exists("//saml:Assertion")
ABresult
1X1
011
000
483 unless $assertion_node || $xpath->exists('//saml:Assertion');
484  
485 35 my $attributes = {};
486 35 ▶ my @attr_owners = $assertion_node
Branch: 1 branch
BranchTrueFalseTotal
$assertion_node ? : 32 3 35
487 ? $xpath->findnodes(
488 './saml:AttributeStatement/saml:Attribute/saml:AttributeValue/..',
489 $assertion_node)
490 : $xpath->findnodes(
491 '//saml:Assertion/saml:AttributeStatement/saml:Attribute/saml:AttributeValue/..');
492 35 for my $node (@attr_owners) {
493 117 my @values = $xpath->findnodes("saml:AttributeValue", $node);
494 117 $attributes->{$node->getAttribute('Name')} = [map $_->string_value, @values];
495 }
496  
497 35 my $not_before = $class->_get_not_before($xpath, $assertion_node);
498 35 my $not_after = $class->_get_not_after($xpath, $assertion_node);
499 35 my $nameid = $class->_get_nameid($xpath, $assertion_node);
500 35 my $authnstatement = $class->_get_authnstatement($xpath, $assertion_node);
501 35 my $actual_issuer = $class->_get_actual_issuer($issuer, $xpath, $assertion_node);
502  
503 34 my $nodeset = $xpath->findnodes('/samlp:Response/samlp:Status/samlp:StatusCode|/samlp:ArtifactResponse/samlp:Status/samlp:StatusCode');
504  
505 34 ▶ croak("Unable to parse status from assertion") unless $nodeset->size;
Branch: 1 branch
BranchTrueFalseTotal
unless $nodeset->size 0 34 34
506  
507 34 my $status_node = $nodeset->get_node(1);
508 34 my $status = $status_node->getAttribute('Value');
509 34 my $substatus;
510  
511 34 ▶ if (my $s = first { $_->isa('XML::LibXML::Element') } $status_node->childNodes) {
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if (my $s = &first(sub { $_->isa("XML::LibXML::Element"); } , $status_node->childNodes)) 1 33 34
512 1 $substatus = $s->getAttribute('Value');
513 }
514  
515 34 ▶ my $self = $class->new(
Branch: 6 branches
BranchTrueFalseTotal
$nameid ? : 32 2 34
$substatus ? : 1 33 34
$authnstatement ? : 33 1 34
$cacert ? : 15 19 34
$cert_text ? : 6 28 34
$insecure_trust_embedded_cert ? : 16 18 34
516 id => $class->_get_id($xpath, $assertion_node),
517 issuer => $actual_issuer,
518 destination => $actual_destination,
519 attributes => $attributes,
520 session => $class->_get_session($xpath, $assertion_node),
521 $nameid ? (nameid => $nameid) : (),
522 audience => $class->_get_audience($xpath, $assertion_node),
523 not_before => $not_before,
524 not_after => $not_after,
525 xpath => $xpath,
526 in_response_to => $class->_get_in_response_to($xpath, $assertion_node),
527 response_status => $status,
528 $substatus ? (response_substatus => $substatus) : (),
529 $authnstatement ? (authnstatement => $authnstatement) : (),
530 $cacert ? (cacert => $cacert) : (),
531 $cert_text ? (cert_text => $cert_text) : (),
532 $insecure_trust_embedded_cert ? (insecure_trust_embedded_cert => $insecure_trust_embedded_cert) : (),
533 );
534  
535 34 return $self;
536 }
537  
538  
539  
540 0 ▶sub name {
Subroutine name: not called CC=1 SCAR=6.9
Pod documented
541 0 my $self = shift;
542 0 return $self->attributes->{CN}[0];
543 }
544  
545  
546 17 ▶sub nameid {
Subroutine nameid: called CC=2 SCAR=7.1
Pod documented
547 17 my $self = shift;
548 17 ▶ return unless $self->has_nameid;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_nameid 0 17 17
549 17 return $self->nameid_object->textContent;
550 }
551  
552  
553 1 ▶sub nameid_format {
Subroutine nameid_format: called CC=2 SCAR=7.1
Pod documented
554 1 my $self = shift;
555 1 ▶ return unless $self->has_nameid;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_nameid 0 1 1
556 1 return $self->nameid_object->getAttribute('Format');
557 }
558  
559  
560 1 ▶sub nameid_name_qualifier {
Subroutine nameid_name_qualifier: called CC=2 SCAR=7.1
Pod documented
561 1 my $self = shift;
562 1 ▶ return unless $self->has_nameid;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_nameid 0 1 1
563 1 return $self->nameid_object->getAttribute('NameQualifier');
564 }
565  
566  
567 1 ▶sub nameid_sp_name_qualifier {
Subroutine nameid_sp_name_qualifier: called CC=2 SCAR=7.1
Pod documented
568 1 my $self = shift;
569 1 ▶ return unless $self->has_nameid;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_nameid 0 1 1
570 1 return $self->nameid_object->getAttribute('SPNameQualifier');
571 }
572  
573  
574 1 ▶sub nameid_sp_provided_id {
Subroutine nameid_sp_provided_id: called CC=2 SCAR=7.1
Pod documented
575 1 my $self = shift;
576 1 ▶ return unless $self->has_nameid;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_nameid 0 1 1
577 1 return $self->nameid_object->getAttribute('SPProvidedID');
578 }
579  
580  
581 0 ▶sub authnstatement {
Subroutine authnstatement: not called CC=2 SCAR=17.9
Pod documented
582 0 my $self = shift;
583 0 ▶ return unless $self->has_authnstatement;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_authnstatement 0 0 0
584 0 return $self->authnstatement_object->textContent;
585 }
586  
587  
588 3 ▶sub authnstatement_authninstant {
Subroutine authnstatement_authninstant: called CC=2 SCAR=7.1
Pod documented
589 3 my $self = shift;
590 3 ▶ return unless $self->has_authnstatement;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_authnstatement 0 3 3
591 3 return $self->authnstatement_object->getAttribute('AuthnInstant');
592 }
593  
594  
595 3 ▶sub authnstatement_sessionindex {
Subroutine authnstatement_sessionindex: called CC=2 SCAR=7.1
Pod documented
596 3 my $self = shift;
597 3 ▶ return unless $self->has_authnstatement;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_authnstatement 0 3 3
598 3 return $self->authnstatement_object->getAttribute('SessionIndex');
599 }
600  
601  
602 6 ▶sub authnstatement_subjectlocality {
Subroutine authnstatement_subjectlocality: called CC=3 SCAR=11.0
Pod documented
603 6 my $self = shift;
604 6 ▶ return unless $self->has_authnstatement;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_authnstatement 0 6 6
605  
606 6 my $xpc = XML::LibXML::XPathContext->new;
607 6 $xpc->registerNs('saml', 'urn:oasis:names:tc:SAML:2.0:assertion');
608 6 my $subjectlocality;
609 6 my $xpath_base = '//saml:AuthnStatement/saml:SubjectLocality';
610 6 ▶ if (my $nodes = $xpc->find($xpath_base, $self->authnstatement_object)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $nodes = $xpc->find($xpath_base, $self->authnstatement_object)) 2 4 6
611 2 my $node = $nodes->get_node(1);
612 2 $subjectlocality = $node;
613 }
614 6 return $subjectlocality;
615 }
616  
617  
618 3 ▶sub subjectlocality_address {
Subroutine subjectlocality_address: called CC=3 SCAR=11.0
Pod documented
619 3 my $self = shift;
620 3 ▶ return unless $self->has_authnstatement;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_authnstatement 0 3 3
621 3 my $subjectlocality = $self->authnstatement_subjectlocality;
622 3 ▶ return unless $subjectlocality;
Branch: 1 branch
BranchTrueFalseTotal
unless $subjectlocality 2 1 3
623 1 return $subjectlocality->getAttribute('Address');
624 }
625  
626  
627 3 ▶sub subjectlocality_dnsname {
Subroutine subjectlocality_dnsname: called CC=3 SCAR=11.0
Pod documented
628 3 my $self = shift;
629 3 ▶ return unless $self->has_authnstatement;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_authnstatement 0 3 3
630 3 my $subjectlocality = $self->authnstatement_subjectlocality;
631 3 ▶ return unless $subjectlocality;
Branch: 1 branch
BranchTrueFalseTotal
unless $subjectlocality 2 1 3
632 1 return $subjectlocality->getAttribute('DNSName');
633 }
634  
635  
636 3 ▶sub authnstatement_authncontext {
Subroutine authnstatement_authncontext: called CC=3 SCAR=11.1
Pod documented
637 3 my $self = shift;
638 3 ▶ return unless $self->has_authnstatement;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_authnstatement 0 3 3
639  
640 3 my $xpc = XML::LibXML::XPathContext->new;
641 3 $xpc->registerNs('saml', 'urn:oasis:names:tc:SAML:2.0:assertion');
642 3 my $authncontext;
643 3 my $xpath_base = '//saml:AuthnStatement/saml:AuthnContext';
644 3 ▶ if (my $nodes = $xpc->find($xpath_base, $self->authnstatement_object)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $nodes = $xpc->find($xpath_base, $self->authnstatement_object)) 3 0 3
645 3 my $node = $nodes->get_node(1);
646 3 $authncontext = $node;
647 }
648 3 return $authncontext;
649 }
650  
651  
652 3 ▶sub contextclass_authncontextclassref {
Subroutine contextclass_authncontextclassref: called CC=4 SCAR=14.2
Pod documented
653 3 my $self = shift;
654 3 ▶ return unless $self->has_authnstatement;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_authnstatement 0 3 3
655 3 my $authncontextclassref = $self->authnstatement_authncontext;
656 3 ▶ return unless $authncontextclassref;
Branch: 1 branch
BranchTrueFalseTotal
unless $authncontextclassref 0 3 3
657 3 my $xpc = XML::LibXML::XPathContext->new;
658 3 $xpc->registerNs('saml', 'urn:oasis:names:tc:SAML:2.0:assertion');
659 3 ▶ if (my $value = $xpc->findvalue('//saml:AuthnContextClassRef', $self->authnstatement_object)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $value = $xpc->findvalue("//saml:AuthnContextClassRef", $self->authnstatement_object)) 3 0 3
660 3 $authncontextclassref = $value;
661 }
662 3 return $authncontextclassref;
663 }
664  
665  
666 28 ▶sub valid {
Subroutine valid: called CC=11 SCAR=24.0
Pod documented
667 28 my ($self, $audience, $in_response_to, $issuer, $destination) = @_;
668  
669 28 ▶ return 0 unless defined $audience;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $audience 0 28 28
670 28 ▶ return 0 unless($audience eq $self->audience);
Branch: 1 branch
BranchTrueFalseTotal
unless $audience eq $self->audience 6 22 28
671  
672 22 ▶ return 0 unless !defined $in_response_to
Branch: 1 branch
BranchTrueFalseTotal
unless not defined $in_response_to or $in_response_to eq $self->in_response_to 4 18 22
Condition100%3/3
not defined $in_response_to or $in_response_to eq $self->in_response_to
l!l&&r!l&&!r
7114
MC/DC100%2/2
not defined $in_response_to or $in_response_to eq $self->in_response_to
not defined $in_response_to $in_response_to eq $self->in_response_to
Truth table100%3/3
not(A) or B
A= not defined $in_response_toB= $in_response_to eq $self->in_response_to
ABresult
1X1
011
000
673 or $in_response_to eq $self->in_response_to;
674  
675 18 ▶ return 0 unless !defined $issuer
Branch: 1 branch
BranchTrueFalseTotal
unless not defined $issuer or $issuer eq $self->issuer 2 16 18
Condition100%3/3
not defined $issuer or $issuer eq $self->issuer
l!l&&r!l&&!r
1332
MC/DC100%2/2
not defined $issuer or $issuer eq $self->issuer
not defined $issuer $issuer eq $self->issuer
Truth table100%3/3
not(A) or B
A= not defined $issuerB= $issuer eq $self->issuer
ABresult
1X1
011
000
676 or $issuer eq $self->issuer;
677  
678 16 ▶ return 0 unless !defined $destination
Branch: 1 branch
BranchTrueFalseTotal
unless not defined $destination or $destination eq $self->destination 1 15 16
Condition100%3/3
not defined $destination or $destination eq $self->destination
l!l&&r!l&&!r
1411
MC/DC100%2/2
not defined $destination or $destination eq $self->destination
not defined $destination $destination eq $self->destination
Truth table100%3/3
not(A) or B
A= not defined $destinationB= $destination eq $self->destination
ABresult
1X1
011
000
679 or $destination eq $self->destination;
680  
681 15 my $now = DateTime::HiRes->now;
682  
683 # not_before is "NotBefore" element - exact match is ok
684 # not_after is "NotOnOrAfter" element - exact match is *not* ok
685 15 ▶ return 0 unless DateTime::->compare($now, $self->not_before) > -1;
Branch: 1 branch
BranchTrueFalseTotal
unless "DateTime"->compare($now, $self->not_before) > -1 4 11 15
686 11 ▶ return 0 unless DateTime::->compare($self->not_after, $now) > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless "DateTime"->compare($self->not_after, $now) > 0 2 9 11
687  
688 9 return 1;
689 }
690  
691  
692 1 ▶sub success {
Subroutine success: called CC=2 SCAR=7.1
Pod documented
693 1 my $self = shift;
694 1 ▶ return 1 if $self->response_status eq STATUS_SUCCESS;
Branch: 1 branch
BranchTrueFalseTotal
if $self->response_status eq "urn:oasis:names:tc:SAML:2.0:status:Success" 0 1 1
695 1 return 0;
696 }
697  
698 40 ▶sub _decrypt {
Subroutine _decrypt: called CC=2 SCAR=6.9
699 40 my $self = shift;
700 40 my $xml = shift;
701 40 my %options = @_;
702  
703 40 ▶ return $xml unless $options{key_file};
Branch: 1 branch
BranchTrueFalseTotal
unless $options{"key_file"} 31 9 40
704  
705 my $enc = XML::Enc->new(
706 {
707 no_xml_declaration => 1,
708 key => $options{key_file},
709 }
710 9 );
711 9 return no_comments($enc->decrypt($xml, %options));
712 }
713  
714 33 1;
715  
716 __END__
↑ Summary SAML2/Object/Response.pm »