| 1 |
|
| MODULE = Punk::SAML PACKAGE = Punk::SAML |
| 2 |
|
| |
| 3 |
|
| # The private primitives, exposed so the suite can drive the bundled |
| 4 |
|
| # codecs against their core oracles. None of this is public API and none |
| 5 |
|
| # of it is documented in POD; the leading underscore says so. |
| 6 |
|
| # |
| 7 |
|
| # They exist because a bundled codec that is only reached through a |
| 8 |
|
| # finished AuthnRequest is a codec whose failures arrive as "the login |
| 9 |
|
| # did not work". Phase 9 tests the flows; these test the pieces. |
| 10 |
|
| |
| 11 |
|
| SV * |
| 12 |
|
| _b64_encode(bytes) |
| 13 |
|
| SV *bytes |
| 14 |
|
| CODE: |
| 15 |
|
| STRLEN n, out; |
| 16 |
16 |
| const char *p = SvPVbyte(bytes, n); |
| 17 |
16 |
| RETVAL = newSV(psaml_b64_encoded_len(n) + 1); |
| 18 |
16 |
| SvPOK_on(RETVAL); |
| 19 |
16 |
| out = psaml_b64_encode(SvPVX(RETVAL), (const unsigned char *)p, n); |
| 20 |
16 |
| SvCUR_set(RETVAL, out); |
| 21 |
16 |
| *SvEND(RETVAL) = '\0'; |
| 22 |
|
| OUTPUT: |
| 23 |
|
| RETVAL |
| 24 |
|
| |
| 25 |
|
| SV * |
| 26 |
|
| _b64_decode(str, allow_ws = 0) |
| 27 |
|
| SV *str |
| 28 |
|
| int allow_ws |
| 29 |
|
| CODE: |
| 30 |
|
| STRLEN n, out; |
| 31 |
21 |
| const char *p = SvPVbyte(str, n); |
| 32 |
21 |
| RETVAL = newSV(psaml_b64_decoded_max(n) + 1); |
| 33 |
21 |
| SvPOK_on(RETVAL); |
| 34 |
21 |
| out = psaml_b64_decode_ws((unsigned char *)SvPVX(RETVAL), p, n, |
| 35 |
|
| allow_ws); |
| 36 |
21 |
▶ | if (out == (STRLEN)-1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (out == (STRLEN)-1) { |
12 |
9 |
21 |
|
| 37 |
12 |
| SvREFCNT_dec(RETVAL); |
| 38 |
12 |
| XSRETURN_UNDEF; |
| 39 |
|
| } |
| 40 |
9 |
| SvCUR_set(RETVAL, out); |
| 41 |
9 |
| *SvEND(RETVAL) = '\0'; |
| 42 |
|
| OUTPUT: |
| 43 |
|
| RETVAL |
| 44 |
|
| |
| 45 |
|
| SV * |
| 46 |
|
| _deflate(bytes) |
| 47 |
|
| SV *bytes |
| 48 |
|
| CODE: |
| 49 |
|
| STRLEN n, out; |
| 50 |
4 |
| const char *p = SvPVbyte(bytes, n); |
| 51 |
4 |
| RETVAL = newSV(psaml_deflate_bound(n) + 1); |
| 52 |
4 |
| SvPOK_on(RETVAL); |
| 53 |
4 |
| out = psaml_deflate_stored((unsigned char *)SvPVX(RETVAL), |
| 54 |
|
| (const unsigned char *)p, n); |
| 55 |
4 |
| SvCUR_set(RETVAL, out); |
| 56 |
4 |
| *SvEND(RETVAL) = '\0'; |
| 57 |
|
| OUTPUT: |
| 58 |
|
| RETVAL |
| 59 |
|
| |
| 60 |
|
| SV * |
| 61 |
|
| _xml_escape(str) |
| 62 |
|
| SV *str |
| 63 |
|
| CODE: |
| 64 |
|
| STRLEN n, out; |
| 65 |
3 |
| const char *p = SvPVbyte(str, n); |
| 66 |
3 |
| RETVAL = newSV(psaml_xml_escaped_max(n) + 1); |
| 67 |
3 |
| SvPOK_on(RETVAL); |
| 68 |
3 |
| out = psaml_xml_escape(SvPVX(RETVAL), p, n); |
| 69 |
3 |
| SvCUR_set(RETVAL, out); |
| 70 |
3 |
| *SvEND(RETVAL) = '\0'; |
| 71 |
|
| OUTPUT: |
| 72 |
|
| RETVAL |
| 73 |
|
| |
| 74 |
|
| # Returns undef on any refusal, so the test can assert the refusals as |
| 75 |
|
| # a set rather than wrapping every case in an eval. (Do not begin this |
| 76 |
|
| # line with the word "undef" after the hash: a .xs comment starting |
| 77 |
|
| # "# undef" or "# if" is passed through as a preprocessor directive.) |
| 78 |
|
| SV * |
| 79 |
|
| _time_parse(str) |
| 80 |
|
| SV *str |
| 81 |
|
| CODE: |
| 82 |
|
| STRLEN n; |
| 83 |
25 |
| const char *p = SvPVbyte(str, n); |
| 84 |
|
| IV t; |
| 85 |
25 |
▶ | if (!psaml_time_parse(p, n, &t)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!psaml_time_parse(p, n, &t)) |
15 |
10 |
25 |
|
| 86 |
15 |
| XSRETURN_UNDEF; |
| 87 |
10 |
| RETVAL = newSViv(t); |
| 88 |
|
| OUTPUT: |
| 89 |
|
| RETVAL |
| 90 |
|
| |
| 91 |
|
| SV * |
| 92 |
|
| _time_format(epoch) |
| 93 |
|
| IV epoch |
| 94 |
|
| CODE: |
| 95 |
|
| char buf[64]; |
| 96 |
1 |
| STRLEN n = psaml_time_format(buf, sizeof buf, epoch); |
| 97 |
1 |
| RETVAL = newSVpvn(buf, n); |
| 98 |
|
| OUTPUT: |
| 99 |
|
| RETVAL |
| 100 |
|
| |
| 101 |
|
| # Throws a blessed Punk::SAML::Error. t/00-load.t calls this on purpose, |
| 102 |
|
| # so the croak_sv shim in psaml_compat.h is exercised on every perl the |
| 103 |
|
| # suite runs on rather than first being reached inside a phase-6 check |
| 104 |
|
| # on somebody else's smoker. |
| 105 |
|
| void |
| 106 |
|
| _throw(code, message = NULL) |
| 107 |
|
| const char *code |
| 108 |
|
| SV *message |
| 109 |
|
| CODE: |
| 110 |
|
| PERL_UNUSED_VAR(message); |
| 111 |
1 |
| psaml_throw(aTHX_ code, NULL); |
| 112 |
|
| |
| 113 |
|
| # The shim itself, called directly rather than through the #ifndef, so |
| 114 |
|
| # the body is compiled and run everywhere. Be honest about what this |
| 115 |
|
| # buys: it catches crashes, wrong types and ref-flattening on any perl, |
| 116 |
|
| # but it cannot catch the location-dropping half of the bug, because the |
| 117 |
|
| # wrong shim passes these assertions on a modern perl too. That half is |
| 118 |
|
| # only ever provable on a smoker. |
| 119 |
|
| void |
| 120 |
|
| _croak_sv_selftest(sv) |
| 121 |
|
| SV *sv |
| 122 |
|
| CODE: |
| 123 |
2 |
| psaml_croak_sv(aTHX_ sv); |
| 124 |
|
| |
| 125 |
|
| # Resolve each provider table and report its version, so a broken |
| 126 |
|
| # install fails in one named place rather than three frames into a |
| 127 |
|
| # login. |
| 128 |
|
| void |
| 129 |
|
| _abi_versions() |
| 130 |
|
| PPCODE: |
| 131 |
|
| int v_frx, v_jws, v_fetch; |
| 132 |
2 |
| # A resolver runs Perl: eval_pv for the require, then call_pv for |
| 133 |
2 |
| # _abi_ptr. Perl code reallocates the argument stack, so an SP |
| 134 |
2 |
| # captured before the call is stale afterwards, and pushing |
| 135 |
2 |
| # through it writes into freed memory. Resolve into locals first, |
| 136 |
2 |
▶ | # SPAGAIN to pick the stack back up, and only then push. |
Branch: 1 branch
| Branch | True | False | Total |
| # SPAGAIN to pick the stack back up, and only then push. |
0 |
2 |
2 |
|
| 137 |
2 |
| v_frx = psaml_frx(aTHX)->abi_version; |
| 138 |
2 |
| v_jws = psaml_jws(aTHX)->version; |
| 139 |
2 |
| v_fetch = psaml_fetch(aTHX)->abi_version; |
| 140 |
|
| SPAGAIN; |
| 141 |
|
| EXTEND(SP, 3); |
| 142 |
|
| mPUSHi(v_frx); |
| 143 |
|
| mPUSHi(v_jws); |
| 144 |
|
| mPUSHi(v_fetch); |
| 145 |
|
| |
| 146 |
|
| void |
| 147 |
|
| _abi_needs() |
| 148 |
|
| PPCODE: |
| 149 |
1 |
▶ | EXTEND(SP, 3); |
Branch: 1 branch
| Branch | True | False | Total |
| EXTEND(SP, 3); |
0 |
1 |
1 |
|
| 150 |
1 |
| mPUSHi(PSAML_FRX_NEED); |
| 151 |
1 |
| mPUSHi(PSAML_JWS_NEED); |
| 152 |
1 |
| mPUSHi(PSAML_FETCH_NEED); |