Skip to content

pin-passphrase#294

Closed
lihuanhuan wants to merge 2 commits intoOneKeyHQ:mainfrom
lihuanhuan:pro_main
Closed

pin-passphrase#294
lihuanhuan wants to merge 2 commits intoOneKeyHQ:mainfrom
lihuanhuan:pro_main

Conversation

@lihuanhuan
Copy link
Copy Markdown
Contributor

@lihuanhuan lihuanhuan commented Apr 17, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Improved display handling during firmware installation cancellation, ensuring the screen is cleared and the status bar is updated.
    • Enhanced USB initialization to prevent repeated initialization during a single session.
    • Improved firmware verification logic to only check external firmware parts when necessary, reducing unnecessary operations.
    • Refined SPI input handling to ignore and flush unexpected data, improving communication reliability.
  • New Features

    • Introduced a background task to flush the FIDO buffer when WebAuthn is disabled, enhancing device responsiveness in certain configurations.
  • Style

    • Updated the user interface by removing some display elements from the firmware installation confirmation screen.

@lihuanhuan lihuanhuan requested a review from a team as a code owner April 17, 2025 01:49
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 17, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

The changes update several core components. USB initialization now only runs once per execution. Firmware verification for the second part is now conditional based on firmware size. Some display calls in the bootloader UI are commented out. The SPI legacy handler now checks headers before processing data. The firmware update process clears the display and updates the status bar after cancellation. A new asynchronous function flushes the FIDO buffer when WebAuthn is disabled.

Changes

Files/Paths Change Summary
core/embed/bootloader/bootui.c Commented out two display calls in the install confirm UI function.
core/embed/bootloader/main.c Added a static flag to ensure USB initialization runs only once.
core/embed/emmc_wrapper/emmc_commands.c Added display clear and status bar update after firmware update cancellation.
core/embed/trezorhal/image.c Made P2 firmware verification conditional on firmware size; moved related checks inside this block.
core/embed/trezorhal/spi_legacy.c Added header check before processing; only flushes FIFO if header is invalid.
core/src/session.py Added async flush_fido_buffer; schedules it when WebAuthn is disabled and not Bitcoin-only.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between 5effed2 and 181eaa5.

📒 Files selected for processing (6)
  • core/embed/bootloader/bootui.c (1 hunks)
  • core/embed/bootloader/main.c (1 hunks)
  • core/embed/emmc_wrapper/emmc_commands.c (1 hunks)
  • core/embed/trezorhal/image.c (1 hunks)
  • core/embed/trezorhal/spi_legacy.c (1 hunks)
  • core/src/session.py (1 hunks)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🔭 Outside diff range comments (3)
core/embed/extmod/modtrezorconfig/modtrezorconfig.c (2)

109-113: ⚠️ Potential issue

Docstring outdated

The text still promises a bool, but the function now returns a tuple.


118-124: ⚠️ Potential issue

Unused parameter

ext_salt is validated but never used.

core/embed/trezorhal/se_thd89.c (1)

1125-1132: ⚠️ Potential issue

Length check mismatch

The check uses PIN_MAX_LEN, but buffer size is hard‑coded to 64.

Also applies to: 1166-1169

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b37a61c and 1210c49.

