Skip to content

fix: zero password buffers and rename misleading APDU constant#932

Merged
matrix-agent116 merged 3 commits into
release_v4.9.6from
fix/fix-stdin-zero-and-apdu-name
May 20, 2026
Merged

fix: zero password buffers and rename misleading APDU constant#932
matrix-agent116 merged 3 commits into
release_v4.9.6from
fix/fix-stdin-zero-and-apdu-name

Conversation

@zerodevblock-cyber
Copy link
Copy Markdown
Collaborator

@zerodevblock-cyber zerodevblock-cyber commented May 20, 2026

Summary

Addresses two code-review findings from PR #931:

  • StdinPasswordReader — wrap the read/parse in try-finally and Arrays.fill the chunk and bytes buffers before returning, matching the existing defensive pattern in StandardCliRunner.authenticate() (added in PR feat: add standard CLI mode with JSON output for AI agents and automation #921). The returned String still holds the password in its own char[] — a Java-language limitation — but the intermediate byte arrays no longer linger on the heap until GC.
  • NonInteractiveLedgerSigner — rename APDU_APP_IS_OPEN to APDU_APP_NOT_OPEN. The Javadoc and the surfaced error message ("Open the Tron app on your Ledger device") already treat 0x6511 as the "app not open" signal; the identifier now reads in the same direction, removing a footgun for future maintainers.

Test plan

  • Existing tests pass (./gradlew test)
  • Spot-check: echo "$pw" | java -jar build/libs/wallet-cli.jar --password-stdin ... still authenticates
  • Spot-check: Ledger sign with Tron app closed still surfaces ledger_app_not_open

🤖 Generated with Claude Code

Will and others added 3 commits May 19, 2026 17:37
- Split LedgerAddressUtil.getTronAddress into getRawAddressResponse +
  parseTronAddress so callers can inspect APDU status words before parsing
- Add LedgerPorts.AppNotOpenException for APDU 0x6511 (Tron app not open),
  distinct from a null return (device not found / address mismatch)
- NonInteractiveLedgerSigner catches AppNotOpenException and returns
  APP_NOT_OPEN outcome instead of NOT_CONNECTED
- ProductionLedgerPorts uses try-finally to unconditionally reset
  standardCliQuiet after executeSignListen returns, fixing permanent stdout
  suppression when device times out without a HID callback
- AliasResolutionException overrides fillInStackTrace as a no-op to avoid
  unnecessary stack capture on control-flow exceptions

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
On some OS/firmware combinations, HidDevice.open() returns false when
the Tron app is not running, causing getLedgerHidDevice() to return null
and the signer to report NOT_CONNECTED instead of APP_NOT_OPEN.

- Add HidServicesWrapper.hasAnyLedgerAttached() to distinguish "no device"
  from "device present but not openable"
- Throw AppNotOpenException in ProductionLedgerPorts when getHidDevice()
  returns null but a Ledger is physically attached
- Also check the return value of the second device.open() call (B2 path)
  which was previously ignored, causing the same misclassification
- Add test: returnsAppNotOpenWhenFinderThrowsAppNotOpenException

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…ng APDU constant

- StdinPasswordReader.readAll wraps the read/parse in try-finally and
  Arrays.fill the chunk and bytes buffers before returning, matching the
  defensive pattern already used in StandardCliRunner.authenticate. The
  returned String still holds the password in its own char[], but the
  intermediate byte arrays no longer linger on the heap until GC.
- Rename APDU_APP_IS_OPEN to APDU_APP_NOT_OPEN. The Javadoc and the error
  message ("Open the Tron app on your Ledger device") already treat 0x6511
  as the "not open" signal; the identifier now matches.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@matrix-agent116 matrix-agent116 merged commit 5877823 into release_v4.9.6 May 20, 2026
@zerodevblock-cyber zerodevblock-cyber deleted the fix/fix-stdin-zero-and-apdu-name branch May 20, 2026 06:27
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.

2 participants