Skip to content

Commit 01ea1e3

Browse files
authored
fix attach to pin issue (#367)
* fix attach to pin issue
1 parent 19d2711 commit 01ea1e3

File tree

9 files changed

+32
-23
lines changed

9 files changed

+32
-23
lines changed

core/src/apps/base.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,7 @@ def get_pinlocked_handler(
664664

665665
async def wrapper(ctx: wire.Context, msg: wire.Msg) -> protobuf.MessageType:
666666
await unlock_device(ctx)
667+
storage.cache.start_session()
667668
return await orig_handler(ctx, msg)
668669

669670
return wrapper
@@ -696,13 +697,8 @@ async def handle_GetPassphraseState(
696697
from trezor.messages import PassphraseState
697698
from apps.common import passphrase, paths
698699

699-
# Check if client supports attach pin
700-
(
701-
hasattr(msg, "allow_create_attach_pin")
702-
and msg.allow_create_attach_pin is not None
703-
)
704700
if not device_is_unlocked():
705-
await unlock_device(ctx, pin_use_type=2)
701+
await unlock_device(ctx, pin_use_type=PinType.USER_AND_PASSPHRASE_PIN)
706702
session_id = storage.cache.start_session()
707703

708704
from trezor.lvglui.scrs import fingerprints
@@ -759,13 +755,15 @@ async def handle_UnLockDevice(
759755
) -> UnLockDeviceResponse:
760756
"""Handle UnLockDevice message to unlock the device if needed."""
761757
if not config.is_unlocked():
762-
await unlock_device(ctx, pin_use_type=2)
758+
await unlock_device(ctx, pin_use_type=PinType.USER_AND_PASSPHRASE_PIN)
759+
storage.cache.start_session()
763760

764761
# Get current device state after unlock attempt
765762
from apps.common import passphrase
766763

767764
unlocked = config.is_unlocked()
768765
unlocked_attach_pin = passphrase.is_passphrase_pin_enabled() if unlocked else False
766+
769767
passphrase_protection = (
770768
storage.device.is_passphrase_enabled() if unlocked else False
771769
)

core/src/apps/homescreen/lockscreen.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ async def lockscreen() -> None:
1616
# to an unlocked state.
1717
try:
1818
await unlock_device()
19+
storage.cache.start_session()
1920
except wire.PinCancelled:
2021
pass
2122

core/src/apps/management/change_pin.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ async def change_pin(ctx: wire.Context, msg: ChangePin) -> Success:
5050
newpin = ""
5151

5252
if newpin:
53-
verified, usertype = config.check_pin(newpin, salt, PinType.PASSPHRASE_PIN)
53+
verified, usertype = config.check_pin(
54+
newpin, salt, PinType.PASSPHRASE_PIN_CHECK
55+
)
5456
if usertype == PinResult.PASSPHRASE_PIN_ENTERED:
5557
return await error_pin_used(ctx)
5658

core/src/apps/management/change_wipe_code.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ async def change_wipe_code(ctx: wire.Context, msg: ChangeWipeCode) -> Success:
3030

3131
if not msg.remove:
3232
# Pre-check the entered PIN.
33-
if config.has_pin() and not config.check_pin(pin, salt)[0]:
33+
from apps.common.pin_constants import PinType
34+
35+
if config.has_pin() and not config.check_pin(pin, salt, PinType.USER_CHECK)[0]:
3436
await error_pin_invalid(ctx)
3537

3638
# Get new wipe code.

core/src/apps/webauthn/fido2.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,9 @@ async def verify_user(keepalive_callback: KeepaliveCallback) -> bool:
663663
trezor.pin.keepalive_callback = keepalive_callback
664664

665665
await unlock_device()
666+
import storage.cache
667+
668+
storage.cache.start_session()
666669
return True
667670
except Exception:
668671
return False
@@ -806,6 +809,9 @@ async def confirm_dialog(self) -> bool:
806809

807810
try:
808811
await unlock_device()
812+
import storage.cache
813+
814+
storage.cache.start_session()
809815
return True
810816
except Exception:
811817
return False

core/src/boot.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ async def bootscreen() -> None:
3636
from apps.common.pin_constants import PinType
3737

3838
await verify_user_pin(pin_use_type=PinType.USER_AND_PASSPHRASE_PIN)
39+
storage.cache.start_session()
3940
storage.init_unlocked()
4041
loop.close(lvgl_task)
4142
return

core/src/trezor/lvglui/scrs/lockscreen.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ def eventhandler(self, event_obj: lv.event_t):
191191
from apps.base import unlock_device
192192

193193
workflow.spawn(unlock_device())
194+
import storage.cache
195+
196+
storage.cache.start_session()
194197

195198
def on_slide_up(self, event_obj: lv.event_t):
196199
code = event_obj.code
@@ -203,6 +206,9 @@ def on_slide_up(self, event_obj: lv.event_t):
203206
from apps.base import unlock_device
204207

205208
workflow.spawn(unlock_device())
209+
import storage.cache
210+
211+
storage.cache.start_session()
206212

207213
def _load_scr(self, scr: "Screen", back: bool = False) -> None:
208214
lv.scr_load(scr)

core/src/trezor/uart.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ async def handle_fingerprint():
160160
if __debug__:
161161
print(f"fingerprint unlock result {res}")
162162
await base.unlock_device()
163+
import storage.cache
164+
165+
storage.cache.start_session()
166+
163167
# await loop.sleep(2000)
164168
return
165169
else:
@@ -331,6 +335,9 @@ async def _deal_ble_pair(value):
331335
if not base.device_is_unlocked():
332336
try:
333337
await base.unlock_device()
338+
import storage.cache
339+
340+
storage.cache.start_session()
334341
except Exception:
335342
await safe_reloop()
336343
workflow.spawn(utils.internal_reloop())

core/src/trezor/ui/layouts/lvgl/attach_to_pin.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -198,20 +198,6 @@ async def show_attach_to_pin_window(ctx):
198198
if not save_result:
199199
return False
200200

201-
# Convert passphrase pin to string if needed
202-
passphrase_pin_str = (
203-
str(passphrase_pin)
204-
if not isinstance(passphrase_pin, str)
205-
else passphrase_pin
206-
)
207-
208-
# Verify the pin
209-
pinstatus, result = config.check_pin(
210-
passphrase_pin_str,
211-
None,
212-
PinType.USER_AND_PASSPHRASE_PIN,
213-
)
214-
215201
# Show success message
216202
await show_passphrase_set_and_attached_to_pin_window(
217203
ctx

0 commit comments

Comments
 (0)