include/psaml/psaml_boot.h

filter: Statementstmt 88.9% 634 / 713 Branchbran 58.1% 415 / 714 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 73.5% 1049 / 1427 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« PSAML.c ↑ Summary xs/response.xs »
1 #ifndef PSAML_BOOT_H
2 #define PSAML_BOOT_H
3  
4 /* Boot: the options, the three keywords, the two helpers, and what each
5 * records on the application hash.
6 *
7 * This header builds the SURFACE. It mounts no routes, writes no cookie
8 * and consumes no assertion: phase 8 reads what is recorded here and
9 * mounts the four routes. The split is deliberate and it is what makes
10 * this phase testable with no HTTP at all.
11 *
12 * State lives as keys on the application's own hash rather than in a
13 * struct, which is what punk_sitemap.h and pfeed_*.h do and for the same
14 * reason: the application is already the thing whose lifetime this state
15 * shares, and a struct would be a second one to keep in step with it.
16 *
17 * punk_saml.opts the validated option hash
18 * punk_saml.idps HV of name -> the provider's config
19 * punk_saml.idp_order AV of names, in declaration order
20 * punk_saml.login HV of path, on_login, on_error
21 * punk_saml.mount the normalised login mount
22 * punk_saml.acs the assertion consumer URL, at on_compile
23 * punk_saml.entity_id the entity id, at on_compile
24 *
25 * Must be included after psaml_reg.h. */
26  
27 #include "psaml_reg.h"
28 #include "psaml_error.h"
29 #include "psaml_idp.h"
30 #include "psaml_metadata.h"
31 #include "psaml_flow.h"
32 #include "psaml_request.h"
33  
34 /* The `cache` store the replay check uses when `seen` does not name
35 * another, and Punk's own name for its unnamed store. */
36 #define PSAML_DEFAULT_CACHE "default"
37  
38 static const char *const PSAML_OPTS[] = {
39 "secret", "entity_id", "prefix", "key", "cert",
40 "sign_requests", "sign_metadata", "require_signed", "skew",
41 "flow_ttl", "max_response", "allow_sha1", "allow_idp_initiated",
42 "default_to", "name_id_format", "force_authn", "metadata",
43 "metadata_refresh", "render", "seen", "allow_replay", NULL
44 };
45  
46 static const char *const PSAML_IDP_OPTS[] = {
47 "metadata", "entity_id", "sso_url", "certs", NULL
48 };
49  
50 static const char *const PSAML_LOGIN_OPTS[] = {
51 "on_login", "on_error", NULL
52 };
53  
54 /* ---- the options ------------------------------------------------------ */
55  
56 /* Validated and normalised at the `plugin` line, with two exceptions that
57 * cannot be settled until on_compile: entity_id, which defaults to the
58 * metadata URL and so needs `host`, and the ACS URL, which needs `host`
59 * and the login mount. `host` may be declared on either side of the
60 * plugin line, so neither may be read here. */
61 49 PERL_STATIC_INLINE HV *psaml_opts(pTHX_ SV *app, SV *optsv) {
62 49 ▶ HV *in = psaml_is_hash(aTHX_ optsv) ? (HV *)SvRV(optsv) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
HV *in = psaml_is_hash(aTHX_ optsv) ? (HV *)SvRV(optsv) : NULL; 49 0 49
63 49 HV *out = newHV();
64 SV *v;
65  
66 49 psaml_check_opts(aTHX_ "option", in, PSAML_OPTS);
67  
68 /* secret. Croaks here rather than at the first login, because a plugin
69 * that mints one per worker fails one login in four the moment a
70 * redirect lands on a worker other than the one that started it, and
71 * that failure looks like an intermittent identity-provider fault
72 * rather than a missing option. Punk-Push and Punk-Challenge both paid
73 * for this lesson already. A list is accepted so a key can be rotated
74 * with both live. */
75 48 v = psaml_hget(aTHX_ in, "secret");
76 48 ▶ if (!v || !SvOK(v) || (!SvROK(v) && !SvCUR(v)))
Branch: 4 branches
BranchTrueFalseTotal
if (!v || !SvOK(v) || (!SvROK(v) && !SvCUR(v))) 47 1 48
if (!v || !SvOK(v) || (!SvROK(v) && !SvCUR(v))) 47 0 47
if (!v || !SvOK(v) || (!SvROK(v) && !SvCUR(v))) 45 2 47
if (!v || !SvOK(v) || (!SvROK(v) && !SvCUR(v))) 0 45 45
77 1 croak("%s: `secret` is required - it signs the flow cookie, and a "
78 "secret minted per worker fails one login in four. Generate one "
79 "with `punk saml key` and keep it with the application's other "
80 "secrets", PSAML_WHO);
81 47 ▶ if (psaml_is_array(aTHX_ v)) {
Branch: 1 branch
BranchTrueFalseTotal
if (psaml_is_array(aTHX_ v)) { 1 46 47
82 1 AV *keys = (AV *)SvRV(v);
83 1 ▶ if (av_len(keys) < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (av_len(keys) < 0) 1 0 1
84 1 croak("%s: `secret` was an empty list", PSAML_WHO);
85 0 (void)hv_stores(out, "secret", newSVsv(v));
86 }
87 46 ▶ else if (SvROK(v)) {
Branch: 1 branch
BranchTrueFalseTotal
else if (SvROK(v)) { 1 45 46
88 1 croak("%s: `secret` takes a string, or a list of them to rotate",
89 PSAML_WHO);
90 }
91 else {
92 45 (void)hv_stores(out, "secret", newSVsv(v));
93 }
94  
95 /* prefix */
96 45 v = psaml_hget(aTHX_ in, "prefix");
97 45 ▶ (void)hv_stores(out, "prefix",
Branch: 3 branches
BranchTrueFalseTotal
(void)hv_stores(out, "prefix", 0 45 45
(void)hv_stores(out, "prefix", 0 0 0
(void)hv_stores(out, "prefix", 0 0 0
98 (v && SvOK(v) && SvCUR(v)) ? newSVsv(v)
99 : newSVpvs("/saml"));
100  
101 /* require_signed. The whole point of the plugin is the signature, so
102 * an unrecognised word here is refused rather than defaulted: a
103 * misspelling that quietly meant `either` would be a weaker check than
104 * the deployer asked for, silently. */
105 {
106 45 SV *r = psaml_hget(aTHX_ in, "require_signed");
107 45 const char *rp = "either";
108 45 STRLEN rl = 6;
109 46 ▶ if (r && SvOK(r)) rp = SvPV_const(r, rl);
Branch: 2 branches
BranchTrueFalseTotal
if (r && SvOK(r)) rp = SvPV_const(r, rl); 1 44 45
if (r && SvOK(r)) rp = SvPV_const(r, rl); 1 0 1
110 45 ▶ if (!((rl == 9 && memEQ(rp, "assertion", 9))
Branch: 2 branches
BranchTrueFalseTotal
if (!((rl == 9 && memEQ(rp, "assertion", 9)) 0 45 45
if (!((rl == 9 && memEQ(rp, "assertion", 9)) 0 0 0
111 45 ▶ || (rl == 8 && memEQ(rp, "response", 8))
Branch: 2 branches
BranchTrueFalseTotal
|| (rl == 8 && memEQ(rp, "response", 8)) 0 45 45
|| (rl == 8 && memEQ(rp, "response", 8)) 0 0 0
112 45 ▶ || (rl == 6 && memEQ(rp, "either", 6))
Branch: 2 branches
BranchTrueFalseTotal
|| (rl == 6 && memEQ(rp, "either", 6)) 44 1 45
|| (rl == 6 && memEQ(rp, "either", 6)) 0 44 44
113 1 ▶ || (rl == 4 && memEQ(rp, "both", 4))))
Branch: 2 branches
BranchTrueFalseTotal
|| (rl == 4 && memEQ(rp, "both", 4)))) 0 1 1
|| (rl == 4 && memEQ(rp, "both", 4)))) 0 0 0
114 1 croak("%s: `require_signed` takes assertion, response, either or "
115 "both, not '%.*s'", PSAML_WHO, (int)rl, rp);
116 44 (void)hv_stores(out, "require_signed", newSVpvn(rp, rl));
117 }
118  
119 44 (void)hv_stores(out, "skew", newSViv(psaml_opt_uv(aTHX_ in, "skew", 120)));
120 43 (void)hv_stores(out, "flow_ttl",
121 newSViv(psaml_opt_uv(aTHX_ in, "flow_ttl", 600)));
122 43 (void)hv_stores(out, "max_response",
123 newSViv(psaml_opt_uv(aTHX_ in, "max_response", 262144)));
124 43 (void)hv_stores(out, "metadata_refresh",
125 newSViv(psaml_opt_uv(aTHX_ in, "metadata_refresh", 3600)));
126  
127 /* the booleans, normalised so nothing downstream reads a string */
128 {
129 static const char *const flags[] = {
130 "sign_requests", "sign_metadata", "allow_sha1",
131 "allow_idp_initiated", "force_authn", "allow_replay", NULL
132 };
133 int i;
134 301 ▶ for (i = 0; flags[i]; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; flags[i]; i++) 258 43 301
135 258 (void)hv_store(out, flags[i], (I32)strlen(flags[i]),
136 newSViv(psaml_opt_bool(aTHX_ in, flags[i], 0)), 0);
137 /* metadata defaults ON: an SP that does not publish its metadata has
138 * to be configured by hand at the other end, every time */
139 43 (void)hv_stores(out, "metadata",
140 newSViv(psaml_opt_bool(aTHX_ in, "metadata", 1)));
141 }
142  
143 /* the pass-through strings and callbacks */
144 {
145 static const char *const keep[] = {
146 "entity_id", "key", "cert", "default_to", "name_id_format",
147 "render", "seen", NULL
148 };
149 int i;
150 344 ▶ for (i = 0; keep[i]; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; keep[i]; i++) { 301 43 344
151 301 SV *k = psaml_hget(aTHX_ in, keep[i]);
152 301 ▶ if (k && SvOK(k))
Branch: 2 branches
BranchTrueFalseTotal
if (k && SvOK(k)) 7 294 301
if (k && SvOK(k)) 7 0 7
153 7 (void)hv_store(out, keep[i], (I32)strlen(keep[i]), newSVsv(k), 0);
154 }
155 43 ▶ if (!hv_exists(out, "default_to", 10))
Branch: 1 branch
BranchTrueFalseTotal
if (!hv_exists(out, "default_to", 10)) 43 0 43
156 43 (void)hv_stores(out, "default_to", newSVpvs("/"));
157 }
158  
159 /* An option that silently does nothing is worse than one that refuses:
160 * a deployer who wrote sign_requests and got unsigned requests has been
161 * told the opposite of the truth by their own configuration. */
162 43 ▶ if (SvTRUE(*hv_fetchs(out, "sign_requests", 0)) && !hv_exists(out, "key", 3))
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(*hv_fetchs(out, "sign_requests", 0)) && !hv_exists(out, "key", 3)) 1 42 43
if (SvTRUE(*hv_fetchs(out, "sign_requests", 0)) && !hv_exists(out, "key", 3)) 1 0 1
163 1 croak("%s: `sign_requests` needs `key`, the SP private key in PEM",
164 PSAML_WHO);
165 42 ▶ if (SvTRUE(*hv_fetchs(out, "sign_metadata", 0))
Branch: 1 branch
BranchTrueFalseTotal
if (SvTRUE(*hv_fetchs(out, "sign_metadata", 0)) 1 41 42
166 1 ▶ && !(hv_exists(out, "key", 3) && hv_exists(out, "cert", 4)))
Branch: 2 branches
BranchTrueFalseTotal
&& !(hv_exists(out, "key", 3) && hv_exists(out, "cert", 4))) 1 0 1
&& !(hv_exists(out, "key", 3) && hv_exists(out, "cert", 4))) 1 0 1
167 1 croak("%s: `sign_metadata` needs `key` and `cert`", PSAML_WHO);
168  
169 {
170 41 SV *r = psaml_hget(aTHX_ out, "render");
171 41 ▶ if (r && SvROK(r) && !psaml_is_code(aTHX_ r))
Branch: 3 branches
BranchTrueFalseTotal
if (r && SvROK(r) && !psaml_is_code(aTHX_ r)) 0 41 41
if (r && SvROK(r) && !psaml_is_code(aTHX_ r)) 0 0 0
if (r && SvROK(r) && !psaml_is_code(aTHX_ r)) 0 0 0
172 0 croak("%s: `render` takes a coderef or the name of a context method",
173 PSAML_WHO);
174 }
175  
176 /* `seen`, the replay store.
177 *
178 * A coderef is a store of the application's own; a string names one of
179 * the `cache` keyword's stores, and the default is the default store.
180 * The default is a NAME rather than nothing because an SP that cannot
181 * detect a replayed assertion is not conformant - Profiles section
182 * 4.1.4.5 makes the check a MUST - and the deployment that configures
183 * nothing is exactly the one that needs it. on_compile checks that the
184 * named store is actually declared. */
185 {
186 41 SV *s = psaml_hget(aTHX_ out, "seen");
187 int use_default;
188 41 ▶ if (s && SvROK(s) && !psaml_is_code(aTHX_ s))
Branch: 3 branches
BranchTrueFalseTotal
if (s && SvROK(s) && !psaml_is_code(aTHX_ s)) 5 36 41
if (s && SvROK(s) && !psaml_is_code(aTHX_ s)) 3 2 5
if (s && SvROK(s) && !psaml_is_code(aTHX_ s)) 1 2 3
189 1 croak("%s: `seen` takes a coderef or the name of a `cache` store",
190 PSAML_WHO);
191 40 ▶ if (!s || !SvOK(s)) use_default = 1;
Branch: 2 branches
BranchTrueFalseTotal
if (!s || !SvOK(s)) use_default = 1; 4 36 40
if (!s || !SvOK(s)) use_default = 1; 0 4 4
192 4 ▶ else if (SvROK(s)) use_default = 0;
Branch: 1 branch
BranchTrueFalseTotal
else if (SvROK(s)) use_default = 0; 2 2 4
193 2 else use_default = SvCUR(s) ? 0 : 1;
194 40 ▶ if (use_default)
Branch: 1 branch
BranchTrueFalseTotal
if (use_default) 36 4 40
195 36 (void)hv_stores(out, "seen", newSVpvs(PSAML_DEFAULT_CACHE));
196 }
197  
198 PERL_UNUSED_ARG(app);
199 40 return out;
200 }
201  
202 /* ---- host ------------------------------------------------------------- */
203  
204 /* The declared origin, which must exist and must be https.
205 *
206 * The request is never consulted. The assertion consumer URL derives from
207 * this and the identity provider compares it against what it was
208 * configured with character for character, so a plugin that guessed the
209 * host from a request header would be letting the request choose which
210 * URL counts as this application.
211 *
212 * https because the phase-8 flow cookie carries SameSite=None, which is
213 * the only value a browser sends on the cross-site POST from the
214 * provider, and which browsers drop without Secure. The croak is loud
215 * because the alternative is silent: a plain-http deployment boots
216 * happily and then fails at every ACS with `unsolicited`, with nothing in
217 * the log to say why. */
218 31 PERL_STATIC_INLINE SV *psaml_host(pTHX_ SV *app) {
219 31 SV *host = psaml_can(aTHX_ app, "host")
220 31 ▶ ? sv_2mortal(psaml_call(aTHX_ app, "host", NULL, 0)) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
? sv_2mortal(psaml_call(aTHX_ app, "host", NULL, 0)) : NULL; 31 0 31
221 31 STRLEN hl = 0;
222 const char *hp;
223 31 ▶ if (!host || !SvOK(host) || !SvCUR(host))
Branch: 3 branches
BranchTrueFalseTotal
if (!host || !SvOK(host) || !SvCUR(host)) 30 1 31
if (!host || !SvOK(host) || !SvCUR(host)) 30 0 30
if (!host || !SvOK(host) || !SvCUR(host)) 0 30 30
224 1 croak("%s: this application has no `host`. The assertion consumer URL "
225 "derives from it and the identity provider compares that URL "
226 "character for character, so it cannot be guessed from a "
227 "request", PSAML_WHO);
228 30 hp = SvPV_const(host, hl);
229 30 ▶ if (!(hl > 8 && memEQ(hp, "https://", 8)))
Branch: 2 branches
BranchTrueFalseTotal
if (!(hl > 8 && memEQ(hp, "https://", 8))) 30 0 30
if (!(hl > 8 && memEQ(hp, "https://", 8))) 1 29 30
230 1 croak("%s: `host` must be https, not '%.*s'. The flow cookie is "
231 "SameSite=None, which is the only value sent on the cross-site "
232 "POST from the provider, and which browsers drop without "
233 "Secure. Over http every login fails at the ACS as "
234 "`unsolicited`", PSAML_WHO, (int)hl, hp);
235 29 return host;
236 }
237  
238 /* An origin and a path joined with exactly one slash between them. */
239 28 PERL_STATIC_INLINE SV *psaml_join_url(pTHX_ SV *base, const char *path) {
240 STRLEN bl;
241 28 const char *bp = SvPV_const(base, bl);
242 SV *out;
243 28 ▶ while (bl && bp[bl - 1] == '/') bl--;
Branch: 2 branches
BranchTrueFalseTotal
while (bl && bp[bl - 1] == '/') bl--; 28 0 28
while (bl && bp[bl - 1] == '/') bl--; 0 28 28
244 28 out = newSVpvn(bp, bl);
245 28 ▶ if (*path != '/') sv_catpvs(out, "/");
Branch: 1 branch
BranchTrueFalseTotal
if (*path != '/') sv_catpvs(out, "/"); 0 28 28
246 28 sv_catpv(out, path);
247 28 return out;
248 }
249  
250 /* The login mount, normalised: a leading slash, no trailing one. The
251 * recorded value and the routes phase 8 mounts must be the same string,
252 * so there is one place that decides what it looks like. */
253 36 PERL_STATIC_INLINE SV *psaml_mount_path(pTHX_ SV *path) {
254 STRLEN pl;
255 const char *pp;
256 SV *out;
257 36 ▶ if (!path || !SvOK(path) || !SvCUR(path))
Branch: 3 branches
BranchTrueFalseTotal
if (!path || !SvOK(path) || !SvCUR(path)) 36 0 36
if (!path || !SvOK(path) || !SvCUR(path)) 36 0 36
if (!path || !SvOK(path) || !SvCUR(path)) 0 36 36
258 0 croak("%s: saml_login needs a path to mount under", PSAML_WHO);
259 36 pp = SvPV_const(path, pl);
260 37 ▶ while (pl > 1 && pp[pl - 1] == '/') pl--;
Branch: 2 branches
BranchTrueFalseTotal
while (pl > 1 && pp[pl - 1] == '/') pl--; 37 0 37
while (pl > 1 && pp[pl - 1] == '/') pl--; 1 36 37
261 36 out = newSVpvs("");
262 36 ▶ if (*pp != '/') sv_catpvs(out, "/");
Branch: 1 branch
BranchTrueFalseTotal
if (*pp != '/') sv_catpvs(out, "/"); 0 36 36
263 36 sv_catpvn(out, pp, pl);
264 36 return out;
265 }
266  
267 /* ---- saml_idp --------------------------------------------------------- */
268  
269 XS_INTERNAL(psaml_kw_idp);
270 42 XS_INTERNAL(psaml_kw_idp) {
271 42 dXSARGS;
272 42 SV *app = psaml_cap_slot(aTHX_ cv, 0);
273 HV *cfg, *in;
274 HV *idps;
275 AV *order;
276 SV *name, *conf;
277 SV *meta, *ent, *sso, *certs;
278 STRLEN nl;
279 const char *np;
280  
281 42 ▶ if (!app) { PERL_UNUSED_VAR(ax); XSRETURN_EMPTY; }
Branch: 1 branch
BranchTrueFalseTotal
if (!app) { PERL_UNUSED_VAR(ax); XSRETURN_EMPTY; } 0 42 42
282 42 ▶ if (items < 1 || !SvOK(ST(0)) || SvROK(ST(0)))
Branch: 3 branches
BranchTrueFalseTotal
if (items < 1 || !SvOK(ST(0)) || SvROK(ST(0))) 42 0 42
if (items < 1 || !SvOK(ST(0)) || SvROK(ST(0))) 42 0 42
if (items < 1 || !SvOK(ST(0)) || SvROK(ST(0))) 0 42 42
283 0 croak("%s: saml_idp takes a name and a hashref", PSAML_WHO);
284 42 name = ST(0);
285 42 np = SvPV_const(name, nl);
286 42 ▶ if (items < 2 || !psaml_is_hash(aTHX_ ST(1)))
Branch: 2 branches
BranchTrueFalseTotal
if (items < 2 || !psaml_is_hash(aTHX_ ST(1))) 42 0 42
if (items < 2 || !psaml_is_hash(aTHX_ ST(1))) 0 42 42
287 0 croak("%s: saml_idp '%.*s' needs a hashref of settings",
288 PSAML_WHO, (int)nl, np);
289 42 in = (HV *)SvRV(ST(1));
290 42 psaml_check_opts(aTHX_ "saml_idp setting", in, PSAML_IDP_OPTS);
291  
292 41 meta = psaml_hget(aTHX_ in, "metadata");
293 41 ent = psaml_hget(aTHX_ in, "entity_id");
294 41 sso = psaml_hget(aTHX_ in, "sso_url");
295 41 certs = psaml_hget(aTHX_ in, "certs");
296  
297 /* The two forms are exclusive and giving both croaks, rather than
298 * letting one silently win. Which one won would decide which key
299 * verifies the assertion, and a deployer who supplied both believes
300 * whichever they wrote last. */
301 41 ▶ if (meta && SvOK(meta) && (ent || sso || certs))
Branch: 5 branches
BranchTrueFalseTotal
if (meta && SvOK(meta) && (ent || sso || certs)) 18 23 41
if (meta && SvOK(meta) && (ent || sso || certs)) 18 0 18
if (meta && SvOK(meta) && (ent || sso || certs)) 18 0 18
if (meta && SvOK(meta) && (ent || sso || certs)) 17 1 18
if (meta && SvOK(meta) && (ent || sso || certs)) 0 17 17
302 1 croak("%s: saml_idp '%.*s' gives both `metadata` and the explicit "
303 "entity_id/sso_url/certs. They are exclusive: one of them would "
304 "decide which key verifies an assertion, and it would not be "
305 "obvious which", PSAML_WHO, (int)nl, np);
306 40 ▶ if (!(meta && SvOK(meta))) {
Branch: 2 branches
BranchTrueFalseTotal
if (!(meta && SvOK(meta))) { 17 23 40
if (!(meta && SvOK(meta))) { 0 17 17
307 23 ▶ if (!(ent && SvOK(ent)) || !(sso && SvOK(sso)) || !certs)
Branch: 5 branches
BranchTrueFalseTotal
if (!(ent && SvOK(ent)) || !(sso && SvOK(sso)) || !certs) 22 1 23
if (!(ent && SvOK(ent)) || !(sso && SvOK(sso)) || !certs) 22 0 22
if (!(ent && SvOK(ent)) || !(sso && SvOK(sso)) || !certs) 22 0 22
if (!(ent && SvOK(ent)) || !(sso && SvOK(sso)) || !certs) 22 0 22
if (!(ent && SvOK(ent)) || !(sso && SvOK(sso)) || !certs) 0 22 22
308 1 croak("%s: saml_idp '%.*s' needs either `metadata`, or all three of "
309 "`entity_id`, `sso_url` and `certs`", PSAML_WHO, (int)nl, np);
310 }
311  
312 39 idps = (HV *)SvRV(psaml_app_hash(aTHX_ app, PSAML_K_IDPS));
313 39 order = (AV *)SvRV(psaml_app_array(aTHX_ app, PSAML_K_IDPORDER));
314  
315 39 ▶ if (hv_exists(idps, np, (I32)nl))
Branch: 1 branch
BranchTrueFalseTotal
if (hv_exists(idps, np, (I32)nl)) 1 38 39
316 1 croak("%s: saml_idp '%.*s' is declared twice. Two providers under one "
317 "name is a configuration nobody meant", PSAML_WHO, (int)nl, np);
318  
319 38 cfg = newHV();
320 38 (void)hv_stores(cfg, "name", newSVsv(name));
321 38 ▶ if (meta && SvOK(meta)) (void)hv_stores(cfg, "metadata", newSVsv(meta));
Branch: 2 branches
BranchTrueFalseTotal
if (meta && SvOK(meta)) (void)hv_stores(cfg, "metadata", newSVsv(meta)); 16 22 38
if (meta && SvOK(meta)) (void)hv_stores(cfg, "metadata", newSVsv(meta)); 16 0 16
322 38 ▶ if (ent && SvOK(ent)) (void)hv_stores(cfg, "entity_id", newSVsv(ent));
Branch: 2 branches
BranchTrueFalseTotal
if (ent && SvOK(ent)) (void)hv_stores(cfg, "entity_id", newSVsv(ent)); 22 16 38
if (ent && SvOK(ent)) (void)hv_stores(cfg, "entity_id", newSVsv(ent)); 22 0 22
323 38 ▶ if (sso && SvOK(sso)) (void)hv_stores(cfg, "sso_url", newSVsv(sso));
Branch: 2 branches
BranchTrueFalseTotal
if (sso && SvOK(sso)) (void)hv_stores(cfg, "sso_url", newSVsv(sso)); 22 16 38
if (sso && SvOK(sso)) (void)hv_stores(cfg, "sso_url", newSVsv(sso)); 22 0 22
324 38 ▶ if (certs) {
Branch: 1 branch
BranchTrueFalseTotal
if (certs) { 22 16 38
325 /* normalised to an arrayref here, so phase 7 reads one shape */
326 22 ▶ if (psaml_is_array(aTHX_ certs)) {
Branch: 1 branch
BranchTrueFalseTotal
if (psaml_is_array(aTHX_ certs)) { 18 4 22
327 18 (void)hv_stores(cfg, "certs", newSVsv(certs));
328 }
329 4 ▶ else if (SvROK(certs)) {
Branch: 1 branch
BranchTrueFalseTotal
else if (SvROK(certs)) { 0 4 4
330 0 croak("%s: saml_idp '%.*s': `certs` takes a PEM or an arrayref of "
331 "them", PSAML_WHO, (int)nl, np);
332 }
333 else {
334 4 AV *av = newAV();
335 4 av_push(av, newSVsv(certs));
336 4 (void)hv_stores(cfg, "certs", newRV_noinc((SV *)av));
337 }
338 }
339 38 conf = newRV_noinc((SV *)cfg);
340 38 (void)hv_store(idps, np, (I32)nl, conf, 0);
341 38 av_push(order, newSVsv(name));
342  
343 /* Nothing is fetched here. `metadata` is a URL and this is the plugin
344 * line: a network call at compile time would make an application that
345 * cannot boot when the provider is briefly down. Phase 7 fetches at
346 * on_compile. */
347 38 XSRETURN_EMPTY;
348 }
349  
350 /* ---- saml_login ------------------------------------------------------- */
351  
352 XS_INTERNAL(psaml_kw_login);
353 37 XS_INTERNAL(psaml_kw_login) {
354 37 dXSARGS;
355 37 SV *app = psaml_cap_slot(aTHX_ cv, 0);
356 HV *in, *rec;
357 SV *on_login, *on_error, *mount;
358  
359 37 ▶ if (!app) { PERL_UNUSED_VAR(ax); XSRETURN_EMPTY; }
Branch: 1 branch
BranchTrueFalseTotal
if (!app) { PERL_UNUSED_VAR(ax); XSRETURN_EMPTY; } 0 37 37
360  
361 /* Declared once. Any number of providers live under one mount, and a
362 * second mount would mean two ACS URLs, only one of which any given
363 * provider was configured with. */
364 37 ▶ if (psaml_app_get(aTHX_ app, PSAML_K_LOGIN))
Branch: 1 branch
BranchTrueFalseTotal
if (psaml_app_get(aTHX_ app, PSAML_K_LOGIN)) 1 36 37
365 1 croak("%s: saml_login is declared twice. One application has one login "
366 "mount; every saml_idp lives under it", PSAML_WHO);
367  
368 36 ▶ if (items < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (items < 1) 0 36 36
369 0 croak("%s: saml_login takes a path and a hashref", PSAML_WHO);
370 36 mount = psaml_mount_path(aTHX_ ST(0));
371 36 ▶ if (items < 2 || !psaml_is_hash(aTHX_ ST(1))) {
Branch: 2 branches
BranchTrueFalseTotal
if (items < 2 || !psaml_is_hash(aTHX_ ST(1))) { 36 0 36
if (items < 2 || !psaml_is_hash(aTHX_ ST(1))) { 0 36 36
372 0 SvREFCNT_dec(mount);
373 0 croak("%s: saml_login needs a hashref with `on_login`", PSAML_WHO);
374 }
375 36 in = (HV *)SvRV(ST(1));
376 36 psaml_check_opts(aTHX_ "saml_login setting", in, PSAML_LOGIN_OPTS);
377  
378 36 on_login = psaml_hget(aTHX_ in, "on_login");
379 36 ▶ if (!psaml_is_code(aTHX_ on_login)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!psaml_is_code(aTHX_ on_login)) { 2 34 36
380 2 SvREFCNT_dec(mount);
381 2 croak("%s: saml_login needs `on_login`, a coderef called with the "
382 "context and the verified identity", PSAML_WHO);
383 }
384 34 on_error = psaml_hget(aTHX_ in, "on_error");
385 34 ▶ if (on_error && SvOK(on_error) && !psaml_is_code(aTHX_ on_error)) {
Branch: 3 branches
BranchTrueFalseTotal
if (on_error && SvOK(on_error) && !psaml_is_code(aTHX_ on_error)) { 15 19 34
if (on_error && SvOK(on_error) && !psaml_is_code(aTHX_ on_error)) { 15 0 15
if (on_error && SvOK(on_error) && !psaml_is_code(aTHX_ on_error)) { 1 14 15
386 1 SvREFCNT_dec(mount);
387 1 croak("%s: saml_login's `on_error` takes a coderef", PSAML_WHO);
388 }
389  
390 33 rec = newHV();
391 33 (void)hv_stores(rec, "path", SvREFCNT_inc_simple_NN(mount));
392 33 (void)hv_stores(rec, "on_login", newSVsv(on_login));
393 33 ▶ if (on_error && SvOK(on_error))
Branch: 2 branches
BranchTrueFalseTotal
if (on_error && SvOK(on_error)) 14 19 33
if (on_error && SvOK(on_error)) 14 0 14
394 14 (void)hv_stores(rec, "on_error", newSVsv(on_error));
395  
396 33 psaml_app_set(aTHX_ app, PSAML_K_LOGIN, newRV_noinc((SV *)rec));
397 33 psaml_app_set(aTHX_ app, PSAML_K_MOUNT, mount);
398  
399 /* No routes here. Phase 8 mounts them at on_compile, where `host` is
400 * certainly declared and the ACS URL can be computed once. */
401 33 XSRETURN_EMPTY;
402 }
403  
404 /* ---- the helpers ------------------------------------------------------ */
405  
406 XS_INTERNAL(psaml_help_idps);
407 1 XS_INTERNAL(psaml_help_idps) {
408 1 dXSARGS;
409 1 SV *app = psaml_cap_slot(aTHX_ cv, 0);
410 1 ▶ SV *ordsv = app ? psaml_app_get(aTHX_ app, PSAML_K_IDPORDER) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
SV *ordsv = app ? psaml_app_get(aTHX_ app, PSAML_K_IDPORDER) : NULL; 1 0 1
411 AV *order;
412 SSize_t i, n;
413 PERL_UNUSED_VAR(items);
414 1 ▶ if (!ordsv || !SvROK(ordsv)) XSRETURN_EMPTY;
Branch: 2 branches
BranchTrueFalseTotal
if (!ordsv || !SvROK(ordsv)) XSRETURN_EMPTY; 1 0 1
if (!ordsv || !SvROK(ordsv)) XSRETURN_EMPTY; 0 1 1
415 1 order = (AV *)SvRV(ordsv);
416 1 n = av_len(order) + 1;
417 1 SP -= items;
418 1 ▶ EXTEND(SP, n);
Branch: 2 branches
BranchTrueFalseTotal
EXTEND(SP, n); 1 0 1
EXTEND(SP, n); 0 1 1
419 3 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 2 1 3
420 2 SV **e = av_fetch(order, i, 0);
421 2 ▶ PUSHs(sv_2mortal(newSVsv(e && *e ? *e : &PL_sv_undef)));
Branch: 2 branches
BranchTrueFalseTotal
PUSHs(sv_2mortal(newSVsv(e && *e ? *e : &PL_sv_undef))); 2 0 2
PUSHs(sv_2mortal(newSVsv(e && *e ? *e : &PL_sv_undef))); 2 0 2
422 }
423 1 PUTBACK;
424 1 return;
425 }
426  
427 XS_INTERNAL(psaml_help_url);
428 3 XS_INTERNAL(psaml_help_url) {
429 3 dXSARGS;
430 3 SV *app = psaml_cap_slot(aTHX_ cv, 0);
431 SV *mount, *idps, *out;
432 STRLEN nl;
433 const char *np;
434 SSize_t i;
435  
436 3 ▶ if (!app || items < 2)
Branch: 2 branches
BranchTrueFalseTotal
if (!app || items < 2) 3 0 3
if (!app || items < 2) 0 3 3
437 0 croak("%s: saml_url takes a provider name", PSAML_WHO);
438 3 ▶ if (!SvOK(ST(1)) || SvROK(ST(1)))
Branch: 2 branches
BranchTrueFalseTotal
if (!SvOK(ST(1)) || SvROK(ST(1))) 3 0 3
if (!SvOK(ST(1)) || SvROK(ST(1))) 0 3 3
439 0 croak("%s: saml_url takes a provider name", PSAML_WHO);
440 3 np = SvPV_const(ST(1), nl);
441  
442 3 idps = psaml_app_get(aTHX_ app, PSAML_K_IDPS);
443 3 mount = psaml_app_get(aTHX_ app, PSAML_K_MOUNT);
444 3 ▶ if (!mount)
Branch: 1 branch
BranchTrueFalseTotal
if (!mount) 0 3 3
445 0 croak("%s: saml_url needs a saml_login mount", PSAML_WHO);
446  
447 /* An unknown provider croaks naming the configured ones. This is
448 * called from a template, and the alternative to a croak is an anchor
449 * with an href that 404s, which looks like a broken provider rather
450 * than a typo in the page. */
451 3 ▶ if (!(idps && SvROK(idps) && hv_exists((HV *)SvRV(idps), np, (I32)nl))) {
Branch: 3 branches
BranchTrueFalseTotal
if (!(idps && SvROK(idps) && hv_exists((HV *)SvRV(idps), np, (I32)nl))) { 3 0 3
if (!(idps && SvROK(idps) && hv_exists((HV *)SvRV(idps), np, (I32)nl))) { 3 0 3
if (!(idps && SvROK(idps) && hv_exists((HV *)SvRV(idps), np, (I32)nl))) { 1 2 3
452 1 SV *known = sv_2mortal(newSVpvs(""));
453 1 SV *ordsv = psaml_app_get(aTHX_ app, PSAML_K_IDPORDER);
454 1 ▶ if (ordsv && SvROK(ordsv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (ordsv && SvROK(ordsv)) { 1 0 1
if (ordsv && SvROK(ordsv)) { 1 0 1
455 1 AV *order = (AV *)SvRV(ordsv);
456 3 ▶ for (i = 0; i <= av_len(order); i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i <= av_len(order); i++) { 2 1 3
457 2 SV **e = av_fetch(order, i, 0);
458 2 ▶ if (i) sv_catpvs(known, ", ");
Branch: 1 branch
BranchTrueFalseTotal
if (i) sv_catpvs(known, ", "); 1 1 2
459 2 ▶ if (e && *e) sv_catsv(known, *e);
Branch: 2 branches
BranchTrueFalseTotal
if (e && *e) sv_catsv(known, *e); 2 0 2
if (e && *e) sv_catsv(known, *e); 2 0 2
460 }
461 }
462 2 ▶ croak("%s: no saml_idp named '%.*s' (configured: %s)", PSAML_WHO,
Branch: 1 branch
BranchTrueFalseTotal
croak("%s: no saml_idp named '%.*s' (configured: %s)", PSAML_WHO, 1 0 1
463 (int)nl, np, SvCUR(known) ? SvPV_nolen(known) : "none");
464 }
465  
466 2 out = newSVsv(mount);
467 2 sv_catpvs(out, "/login/");
468 2 sv_catpvn(out, np, nl);
469  
470 /* `to` is recorded on the query string here and goes through
471 * $c->safe_path in phase 8, where it is used. It is not sanitised
472 * twice: one place decides, and that place is the one that acts on it. */
473 2 ▶ if (items > 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (items > 2) { 1 1 2
474 int j;
475 1 int first = 1;
476 2 ▶ for (j = 2; j + 1 < items; j += 2) {
Branch: 1 branch
BranchTrueFalseTotal
for (j = 2; j + 1 < items; j += 2) { 1 1 2
477 STRLEN kl, vl;
478 1 const char *kp = SvPV_const(ST(j), kl);
479 1 ▶ const char *vp = SvPV_const(ST(j + 1), vl);
Branch: 1 branch
BranchTrueFalseTotal
const char *vp = SvPV_const(ST(j + 1), vl); 1 0 1
480 STRLEN q;
481 1 sv_catpvs(out, "");
482 1 ▶ sv_catpvn(out, first ? "?" : "&", 1);
Branch: 1 branch
BranchTrueFalseTotal
sv_catpvn(out, first ? "?" : "&", 1); 1 0 1
483 1 first = 0;
484 1 sv_catpvn(out, kp, kl);
485 1 sv_catpvs(out, "=");
486 13 ▶ for (q = 0; q < vl; q++) {
Branch: 1 branch
BranchTrueFalseTotal
for (q = 0; q < vl; q++) { 12 1 13
487 12 unsigned char c = (unsigned char)vp[q];
488 12 ▶ if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')
Branch: 4 branches
BranchTrueFalseTotal
if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') 8 4 12
if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') 8 0 8
if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') 8 4 12
if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') 0 8 8
489 4 ▶ || (c >= '0' && c <= '9') || c == '-' || c == '_'
Branch: 4 branches
BranchTrueFalseTotal
|| (c >= '0' && c <= '9') || c == '-' || c == '_' 3 1 4
|| (c >= '0' && c <= '9') || c == '-' || c == '_' 2 1 3
|| (c >= '0' && c <= '9') || c == '-' || c == '_' 3 0 3
|| (c >= '0' && c <= '9') || c == '-' || c == '_' 3 0 3
490 3 ▶ || c == '.' || c == '~') {
Branch: 2 branches
BranchTrueFalseTotal
|| c == '.' || c == '~') { 3 0 3
|| c == '.' || c == '~') { 0 3 3
491 9 sv_catpvn(out, (const char *)&c, 1);
492 }
493 else {
494 char esc[4];
495 3 my_snprintf(esc, sizeof esc, "%%%02X", c);
496 3 sv_catpvn(out, esc, 3);
497 }
498 }
499 }
500 }
501  
502 2 SP -= items;
503 2 ▶ XPUSHs(sv_2mortal(out));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(out)); 0 2 2
504 2 PUTBACK;
505 2 return;
506 }
507  
508 /* ---- the boot fetch --------------------------------------------------- */
509  
510 /* Metadata bytes, from wherever the provider's `metadata` points.
511 *
512 * A `file:` URL or a bare path is read here; an http(s) URL goes through
513 * the fetch table on an agent built with ua_new, and the future is
514 * resolved BLOCKING, because this runs at on_compile, before the server
515 * forks. Fetch 0.23 is the floor because it pid-stamps its loop: a loop
516 * created in the parent and inherited by every worker is a hang this
517 * family has already recorded once.
518 *
519 * A FAILURE HERE IS A CROAK, not a warning. An application whose only
520 * login is SAML cannot sign anyone in without its provider, and refusing
521 * to boot says so at deploy time, in the deploy log, to the person
522 * deploying. A warning says it at the first login, to a user, as a 403,
523 * hours later, to somebody who cannot act on it. */
524 /* The fetch table's map callback: shape the settled request into a
525 * [status, body] pair. Must not croak, and must return a +1 SV. */
526 0 static SV *psaml_fetch_map(pTHX_ int ok, int status, AV *headers,
527 SV *body, SV *err, void *ud) {
528 0 AV *out = newAV();
529 PERL_UNUSED_ARG(headers);
530 PERL_UNUSED_ARG(err);
531 PERL_UNUSED_ARG(ud);
532 0 ▶ av_push(out, newSViv(ok ? status : 0));
Branch: 1 branch
BranchTrueFalseTotal
av_push(out, newSViv(ok ? status : 0)); 0 0 0
533 0 ▶ av_push(out, (ok && body && SvOK(body)) ? newSVsv(body) : newSV(0));
Branch: 3 branches
BranchTrueFalseTotal
av_push(out, (ok && body && SvOK(body)) ? newSVsv(body) : newSV(0)); 0 0 0
av_push(out, (ok && body && SvOK(body)) ? newSVsv(body) : newSV(0)); 0 0 0
av_push(out, (ok && body && SvOK(body)) ? newSVsv(body) : newSV(0)); 0 0 0
534 0 return newRV_noinc((SV *)out);
535 }
536  
537 11 PERL_STATIC_INLINE SV *psaml_fetch_metadata(pTHX_ SV *app, SV *src,
538 const char *idp_name) {
539 STRLEN sl;
540 11 const char *sp = SvPVbyte(src, sl);
541 11 ▶ int is_http = (sl > 7 && memEQ(sp, "http://", 7))
Branch: 1 branch
BranchTrueFalseTotal
int is_http = (sl > 7 && memEQ(sp, "http://", 7)) 11 0 11
542 22 ▶ || (sl > 8 && memEQ(sp, "https://", 8));
Branch: 3 branches
BranchTrueFalseTotal
|| (sl > 8 && memEQ(sp, "https://", 8)); 11 0 11
|| (sl > 8 && memEQ(sp, "https://", 8)); 11 0 11
|| (sl > 8 && memEQ(sp, "https://", 8)); 0 11 11
543  
544 11 ▶ if (!is_http) {
Branch: 1 branch
BranchTrueFalseTotal
if (!is_http) { 11 0 11
545 /* file:/path or a bare path */
546 11 const char *path = sp;
547 11 STRLEN pl = sl;
548 PerlIO *fh;
549 SV *out;
550 11 ▶ if (pl > 5 && memEQ(path, "file:", 5)) { path += 5; pl -= 5; }
Branch: 2 branches
BranchTrueFalseTotal
if (pl > 5 && memEQ(path, "file:", 5)) { path += 5; pl -= 5; } 11 0 11
if (pl > 5 && memEQ(path, "file:", 5)) { path += 5; pl -= 5; } 11 0 11
551 {
552 11 SV *pn = sv_2mortal(newSVpvn(path, pl));
553 11 fh = PerlIO_open(SvPV_nolen(pn), "rb");
554 11 ▶ if (!fh)
Branch: 1 branch
BranchTrueFalseTotal
if (!fh) 0 11 11
555 0 croak("%s: saml_idp '%s': cannot read metadata from %s: %s",
556 PSAML_WHO, idp_name, SvPV_nolen(pn), Strerror(errno));
557 }
558 11 out = newSVpvs("");
559 {
560 char buf[8192];
561 SSize_t n;
562 22 ▶ while ((n = PerlIO_read(fh, buf, sizeof buf)) > 0)
Branch: 1 branch
BranchTrueFalseTotal
while ((n = PerlIO_read(fh, buf, sizeof buf)) > 0) 11 11 22
563 11 sv_catpvn(out, buf, (STRLEN)n);
564 }
565 11 PerlIO_close(fh);
566 11 return out;
567 }
568  
569 {
570 0 const fetch_abi *FE = psaml_fetch(aTHX);
571 SV *kv[4];
572 SV *ua, *future, *res;
573  
574 0 kv[0] = sv_2mortal(newSVpvs("timeout"));
575 0 kv[1] = sv_2mortal(newSVnv(10.0));
576 0 kv[2] = sv_2mortal(newSVpvs("tls_verify"));
577 0 kv[3] = sv_2mortal(newSViv(1));
578 0 ua = FE->ua_new(aTHX_ kv, 4);
579 0 ▶ if (!ua)
Branch: 1 branch
BranchTrueFalseTotal
if (!ua) 0 0 0
580 0 croak("%s: saml_idp '%s': could not build a user agent to fetch "
581 "metadata", PSAML_WHO, idp_name);
582 0 sv_2mortal(ua);
583  
584 /* `map` is invoked UNCONDITIONALLY by the table, with no NULL guard,
585 * so it must always be passed. Passing NULL is a SEGV at the first
586 * boot fetch, which is a long way from where it looks like it came
587 * from. Punk-OAuth2's pox_http.h says this in a comment; this dist
588 * learned it the other way. */
589 0 future = FE->request(aTHX_ ua, "GET", SvPV_nolen(src), NULL, 0,
590 NULL, 0, 10.0, -1, psaml_fetch_map, NULL);
591 0 ▶ if (!future)
Branch: 1 branch
BranchTrueFalseTotal
if (!future) 0 0 0
592 0 croak("%s: saml_idp '%s': the metadata request could not be made",
593 PSAML_WHO, idp_name);
594 0 sv_2mortal(future);
595  
596 /* resolved blocking: this is boot, there is no loop to yield to yet,
597 * and the whole point is that the application does not start without
598 * its provider */
599 0 res = psaml_call(aTHX_ future, "get", NULL, 0);
600 0 ▶ if (!res)
Branch: 1 branch
BranchTrueFalseTotal
if (!res) 0 0 0
601 0 croak("%s: saml_idp '%s': fetching %s produced no response",
602 PSAML_WHO, idp_name, SvPV_nolen(src));
603 0 sv_2mortal(res);
604  
605 /* the map above shaped it into [status, body] */
606 {
607 AV *pair;
608 SV **st, **bd;
609 IV status;
610 0 ▶ if (!SvROK(res) || SvTYPE(SvRV(res)) != SVt_PVAV)
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(res) || SvTYPE(SvRV(res)) != SVt_PVAV) 0 0 0
if (!SvROK(res) || SvTYPE(SvRV(res)) != SVt_PVAV) 0 0 0
611 0 croak("%s: saml_idp '%s': fetching %s produced no usable response",
612 PSAML_WHO, idp_name, SvPV_nolen(src));
613 0 pair = (AV *)SvRV(res);
614 0 st = av_fetch(pair, 0, 0);
615 0 bd = av_fetch(pair, 1, 0);
616 0 ▶ status = (st && *st) ? SvIV(*st) : 0;
Branch: 2 branches
BranchTrueFalseTotal
status = (st && *st) ? SvIV(*st) : 0; 0 0 0
status = (st && *st) ? SvIV(*st) : 0; 0 0 0
617 0 ▶ if (status < 200 || status > 299)
Branch: 2 branches
BranchTrueFalseTotal
if (status < 200 || status > 299) 0 0 0
if (status < 200 || status > 299) 0 0 0
618 0 croak("%s: saml_idp '%s': fetching %s answered %" IVdf,
619 PSAML_WHO, idp_name, SvPV_nolen(src), status);
620 0 ▶ if (!bd || !*bd || !SvOK(*bd) || !SvCUR(*bd))
Branch: 4 branches
BranchTrueFalseTotal
if (!bd || !*bd || !SvOK(*bd) || !SvCUR(*bd)) 0 0 0
if (!bd || !*bd || !SvOK(*bd) || !SvCUR(*bd)) 0 0 0
if (!bd || !*bd || !SvOK(*bd) || !SvCUR(*bd)) 0 0 0
if (!bd || !*bd || !SvOK(*bd) || !SvCUR(*bd)) 0 0 0
621 0 croak("%s: saml_idp '%s': fetching %s answered an empty body",
622 PSAML_WHO, idp_name, SvPV_nolen(src));
623 PERL_UNUSED_ARG(app);
624 0 return newSVsv(*bd);
625 }
626 }
627 }
628  
629  
630 /* Metadata bytes into a provider's recorded configuration.
631 *
632 * Shared by the boot resolution and the rotation refetch below, so a
633 * provider re-read mid-run ends up with exactly the configuration it
634 * would have had at boot. Two code paths filling the same hash by
635 * different rules would be a bug that could only appear after a key
636 * rotation, which is the least observable moment there is. */
637 11 PERL_STATIC_INLINE void psaml_idp_merge(pTHX_ HV *cfg, SV *bytes, HV *opts) {
638 11 SV *want = psaml_hget(aTHX_ cfg, "entity_id");
639 13 ▶ SV *read = psaml_idp_from_metadata(aTHX_ bytes,
Branch: 1 branch
BranchTrueFalseTotal
SV *read = psaml_idp_from_metadata(aTHX_ bytes, 2 9 11
640 4 ▶ (want && SvOK(want)) ? SvPV_nolen(want) : NULL,
Branch: 1 branch
BranchTrueFalseTotal
(want && SvOK(want)) ? SvPV_nolen(want) : NULL, 2 0 2
641 psaml_opt_bool(aTHX_ opts, "enforce_cert_validity", 0));
642 11 HV *got = (HV *)SvRV(read);
643 HE *he;
644 11 sv_2mortal(read);
645 11 hv_iterinit(got);
646 77 ▶ while ((he = hv_iternext(got))) {
Branch: 1 branch
BranchTrueFalseTotal
while ((he = hv_iternext(got))) { 66 11 77
647 STRLEN kl;
648 66 ▶ const char *k = HePV(he, kl);
Branch: 1 branch
BranchTrueFalseTotal
const char *k = HePV(he, kl); 0 66 66
649 66 (void)hv_store(cfg, k, (I32)kl, newSVsv(HeVAL(he)), 0);
650 }
651 11 }
652  
653  
654 /* ---- the rotation refetch ---------------------------------------------- */
655  
656 /* A provider that rotates its signing key signs the next assertion with a
657 * certificate this application has never seen. Every login then fails
658 * with `bad_signature` until somebody notices and redeploys - an outage
659 * caused by the far side doing something routine that it announced only
660 * in its metadata.
661 *
662 * So: one re-read of the metadata, on the failure, and one retry.
663 *
664 * ONLY for a provider configured from `metadata`. An explicit
665 * entity_id/sso_url/certs trio is what the deployer typed, and this dist
666 * does not overwrite it from the network.
667 *
668 * RATE LIMITED, and that is the security half rather than a politeness.
669 * `bad_signature` is also exactly what a forged Response produces, so an
670 * unlimited refetch would let anybody make this application fetch a URL
671 * as fast as they can POST to the ACS. `metadata_refresh` is the floor
672 * between two refetches, and the stamp is written BEFORE the fetch so a
673 * provider that hangs until the timeout cannot leave the limit unset.
674 *
675 * PER WORKER: the stamp lives on the provider's configuration hash, of
676 * which every worker holds its own copy after the fork. A deployment with
677 * N workers therefore allows at most N refetches per interval. That is
678 * the same bound the replay store lives with, and it is written down
679 * here because it is the kind of thing that looks like a leak later.
680 *
681 * CROAKS on a fetch failure, so the caller must be inside a G_EVAL: a
682 * provider that is down during somebody's login must produce a refused
683 * login, never a 500. */
684 6 PERL_STATIC_INLINE int psaml_idp_refetch(pTHX_ SV *app, HV *opts,
685 SV *idp_name, HV *cfg, IV now) {
686 6 SV *meta = psaml_hget(aTHX_ cfg, "metadata");
687 SV **le;
688 IV every, last;
689 SV *bytes;
690  
691 6 ▶ if (!meta || !SvOK(meta)) return 0; /* an explicit trio */
Branch: 2 branches
BranchTrueFalseTotal
if (!meta || !SvOK(meta)) return 0; /* an explicit trio */ 4 2 6
if (!meta || !SvOK(meta)) return 0; /* an explicit trio */ 0 4 4
692 4 ▶ if (!idp_name || !SvOK(idp_name)) return 0;
Branch: 2 branches
BranchTrueFalseTotal
if (!idp_name || !SvOK(idp_name)) return 0; 4 0 4
if (!idp_name || !SvOK(idp_name)) return 0; 0 4 4
693  
694 4 every = psaml_opt_iv(aTHX_ opts, "metadata_refresh", 3600);
695 4 ▶ if (every <= 0) return 0; /* turned off deliberately */
Branch: 1 branch
BranchTrueFalseTotal
if (every <= 0) return 0; /* turned off deliberately */ 1 3 4
696  
697 3 le = hv_fetchs(cfg, "last_refresh", 0);
698 3 ▶ last = (le && *le && SvOK(*le)) ? SvIV(*le) : 0;
Branch: 3 branches
BranchTrueFalseTotal
last = (le && *le && SvOK(*le)) ? SvIV(*le) : 0; 1 2 3
last = (le && *le && SvOK(*le)) ? SvIV(*le) : 0; 1 0 1
last = (le && *le && SvOK(*le)) ? SvIV(*le) : 0; 1 0 1
699 3 ▶ if (last && now - last < every) return 0;
Branch: 2 branches
BranchTrueFalseTotal
if (last && now - last < every) return 0; 1 2 3
if (last && now - last < every) return 0; 1 0 1
700  
701 2 (void)hv_stores(cfg, "last_refresh", newSViv(now));
702  
703 2 bytes = sv_2mortal(psaml_fetch_metadata(aTHX_ app, meta,
704 SvPV_nolen(idp_name)));
705 2 psaml_idp_merge(aTHX_ cfg, bytes, opts);
706 2 return 1;
707 }
708  
709  
710 /* Is this failure one a key rotation would explain?
711 *
712 * `bad_signature` is a signature no configured key verifies, and
713 * `no_key` is no configured key at all. Both are answered by reading the
714 * metadata again. `bad_digest` is NOT: the signature verified and the
715 * content did not match it, which is tampering, and refetching would be
716 * fetching a URL on an attacker's say-so for no possible benefit. */
717 11 PERL_STATIC_INLINE int psaml_rotation_explains(pTHX_ SV *err) {
718 SV *code;
719 11 ▶ if (!err || !SvROK(err) || SvTYPE(SvRV(err)) != SVt_PVHV) return 0;
Branch: 3 branches
BranchTrueFalseTotal
if (!err || !SvROK(err) || SvTYPE(SvRV(err)) != SVt_PVHV) return 0; 11 0 11
if (!err || !SvROK(err) || SvTYPE(SvRV(err)) != SVt_PVHV) return 0; 11 0 11
if (!err || !SvROK(err) || SvTYPE(SvRV(err)) != SVt_PVHV) return 0; 0 11 11
720 11 code = psaml_hget(aTHX_ (HV *)SvRV(err), "code");
721 11 ▶ if (!code || !SvOK(code)) return 0;
Branch: 2 branches
BranchTrueFalseTotal
if (!code || !SvOK(code)) return 0; 11 0 11
if (!code || !SvOK(code)) return 0; 0 11 11
722 11 return strEQ(SvPV_nolen(code), PSAML_E_BAD_SIGNATURE)
723 16 ▶ || strEQ(SvPV_nolen(code), PSAML_E_NO_KEY);
Branch: 2 branches
BranchTrueFalseTotal
|| strEQ(SvPV_nolen(code), PSAML_E_NO_KEY); 5 6 11
|| strEQ(SvPV_nolen(code), PSAML_E_NO_KEY); 0 5 5
724 }
725  
726  
727 /* ---- the routes -------------------------------------------------------- */
728  
729 /* WantAssertionsSigned in the published metadata reflects what this
730 * application actually requires. `response` alone is the one setting that
731 * does not require a signed assertion. */
732 14 PERL_STATIC_INLINE int psaml_want_assertions_signed(pTHX_ HV *opts) {
733 14 SV *r = psaml_hget(aTHX_ opts, "require_signed");
734 28 ▶ return !(r && SvOK(r) && strEQ(SvPV_nolen(r), "response"));
Branch: 3 branches
BranchTrueFalseTotal
return !(r && SvOK(r) && strEQ(SvPV_nolen(r), "response")); 14 0 14
return !(r && SvOK(r) && strEQ(SvPV_nolen(r), "response")); 14 0 14
return !(r && SvOK(r) && strEQ(SvPV_nolen(r), "response")); 14 0 14
735 }
736  
737  
738 /* Everything below runs per request. The four routes are mounted at
739 * on_compile from the ONE mount string phase 4 recorded, so the ACS URL
740 * in the AuthnRequest, in the metadata, in the Destination check and in
741 * the route that receives it are four readings of one variable. */
742  
743 PERL_STATIC_INLINE SV *psaml_ctx_app(pTHX_ SV *c) {
744 return psaml_call(aTHX_ c, "app", NULL, 0);
745 }
746  
747 137 PERL_STATIC_INLINE HV *psaml_opts_of(pTHX_ SV *app) {
748 137 SV *o = psaml_app_get(aTHX_ app, PSAML_K_OPTS);
749 137 ▶ if (!o || !SvROK(o)) croak("%s: the plugin is not configured", PSAML_WHO);
Branch: 2 branches
BranchTrueFalseTotal
if (!o || !SvROK(o)) croak("%s: the plugin is not configured", PSAML_WHO); 137 0 137
if (!o || !SvROK(o)) croak("%s: the plugin is not configured", PSAML_WHO); 0 137 137
750 137 return (HV *)SvRV(o);
751 }
752  
753 /* GET <mount>/metadata */
754 XS_INTERNAL(psaml_rt_metadata);
755 14 XS_INTERNAL(psaml_rt_metadata) {
756 14 dXSARGS;
757 14 SV *app = psaml_cap_slot(aTHX_ cv, 0);
758 14 ▶ SV *c = items > 0 ? ST(0) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
SV *c = items > 0 ? ST(0) : NULL; 14 0 14
759 HV *opts;
760 SV *doc, *argv[2], *res;
761  
762 14 ▶ if (!app || !c) { PERL_UNUSED_VAR(ax); XSRETURN_EMPTY; }
Branch: 2 branches
BranchTrueFalseTotal
if (!app || !c) { PERL_UNUSED_VAR(ax); XSRETURN_EMPTY; } 14 0 14
if (!app || !c) { PERL_UNUSED_VAR(ax); XSRETURN_EMPTY; } 0 14 14
763 14 opts = psaml_opts_of(aTHX_ app);
764 14 doc = sv_2mortal(psaml_sp_metadata(aTHX_
765 psaml_app_get(aTHX_ app, PSAML_K_ENTITY),
766 psaml_app_get(aTHX_ app, PSAML_K_ACS),
767 psaml_hget(aTHX_ opts, "cert"),
768 psaml_hget(aTHX_ opts, "name_id_format"),
769 psaml_opt_bool(aTHX_ opts, "sign_requests", 0),
770 psaml_want_assertions_signed(aTHX_ opts)));
771  
772 14 ▶ if (psaml_opt_bool(aTHX_ opts, "sign_metadata", 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (psaml_opt_bool(aTHX_ opts, "sign_metadata", 0)) { 0 14 14
773 0 SV *id = sv_2mortal(psaml_request_id(aTHX));
774 0 SV *withid = sv_2mortal(newSVpvs(""));
775 STRLEN dl;
776 0 const char *dp = SvPVbyte(doc, dl);
777 0 const char *gt = (const char *)memchr(dp, ' ', dl);
778 /* the ID goes on the root before it is signed, because a Reference
779 * names an ID and the document as built carries none */
780 0 sv_catpvn(withid, dp, (STRLEN)(gt - dp));
781 0 sv_catpvs(withid, " ID=\"");
782 0 sv_catsv(withid, id);
783 0 sv_catpvs(withid, "\"");
784 0 sv_catpvn(withid, gt, dl - (STRLEN)(gt - dp));
785 0 doc = sv_2mortal(psaml_sign_document(aTHX_ withid, id,
786 psaml_hget(aTHX_ opts, "key"),
787 psaml_hget(aTHX_ opts, "cert")));
788 }
789  
790 /* A raw PSGI triplet, because the media type here is the
791 * specification's and neither $c->text nor Punk 0.46's $c->xml will
792 * send it: text sends text/plain and xml sends application/xml. This
793 * is the shape Punk-Feed returns, for the same reason. */
794 {
795 14 AV *resp = newAV(), *hdrs = newAV(), *body = newAV();
796 14 av_push(hdrs, newSVpvs("Content-Type"));
797 14 av_push(hdrs, newSVpvs(PSAML_CT_METADATA));
798 14 av_push(hdrs, newSVpvs("Content-Length"));
799 14 av_push(hdrs, newSViv((IV)SvCUR(doc)));
800 14 av_push(body, newSVsv(doc));
801 14 av_push(resp, newSViv(200));
802 14 av_push(resp, newRV_noinc((SV *)hdrs));
803 14 av_push(resp, newRV_noinc((SV *)body));
804 14 res = newRV_noinc((SV *)resp);
805 }
806 PERL_UNUSED_VAR(argv);
807 /* ST(0)/XSRETURN, never a captured SP: see the note at psaml_rt_login. */
808 14 ST(0) = sv_2mortal(res);
809 14 XSRETURN(1);
810 }
811  
812 /* GET <mount>/login/:idp and GET <mount>/login */
813 XS_INTERNAL(psaml_rt_login);
814 34 XS_INTERNAL(psaml_rt_login) {
815 34 dXSARGS;
816 34 SV *app = psaml_cap_slot(aTHX_ cv, 0);
817 34 ▶ SV *c = items > 0 ? ST(0) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
SV *c = items > 0 ? ST(0) : NULL; 34 0 34
818 HV *opts, *idps, *rec;
819 34 SV *name = NULL, *cfgsv, *to, *id, *instant, *xml, *url, *argv[3], *res;
820 AV *records, *order;
821 SV *cookie, *value, *setc;
822 IV ttl, now;
823 HV *cfg;
824  
825 34 ▶ if (!app || !c) { PERL_UNUSED_VAR(ax); XSRETURN_EMPTY; }
Branch: 2 branches
BranchTrueFalseTotal
if (!app || !c) { PERL_UNUSED_VAR(ax); XSRETURN_EMPTY; } 34 0 34
if (!app || !c) { PERL_UNUSED_VAR(ax); XSRETURN_EMPTY; } 0 34 34
826 34 opts = psaml_opts_of(aTHX_ app);
827 34 idps = (HV *)SvRV(psaml_app_get(aTHX_ app, PSAML_K_IDPS));
828 34 order = (AV *)SvRV(psaml_app_get(aTHX_ app, PSAML_K_IDPORDER));
829  
830 34 ▶ if (items > 1 && SvOK(ST(1)) && SvCUR(ST(1))) {
Branch: 3 branches
BranchTrueFalseTotal
if (items > 1 && SvOK(ST(1)) && SvCUR(ST(1))) { 0 34 34
if (items > 1 && SvOK(ST(1)) && SvCUR(ST(1))) { 0 0 0
if (items > 1 && SvOK(ST(1)) && SvCUR(ST(1))) { 0 0 0
831 0 name = ST(1);
832 }
833 34 ▶ else if (av_len(order) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
else if (av_len(order) == 0) { 34 0 34
834 /* exactly one provider: /login with no name is unambiguous */
835 34 SV **e = av_fetch(order, 0, 0);
836 34 ▶ name = (e && *e) ? *e : NULL;
Branch: 2 branches
BranchTrueFalseTotal
name = (e && *e) ? *e : NULL; 34 0 34
name = (e && *e) ? *e : NULL; 34 0 34
837 }
838 34 ▶ if (!name) {
Branch: 1 branch
BranchTrueFalseTotal
if (!name) { 0 34 34
839 /* more than one provider and none named: a 404, because guessing
840 * which one the user meant is guessing which company signs them in */
841 0 argv[0] = sv_2mortal(newSVpvs("no such login"));
842 0 argv[1] = sv_2mortal(newSViv(404));
843 0 res = psaml_call(aTHX_ c, "text", argv, 2);
844 0 ▶ if (!res) XSRETURN_EMPTY;
Branch: 1 branch
BranchTrueFalseTotal
if (!res) XSRETURN_EMPTY; 0 0 0
845 0 ST(0) = sv_2mortal(res);
846 0 XSRETURN(1);
847 }
848  
849 {
850 STRLEN nl;
851 34 const char *np = SvPV_const(name, nl);
852 34 SV **e = hv_fetch(idps, np, (I32)nl, 0);
853 34 ▶ if (!e || !*e || !SvROK(*e)) {
Branch: 3 branches
BranchTrueFalseTotal
if (!e || !*e || !SvROK(*e)) { 34 0 34
if (!e || !*e || !SvROK(*e)) { 34 0 34
if (!e || !*e || !SvROK(*e)) { 0 34 34
854 0 argv[0] = sv_2mortal(newSVpvs("no such login"));
855 0 argv[1] = sv_2mortal(newSViv(404));
856 0 res = psaml_call(aTHX_ c, "text", argv, 2);
857 0 ▶ if (!res) XSRETURN_EMPTY;
Branch: 1 branch
BranchTrueFalseTotal
if (!res) XSRETURN_EMPTY; 0 0 0
858 0 ST(0) = sv_2mortal(res);
859 0 XSRETURN(1);
860 }
861 34 cfgsv = *e;
862 }
863 34 cfg = (HV *)SvRV(cfgsv);
864  
865 /* `to` came from a link somebody wrote, so it goes through safe_path
866 * before it is recorded and never after */
867 {
868 SV *raw;
869 34 argv[0] = sv_2mortal(newSVpvs("to"));
870 34 raw = sv_2mortal(psaml_call(aTHX_ c, "param", argv, 1));
871 34 ▶ argv[0] = raw ? raw : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
argv[0] = raw ? raw : &PL_sv_undef; 15 19 34
872 34 argv[1] = psaml_hget(aTHX_ opts, "default_to");
873 34 to = sv_2mortal(psaml_call(aTHX_ c, "safe_path", argv, 2));
874 34 ▶ if (!to || !SvOK(to)) to = psaml_hget(aTHX_ opts, "default_to");
Branch: 2 branches
BranchTrueFalseTotal
if (!to || !SvOK(to)) to = psaml_hget(aTHX_ opts, "default_to"); 34 0 34
if (!to || !SvOK(to)) to = psaml_hget(aTHX_ opts, "default_to"); 0 34 34
875 }
876  
877 34 now = (IV)time(NULL);
878 34 ttl = psaml_opt_iv(aTHX_ opts, "flow_ttl", 600);
879 34 id = sv_2mortal(psaml_request_id(aTHX));
880  
881 {
882 char b[64];
883 34 STRLEN bn = psaml_time_format(b, sizeof b, now);
884 34 instant = sv_2mortal(newSVpvn(b, bn));
885 }
886 34 xml = sv_2mortal(psaml_authn_request(aTHX_ id, instant,
887 psaml_hget(aTHX_ cfg, "sso_url"),
888 psaml_app_get(aTHX_ app, PSAML_K_ACS),
889 psaml_app_get(aTHX_ app, PSAML_K_ENTITY),
890 psaml_hget(aTHX_ opts, "name_id_format"),
891 psaml_opt_bool(aTHX_ opts, "force_authn", 0)));
892  
893 34 ▶ url = sv_2mortal(psaml_redirect_url(aTHX_
Branch: 1 branch
BranchTrueFalseTotal
url = sv_2mortal(psaml_redirect_url(aTHX_ 0 34 34
894 psaml_hget(aTHX_ cfg, "sso_url"), xml, id,
895 psaml_opt_bool(aTHX_ opts, "sign_requests", 0)
896 ? psaml_hget(aTHX_ opts, "key") : NULL));
897  
898 /* the record into the cookie. Nothing is stored server side: the
899 * cookie is the store and the signature is what makes it one. */
900 34 argv[0] = sv_2mortal(newSVpvs(PSAML_FLOW_COOKIE));
901 34 cookie = sv_2mortal(psaml_call(aTHX_ c, "cookie", argv, 1));
902 34 records = psaml_flow_parse(aTHX_ cookie,
903 psaml_hget(aTHX_ opts, "secret"), now, ttl);
904 34 sv_2mortal(newRV_noinc((SV *)records));
905  
906 34 rec = newHV();
907 34 (void)hv_stores(rec, "id", newSVsv(id));
908 34 (void)hv_stores(rec, "idp", newSVsv(name));
909 34 ▶ (void)hv_stores(rec, "to", newSVsv(to ? to : &PL_sv_undef));
Branch: 1 branch
BranchTrueFalseTotal
(void)hv_stores(rec, "to", newSVsv(to ? to : &PL_sv_undef)); 34 0 34
910 34 (void)hv_stores(rec, "issued", newSViv(now));
911 34 psaml_flow_add(aTHX_ records, newRV_noinc((SV *)rec));
912  
913 34 value = sv_2mortal(psaml_flow_serialise(aTHX_ records,
914 psaml_hget(aTHX_ opts, "secret")));
915 34 setc = sv_2mortal(psaml_flow_cookie(aTHX_ value,
916 psaml_app_get(aTHX_ app, PSAML_K_MOUNT), ttl));
917 34 argv[0] = sv_2mortal(newSVpvs("Set-Cookie"));
918 34 argv[1] = setc;
919 34 SvREFCNT_dec(psaml_call(aTHX_ c, "header", argv, 2));
920  
921 34 argv[0] = url;
922 34 argv[1] = sv_2mortal(newSViv(302));
923 34 res = psaml_call(aTHX_ c, "redirect", argv, 2);
924 /* ST(0) and XSRETURN, NEVER a captured SP.
925 *
926 * This body calls into Perl repeatedly - param, safe_path, cookie,
927 * header, redirect - and Perl code reallocates the argument stack, so
928 * the `sp` dXSARGS captured at entry is stale by the time the answer is
929 * pushed. ST() indexes from PL_stack_base through `ax`, which survives
930 * a realloc. Getting this wrong is a SEGV, not a wrong answer, and it
931 * is the second time this dist has paid for it. */
932 34 ▶ if (!res) XSRETURN_EMPTY;
Branch: 1 branch
BranchTrueFalseTotal
if (!res) XSRETURN_EMPTY; 0 34 34
933 34 ST(0) = sv_2mortal(res);
934 34 XSRETURN(1);
935 }
936  
937  
938 /* POST <mount>/acs
939 *
940 * The one request in this application that is supposed to look exactly
941 * like a cross-site request forgery. What protects it is not a token, it
942 * is phase 6 in its entirety. */
943 XS_INTERNAL(psaml_rt_acs);
944 56 XS_INTERNAL(psaml_rt_acs) {
945 56 dXSARGS;
946 56 SV *app = psaml_cap_slot(aTHX_ cv, 0);
947 56 ▶ SV *c = items > 0 ? ST(0) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
SV *c = items > 0 ? ST(0) : NULL; 56 0 56
948 HV *opts, *idps, *login;
949 AV *records;
950 56 SV *cookie, *relay, *field, *rec = NULL, *argv[4], *res;
951 56 SV *idp_name = NULL, *to = NULL, *flow_id = NULL;
952 IV ttl, now;
953 56 int failed = 0;
954 56 SV *err = NULL, *identity = NULL;
955  
956 56 ▶ if (!app || !c) { PERL_UNUSED_VAR(ax); XSRETURN_EMPTY; }
Branch: 2 branches
BranchTrueFalseTotal
if (!app || !c) { PERL_UNUSED_VAR(ax); XSRETURN_EMPTY; } 56 0 56
if (!app || !c) { PERL_UNUSED_VAR(ax); XSRETURN_EMPTY; } 0 56 56
957 56 opts = psaml_opts_of(aTHX_ app);
958 56 idps = (HV *)SvRV(psaml_app_get(aTHX_ app, PSAML_K_IDPS));
959 56 login = (HV *)SvRV(psaml_app_get(aTHX_ app, PSAML_K_LOGIN));
960 56 now = (IV)time(NULL);
961 56 ttl = psaml_opt_iv(aTHX_ opts, "flow_ttl", 600);
962  
963 56 argv[0] = sv_2mortal(newSVpvs("RelayState"));
964 56 relay = sv_2mortal(psaml_call(aTHX_ c, "param", argv, 1));
965 56 argv[0] = sv_2mortal(newSVpvs("SAMLResponse"));
966 56 field = sv_2mortal(psaml_call(aTHX_ c, "param", argv, 1));
967  
968 56 argv[0] = sv_2mortal(newSVpvs(PSAML_FLOW_COOKIE));
969 56 cookie = sv_2mortal(psaml_call(aTHX_ c, "cookie", argv, 1));
970 56 records = psaml_flow_parse(aTHX_ cookie,
971 psaml_hget(aTHX_ opts, "secret"), now, ttl);
972 56 sv_2mortal(newRV_noinc((SV *)records));
973  
974 56 ▶ if (relay && SvOK(relay) && SvCUR(relay))
Branch: 3 branches
BranchTrueFalseTotal
if (relay && SvOK(relay) && SvCUR(relay)) 38 18 56
if (relay && SvOK(relay) && SvCUR(relay)) 38 0 38
if (relay && SvOK(relay) && SvCUR(relay)) 37 1 38
975 37 rec = psaml_flow_take(aTHX_ records, relay);
976 56 ▶ if (rec) sv_2mortal(rec);
Branch: 1 branch
BranchTrueFalseTotal
if (rec) sv_2mortal(rec); 27 29 56
977  
978 /* THE COOKIE IS WRITTEN BACK NOW, BEFORE ANY VERIFICATION.
979 *
980 * One flow, one answer, whichever way it goes. A record left in place
981 * on failure would let an attacker retry a tampered assertion against
982 * the same flow until something got through, and the flow record is
983 * the only thing standing between an SP-initiated login and a replay. */
984 {
985 56 SV *value = sv_2mortal(psaml_flow_serialise(aTHX_ records,
986 psaml_hget(aTHX_ opts, "secret")));
987 56 SV *setc = sv_2mortal(psaml_flow_cookie(aTHX_ value,
988 psaml_app_get(aTHX_ app, PSAML_K_MOUNT), ttl));
989 56 argv[0] = sv_2mortal(newSVpvs("Set-Cookie"));
990 56 argv[1] = setc;
991 56 SvREFCNT_dec(psaml_call(aTHX_ c, "header", argv, 2));
992 }
993  
994 56 ▶ if (rec) {
Branch: 1 branch
BranchTrueFalseTotal
if (rec) { 27 29 56
995 27 HV *r = (HV *)SvRV(rec);
996 27 idp_name = psaml_hget(aTHX_ r, "idp");
997 27 to = psaml_hget(aTHX_ r, "to");
998 27 flow_id = psaml_hget(aTHX_ r, "id");
999 }
1000 29 ▶ else if (psaml_opt_bool(aTHX_ opts, "allow_idp_initiated", 0)) {
Branch: 1 branch
BranchTrueFalseTotal
else if (psaml_opt_bool(aTHX_ opts, "allow_idp_initiated", 0)) { 11 18 29
1001 /* no record, and the deployment has decided its provider may start a
1002 * login. RelayState is then the provider's own and IS treated as a
1003 * path, which is the one place this dist reads it that way, so it
1004 * goes through safe_path. */
1005 11 ▶ argv[0] = relay ? relay : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
argv[0] = relay ? relay : &PL_sv_undef; 7 4 11
1006 11 argv[1] = psaml_hget(aTHX_ opts, "default_to");
1007 11 to = sv_2mortal(psaml_call(aTHX_ c, "safe_path", argv, 2));
1008 11 ▶ if (av_len((AV *)SvRV(psaml_app_get(aTHX_ app, PSAML_K_IDPORDER))) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (av_len((AV *)SvRV(psaml_app_get(aTHX_ app, PSAML_K_IDPORDER))) == 0) { 11 0 11
1009 11 SV **e = av_fetch((AV *)SvRV(psaml_app_get(aTHX_ app, PSAML_K_IDPORDER)),
1010 0, 0);
1011 11 ▶ idp_name = (e && *e) ? *e : NULL;
Branch: 2 branches
BranchTrueFalseTotal
idp_name = (e && *e) ? *e : NULL; 11 0 11
idp_name = (e && *e) ? *e : NULL; 11 0 11
1012 }
1013 }
1014  
1015 /* No flow record, and the provider may not start a login: that is
1016 * `unsolicited`, and it is decided HERE rather than by handing the
1017 * verifier a Response with no provider to check it against. Calling
1018 * verify with no certs produces a plain croak about a missing option,
1019 * which is a configuration message answering a security question. */
1020 56 ▶ if (!rec && !psaml_opt_bool(aTHX_ opts, "allow_idp_initiated", 0)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!rec && !psaml_opt_bool(aTHX_ opts, "allow_idp_initiated", 0)) { 29 27 56
if (!rec && !psaml_opt_bool(aTHX_ opts, "allow_idp_initiated", 0)) { 18 11 29
1021 18 failed = 1;
1022 /* psaml_error_new already hands back a mortal; mortalising it again
1023 * here would free it twice. */
1024 18 err = psaml_error_new(aTHX_ PSAML_E_UNSOLICITED,
1025 newSVpvs("no flow record matches this RelayState, and "
1026 "allow_idp_initiated is off"));
1027 }
1028 else
1029 {
1030 38 dSP;
1031 38 HV *cfg = NULL;
1032 int attempt;
1033 38 ▶ if (idp_name) {
Branch: 1 branch
BranchTrueFalseTotal
if (idp_name) { 38 0 38
1034 STRLEN nl;
1035 38 const char *np = SvPV_const(idp_name, nl);
1036 38 SV **e = hv_fetch(idps, np, (I32)nl, 0);
1037 38 ▶ if (e && *e && SvROK(*e)) cfg = (HV *)SvRV(*e);
Branch: 3 branches
BranchTrueFalseTotal
if (e && *e && SvROK(*e)) cfg = (HV *)SvRV(*e); 38 0 38
if (e && *e && SvROK(*e)) cfg = (HV *)SvRV(*e); 38 0 38
if (e && *e && SvROK(*e)) cfg = (HV *)SvRV(*e); 38 0 38
1038 }
1039  
1040 /* Twice at most. The second attempt happens only when the first
1041 * failed in a way a key rotation explains AND re-reading the
1042 * provider's metadata actually produced something new; every other
1043 * failure leaves the loop on the first pass. `certs` is read off cfg
1044 * inside the loop, so the retry uses what the refetch just wrote. */
1045 50 ▶ for (attempt = 0; attempt < 2; attempt++) {
Branch: 1 branch
BranchTrueFalseTotal
for (attempt = 0; attempt < 2; attempt++) { 49 1 50
1046  
1047 49 ▶ if (attempt) {
Branch: 1 branch
BranchTrueFalseTotal
if (attempt) { 11 38 49
1048 11 int refetched = 0;
1049 11 ▶ if (!cfg || !psaml_rotation_explains(aTHX_ err)) break;
Branch: 2 branches
BranchTrueFalseTotal
if (!cfg || !psaml_rotation_explains(aTHX_ err)) break; 11 0 11
if (!cfg || !psaml_rotation_explains(aTHX_ err)) break; 6 5 11
1050  
1051 /* through Perl, for the G_EVAL: psaml_idp_refetch croaks when the
1052 * provider cannot be reached, and an unreachable provider during
1053 * somebody's login is a refused login, never a 500. */
1054 6 ENTER;
1055 6 SAVETMPS;
1056 6 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 6 6
1057 6 ▶ XPUSHs(sv_2mortal(newSVpvs("Punk::Plugin::SAML")));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvs("Punk::Plugin::SAML"))); 0 6 6
1058 6 ▶ XPUSHs(app);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(app); 0 6 6
1059 6 ▶ XPUSHs(idp_name);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(idp_name); 0 6 6
1060 6 ▶ XPUSHs(sv_2mortal(newSViv(now)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv(now))); 0 6 6
1061 6 PUTBACK;
1062 {
1063 6 int count = call_method("_refetch_idp", G_SCALAR | G_EVAL);
1064 6 SPAGAIN;
1065 6 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 6 0 6
if (SvTRUE(ERRSV)) { 0 6 6
1066 /* its own line: "the login failed" and "the provider could not
1067 * be re-read" are two different operational problems and a
1068 * deployment chasing the first should not have to infer the
1069 * second. */
1070 0 ▶ SV *why = sv_2mortal(newSVsv(ERRSV));
Branch: 1 branch
BranchTrueFalseTotal
SV *why = sv_2mortal(newSVsv(ERRSV)); 0 0 0
1071 0 ▶ if (count > 0) (void)POPs;
Branch: 1 branch
BranchTrueFalseTotal
if (count > 0) (void)POPs; 0 0 0
1072 0 Perl_warn(aTHX_ "saml: metadata refetch failed: %s",
1073 SvPV_nolen(why));
1074 }
1075 6 ▶ else if (count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
else if (count > 0) { 6 0 6
1076 /* one POP, then the test: SvTRUE(POPs) evaluates its argument
1077 * more than once and would move the stack pointer with it. */
1078 6 SV *r2 = POPs;
1079 6 refetched = SvTRUE(r2) ? 1 : 0;
1080 }
1081 6 PUTBACK;
1082 }
1083 6 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 6 0 6
1084 6 LEAVE;
1085  
1086 6 ▶ if (!refetched) break;
Branch: 1 branch
BranchTrueFalseTotal
if (!refetched) break; 4 2 6
1087 /* the first failure is discarded only now that there is going to be
1088 * a second answer to replace it */
1089 2 SvREFCNT_dec(err);
1090 2 err = NULL;
1091 2 failed = 0;
1092 }
1093  
1094 40 ENTER;
1095 40 SAVETMPS;
1096 {
1097 /* G_EVAL around the whole verification: every check throws a
1098 * blessed Punk::SAML::Error, and the route turns that into one
1099 * page and one log line. */
1100 int i;
1101 SV *args[24];
1102 40 int n = 0;
1103 40 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 40 40
1104 40 args[n++] = sv_2mortal(newSVpvs("Punk::SAML::Response"));
1105 40 ▶ args[n++] = field ? field : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
args[n++] = field ? field : &PL_sv_undef; 40 0 40
1106 40 args[n++] = sv_2mortal(newSVpvs("entity_id"));
1107 40 args[n++] = psaml_app_get(aTHX_ app, PSAML_K_ENTITY);
1108 40 args[n++] = sv_2mortal(newSVpvs("acs_url"));
1109 40 args[n++] = psaml_app_get(aTHX_ app, PSAML_K_ACS);
1110 40 args[n++] = sv_2mortal(newSVpvs("idp"));
1111 40 ▶ args[n++] = idp_name ? idp_name : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
args[n++] = idp_name ? idp_name : &PL_sv_undef; 40 0 40
1112 40 args[n++] = sv_2mortal(newSVpvs("idp_entity_id"));
1113 40 ▶ args[n++] = cfg ? psaml_hget(aTHX_ cfg, "entity_id") : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
args[n++] = cfg ? psaml_hget(aTHX_ cfg, "entity_id") : &PL_sv_undef; 40 0 40
1114 40 args[n++] = sv_2mortal(newSVpvs("certs"));
1115 40 ▶ args[n++] = cfg ? psaml_hget(aTHX_ cfg, "certs") : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
args[n++] = cfg ? psaml_hget(aTHX_ cfg, "certs") : &PL_sv_undef; 40 0 40
1116 40 args[n++] = sv_2mortal(newSVpvs("now"));
1117 40 args[n++] = sv_2mortal(newSViv(now));
1118 40 args[n++] = sv_2mortal(newSVpvs("skew"));
1119 40 args[n++] = sv_2mortal(newSViv(psaml_opt_iv(aTHX_ opts, "skew", 120)));
1120 40 args[n++] = sv_2mortal(newSVpvs("require_signed"));
1121 40 args[n++] = psaml_hget(aTHX_ opts, "require_signed");
1122 40 args[n++] = sv_2mortal(newSVpvs("allow_sha1"));
1123 40 args[n++] = sv_2mortal(newSViv(psaml_opt_bool(aTHX_ opts,
1124 "allow_sha1", 0)));
1125 40 args[n++] = sv_2mortal(newSVpvs("allow_idp_initiated"));
1126 40 args[n++] = sv_2mortal(newSViv(psaml_opt_bool(aTHX_ opts,
1127 "allow_idp_initiated", 0)));
1128 40 args[n++] = sv_2mortal(newSVpvs("in_response_to"));
1129 40 ▶ args[n++] = flow_id ? flow_id : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
args[n++] = flow_id ? flow_id : &PL_sv_undef; 29 11 40
1130 1000 ▶ for (i = 0; i < n; i++) XPUSHs(args[i] ? args[i] : &PL_sv_undef);
Branch: 3 branches
BranchTrueFalseTotal
for (i = 0; i < n; i++) XPUSHs(args[i] ? args[i] : &PL_sv_undef); 0 960 960
for (i = 0; i < n; i++) XPUSHs(args[i] ? args[i] : &PL_sv_undef); 960 0 960
for (i = 0; i < n; i++) XPUSHs(args[i] ? args[i] : &PL_sv_undef); 960 40 1000
1131 40 PUTBACK;
1132 }
1133 {
1134 40 int count = call_method("_verify_field", G_SCALAR | G_EVAL);
1135 40 SPAGAIN;
1136 40 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 40 0 40
if (SvTRUE(ERRSV)) { 12 28 40
1137 12 failed = 1;
1138 /* +1 and NOT mortalised here: this is inside the ENTER/SAVETMPS
1139 * frame, and the FREETMPS below would free it before the failure
1140 * path reads its `code`. Mortalised after LEAVE instead. */
1141 12 ▶ err = newSVsv(ERRSV);
Branch: 1 branch
BranchTrueFalseTotal
err = newSVsv(ERRSV); 12 0 12
1142 12 ▶ if (count > 0) (void)POPs;
Branch: 1 branch
BranchTrueFalseTotal
if (count > 0) (void)POPs; 12 0 12
1143 }
1144 28 ▶ else if (count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
else if (count > 0) { 28 0 28
1145 28 SV *r2 = POPs;
1146 28 identity = SvREFCNT_inc_simple_NN(r2);
1147 }
1148 40 PUTBACK;
1149 }
1150 40 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 40 0 40
1151 40 LEAVE;
1152 40 ▶ if (identity) break;
Branch: 1 branch
BranchTrueFalseTotal
if (identity) break; 28 12 40
1153  
1154 } /* for attempt */
1155  
1156 /* mortalised out here, not inside the loop: an `err` freed at the end
1157 * of the first pass is one the second pass would read after it was
1158 * gone. */
1159 38 ▶ if (identity) sv_2mortal(identity);
Branch: 1 branch
BranchTrueFalseTotal
if (identity) sv_2mortal(identity); 28 10 38
1160 38 ▶ if (err) sv_2mortal(err);
Branch: 1 branch
BranchTrueFalseTotal
if (err) sv_2mortal(err); 10 28 38
1161 }
1162  
1163 /* Anything that reached here as a plain string is a bug or a
1164 * misconfiguration rather than a check result, and on_error is
1165 * documented to receive a Punk::SAML::Error. Wrap it so that contract
1166 * holds on every path. */
1167 56 ▶ if (failed && err && !(SvROK(err) && sv_isobject(err)))
Branch: 4 branches
BranchTrueFalseTotal
if (failed && err && !(SvROK(err) && sv_isobject(err))) 28 28 56
if (failed && err && !(SvROK(err) && sv_isobject(err))) 28 0 28
if (failed && err && !(SvROK(err) && sv_isobject(err))) 28 0 28
if (failed && err && !(SvROK(err) && sv_isobject(err))) 0 28 28
1168 0 err = psaml_error_new(aTHX_ PSAML_E_CONFIG, newSVsv(err));
1169 56 ▶ if (!failed && !identity) {
Branch: 2 branches
BranchTrueFalseTotal
if (!failed && !identity) { 28 28 56
if (!failed && !identity) { 0 28 28
1170 0 failed = 1;
1171 0 err = psaml_error_new(aTHX_ PSAML_E_XML_SHAPE,
1172 newSVpvs("the Response produced no identity"));
1173 }
1174  
1175 /* Replay, AFTER the signature and the windows and BEFORE on_login.
1176 *
1177 * After, because an id out of an unverified document is attacker-chosen
1178 * and writing it to the store would let anyone fill the cache with
1179 * whatever they liked. Before, because on_login is where the session
1180 * is established and an assertion that has already bought one must not
1181 * buy a second.
1182 *
1183 * The flow record is NOT this check and never was. It is single-use per
1184 * BROWSER: the ACS takes it and writes the cookie back before verifying,
1185 * so the browser that just signed in cannot replay. An attacker holding
1186 * a copy of the request as it went over the wire holds the cookie as it
1187 * was BEFORE that, record and all, and until 0.03 could present the
1188 * pair again until flow_ttl ran out. With allow_idp_initiated on there
1189 * is no record at all and nothing bounded it but the assertion.
1190 *
1191 * G_EVAL because the store is the application's: a cache that cannot be
1192 * reached is a `config` refusal in the log, not a 500 for the browser,
1193 * and either way the login does not proceed. Fail closed. */
1194 56 ▶ if (!failed && identity
Branch: 2 branches
BranchTrueFalseTotal
if (!failed && identity 28 28 56
if (!failed && identity 28 0 28
1195 28 ▶ && !psaml_opt_bool(aTHX_ opts, "allow_replay", 0)) {
Branch: 1 branch
BranchTrueFalseTotal
&& !psaml_opt_bool(aTHX_ opts, "allow_replay", 0)) { 26 2 28
1196 26 dSP;
1197 int count;
1198 26 int replayed = 0;
1199 26 SV *ev = NULL;
1200 26 SV *seen = psaml_hget(aTHX_ opts, "seen");
1201 26 ENTER; SAVETMPS;
1202 26 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 26 26
1203 26 ▶ XPUSHs(sv_2mortal(newSVpvs("Punk::SAML::Response")));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvs("Punk::SAML::Response"))); 0 26 26
1204 26 ▶ XPUSHs(c);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(c); 0 26 26
1205 26 ▶ XPUSHs(seen ? seen : &PL_sv_undef);
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(seen ? seen : &PL_sv_undef); 0 26 26
XPUSHs(seen ? seen : &PL_sv_undef); 26 0 26
1206 26 ▶ XPUSHs(identity);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(identity); 0 26 26
1207 /* skew as well: the verifier accepts an assertion until its window
1208 * plus the skew, so a cache entry that expired at the window alone
1209 * would stop remembering it while it was still being accepted. */
1210 26 ▶ XPUSHs(sv_2mortal(newSViv(psaml_opt_iv(aTHX_ opts, "skew", 120))));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv(psaml_opt_iv(aTHX_ opts, "skew", 120)))); 0 26 26
1211 26 PUTBACK;
1212 26 count = call_method("_replayed", G_SCALAR | G_EVAL);
1213 26 SPAGAIN;
1214 26 ▶ if (SvTRUE(ERRSV)) ev = newSVsv(ERRSV);
Branch: 3 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) ev = newSVsv(ERRSV); 26 0 26
if (SvTRUE(ERRSV)) ev = newSVsv(ERRSV); 1 25 26
if (SvTRUE(ERRSV)) ev = newSVsv(ERRSV); 1 0 1
1215 26 ▶ if (count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (count > 0) { 26 0 26
1216 26 SV *r = POPs;
1217 26 replayed = SvTRUE(r) ? 1 : 0;
1218 }
1219 26 PUTBACK;
1220 26 ▶ FREETMPS; LEAVE;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; LEAVE; 26 0 26
1221 26 ▶ if (ev) {
Branch: 1 branch
BranchTrueFalseTotal
if (ev) { 1 25 26
1222 /* the store itself broke. Not a replay, not a pass.
1223 *
1224 * `ev` goes in as the +1 it already is: psaml_error_new puts the
1225 * message straight into the hash, so a mortal here would be freed
1226 * by the next FREETMPS while the error still held it. */
1227 1 failed = 1;
1228 1 err = psaml_error_new(aTHX_ PSAML_E_CONFIG, ev);
1229 }
1230 25 ▶ else if (replayed) {
Branch: 1 branch
BranchTrueFalseTotal
else if (replayed) { 6 19 25
1231 6 failed = 1;
1232 6 err = psaml_error_new(aTHX_ PSAML_E_REPLAY,
1233 newSVpvs("this assertion has been presented before"));
1234 }
1235 }
1236  
1237 56 ▶ if (failed || !identity) {
Branch: 2 branches
BranchTrueFalseTotal
if (failed || !identity) { 21 35 56
if (failed || !identity) { 0 21 21
1238 /* the code goes to the log with the provider; the REASON never
1239 * reaches the browser. A verifier that told the far side which check
1240 * it failed would be telling an attacker which one to work on. */
1241 35 SV *on_error = psaml_hget(aTHX_ login, "on_error");
1242 {
1243 35 ▶ SV *code = (err && SvROK(err) && SvTYPE(SvRV(err)) == SVt_PVHV)
Branch: 2 branches
BranchTrueFalseTotal
SV *code = (err && SvROK(err) && SvTYPE(SvRV(err)) == SVt_PVHV) 35 0 35
SV *code = (err && SvROK(err) && SvTYPE(SvRV(err)) == SVt_PVHV) 35 0 35
1244 70 ▶ ? psaml_hget(aTHX_ (HV *)SvRV(err), "code") : NULL;
Branch: 1 branch
BranchTrueFalseTotal
? psaml_hget(aTHX_ (HV *)SvRV(err), "code") : NULL; 35 0 35
1245 35 ▶ SV *msg = (err && SvROK(err) && SvTYPE(SvRV(err)) == SVt_PVHV)
Branch: 2 branches
BranchTrueFalseTotal
SV *msg = (err && SvROK(err) && SvTYPE(SvRV(err)) == SVt_PVHV) 35 0 35
SV *msg = (err && SvROK(err) && SvTYPE(SvRV(err)) == SVt_PVHV) 35 0 35
1246 70 ▶ ? psaml_hget(aTHX_ (HV *)SvRV(err), "message") : NULL;
Branch: 1 branch
BranchTrueFalseTotal
? psaml_hget(aTHX_ (HV *)SvRV(err), "message") : NULL; 35 0 35
1247 35 SV *line = sv_2mortal(newSVpvs("saml: "));
1248 35 ▶ sv_catsv(line, code ? code : sv_2mortal(newSVpvs("error")));
Branch: 1 branch
BranchTrueFalseTotal
sv_catsv(line, code ? code : sv_2mortal(newSVpvs("error"))); 0 35 35
1249 35 ▶ if (idp_name) { sv_catpvs(line, " idp="); sv_catsv(line, idp_name); }
Branch: 1 branch
BranchTrueFalseTotal
if (idp_name) { sv_catpvs(line, " idp="); sv_catsv(line, idp_name); } 17 18 35
1250 35 ▶ if (msg) { sv_catpvs(line, " "); sv_catsv(line, msg); }
Branch: 1 branch
BranchTrueFalseTotal
if (msg) { sv_catpvs(line, " "); sv_catsv(line, msg); } 35 0 35
1251 /* warn, not $c->log: this reaches psgi.errors on every server and
1252 * does not tie the plugin to a logger's signature. The CODE and the
1253 * provider go here; none of it reaches the browser. */
1254 35 Perl_warn(aTHX_ "%s", SvPV_nolen(line));
1255 }
1256 35 ▶ if (psaml_is_code(aTHX_ on_error)) {
Branch: 1 branch
BranchTrueFalseTotal
if (psaml_is_code(aTHX_ on_error)) { 12 23 35
1257 SV *cbargs[2];
1258 12 cbargs[0] = c;
1259 12 cbargs[1] = err;
1260 12 res = psaml_call_cv(aTHX_ on_error, cbargs, 2);
1261 12 ▶ if (!res) XSRETURN_EMPTY;
Branch: 1 branch
BranchTrueFalseTotal
if (!res) XSRETURN_EMPTY; 0 12 12
1262 12 ST(0) = sv_2mortal(res);
1263 12 XSRETURN(1);
1264 }
1265 23 argv[0] = sv_2mortal(newSVpvs(
1266 "<!doctype html><title>Sign-in failed</title>"
1267 "<h1>Sign-in failed</h1><p>Please try again.</p>"));
1268 23 argv[1] = sv_2mortal(newSViv(403));
1269 23 res = psaml_call(aTHX_ c, "html", argv, 2);
1270 23 ▶ if (!res) XSRETURN_EMPTY;
Branch: 1 branch
BranchTrueFalseTotal
if (!res) XSRETURN_EMPTY; 0 23 23
1271 23 ST(0) = sv_2mortal(res);
1272 23 XSRETURN(1);
1273 }
1274  
1275 /* session_rotate BEFORE on_login, because that is session fixation: the
1276 * session that existed before authentication must not be the one that
1277 * exists after. The plugin does it so no on_login body has to remember
1278 * to, and it is called regardless of what the session store is - the
1279 * cost is nothing and the day it becomes server side is the day it
1280 * matters. */
1281 21 ▶ if (psaml_can(aTHX_ c, "session_rotate"))
Branch: 1 branch
BranchTrueFalseTotal
if (psaml_can(aTHX_ c, "session_rotate")) 21 0 21
1282 21 SvREFCNT_dec(psaml_call(aTHX_ c, "session_rotate", NULL, 0));
1283  
1284 /* recorded for the logout 0.02 may bring, and read never */
1285 /* Recorded for the logout 0.02 may bring, and read never.
1286 *
1287 * $c->session takes NO arguments and hands back the session hashref;
1288 * storing is done into that hash. Calling it as session(key, value)
1289 * is a SEGV rather than an error, which is how this was found. */
1290 21 ▶ if (psaml_can(aTHX_ c, "session")) {
Branch: 1 branch
BranchTrueFalseTotal
if (psaml_can(aTHX_ c, "session")) { 21 0 21
1291 21 SV *sess = sv_2mortal(psaml_call(aTHX_ c, "session", NULL, 0));
1292 21 ▶ if (sess && SvROK(sess) && SvTYPE(SvRV(sess)) == SVt_PVHV) {
Branch: 3 branches
BranchTrueFalseTotal
if (sess && SvROK(sess) && SvTYPE(SvRV(sess)) == SVt_PVHV) { 21 0 21
if (sess && SvROK(sess) && SvTYPE(SvRV(sess)) == SVt_PVHV) { 21 0 21
if (sess && SvROK(sess) && SvTYPE(SvRV(sess)) == SVt_PVHV) { 21 0 21
1293 21 HV *sh = (HV *)SvRV(sess);
1294 21 HV *note = newHV();
1295 21 ▶ HV *idh = (SvROK(identity) && SvTYPE(SvRV(identity)) == SVt_PVHV)
Branch: 1 branch
BranchTrueFalseTotal
HV *idh = (SvROK(identity) && SvTYPE(SvRV(identity)) == SVt_PVHV) 21 0 21
1296 42 ▶ ? (HV *)SvRV(identity) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
? (HV *)SvRV(identity) : NULL; 21 0 21
1297 SV *v;
1298 21 ▶ if (idp_name) (void)hv_stores(note, "idp", newSVsv(idp_name));
Branch: 1 branch
BranchTrueFalseTotal
if (idp_name) (void)hv_stores(note, "idp", newSVsv(idp_name)); 21 0 21
1299 21 ▶ if (idh) {
Branch: 1 branch
BranchTrueFalseTotal
if (idh) { 21 0 21
1300 21 v = psaml_hget(aTHX_ idh, "name_id");
1301 21 ▶ if (v) (void)hv_stores(note, "name_id", newSVsv(v));
Branch: 1 branch
BranchTrueFalseTotal
if (v) (void)hv_stores(note, "name_id", newSVsv(v)); 21 0 21
1302 21 v = psaml_hget(aTHX_ idh, "session_index");
1303 21 ▶ if (v) (void)hv_stores(note, "session_index", newSVsv(v));
Branch: 1 branch
BranchTrueFalseTotal
if (v) (void)hv_stores(note, "session_index", newSVsv(v)); 21 0 21
1304 }
1305 21 (void)hv_stores(sh, "punk_saml", newRV_noinc((SV *)note));
1306 }
1307 }
1308  
1309 {
1310 21 SV *on_login = psaml_hget(aTHX_ login, "on_login");
1311 SV *cbargs[2];
1312 21 cbargs[0] = c;
1313 21 cbargs[1] = identity;
1314 21 res = psaml_call_cv(aTHX_ on_login, cbargs, 2);
1315 }
1316  
1317 /* on_login's return value is the answer when there is one; otherwise
1318 * the plugin redirects to where the login started */
1319 21 ▶ if (!res) {
Branch: 1 branch
BranchTrueFalseTotal
if (!res) { 21 0 21
1320 21 ▶ argv[0] = to ? to : psaml_hget(aTHX_ opts, "default_to");
Branch: 1 branch
BranchTrueFalseTotal
argv[0] = to ? to : psaml_hget(aTHX_ opts, "default_to"); 0 21 21
1321 21 argv[1] = sv_2mortal(newSViv(303));
1322 21 res = psaml_call(aTHX_ c, "redirect", argv, 2);
1323 }
1324 21 ▶ if (!res) XSRETURN_EMPTY;
Branch: 1 branch
BranchTrueFalseTotal
if (!res) XSRETURN_EMPTY; 0 21 21
1325 21 ST(0) = sv_2mortal(res);
1326 21 XSRETURN(1);
1327 }
1328  
1329 27 PERL_STATIC_INLINE void psaml_mount_routes(pTHX_ SV *app) {
1330 27 SV *mount = psaml_app_get(aTHX_ app, PSAML_K_MOUNT);
1331 27 HV *opts = psaml_opts_of(aTHX_ app);
1332 AV *cap;
1333 SV *path;
1334  
1335 27 ▶ if (psaml_opt_bool(aTHX_ opts, "metadata", 1)) {
Branch: 1 branch
BranchTrueFalseTotal
if (psaml_opt_bool(aTHX_ opts, "metadata", 1)) { 27 0 27
1336 27 cap = newAV(); av_push(cap, newSVsv(app));
1337 27 path = sv_2mortal(newSVsv(mount));
1338 27 sv_catpvs(path, "/metadata");
1339 27 psaml_route(aTHX_ app, "GET", path, psaml_rt_metadata, cap);
1340 }
1341  
1342 27 cap = newAV(); av_push(cap, newSVsv(app));
1343 27 path = sv_2mortal(newSVsv(mount));
1344 27 sv_catpvs(path, "/login/:idp");
1345 27 psaml_route(aTHX_ app, "GET", path, psaml_rt_login, cap);
1346  
1347 27 cap = newAV(); av_push(cap, newSVsv(app));
1348 27 path = sv_2mortal(newSVsv(mount));
1349 27 sv_catpvs(path, "/login");
1350 27 psaml_route(aTHX_ app, "GET", path, psaml_rt_login, cap);
1351  
1352 27 cap = newAV(); av_push(cap, newSVsv(app));
1353 27 path = sv_2mortal(newSVsv(mount));
1354 27 sv_catpvs(path, "/acs");
1355 27 psaml_route(aTHX_ app, "POST", path, psaml_rt_acs, cap);
1356 27 }
1357  
1358 /* ---- on_compile ------------------------------------------------------- */
1359  
1360 /* Everything that needs `host`, or needs every keyword to have run.
1361 *
1362 * saml_login with no provider is caught HERE rather than at the keyword,
1363 * because the two may be declared in either order and a plugin that
1364 * insisted on one order would be enforcing a rule the application never
1365 * agreed to. */
1366 XS_INTERNAL(psaml_on_compile);
1367 32 XS_INTERNAL(psaml_on_compile) {
1368 32 dXSARGS;
1369 32 SV *app = psaml_cap_slot(aTHX_ cv, 0);
1370 SV *login, *host, *entity, *mount, *ordsv;
1371 HV *opts;
1372  
1373 PERL_UNUSED_VAR(items);
1374 32 ▶ if (!app) { PERL_UNUSED_VAR(ax); XSRETURN_EMPTY; }
Branch: 1 branch
BranchTrueFalseTotal
if (!app) { PERL_UNUSED_VAR(ax); XSRETURN_EMPTY; } 0 32 32
1375  
1376 32 login = psaml_app_get(aTHX_ app, PSAML_K_LOGIN);
1377 32 ▶ if (!login) XSRETURN_EMPTY; /* the plugin without a login mount does
Branch: 1 branch
BranchTrueFalseTotal
if (!login) XSRETURN_EMPTY; /* the plugin without a login mount does 0 32 32
1378 * nothing, and that is allowed: an
1379 * application may load it to publish
1380 * metadata and nothing else */
1381  
1382 32 ordsv = psaml_app_get(aTHX_ app, PSAML_K_IDPORDER);
1383 32 ▶ if (!ordsv || !SvROK(ordsv) || av_len((AV *)SvRV(ordsv)) < 0)
Branch: 3 branches
BranchTrueFalseTotal
if (!ordsv || !SvROK(ordsv) || av_len((AV *)SvRV(ordsv)) < 0) 31 1 32
if (!ordsv || !SvROK(ordsv) || av_len((AV *)SvRV(ordsv)) < 0) 31 0 31
if (!ordsv || !SvROK(ordsv) || av_len((AV *)SvRV(ordsv)) < 0) 0 31 31
1384 1 croak("%s: saml_login is declared but no saml_idp is. There is nothing "
1385 "to log in against", PSAML_WHO);
1386  
1387 31 host = psaml_host(aTHX_ app);
1388 29 mount = psaml_app_get(aTHX_ app, PSAML_K_MOUNT);
1389 {
1390 STRLEN ml;
1391 29 const char *mp = SvPV_const(mount, ml);
1392 29 SV *acs = newSVsv(host);
1393 STRLEN al;
1394 29 const char *ap = SvPV_const(acs, al);
1395 29 ▶ while (al && ap[al - 1] == '/') al--;
Branch: 2 branches
BranchTrueFalseTotal
while (al && ap[al - 1] == '/') al--; 29 0 29
while (al && ap[al - 1] == '/') al--; 0 29 29
1396 29 SvCUR_set(acs, al);
1397 29 sv_catpvn(acs, mp, ml);
1398 29 sv_catpvs(acs, "/acs");
1399 /* One variable, computed once. The AuthnRequest, the metadata, the
1400 * Destination check and the Recipient check all read it, and four
1401 * derivations of one URL is four chances for them to disagree. */
1402 29 psaml_app_set(aTHX_ app, PSAML_K_ACS, acs);
1403 }
1404  
1405 29 opts = (HV *)SvRV(psaml_app_get(aTHX_ app, PSAML_K_OPTS));
1406 29 entity = psaml_hget(aTHX_ opts, "entity_id");
1407 29 ▶ if (entity && SvOK(entity)) {
Branch: 2 branches
BranchTrueFalseTotal
if (entity && SvOK(entity)) { 1 28 29
if (entity && SvOK(entity)) { 1 0 1
1408 1 psaml_app_set(aTHX_ app, PSAML_K_ENTITY, newSVsv(entity));
1409 }
1410 else {
1411 /* the metadata URL, which is what an identity provider will have been
1412 * given to identify us by if we did not say otherwise */
1413 28 SV *pfx = psaml_hget(aTHX_ opts, "prefix");
1414 28 SV *url = psaml_join_url(aTHX_ host, SvPV_nolen(pfx));
1415 28 sv_catpvs(url, "/metadata");
1416 28 psaml_app_set(aTHX_ app, PSAML_K_ENTITY, url);
1417 }
1418  
1419 /* The replay store, checked HERE and not at the first login.
1420 *
1421 * on_compile runs before Punk builds the cache stores, so what exists
1422 * to look at is `cache_spec`, the keyword's own record. That is enough,
1423 * and it is the right thing to read: every keyword has recorded by now,
1424 * so `cache` on either side of the `plugin` line reads the same.
1425 *
1426 * Croaking is deliberate. A replay cache that is quietly absent is the
1427 * 0.01 and 0.02 behaviour, where the POD promised a check that nothing
1428 * performed, and an option that silently does nothing is worse than one
1429 * that refuses. A deployment that genuinely wants no cache says so with
1430 * `allow_replay`. */
1431 29 ▶ if (!psaml_opt_bool(aTHX_ opts, "allow_replay", 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!psaml_opt_bool(aTHX_ opts, "allow_replay", 0)) { 27 2 29
1432 27 SV *seen = psaml_hget(aTHX_ opts, "seen");
1433 27 ▶ if (seen && SvOK(seen) && !SvROK(seen)) {
Branch: 3 branches
BranchTrueFalseTotal
if (seen && SvOK(seen) && !SvROK(seen)) { 27 0 27
if (seen && SvOK(seen) && !SvROK(seen)) { 27 0 27
if (seen && SvOK(seen) && !SvROK(seen)) { 25 2 27
1434 STRLEN nl;
1435 25 const char *np = SvPV_const(seen, nl);
1436 25 ▶ HV *ah = (SvROK(app) && SvTYPE(SvRV(app)) == SVt_PVHV)
Branch: 1 branch
BranchTrueFalseTotal
HV *ah = (SvROK(app) && SvTYPE(SvRV(app)) == SVt_PVHV) 25 0 25
1437 50 ▶ ? (HV *)SvRV(app) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
? (HV *)SvRV(app) : NULL; 25 0 25
1438 25 ▶ SV **spec = ah ? hv_fetchs(ah, "cache_spec", 0) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
SV **spec = ah ? hv_fetchs(ah, "cache_spec", 0) : NULL; 25 0 25
1439 23 ▶ HV *specs = (spec && *spec && SvROK(*spec)
Branch: 2 branches
BranchTrueFalseTotal
HV *specs = (spec && *spec && SvROK(*spec) 23 0 23
HV *specs = (spec && *spec && SvROK(*spec) 23 0 23
1440 23 ▶ && SvTYPE(SvRV(*spec)) == SVt_PVHV)
Branch: 1 branch
BranchTrueFalseTotal
&& SvTYPE(SvRV(*spec)) == SVt_PVHV) 23 0 23
1441 48 ▶ ? (HV *)SvRV(*spec) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
? (HV *)SvRV(*spec) : NULL; 23 2 25
1442 25 ▶ if (!specs || !hv_exists(specs, np, (I32)nl))
Branch: 2 branches
BranchTrueFalseTotal
if (!specs || !hv_exists(specs, np, (I32)nl)) 23 2 25
if (!specs || !hv_exists(specs, np, (I32)nl)) 0 23 23
1443 2 croak("%s: the replay check needs somewhere to remember assertion "
1444 "ids, and there is no `cache` store named '%.*s'. Profiles "
1445 "section 4.1.4.5 makes the check a MUST, so this is a "
1446 "refusal and not a warning. Declare a store (`cache 'file', "
1447 "dir => '/var/cache/myapp'`), or name another with `seen "
1448 "=> 'store'`, or pass your own `seen => sub {...}`. "
1449 "`allow_replay => 1` turns the check off and says in the "
1450 "configuration that you meant to",
1451 PSAML_WHO, (int)nl, np);
1452 }
1453 }
1454  
1455 /* Every provider resolved HERE, before the fork. A `metadata` source is
1456 * fetched or read and run through psaml_idp_from_metadata; an explicit
1457 * trio is used as given. */
1458 {
1459 27 HV *idps = (HV *)SvRV(psaml_app_get(aTHX_ app, PSAML_K_IDPS));
1460 27 AV *order = (AV *)SvRV(ordsv);
1461 27 SSize_t i, n = av_len(order) + 1;
1462 56 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 29 27 56
1463 29 SV **e = av_fetch(order, i, 0);
1464 STRLEN nl;
1465 const char *np;
1466 SV **cfge;
1467 HV *cfg;
1468 SV *meta;
1469 29 ▶ if (!e || !*e) continue;
Branch: 2 branches
BranchTrueFalseTotal
if (!e || !*e) continue; 29 0 29
if (!e || !*e) continue; 0 29 29
1470 29 np = SvPV_const(*e, nl);
1471 29 cfge = hv_fetch(idps, np, (I32)nl, 0);
1472 29 ▶ if (!cfge || !*cfge || !SvROK(*cfge)) continue;
Branch: 3 branches
BranchTrueFalseTotal
if (!cfge || !*cfge || !SvROK(*cfge)) continue; 29 0 29
if (!cfge || !*cfge || !SvROK(*cfge)) continue; 29 0 29
if (!cfge || !*cfge || !SvROK(*cfge)) continue; 0 29 29
1473 29 cfg = (HV *)SvRV(*cfge);
1474 29 meta = psaml_hget(aTHX_ cfg, "metadata");
1475 29 ▶ if (meta && SvOK(meta)) {
Branch: 2 branches
BranchTrueFalseTotal
if (meta && SvOK(meta)) { 9 20 29
if (meta && SvOK(meta)) { 9 0 9
1476 9 SV *bytes = sv_2mortal(psaml_fetch_metadata(aTHX_ app, meta, np));
1477 9 psaml_idp_merge(aTHX_ cfg, bytes, opts);
1478 /* No `last_refresh` is stamped here. The clock the rotation
1479 * refetch runs on starts at the first REFETCH, not at boot: a
1480 * provider that rotates its key an hour after this application
1481 * started should be picked up at the first failed login, not an
1482 * interval after one. */
1483 /* WantAuthnRequestsSigned, acted on. With a key, sign_requests
1484 * turns itself on; without one a croak naming the option, because
1485 * a provider that demands signed requests refuses every unsigned
1486 * one and every login fails. */
1487 9 ▶ if (psaml_opt_bool(aTHX_ cfg, "want_authn_requests_signed", 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (psaml_opt_bool(aTHX_ cfg, "want_authn_requests_signed", 0)) { 0 9 9
1488 0 ▶ if (hv_exists(opts, "key", 3))
Branch: 1 branch
BranchTrueFalseTotal
if (hv_exists(opts, "key", 3)) 0 0 0
1489 0 (void)hv_stores(opts, "sign_requests", newSViv(1));
1490 else
1491 0 croak("%s: saml_idp '%.*s' publishes "
1492 "WantAuthnRequestsSigned=\"true\" and this application "
1493 "has no `key`. Every AuthnRequest would be refused; "
1494 "configure `key` with the SP private key",
1495 PSAML_WHO, (int)nl, np);
1496 }
1497 }
1498 }
1499 }
1500  
1501 /* The ACS is a POST with no session and no token, from another origin.
1502 * It is the one request in the application that is SUPPOSED to look
1503 * exactly like a cross-site request forgery, and csrf must not check
1504 * it.
1505 *
1506 * MEASURED rather than assumed, which is what the plan asked for: the
1507 * exempt list is an arrayref on the application hash under `csrf`, it
1508 * is reachable here, and matching is a prefix match. So the path is
1509 * added. A silent requirement would be a 403 on every login. */
1510 {
1511 27 SV **csrf = hv_fetchs(psaml_app_hv(aTHX_ app), "csrf", 0);
1512 27 ▶ if (csrf && *csrf && SvROK(*csrf) && SvTYPE(SvRV(*csrf)) == SVt_PVHV) {
Branch: 4 branches
BranchTrueFalseTotal
if (csrf && *csrf && SvROK(*csrf) && SvTYPE(SvRV(*csrf)) == SVt_PVHV) { 1 26 27
if (csrf && *csrf && SvROK(*csrf) && SvTYPE(SvRV(*csrf)) == SVt_PVHV) { 1 0 1
if (csrf && *csrf && SvROK(*csrf) && SvTYPE(SvRV(*csrf)) == SVt_PVHV) { 1 0 1
if (csrf && *csrf && SvROK(*csrf) && SvTYPE(SvRV(*csrf)) == SVt_PVHV) { 1 0 1
1513 1 HV *ccfg = (HV *)SvRV(*csrf);
1514 1 SV **ex = hv_fetchs(ccfg, "exempt", 0);
1515 AV *list;
1516 SV *acs;
1517 1 ▶ if (ex && *ex && SvROK(*ex) && SvTYPE(SvRV(*ex)) == SVt_PVAV) {
Branch: 4 branches
BranchTrueFalseTotal
if (ex && *ex && SvROK(*ex) && SvTYPE(SvRV(*ex)) == SVt_PVAV) { 0 1 1
if (ex && *ex && SvROK(*ex) && SvTYPE(SvRV(*ex)) == SVt_PVAV) { 0 0 0
if (ex && *ex && SvROK(*ex) && SvTYPE(SvRV(*ex)) == SVt_PVAV) { 0 0 0
if (ex && *ex && SvROK(*ex) && SvTYPE(SvRV(*ex)) == SVt_PVAV) { 0 0 0
1518 0 list = (AV *)SvRV(*ex);
1519 }
1520 else {
1521 1 list = newAV();
1522 1 (void)hv_stores(ccfg, "exempt", newRV_noinc((SV *)list));
1523 }
1524 1 acs = newSVsv(mount);
1525 1 sv_catpvs(acs, "/acs");
1526 1 av_push(list, acs);
1527 }
1528 }
1529  
1530 27 psaml_mount_routes(aTHX_ app);
1531 27 XSRETURN_EMPTY;
1532 }
1533  
1534  
1535 /* ---- installing ------------------------------------------------------- */
1536  
1537 /* The keywords, and ONLY the keywords.
1538 *
1539 * Punk makes a second install_kw by the same owner a no-op, which is what
1540 * lets `use Punk::Plugin::SAML` and `plugin \'SAML\'` both ask and only the
1541 * first do anything. That is not true of `helper`, which refuses a second
1542 * registration of the same name even by the same owner, nor of
1543 * `on_compile`, which would simply run twice. So those go in register,
1544 * once, and this is called from both. */
1545 89 PERL_STATIC_INLINE void psaml_install_kw(pTHX_ SV *app) {
1546 AV *cap;
1547 89 cap = newAV(); av_push(cap, newSVsv(app));
1548 89 psaml_keyword(aTHX_ app, "saml_idp", psaml_kw_idp, cap);
1549 89 cap = newAV(); av_push(cap, newSVsv(app));
1550 89 psaml_keyword(aTHX_ app, "saml_login", psaml_kw_login, cap);
1551 89 }
1552  
1553 /* The helpers and the compile hook, from register only, and once.
1554 *
1555 * An application that says `use Punk::Plugin::SAML` and never
1556 * `plugin \'SAML\'` gets the keywords and no helpers, which is right: with
1557 * no plugin line there is no secret, no options and nothing for a helper
1558 * to answer from. */
1559 40 PERL_STATIC_INLINE void psaml_install_rest(pTHX_ SV *app) {
1560 AV *cap;
1561 40 ▶ if (psaml_app_get(aTHX_ app, PSAML_K_INSTALLED)) return;
Branch: 1 branch
BranchTrueFalseTotal
if (psaml_app_get(aTHX_ app, PSAML_K_INSTALLED)) return; 0 40 40
1562 40 psaml_app_set(aTHX_ app, PSAML_K_INSTALLED, newSViv(1));
1563 40 cap = newAV(); av_push(cap, newSVsv(app));
1564 40 psaml_helper(aTHX_ app, "saml_idps", psaml_help_idps, cap);
1565 40 cap = newAV(); av_push(cap, newSVsv(app));
1566 40 psaml_helper(aTHX_ app, "saml_url", psaml_help_url, cap);
1567 40 cap = newAV(); av_push(cap, newSVsv(app));
1568 40 psaml_at_compile(aTHX_ app, psaml_on_compile, cap);
1569 }
1570  
1571 #endif /* PSAML_BOOT_H */
« PSAML.c ↑ Summary xs/response.xs »