From 9761c65614b7e10831a4880ff81dcd8a7759f977 Mon Sep 17 00:00:00 2001 From: scgbckbone Date: Thu, 10 Oct 2024 21:44:26 +0200 Subject: [PATCH] fixes 02 --- shared/auth.py | 3 +-- shared/ccc.py | 12 ++++++------ testing/test_ccc.py | 13 +++++++------ 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/shared/auth.py b/shared/auth.py index fedf4896..211b12b4 100644 --- a/shared/auth.py +++ b/shared/auth.py @@ -792,7 +792,6 @@ class ApproveTransaction(UserAuthorizedAction): # Prompt user w/ details and get approval from glob import dis, hsm_active from ccc import CCCFeature - from exceptions import CCCPolicyViolationError # step 1: parse PSBT from PSRAM into in-memory objects. @@ -847,7 +846,7 @@ class ApproveTransaction(UserAuthorizedAction): # early test for spending policy; not an error if violates policy # - might add warnings - could_ccc_sign, needs_2fa = CCCFeature.could_sign(self.psbt) + could_ccc_sign, needs_2fa = await CCCFeature.could_sign(self.psbt) # step 2: figure out what we are approving, so we can get sign-off # - outputs, amounts diff --git a/shared/ccc.py b/shared/ccc.py index 92e7da69..32a664dd 100644 --- a/shared/ccc.py +++ b/shared/ccc.py @@ -126,10 +126,10 @@ class CCCFeature: @classmethod - def could_sign(cls, psbt): + async def could_sign(cls, psbt): # We are looking at a PSBT: can we sign it, and would we? # - if we **could** but will not, due to policy, add warning msg - # - return (we could sign, needs2fa step) + # - return (we could sign, needs 2fa step) if not cls.is_enabled: return False, False @@ -139,15 +139,15 @@ class CCCFeature: return False, False xfp = cls.get_xfp() - if (xfp not in ms.xfp_paths): + if xfp not in ms.xfp_paths: # does not involve us return False, False try: # check policy - needs_2fa = cls.meets_policy(psbt) - except CCCPolicyViolationError: - psbt.warning.append(('CCC', "Violates spending policy. Won't sign.")) + needs_2fa = await cls.meets_policy(psbt) + except CCCPolicyViolationError as e: + psbt.warnings.append(('CCC', "Violates spending policy - %s. Won't sign." % e)) return False, False return True, needs_2fa diff --git a/testing/test_ccc.py b/testing/test_ccc.py index 547d05f7..bdc933ca 100644 --- a/testing/test_ccc.py +++ b/testing/test_ccc.py @@ -372,13 +372,14 @@ def test_ccc_cosign(setup_ccc, enter_enabled_ccc, ccc_ms_setup, fake_ms_txn, sta psbt = psbt_resp.get("psbt") start_sign(base64.b64decode(psbt)) + time.sleep(.1) + title, story = cap_story() + assert 'OK TO SEND?' == title if not magnitude_ok: - time.sleep(.1) - title, story = cap_story() - assert "Policy Violation" == title - assert "magnitude" in story - assert "sign with A key" in story - press_select() + assert "(1 warning below)" in story + assert "CCC: Violates spending policy - magnitude. Won't sign." in story + else: + assert "warning" not in story signed = end_sign(accept=True) po = BasicPSBT().parse(signed)