xs/response.xs

filter: Statementstmt 89.8% 44 / 49 Branchbran 60.8% 28 / 46 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 75.7% 72 / 95 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« include/psaml/psaml_boot.h ↑ Summary include/psaml/psaml_flow.h »
1 MODULE = Punk::SAML PACKAGE = Punk::SAML::Response
2  
3 # verify($bytes, %opts): the decoded XML in, an identity hashref out, or a
4 # Punk::SAML::Error thrown.
5 #
6 # No application and no request. The ACS route in phase 8 is a thin
7 # wrapper that supplies now, acs_url, entity_id, the keys and the flow
8 # from configuration; `punk saml verify` is another; and the suite is a
9 # third, running this a thousand times with none of the three.
10 SV *
11 verify(class, bytes, ...)
12 SV *class
13 SV *bytes
14 ALIAS:
15 _verify_field = 1
16 CODE:
17 HV *a;
18 psaml_checks o;
19 SV *v;
20 int i;
21 PERL_UNUSED_VAR(class);
22 397 ▶ if ((items - 2) % 2)
Branch: 1 branch
BranchTrueFalseTotal
if ((items - 2) % 2) 0 397 397
23 0 croak("%s: Response->verify takes bytes and a list of pairs",
24 PSAML_WHO);
25 397 a = newHV();
26 397 sv_2mortal((SV *)a);
27 3053 ▶ for (i = 2; i + 1 < items; i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 2; i + 1 < items; i += 2) { 2656 397 3053
28 STRLEN kl;
29 2656 const char *k = SvPV_const(ST(i), kl);
30 2656 (void)hv_store(a, k, (I32)kl, newSVsv(ST(i + 1)), 0);
31 }
32  
33 /* _verify_field is verify with the transport in front of it: the
34 * size cap on the ENCODED field, then the strict base64. It is an
35 * ALIAS rather than a wrapper that re-enters verify through
36 * call_method - the wrapper was written first, and pushing the
37 * caller\'s own arguments back onto the stack it was reading them
38 * from produced a freed-string panic. One body, two names. */
39 397 ▶ if (ix == 1)
Branch: 1 branch
BranchTrueFalseTotal
if (ix == 1) 40 357 397
40 40 bytes = sv_2mortal(psaml_decode_field(aTHX_ bytes,
41 psaml_opt_iv(aTHX_ a, "max_response", 262144)));
42  
43 397 Zero(&o, 1, psaml_checks);
44 397 v = psaml_hget(aTHX_ a, "idp");
45 794 ▶ o.idp_name = (v && SvOK(v)) ? SvPV_nolen(v) : "";
Branch: 2 branches
BranchTrueFalseTotal
o.idp_name = (v && SvOK(v)) ? SvPV_nolen(v) : ""; 397 0 397
o.idp_name = (v && SvOK(v)) ? SvPV_nolen(v) : ""; 397 0 397
46 397 v = psaml_hget(aTHX_ a, "entity_id");
47 397 ▶ if (!v || !SvOK(v))
Branch: 2 branches
BranchTrueFalseTotal
if (!v || !SvOK(v)) 397 0 397
if (!v || !SvOK(v)) 0 397 397
48 0 croak("%s: Response->verify needs `entity_id`, this "
49 "application's own", PSAML_WHO);
50 397 o.entity_id = SvPV_nolen(v);
51 397 v = psaml_hget(aTHX_ a, "idp_entity_id");
52 397 ▶ if (!v || !SvOK(v))
Branch: 2 branches
BranchTrueFalseTotal
if (!v || !SvOK(v)) 397 0 397
if (!v || !SvOK(v)) 0 397 397
53 0 croak("%s: Response->verify needs `idp_entity_id`, the "
54 "provider's", PSAML_WHO);
55 397 o.idp_entity_id = SvPV_nolen(v);
56 397 v = psaml_hget(aTHX_ a, "acs_url");
57 397 ▶ if (!v || !SvOK(v))
Branch: 2 branches
BranchTrueFalseTotal
if (!v || !SvOK(v)) 397 0 397
if (!v || !SvOK(v)) 0 397 397
58 0 croak("%s: Response->verify needs `acs_url`", PSAML_WHO);
59 397 o.acs_url = SvPV_nolen(v);
60  
61 397 v = psaml_hget(aTHX_ a, "certs");
62 397 ▶ if (!v || !SvROK(v) || SvTYPE(SvRV(v)) != SVt_PVAV)
Branch: 3 branches
BranchTrueFalseTotal
if (!v || !SvROK(v) || SvTYPE(SvRV(v)) != SVt_PVAV) 397 0 397
if (!v || !SvROK(v) || SvTYPE(SvRV(v)) != SVt_PVAV) 397 0 397
if (!v || !SvROK(v) || SvTYPE(SvRV(v)) != SVt_PVAV) 0 397 397
63 0 croak("%s: Response->verify needs `certs`, an arrayref of the "
64 "provider's signing certificates", PSAML_WHO);
65 397 o.keys = (AV *)SvRV(v);
66  
67 397 v = psaml_hget(aTHX_ a, "now");
68 397 ▶ o.now = (v && SvOK(v)) ? SvIV(v) : (IV)time(NULL);
Branch: 2 branches
BranchTrueFalseTotal
o.now = (v && SvOK(v)) ? SvIV(v) : (IV)time(NULL); 45 352 397
o.now = (v && SvOK(v)) ? SvIV(v) : (IV)time(NULL); 45 0 45
69 397 o.skew = psaml_opt_iv(aTHX_ a, "skew", 120);
70 397 o.allow_sha1 = psaml_opt_bool(aTHX_ a, "allow_sha1", 0);
71 397 o.allow_idp_initiated =
72 397 psaml_opt_bool(aTHX_ a, "allow_idp_initiated", 0);
73 397 v = psaml_hget(aTHX_ a, "require_signed");
74 442 ▶ o.require_signed = (v && SvOK(v)) ? SvPV_nolen(v) : "either";
Branch: 2 branches
BranchTrueFalseTotal
o.require_signed = (v && SvOK(v)) ? SvPV_nolen(v) : "either"; 45 352 397
o.require_signed = (v && SvOK(v)) ? SvPV_nolen(v) : "either"; 45 0 45
75 397 o.flow_id = psaml_hget(aTHX_ a, "in_response_to");
76 397 o.seen_cb = psaml_hget(aTHX_ a, "seen");
77  
78 397 RETVAL = psaml_verify_response(aTHX_ bytes, &o);
79 OUTPUT:
80 RETVAL
81  
82 # _replayed($c, $seen, $identity, $skew): true if this assertion has been
83 # presented before.
84 #
85 # The route's half of the replay check, and NOT part of verify: verify
86 # takes its own `seen` coderef and has no application to find a cache in,
87 # while this has a context and reaches the `cache` store through it.
88 #
89 # Croaks when it cannot tell. The ACS calls it under G_EVAL and turns
90 # that into a `config` refusal, because a store that cannot be reached
91 # must not produce the same login as an assertion that is fresh.
92 IV
93 _replayed(class, c, seen, identity, skew)
94 SV *class
95 SV *c
96 SV *seen
97 SV *identity
98 IV skew
99 CODE:
100 PERL_UNUSED_VAR(class);
101 185 ▶ RETVAL = psaml_replayed(aTHX_ c, seen, identity, skew);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = psaml_replayed(aTHX_ c, seen, identity, skew); 104 27 131
102 OUTPUT:
103 RETVAL
104  
105 MODULE = Punk::SAML PACKAGE = Punk::SAML
106  
107 # Sign raw bytes, for the suite's fixture builder. The same gap phase 5
108 # hit from the other side: jws_abi signs arbitrary bytes but Crypt::JWS's
109 # Perl surface only makes compact tokens, so a Perl harness that has to
110 # produce an XML-DSig SignatureValue has no way in without this.
111 SV *
112 _sign_bytes(priv_pem, alg, input)
113 SV *priv_pem
114 SV *alg
115 SV *input
116 CODE:
117 95 const jws_abi *J = psaml_jws(aTHX);
118 STRLEN pl, al, il;
119 95 ▶ const char *pp = SvPVbyte(priv_pem, pl);
Branch: 1 branch
BranchTrueFalseTotal
const char *pp = SvPVbyte(priv_pem, pl); 95 0 95
120 95 ▶ const char *ap = SvPVbyte(alg, al);
Branch: 1 branch
BranchTrueFalseTotal
const char *ap = SvPVbyte(alg, al); 95 0 95
121 95 const char *ip = SvPVbyte(input, il);
122 95 void *k = J->key_from_pem(aTHX_ pp, pl);
123 95 ▶ if (!k) croak("%s: the private key will not parse", PSAML_WHO);
Branch: 1 branch
BranchTrueFalseTotal
if (!k) croak("%s: the private key will not parse", PSAML_WHO); 0 95 95
124 95 RETVAL = J->sign(aTHX_ k, ap, al, (const unsigned char *)ip, il);
125 95 J->key_free(aTHX_ k);
126 95 ▶ if (!RETVAL) croak("%s: signing failed", PSAML_WHO);
Branch: 1 branch
BranchTrueFalseTotal
if (!RETVAL) croak("%s: signing failed", PSAML_WHO); 0 95 95
127 OUTPUT:
128 RETVAL
129  
« include/psaml/psaml_boot.h ↑ Summary include/psaml/psaml_flow.h »