repro_mailbox_private_keys_in_log.py (2022B)
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: mailbox private keys end up in the log. 15 16 The periodic refresh runs every 30 seconds while developer mode is on, so this 17 waits a little over one period. 18 19 cd /opt/taler-sim/driver 20 python3 ../findings/repro_mailbox_private_keys_in_log.py [emulator-5554] 21 22 Exits 0 when a private key is found in logcat. 23 """ 24 25 from __future__ import annotations 26 27 import re 28 import sys 29 import time 30 from pathlib import Path 31 32 sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "driver")) 33 34 from device import Device # noqa: E402 35 from wallet import Wallet # noqa: E402 36 37 KEYS = re.compile(r"(privateKey|privateEncryptionKey)=([A-Z0-9]{20,})") 38 39 40 def main() -> int: 41 serial = sys.argv[1] if len(sys.argv) > 1 else "emulator-5554" 42 dev = Device(serial) 43 app = Wallet(dev) 44 app.fresh_start(dev_mode=True) 45 dev.logcat(clear=True) 46 47 print("waiting for the 30 s mailbox refresh ...") 48 found: list[tuple[str, str]] = [] 49 deadline = time.time() + 120 50 while time.time() < deadline and not found: 51 time.sleep(10) 52 found = KEYS.findall(dev.logcat()) 53 54 for field, value in found[:4]: 55 print(f" {field} = {value[:12]}… ({len(value)} chars) in logcat") 56 print(f"\nreproduced: {bool(found)}") 57 return 0 if found else 1 58 59 60 if __name__ == "__main__": 61 raise SystemExit(main())