Skip to content

Harden CVC authentication and preserve APDU errors - #74

Draft
praveenperera wants to merge 8 commits into
bitcoindevkit:masterfrom
bitcoinppl:cvc-error-hardening
Draft

Harden CVC authentication and preserve APDU errors#74
praveenperera wants to merge 8 commits into
bitcoindevkit:masterfrom
bitcoinppl:cvc-error-hardening

Conversation

@praveenperera

@praveenperera praveenperera commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add a redacted and zeroizing Cvc type for Rust callers
  • Validate CVCs as 6–32 ASCII digits before authenticated commands
  • Document support for numeric CVC behavior in public firmware 1.0.1 and later
  • Return typed local CVC validation errors through UniFFI instead of reporting card BadArguments
  • Distinguish invalid current and replacement CVC values for change
  • Return BadAuth when a wait response reports failure
  • Preserve unknown card error codes and typed transport callback errors
  • Trim prompted CLI CVC input and return xpub failures instead of panicking
  • Regenerate the Swift bindings for the updated error model

Compatibility

  • Rust library callers must construct a Cvc instead of passing a raw string
  • UniFFI callers continue to pass strings, but invalid values now return typed CVC errors
  • UnknownStatusWord is renamed to UnknownErrorCode because the value comes from a CBOR card response
  • The Swift package now requires Swift 5.10 because UniFFI 0.32 emits nonisolated(unsafe)

Validation

  • cargo fmt --all --check
  • cargo test --workspace
  • cargo clippy --all-features --all-targets -- -D warnings
  • swift build

@praveenperera
praveenperera marked this pull request as draft August 18, 2026 15:30
Represent CVCs as zeroizing, redacted ASCII values and validate foreign and CLI inputs before card commands.

Reject unsuccessful wait responses so authentication failures cannot appear as completed delays.
Keep unknown status codes and callback error variants intact so callers can classify protocol failures without parsing transport strings.
Regenerate the Swift bindings for the updated error model and handle UniFFI's module-based artifact names in the XCFramework build.
Return local CVC validation details through each operation instead of reporting them as card BadArguments errors.

Name unknown CBOR error codes as card error codes, and document that the numeric CVC model targets public firmware 1.0.1 and later.
Trim surrounding whitespace from prompted CVC values and preserve internal whitespace for validation.

Return xpub input and command failures instead of panicking.
Expose the new CVC and card error variants to Swift consumers.

UniFFI 0.32 emits nonisolated(unsafe), which requires Swift 5.10. Raise the package minimum instead of patching generated source so the checked-in bindings remain direct generator output.
UniFFI 0.32 derives Swift artifact names from the configured CKTap
module. Keep those names in the package and build script so generation no
longer needs a version-dependent rename branch.
Deduplicate optional CVC parsing and ChangeError wrapping so
card entry points map validation failures consistently.
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