SAML2/Role/VerifyXML.pm

filter: Statementstmt 94.2% 49 / 52 Branchbran 83.3% 15 / 18 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 91.6% 11 / 12 Podpod 100% 1 / 1 totaltotal 92.0% 81 / 88 CC 11 SCAR 18.2
CC
11
Cov
92%
verify_xml
11.2
__ANON__
2.0
__ANON__
1.0
CRAP 6.2
« SAML2/Binding/Redirect.pm ↑ Summary SAML2/IdP.pm »
1 package Net::SAML2::Role::VerifyXML;
2 33 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 33 our $VERSION = '0.89'; # VERSION
4  
5 33 ▶use Net::SAML2::XML::Sig;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 33 ▶use Crypt::OpenSSL::Verify;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 33 ▶use Crypt::OpenSSL::X509;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 33 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 33 ▶use List::Util qw(none);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 33 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # ABSTRACT: A role to verify the SAML response XML
13  
14  
15  
16  
17 17 ▶sub verify_xml {
Subroutine verify_xml: called CC=11 SCAR=24.2
Pod documented
18 17 my $self = shift;
19 17 my $xml = shift;
20 17 my %args = @_;
21  
22 17 my $cacert = delete $args{cacert};
23 17 my $anchors = delete $args{anchors};
24  
25 17 my $x = Net::SAML2::XML::Sig->new({
26 x509 => 1,
27 %args,
28 });
29  
30 17 ▶ croak("XML signature check failed") unless $x->verify($xml);
Branch: 1 branch
BranchTrueFalseTotal
unless $x->verify($xml) 1 15 16
31  
32 15 ▶ return if !$anchors && !$cacert;
Branch: 1 branch
BranchTrueFalseTotal
unless $anchors or $cacert 3 12 15
Condition100%3/3
$anchors or $cacert
l!l&&r!l&&!r
573
MC/DC100%2/2
$anchors or $cacert
$anchors $cacert
Truth table100%3/3
A or B
A= $anchorsB= $cacert
ABresult
1X1
011
000
33  
34 12 ▶ my $cert = $x->signer_cert
Branch: 1 branch
BranchTrueFalseTotal
my $cert = $x->signer_cert or die "Certificate not provided in SAML Response, cannot validate\n" 12 0 12
35 or die "Certificate not provided in SAML Response, cannot validate\n";
36  
37 12 ▶ if ($cacert) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cacert) 7 5 12
38 7 my $ca = Crypt::OpenSSL::Verify->new($cacert, { strict_certs => 0 });
39 7 ▶ try { $ca->verify($cert) }
Subroutine __ANON__: called CC=1 SCAR=0.0
40 0 ▶ catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
41 0 croak("Could not verify CA certificate: $_");
42 7 };
43 }
44  
45 12 ▶ return if !$anchors;
Branch: 1 branch
BranchTrueFalseTotal
unless $anchors 7 5 12
46  
47 5 ▶ if (ref $anchors ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $anchors ne "HASH") 0 5 5
48 0 croak("Unable to verify anchor trust");
49 }
50  
51 5 my ($key) = keys %$anchors;
52 5 ▶ if (none { $key eq $_ } qw(subject issuer issuer_hash)) {
Subroutine __ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
if (&none(sub { $key eq $_; } , "subject", "issuer", "issuer_hash")) 0 5 5
53 0 croak("Unable to verify anchor trust, requires subject, issuer or issuer_hash");
54 }
55  
56 5 my $got = $cert->$key;
57 5 my $want = $anchors->{$key};
58 5 ▶ if (!ref $want) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $want) 3 2 5
59 3 $want = [ $want ];
60 }
61  
62 5 ▶ if (none { $_ eq $got } @$want) {
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if (&none(sub { $_ eq $got; } , @$want)) 1 4 5
63 1 croak("Could not verify trust anchors of certificate!");
64 }
65 4 return;
66  
67 }
68  
69  
70 33 1;
71  
72 __END__
« SAML2/Binding/Redirect.pm ↑ Summary SAML2/IdP.pm »