Skip to content

fix(suite-desktop-core): fix async error in Windows signing#17446

Merged
Lemonexe merged 1 commit intodevelopfrom
fix-win-signing-async
Mar 6, 2025
Merged

fix(suite-desktop-core): fix async error in Windows signing#17446
Lemonexe merged 1 commit intodevelopfrom
fix-win-signing-async

Conversation

@Lemonexe
Copy link
Copy Markdown
Contributor

@Lemonexe Lemonexe commented Mar 6, 2025

Description

In #17056 and #17234, the electron-builder hook for windows signing was rewritten from CJS to TS.
➡️ fix inconsistent SHA hashes caused by async code.

Screenshots:

Verified locally by first changing L19 to

`java -jar ../suite-desktop-core/scripts/jsign-6.0.jar --keystore /my-folder/cert.pfx --storepass 1234 --storetype PKCS12 --tsaurl http://timestamp.digicert.com "${configuration.path}"`,

Using a locally generated .pfx file with password 1234.

Then I built and verified that SHA sums are the same (starts with ajWzamhw)

$ yarn workspace @trezor/suite-build run build:desktop
$ yarn workspace @trezor/suite-desktop build:app
$ yarn workspace @trezor/suite-desktop-core build:app:electron --publish never --win --x64

$ cat latest.yml | head -7
version: 25.4.0
files:
  - url: Trezor-Suite-25.4.0-win-x64.exe
    sha512: ajWzamhw4RD8LMfC5tGkBuSWL9qfTRjqBVx/DDeCVu7Q5TItG6pV/vmUiO3R/+nn/dFtf3hekcqpMY8sJ1tczA==
    size: 156784784
path: Trezor-Suite-25.4.0-win-x64.exe
sha512: ajWzamhw4RD8LMfC5tGkBuSWL9qfTRjqBVx/DDeCVu7Q5TItG6pV/vmUiO3R/+nn/dFtf3hekcqpMY8sJ1tczA==

$ shasum -a 512 Trezor-Suite-25.4.0-win-x64.exe | awk '{print $1}' | xxd -r -p | base64
ajWzamhw4RD8LMfC5tGkBuSWL9qfTRjqBVx/DDeCVu7Q5TItG6pV/vmUiO3R/+nn/dFtf3hekcqpMY8sJ1tczA==

@Lemonexe Lemonexe added the no-project This label is used to specify that PR doesn't need to be added to a project label Mar 6, 2025
const TOKEN_PASSWORD = process.env.WINDOWS_SIGN_TOKEN_PASSWORD;

await require('child_process').exec(
require('child_process').execSync(
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

in comment in the original PR, I thought this could be a problem, so I verified the electron-builder source code.

Still, it seems that the signing was finished async, after electron-builder calculated SHA hash and emitted latest.yml. The singing then changed the binary, which then produced inconsistent hash.

@Lemonexe Lemonexe marked this pull request as ready for review March 6, 2025 13:35
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 6, 2025

Walkthrough

The changes modify the implementation of the Windows signing function. The function's execution method has been updated to use a synchronous command execution approach provided by execSync from the child_process module, replacing the previous asynchronous implementation using exec. This adjustment ensures that the signing tool, jsign, is called synchronously. Additionally, the function signature has been updated by removing the async keyword, although it continues to return a Promise to meet TypeScript requirements. Comments within the file have been revised to document the necessity for the synchronous call and the associated control flow changes.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 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 generate docstrings to generate docstrings for this 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: 0

🧹 Nitpick comments (1)
packages/suite-desktop-core/scripts/sign-windows.ts (1)

5-5: Consider removing the async keyword.

Since the function now uses synchronous execution and doesn't contain any await statements (hence the ESLint directive), you could consider removing the async keyword from the function signature while still returning a Promise to satisfy the TypeScript requirements.

- const signWindows: CustomWindowsSign = async configuration => {
+ const signWindows: CustomWindowsSign = configuration => {

However, verify with electron-builder documentation if the function must be declared as async or if returning a Promise is sufficient.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3736dec and ded0606.

📒 Files selected for processing (1)
  • packages/suite-desktop-core/scripts/sign-windows.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (15)
  • GitHub Check: e2e-test-suite-web (@group=wallet)
  • GitHub Check: e2e-test-suite-web (@group=other)
  • GitHub Check: e2e-test-suite-web (@group=metadata2)
  • GitHub Check: e2e-test-suite-web (@group=metadata1)
  • GitHub Check: e2e-test-suite-web (@group=settings)
  • GitHub Check: e2e-test-suite-web (@group=device-management)
  • GitHub Check: e2e-test-suite-web (@group=suite)
  • GitHub Check: Linting and formatting
  • GitHub Check: run-desktop-tests (@group=wallet, trezor-user-env-unix bitcoin-regtest)
  • GitHub Check: run-desktop-tests (@group=other, trezor-user-env-unix)
  • GitHub Check: run-desktop-tests (@group=passphrase, trezor-user-env-unix)
  • GitHub Check: run-desktop-tests (@group=settings, trezor-user-env-unix bitcoin-regtest)
  • GitHub Check: run-desktop-tests (@group=device-management, trezor-user-env-unix)
  • GitHub Check: run-desktop-tests (@group=suite, trezor-user-env-unix)
  • GitHub Check: Analyze with CodeQL (javascript)
🔇 Additional comments (1)
packages/suite-desktop-core/scripts/sign-windows.ts (1)

3-4: Synchronous signing fixes the hash inconsistency issue.

This change resolves the issue where asynchronous signing caused inconsistent SHA hashes. By switching to execSync, we ensure the signing process completes before electron-builder continues with hash calculation.

This matches the concern in the previous PR where the signing was finishing async, after electron-builder calculated SHA hash and emitted latest.yml.

Also applies to: 18-23

@Lemonexe Lemonexe requested a review from vdovhanych March 6, 2025 14:00
@Lemonexe Lemonexe merged commit 83808a4 into develop Mar 6, 2025
@Lemonexe Lemonexe deleted the fix-win-signing-async branch March 6, 2025 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-project This label is used to specify that PR doesn't need to be added to a project

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants