| 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 |
378 |
▶ | if ((items - 2) % 2) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((items - 2) % 2) |
0 |
378 |
378 |
|
| 23 |
0 |
| croak("%s: Response->verify takes bytes and a list of pairs", |
| 24 |
|
| PSAML_WHO); |
| 25 |
378 |
| a = newHV(); |
| 26 |
378 |
| sv_2mortal((SV *)a); |
| 27 |
2825 |
▶ | for (i = 2; i + 1 < items; i += 2) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 2; i + 1 < items; i += 2) { |
2447 |
378 |
2825 |
|
| 28 |
|
| STRLEN kl; |
| 29 |
2447 |
| const char *k = SvPV_const(ST(i), kl); |
| 30 |
2447 |
| (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 |
378 |
▶ | if (ix == 1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (ix == 1) |
21 |
357 |
378 |
|
| 40 |
21 |
| bytes = sv_2mortal(psaml_decode_field(aTHX_ bytes, |
| 41 |
|
| psaml_opt_iv(aTHX_ a, "max_response", 262144))); |
| 42 |
|
| |
| 43 |
378 |
| Zero(&o, 1, psaml_checks); |
| 44 |
378 |
| v = psaml_hget(aTHX_ a, "idp"); |
| 45 |
756 |
▶ | o.idp_name = (v && SvOK(v)) ? SvPV_nolen(v) : ""; |
Branch: 2 branches
| Branch | True | False | Total |
| o.idp_name = (v && SvOK(v)) ? SvPV_nolen(v) : ""; |
378 |
0 |
378 |
| o.idp_name = (v && SvOK(v)) ? SvPV_nolen(v) : ""; |
378 |
0 |
378 |
|
| 46 |
378 |
| v = psaml_hget(aTHX_ a, "entity_id"); |
| 47 |
378 |
▶ | if (!v || !SvOK(v)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!v || !SvOK(v)) |
378 |
0 |
378 |
| if (!v || !SvOK(v)) |
0 |
378 |
378 |
|
| 48 |
0 |
| croak("%s: Response->verify needs `entity_id`, this " |
| 49 |
|
| "application's own", PSAML_WHO); |
| 50 |
378 |
| o.entity_id = SvPV_nolen(v); |
| 51 |
378 |
| v = psaml_hget(aTHX_ a, "idp_entity_id"); |
| 52 |
378 |
▶ | if (!v || !SvOK(v)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!v || !SvOK(v)) |
378 |
0 |
378 |
| if (!v || !SvOK(v)) |
0 |
378 |
378 |
|
| 53 |
0 |
| croak("%s: Response->verify needs `idp_entity_id`, the " |
| 54 |
|
| "provider's", PSAML_WHO); |
| 55 |
378 |
| o.idp_entity_id = SvPV_nolen(v); |
| 56 |
378 |
| v = psaml_hget(aTHX_ a, "acs_url"); |
| 57 |
378 |
▶ | if (!v || !SvOK(v)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!v || !SvOK(v)) |
378 |
0 |
378 |
| if (!v || !SvOK(v)) |
0 |
378 |
378 |
|
| 58 |
0 |
| croak("%s: Response->verify needs `acs_url`", PSAML_WHO); |
| 59 |
378 |
| o.acs_url = SvPV_nolen(v); |
| 60 |
|
| |
| 61 |
378 |
| v = psaml_hget(aTHX_ a, "certs"); |
| 62 |
378 |
▶ | if (!v || !SvROK(v) || SvTYPE(SvRV(v)) != SVt_PVAV) |
Branch: 3 branches
| Branch | True | False | Total |
| if (!v || !SvROK(v) || SvTYPE(SvRV(v)) != SVt_PVAV) |
378 |
0 |
378 |
| if (!v || !SvROK(v) || SvTYPE(SvRV(v)) != SVt_PVAV) |
378 |
0 |
378 |
| if (!v || !SvROK(v) || SvTYPE(SvRV(v)) != SVt_PVAV) |
0 |
378 |
378 |
|
| 63 |
0 |
| croak("%s: Response->verify needs `certs`, an arrayref of the " |
| 64 |
|
| "provider's signing certificates", PSAML_WHO); |
| 65 |
378 |
| o.keys = (AV *)SvRV(v); |
| 66 |
|
| |
| 67 |
378 |
| v = psaml_hget(aTHX_ a, "now"); |
| 68 |
378 |
▶ | o.now = (v && SvOK(v)) ? SvIV(v) : (IV)time(NULL); |
Branch: 2 branches
| Branch | True | False | Total |
| o.now = (v && SvOK(v)) ? SvIV(v) : (IV)time(NULL); |
26 |
352 |
378 |
| o.now = (v && SvOK(v)) ? SvIV(v) : (IV)time(NULL); |
26 |
0 |
26 |
|
| 69 |
378 |
| o.skew = psaml_opt_iv(aTHX_ a, "skew", 120); |
| 70 |
378 |
| o.allow_sha1 = psaml_opt_bool(aTHX_ a, "allow_sha1", 0); |
| 71 |
378 |
| o.allow_idp_initiated = |
| 72 |
378 |
| psaml_opt_bool(aTHX_ a, "allow_idp_initiated", 0); |
| 73 |
378 |
| v = psaml_hget(aTHX_ a, "require_signed"); |
| 74 |
404 |
▶ | o.require_signed = (v && SvOK(v)) ? SvPV_nolen(v) : "either"; |
Branch: 2 branches
| Branch | True | False | Total |
| o.require_signed = (v && SvOK(v)) ? SvPV_nolen(v) : "either"; |
26 |
352 |
378 |
| o.require_signed = (v && SvOK(v)) ? SvPV_nolen(v) : "either"; |
26 |
0 |
26 |
|
| 75 |
378 |
| o.flow_id = psaml_hget(aTHX_ a, "in_response_to"); |
| 76 |
378 |
| o.seen_cb = psaml_hget(aTHX_ a, "seen"); |
| 77 |
|
| |
| 78 |
378 |
| RETVAL = psaml_verify_response(aTHX_ bytes, &o); |
| 79 |
|
| OUTPUT: |
| 80 |
|
| RETVAL |
| 81 |
|
| |
| 82 |
|
| MODULE = Punk::SAML PACKAGE = Punk::SAML |
| 83 |
|
| |
| 84 |
|
| # Sign raw bytes, for the suite's fixture builder. The same gap phase 5 |
| 85 |
|
| # hit from the other side: jws_abi signs arbitrary bytes but Crypt::JWS's |
| 86 |
|
| # Perl surface only makes compact tokens, so a Perl harness that has to |
| 87 |
|
| # produce an XML-DSig SignatureValue has no way in without this. |
| 88 |
|
| SV * |
| 89 |
|
| _sign_bytes(priv_pem, alg, input) |
| 90 |
|
| SV *priv_pem |
| 91 |
|
| SV *alg |
| 92 |
|
| SV *input |
| 93 |
|
| CODE: |
| 94 |
82 |
| const jws_abi *J = psaml_jws(aTHX); |
| 95 |
|
| STRLEN pl, al, il; |
| 96 |
82 |
▶ | const char *pp = SvPVbyte(priv_pem, pl); |
Branch: 1 branch
| Branch | True | False | Total |
| const char *pp = SvPVbyte(priv_pem, pl); |
82 |
0 |
82 |
|
| 97 |
82 |
▶ | const char *ap = SvPVbyte(alg, al); |
Branch: 1 branch
| Branch | True | False | Total |
| const char *ap = SvPVbyte(alg, al); |
82 |
0 |
82 |
|
| 98 |
82 |
| const char *ip = SvPVbyte(input, il); |
| 99 |
82 |
| void *k = J->key_from_pem(aTHX_ pp, pl); |
| 100 |
82 |
▶ | if (!k) croak("%s: the private key will not parse", PSAML_WHO); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!k) croak("%s: the private key will not parse", PSAML_WHO); |
0 |
82 |
82 |
|
| 101 |
82 |
| RETVAL = J->sign(aTHX_ k, ap, al, (const unsigned char *)ip, il); |
| 102 |
82 |
| J->key_free(aTHX_ k); |
| 103 |
82 |
▶ | if (!RETVAL) croak("%s: signing failed", PSAML_WHO); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!RETVAL) croak("%s: signing failed", PSAML_WHO); |
0 |
82 |
82 |
|
| 104 |
|
| OUTPUT: |
| 105 |
|
| RETVAL |
| 106 |
|
| |