From c9ecc2ddf73039dc4e829bb2cb5fe299dff821d5 Mon Sep 17 00:00:00 2001 From: "Peter D. Gray" Date: Tue, 26 Mar 2024 10:35:22 -0400 Subject: [PATCH] cleanups --- shared/calc.py | 15 +++++++++++---- shared/flow.py | 3 ++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/shared/calc.py b/shared/calc.py index d1f6e2cd..c09366e6 100644 --- a/shared/calc.py +++ b/shared/calc.py @@ -22,10 +22,12 @@ async def login_repl(): NUM_LINES = 7 # 10 - title - 2 for prompt - re_prefix = re.compile(r'^(\d\d+)-$') - re_pin = re.compile(r'^(\d\d+)-(\d\d+)$') + # recognise 12-12 / 12- but also accept underscore, or even space in pin: "12 12" + re_prefix = re.compile(r'^(\d\d+)[-_]$') + re_pin = re.compile(r'^(\d\d+)[-_ ](\d\d+)$') - blacklist = ['import', '__', ] + # in decreasing order of hazard... + blacklist = ['import', '__', 'exec', 'locals', 'globals', 'eval' ] lines = '''\ @@ -40,8 +42,10 @@ Example Commands: state = dict() state['sha256'] = lambda x: B2A(ngu.hash.sha256s(x)) + state['sha512'] = lambda x: B2A(ngu.hash.sha512(x).digest()) + state['ripemd'] = lambda x: B2A(ngu.hash.ripemd160(x)) state['cls'] = lambda: lines.clear() - state['help'] = lambda: 'Sorry, no help!' + state['help'] = lambda: 'Commands: ' + (', '.join(state)) while 1: dis.clear() @@ -69,6 +73,9 @@ Example Commands: ans = state[ln]() elif re_pin.match(ln) and len(ln) <= 13: # try login + m = re_pin.match(ln) + ln = m.group(1)+ '-' + m.group(2) + print(ln) try: pa.setup(ln) ok = pa.login() diff --git a/shared/flow.py b/shared/flow.py index 85c58fa7..a0efc8be 100644 --- a/shared/flow.py +++ b/shared/flow.py @@ -108,7 +108,7 @@ LoginPrefsMenu = [ NonDefaultMenuItem('Login Countdown', 'lgto', prelogin=True, chooser=countdown_chooser), NonDefaultMenuItem('MicroSD 2FA', 'sd2fa', menu=microsd_2fa, predicate=se2_and_real_secret), PreloginToggleMenuItem('Calculator Login', 'calc', ['Default Off', 'Calculator Login'], - story='''Boots into calculator mode. Enter your PIN as formula to login, or 12- to see prefix words. Normal calculator math works too.'''), + story='''Boots into calculator mode. Enter your PIN as formula to login, or 12- to see prefix words. Normal calculator math works too.''', predicate=lambda: version.has_qwerty), MenuItem('Test Login Now', f=login_now, arg=1), ] @@ -265,6 +265,7 @@ DangerZoneMenu = [ MenuItem("Set High-Water", f=set_highwater), MenuItem('Wipe HSM Policy', f=wipe_hsm_policy, predicate=hsm_policy_available), MenuItem('Clear OV cache', f=wipe_ovc), + MenuItem("Clear Address cache", f=wipe_address_cache), ToggleMenuItem("Sighash Checks", "sighshchk", ["Default: Block", "Warn"], invert=True, story='''\ If you disable sighash flag restrictions, and ignore the \