⛔ Files ignored due to path filters (2)
  • core/mocks/generated/trezorconfig.pyi is excluded by !**/generated/**
  • core/mocks/generated/trezorcrypto/se_thd89.pyi is excluded by !**/generated/**
📒 Files selected for processing (4)
  • core/embed/extmod/modtrezorconfig/modtrezorconfig.c (2 hunks)
  • core/embed/extmod/modtrezorcrypto/modtrezorcrypto-se-thd89.h (1 hunks)
  • core/embed/trezorhal/se_thd89.c (9 hunks)
  • core/embed/trezorhal/se_thd89.h (3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
core/embed/extmod/modtrezorconfig/modtrezorconfig.c (4)
core/embed/trezorhal/se_thd89.h (1)
  • se_get_pin_type (102-102)
core/embed/trezorhal/se_thd89.c (1)
  • se_get_pin_type (1347-1347)
core/embed/fp_sensor_wrapper/fpsensor_platform.c (1)
  • fpsensor_data_init (399-449)
core/embed/fp_sensor_wrapper/fpsensor_platform.h (1)
  • fpsensor_data_init (41-41)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Style check
  • GitHub Check: Defs check
  • GitHub Check: Gen check

Comment on lines +15 to +30
#define PIN_MAX_LENGTH (50)
#define PASSPHRASE_MAX_LENGTH (50)

typedef enum {
PIN_SUCCESS,
USER_PIN_ENTERED,
PASSPHRASE_PIN_ENTERED,
USER_PIN_NOT_ENTERED,
WIPE_CODE_ENTERED,
PIN_SAME_AS_USER_PIN,
PIN_SAME_AS_WIPE_CODE,
PIN_PASSPHRASE_MAX_ITEMS_REACHED,
PIN_PASSPHRASE_SAVE_FAILED,
PIN_PASSPHRASE_READ_FAILED,
PIN_FAILED
} pin_result_t;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Duplicate constant names

PIN_MAX_LENGTH here conflicts with PIN_MAX_LEN in the .c file.

Comment on lines +18 to +19
#define PIN_MAX_LEN (50)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Shadowed macro

Defines PIN_MAX_LEN while header uses PIN_MAX_LENGTH.

Comment on lines +943 to +951
/// def save_pin_passphrase(pin: str, passphrase: str) -> bool:
/// """
/// Save the pin and passphrase to the list.
/// Returns True on success, False on failure.
/// """
STATIC mp_obj_t mod_trezorcrypto_se_thd89_save_pin_passphrase(
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Docstring inconsistent

Message says “Returns True on success, False on failure” but the function can raise ValueError.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (2)
core/embed/trezorhal/se_thd89.c (2)

18-19: Shadowed macro

Defines PIN_MAX_LEN while header uses PIN_MAX_LENGTH.


1317-1345: ⚠️ Potential issue

Inconsistent constant usage

Using PIN_MAX_LENGTH instead of PIN_MAX_LEN here.

-  if (strlen(pin) < 6 || strlen(pin) > PIN_MAX_LENGTH) {
+  if (strlen(pin) < 6 || strlen(pin) > PIN_MAX_LEN) {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between 1210c49 and 5effed2.

⛔ Files ignored due to path filters (2)
  • core/mocks/generated/trezorconfig.pyi is excluded by !**/generated/**
  • core/mocks/generated/trezorcrypto/se_thd89.pyi is excluded by !**/generated/**
📒 Files selected for processing (4)
  • core/embed/extmod/modtrezorconfig/modtrezorconfig.c (2 hunks)
  • core/embed/extmod/modtrezorcrypto/modtrezorcrypto-se-thd89.h (3 hunks)
  • core/embed/trezorhal/se_thd89.c (9 hunks)
  • core/embed/trezorhal/se_thd89.h (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • core/embed/extmod/modtrezorcrypto/modtrezorcrypto-se-thd89.h
  • core/embed/trezorhal/se_thd89.h
  • core/embed/extmod/modtrezorconfig/modtrezorconfig.c
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Defs check
  • GitHub Check: Gen check
  • GitHub Check: Style check
🔇 Additional comments (3)
core/embed/trezorhal/se_thd89.c (3)

255-258: Good defensive coding

Avoids undefined behavior when no data is received.


1183-1186: Update pin_type correctly

Properly captures PIN verification result type.


1347-1348: Good accessor methods

Clean implementation of getter functions.

@@ -1147,12 +1160,18 @@ secbool se_setPin(const char *pin) {
static secbool se_verifyPin_ex(uint8_t addr, uint8_t *session_key,
const char *pin) {
uint8_t pin_buf[50 + 1] = {0};
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Buffer size concern

Fixed size pin_buf[50 + 1] but PIN_MAX_LEN is 50. Use PIN_MAX_LEN + 1.

-  uint8_t pin_buf[50 + 1] = {0};
+  uint8_t pin_buf[PIN_MAX_LEN + 1] = {0};
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
uint8_t pin_buf[50 + 1] = {0};
uint8_t pin_buf[PIN_MAX_LEN + 1] = {0};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant