Skip to content

Normalize UID casing in testPAndC PICC comparison#2

Open
Amperstrand wants to merge 1 commit into
boltcard:masterfrom
Amperstrand:fix/uid-case-sensitivity
Open

Normalize UID casing in testPAndC PICC comparison#2
Amperstrand wants to merge 1 commit into
boltcard:masterfrom
Amperstrand:fix/uid-case-sensitivity

Conversation

@Amperstrand
Copy link
Copy Markdown

@Amperstrand Amperstrand commented Apr 18, 2026

Summary

Normalize the NFC UID to lowercase before comparing it with decrypted PICC data in testPAndC. Fixes false "Test PICC: decrypt with key failed" results on Android when the UID contains A-F characters.

Root cause

In SetupBoltcard.tsx, the app passes tag?.id from Android NFC into Ntag424.testPAndC(...).

On Android, tag?.id is uppercase (e.g. 049F70FA967380).

In NTag424.tsx, the decrypted PICC data is converted to hex with CryptoJS.enc.Hex.stringify(decPiccData), which returns lowercase hex. The comparison:

if (decryptedPiccData.startsWith("c7" + uid)) result.pTest = true;

fails because:

  • decrypted PICC data: c7049f70fa967380...
  • expected prefix: c7049F70FA967380

The decryption succeeds — only the string comparison fails due to case.

Fix

- if (decryptedPiccData.startsWith("c7" + uid)) result.pTest = true;
+ if (decryptedPiccData.startsWith("c7" + uid.toLowerCase())) result.pTest = true;

This aligns with the CMAC comparison in the same function, which already normalizes case with cVal.toLowerCase().

Verification

Confirmed the full source flow:

  • SetupBoltcard.tsx passes tag?.id (uppercase on Android) into Ntag424.testPAndC(...)
  • NTag424.tsx compares that UID against CryptoJS.enc.Hex.stringify(decPiccData) (lowercase)
  • One-line fix normalizes the UID before comparison

Fixes #1

CryptoJS.enc.Hex.stringify() returns lowercase hex, while tag.id is uppercase on Android. Lowercase the UID before the startsWith check so valid PICC decryptions don't show a false failure.

Fixes boltcard#1

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Amperstrand pushed a commit to Amperstrand/bolt-card-programmer that referenced this pull request Apr 19, 2026
AGENTS.md:
- Add lesson boltcard#2: partial reset cards can have any combination of keys
  at original values or all-zeros (0000...0000).
- Clarify that getKeyVersion is a plain APDU — no auth, no side effects,
  does NOT trigger 91ad AUTHENTICATION_DELAY. Only failed authentication
  attempts cause card delays.
- Document the automatic recovery flow (probe, adapt, skip).

read.tsx:
- Key version display now explains what version 00 means:
  "key is all-zeros (factory default)" vs "key has been changed".

reset.tsx + ResetBoltcard.tsx:
- Probe output explicitly states "key is 0000...0000, skipping" when
  a key is already at factory defaults.
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.

[Bug] Test PICC: decrypt with key failed

1 participant