| 1 |
|
| MODULE = Punk::SAML PACKAGE = Punk::SAML::IdP |
| 2 |
|
| |
| 3 |
|
| # read($bytes, %opts): a provider out of metadata bytes. |
| 4 |
|
| # |
| 5 |
|
| # Bytes, not a URL. The fetch is a separate thing, so every refusal this |
| 6 |
|
| # reader makes is testable against a string and needs no network. |
| 7 |
|
| SV * |
| 8 |
|
| read(class, bytes, ...) |
| 9 |
|
| SV *class |
| 10 |
|
| SV *bytes |
| 11 |
|
| CODE: |
| 12 |
|
| HV *a; |
| 13 |
|
| SV *want; |
| 14 |
|
| int i; |
| 15 |
|
| PERL_UNUSED_VAR(class); |
| 16 |
18 |
▶ | if ((items - 2) % 2) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((items - 2) % 2) |
0 |
18 |
18 |
|
| 17 |
0 |
| croak("%s: IdP->read takes bytes and a list of pairs", PSAML_WHO); |
| 18 |
18 |
| a = newHV(); |
| 19 |
18 |
| sv_2mortal((SV *)a); |
| 20 |
21 |
▶ | for (i = 2; i + 1 < items; i += 2) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 2; i + 1 < items; i += 2) { |
3 |
18 |
21 |
|
| 21 |
|
| STRLEN kl; |
| 22 |
3 |
| const char *k = SvPV_const(ST(i), kl); |
| 23 |
3 |
| (void)hv_store(a, k, (I32)kl, newSVsv(ST(i + 1)), 0); |
| 24 |
|
| } |
| 25 |
18 |
| want = psaml_hget(aTHX_ a, "entity_id"); |
| 26 |
21 |
▶ | RETVAL = psaml_idp_from_metadata(aTHX_ bytes, |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = psaml_idp_from_metadata(aTHX_ bytes, |
3 |
15 |
18 |
|
| 27 |
6 |
▶ | (want && SvOK(want)) ? SvPV_nolen(want) : NULL, |
Branch: 1 branch
| Branch | True | False | Total |
| (want && SvOK(want)) ? SvPV_nolen(want) : NULL, |
3 |
0 |
3 |
|
| 28 |
|
| psaml_opt_bool(aTHX_ a, "enforce_cert_validity", 0)); |
| 29 |
|
| OUTPUT: |
| 30 |
|
| RETVAL |
| 31 |
|
| |
| 32 |
|
| MODULE = Punk::SAML PACKAGE = Punk::SAML::Metadata |
| 33 |
|
| |
| 34 |
|
| # The SP document. The ACS URL is passed in because phase 4 computed it |
| 35 |
|
| # once at on_compile and this must not be a second derivation of it. |
| 36 |
|
| SV * |
| 37 |
|
| build(class, ...) |
| 38 |
|
| SV *class |
| 39 |
|
| CODE: |
| 40 |
|
| HV *a; |
| 41 |
|
| int i; |
| 42 |
|
| PERL_UNUSED_VAR(class); |
| 43 |
57 |
▶ | if ((items - 1) % 2) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((items - 1) % 2) |
0 |
57 |
57 |
|
| 44 |
0 |
| croak("%s: Metadata->build takes a list of pairs", PSAML_WHO); |
| 45 |
57 |
| a = newHV(); |
| 46 |
57 |
| sv_2mortal((SV *)a); |
| 47 |
175 |
▶ | for (i = 1; i + 1 < items; i += 2) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 1; i + 1 < items; i += 2) { |
118 |
57 |
175 |
|
| 48 |
|
| STRLEN kl; |
| 49 |
118 |
| const char *k = SvPV_const(ST(i), kl); |
| 50 |
118 |
| (void)hv_store(a, k, (I32)kl, newSVsv(ST(i + 1)), 0); |
| 51 |
|
| } |
| 52 |
57 |
| RETVAL = psaml_sp_metadata(aTHX_ |
| 53 |
|
| psaml_hget(aTHX_ a, "entity_id"), |
| 54 |
|
| psaml_hget(aTHX_ a, "acs_url"), |
| 55 |
|
| psaml_hget(aTHX_ a, "cert"), |
| 56 |
|
| psaml_hget(aTHX_ a, "name_id_format"), |
| 57 |
|
| psaml_opt_bool(aTHX_ a, "authn_requests_signed", 0), |
| 58 |
|
| psaml_opt_bool(aTHX_ a, "want_assertions_signed", 1)); |
| 59 |
|
| OUTPUT: |
| 60 |
|
| RETVAL |
| 61 |
|
| |
| 62 |
|
| # sign($xml, $id, $key_pem, $cert_pem): an enveloped signature over the |
| 63 |
|
| # element with that ID, spliced in as its first child. |
| 64 |
|
| SV * |
| 65 |
|
| sign(class, xml, id, key_pem, cert_pem = &PL_sv_undef) |
| 66 |
|
| SV *class |
| 67 |
|
| SV *xml |
| 68 |
|
| SV *id |
| 69 |
|
| SV *key_pem |
| 70 |
|
| SV *cert_pem |
| 71 |
|
| CODE: |
| 72 |
|
| PERL_UNUSED_VAR(class); |
| 73 |
1 |
| RETVAL = psaml_sign_document(aTHX_ xml, id, key_pem, cert_pem); |
| 74 |
|
| OUTPUT: |
| 75 |
|
| RETVAL |
| 76 |
|
| |
| 77 |
|
| SV * |
| 78 |
|
| content_type(class) |
| 79 |
|
| SV *class |
| 80 |
|
| CODE: |
| 81 |
|
| PERL_UNUSED_VAR(class); |
| 82 |
1 |
| RETVAL = newSVpvs(PSAML_CT_METADATA); |
| 83 |
|
| OUTPUT: |
| 84 |
|
| RETVAL |
| 85 |
|
| |
| 86 |
|
| MODULE = Punk::SAML PACKAGE = Punk::SAML |
| 87 |
|
| |
| 88 |
|
| # Verify an enveloped signature on an arbitrary document, for t/. The |
| 89 |
|
| # same psaml_signature.h the Response verifier uses, so sign_metadata is |
| 90 |
|
| # checked against the real verifier rather than a second one written to |
| 91 |
|
| # agree with it. |
| 92 |
|
| int |
| 93 |
|
| _verify_document(xml, id, certs) |
| 94 |
|
| SV *xml |
| 95 |
|
| SV *id |
| 96 |
|
| SV *certs |
| 97 |
|
| CODE: |
| 98 |
2 |
| psaml_doc_guard *guard = NULL; |
| 99 |
|
| frx_doc *doc; |
| 100 |
|
| const frx_node *target; |
| 101 |
|
| psaml_verify_ctx ctx; |
| 102 |
|
| STRLEN il; |
| 103 |
2 |
| const char *ip = SvPVbyte(id, il); |
| 104 |
2 |
▶ | if (!SvROK(certs) || SvTYPE(SvRV(certs)) != SVt_PVAV) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!SvROK(certs) || SvTYPE(SvRV(certs)) != SVt_PVAV) |
2 |
0 |
2 |
| if (!SvROK(certs) || SvTYPE(SvRV(certs)) != SVt_PVAV) |
0 |
2 |
2 |
|
| 105 |
0 |
| croak("%s: _verify_document takes an arrayref of certificates", |
| 106 |
|
| PSAML_WHO); |
| 107 |
2 |
| doc = psaml_parse_response(aTHX_ xml, &guard); |
| 108 |
2 |
| target = psaml_frx(aTHX)->by_id(doc, "ID", ip, il); |
| 109 |
2 |
▶ | if (!target) XSRETURN_NO; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!target) XSRETURN_NO; |
0 |
2 |
2 |
|
| 110 |
2 |
| ctx.doc = doc; |
| 111 |
2 |
| ctx.keys = (AV *)SvRV(certs); |
| 112 |
2 |
| ctx.allow_sha1 = 0; |
| 113 |
2 |
| RETVAL = psaml_verify_element(aTHX_ &ctx, target); |
| 114 |
|
| OUTPUT: |
| 115 |
|
| RETVAL |
| 116 |
|
| |
| 117 |
|
| MODULE = Punk::SAML PACKAGE = Punk::SAML |
| 118 |
|
| |
| 119 |
|
| # The flow cookie's pieces, for t/. Phase 8's routes call the same |
| 120 |
|
| # functions; these let the suite prove the cookie itself without driving |
| 121 |
|
| # a browser through a cross-site POST. |
| 122 |
|
| |
| 123 |
|
| SV * |
| 124 |
|
| _flow_serialise(records, secret) |
| 125 |
|
| SV *records |
| 126 |
|
| SV *secret |
| 127 |
|
| CODE: |
| 128 |
0 |
▶ | if (!SvROK(records) || SvTYPE(SvRV(records)) != SVt_PVAV) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!SvROK(records) || SvTYPE(SvRV(records)) != SVt_PVAV) |
0 |
0 |
0 |
| if (!SvROK(records) || SvTYPE(SvRV(records)) != SVt_PVAV) |
0 |
0 |
0 |
|
| 129 |
0 |
| croak("%s: _flow_serialise takes an arrayref", PSAML_WHO); |
| 130 |
0 |
| RETVAL = psaml_flow_serialise(aTHX_ (AV *)SvRV(records), secret); |
| 131 |
|
| OUTPUT: |
| 132 |
|
| RETVAL |
| 133 |
|
| |
| 134 |
|
| SV * |
| 135 |
|
| _flow_parse(cookie, secret, now, ttl) |
| 136 |
|
| SV *cookie |
| 137 |
|
| SV *secret |
| 138 |
|
| IV now |
| 139 |
|
| IV ttl |
| 140 |
|
| CODE: |
| 141 |
0 |
| RETVAL = newRV_noinc((SV *)psaml_flow_parse(aTHX_ cookie, secret, |
| 142 |
|
| now, ttl)); |
| 143 |
|
| OUTPUT: |
| 144 |
|
| RETVAL |
| 145 |
|
| |
| 146 |
|
| SV * |
| 147 |
|
| _flow_cookie(value, mount, ttl) |
| 148 |
|
| SV *value |
| 149 |
|
| SV *mount |
| 150 |
|
| IV ttl |
| 151 |
|
| CODE: |
| 152 |
0 |
| RETVAL = psaml_flow_cookie(aTHX_ value, mount, ttl); |
| 153 |
|
| OUTPUT: |
| 154 |
|
| RETVAL |