Skip to content

Core for v3.1.x - #162

Closed
dangfan wants to merge 397 commits into
masterfrom
dev
Closed

dangfan wants to merge 397 commits into
masterfrom
dev

Conversation

@dangfan

@dangfan dangfan commented Sep 1, 2026

Copy link
Copy Markdown
Member
  • Streaming APDU
  • Add support for ML-DSA-65 & ML-KEM-768
  • CTAP 2.3
  • More extentions for PIV

dangfan and others added 28 commits August 29, 2026 16:17
Adopt GNU GCC/AFL++ builds and optimize ML-DSA streaming
Remove the FM11NC (SPI, HW_NFCA/HW_NFCA_LEGACY) code paths; FM11NT over
I2C is the only supported NFC front-end now. The porting contract gains
i2c_bus_recover() and loses spi_transmit()/spi_receive().

Rework the FM11NT idle recovery into an explicit state machine
(NONE/REQUESTED/SILENCED/UNSILENCE): the RF-silence period is timed with
a one-shot timeout instead of a blocking device_delay(), chip-level IRQ
masking replaces in-ISR draining during the silent period (with a drain
fallback if the mask write fails), and forced (error-triggered)
recoveries are latched before the session reset so an IRQ landing
mid-recovery is drained instead of being handled as normal activity.
…y first chunk

When Le is absent, apdu_output sends a zero-length first chunk and the
transport stamps the SW trailer at abData[0..1], which aliases the
pending chain store. The saved response_tail was discarded at the next
apdu_output entry because it keyed invalidation on sent == 0, which a
GET RESPONSE continuation also satisfies. Invalidate the tail at the
new-command dispatch points instead, so the restore actually runs.

A spurious GET RESPONSE with nothing pending now returns
SW_COMMAND_NOT_ALLOWED on the applet streaming path too, matching the
generic path, instead of 9000 with stale buffer contents.

Found by differential fuzzing against CIU98320B hardware.
…fuzzing

Reads hex APDUs on stdin, drives them through the virt-card via
process_apdu_from (APDU_TRANSPORT_CCID) with GET RESPONSE chaining, and
prints RESP <sw><data> per line. Long-lived: card state persists across
lines, so the host side can mirror a hardware fuzz campaign APDU for
APDU. DBG output is diverted to stderr to keep the pipe protocol clean.

Built via the new ENABLE_APDU_REPLAY option, which defines TEST but not
FUZZ: the FUZZ gates skip PIN/touch verification paths and would diverge
from real fuzz firmware, defeating the comparison.
A completed or abandoned chained response left rapdu_chaining.len > 0
behind, and neither a new non-GET-RESPONSE command nor a CCID slot
power cycle cleared it. A later spurious GET RESPONSE then served stale
shared_io_buffer bytes with the old SW (typically 9000), leaking
leftover response/request data across commands and sessions.

Per ISO 7816-4 a new command abandons any pending chain: dispatch now
resets both rapdu.len and sent (chaining handlers re-establish them;
OATH/ADMIN/SELECT/error paths leave len=0), and session expiry and the
no-owner session-reset branch drop pending RAPDU chains like they
already did for response sources and FIDO CAPDU chains.

Also gate the INS 0xEE/0xEF APDU test hooks behind TESTMODE_INS_HOOKS
(defined by ENABLE_TESTS/ENABLE_FUZZING, not ENABLE_APDU_REPLAY) so the
differential-fuzz replay build matches real firmware, which answers
6D00 to those INS.

Found by differential fuzzing against CIU98320B hardware.
Read LittleFS attributes using their stored payload length instead of the
overall PIV object capacity. This prevents PRINTED reads from clearing past
the 256-byte APDU response buffer on CIU firmware.

Add a bounded response-buffer regression test for the PIN-protected
management-key object.

Signed-off-by: Shengqi Chen <harry-chen@outlook.com>
canokey-crypto 5033de4/cf2f724: host software RSA and ECDH now reject
inconsistent CRT keys and invalid peer points instead of silently
repairing/accepting them, matching the hardware contract. Regression
tests exercise both via PIV import + GENERAL AUTHENTICATE.
PIV and OpenPGP imports now reject inconsistent CRT keys with 6A80 via
rsa_check_crt instead of accepting them and failing later (and
differently per platform) at use. Found by hardware differential
fuzzing (p==q import accepted, GET METADATA then diverged 6900/9000).
Update checkout, cache, and setup-go to their current major versions.
Advance canokey-crypto for its matching checkout update.

Signed-off-by: Shengqi Chen <harry-chen@outlook.com>
Advance canokey-crypto to the fixture fix that supplies valid CRT values
for the host RSA private-operation test.

Signed-off-by: Shengqi Chen <harry-chen@outlook.com>
The HIL runner opens a fresh PC/SC connection per fuzz case, so the
device's applet session (PIN validation, pending chains) expires between
cases via PC_to_RDR_IccPowerOff -> device_applet_session_reset. The
persistent harness process had no equivalent boundary, so host-side
validation outlived the device's and gated commands diverged (6982 vs
6D00). !POWEROFF expires the session identically (applets_poweroff +
chain/source resets); the runner sends one per case.
Return up to 256 random bytes for 00 84 and validate its APDU parameters. Also update the reported PIV firmware version to 6.0.0.
Require English for source comments, engineering documentation, diagnostics, and contribution metadata while allowing explicitly identified localization resources.

Signed-off-by: Shengqi Chen <harry-chen@outlook.com>
@coderabbitai

coderabbitai Bot commented Sep 1, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Too many files!

This PR contains 131 files, which is 31 over the limit of 100.

To get a review, reduce the PR to 100 files or fewer by splitting it into smaller PRs or changing its base branch.

Upgrade to a paid plan to raise the limit.

This review couldn't start because sufficient usage credits or metered capacity aren't available. Add credits or update usage-based reviews in the billing tab, then retry.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: c317faeb-7667-4de2-b64d-ccee45ab79ba

📥 Commits

Reviewing files that changed from the base of the PR and between 8b16814 and 70b89b6.

📒 Files selected for processing (131)
  • .clang-format
  • .github/workflows/test-openpgp.sh
  • .github/workflows/test-piv.sh
  • .github/workflows/tests.yml
  • .gitignore
  • AGENTS.md
  • CMakeLists.txt
  • DESIGN.md
  • FIDO2 Conformance Testing.json
  • README.md
  • applets/admin/admin.c
  • applets/ctap/cose-key.h
  • applets/ctap/ctap-errors.h
  • applets/ctap/ctap-internal.h
  • applets/ctap/ctap-parser.c
  • applets/ctap/ctap-parser.h
  • applets/ctap/ctap.c
  • applets/ctap/secret.c
  • applets/ctap/secret.h
  • applets/ctap/u2f.c
  • applets/ctap/u2f.h
  • applets/ndef/ndef.c
  • applets/oath/oath.c
  • applets/openpgp/openpgp.c
  • applets/pass/pass.c
  • applets/piv/piv-attestation.c
  • applets/piv/piv-attestation.h
  • applets/piv/piv.c
  • canokey-crypto
  • fuzzer/afl-fuzzer.c
  • fuzzer/apdu-replay.c
  • fuzzer/honggfuzz-debug.c
  • fuzzer/run-fuzzer.sh
  • fuzzing/.gitignore
  • include/admin.h
  • include/apdu.h
  • include/applet-scratch.h
  • include/applets.h
  • include/common.h
  • include/ctap.h
  • include/device-config.h
  • include/device.h
  • include/fs.h
  • include/key.h
  • include/ndef.h
  • include/nfc.h
  • include/openpgp.h
  • include/pass.h
  • include/pin.h
  • include/piv.h
  • include/pke.h
  • include/platform-config.h
  • interfaces/NFC/fm.c
  • interfaces/NFC/nfc.c
  • interfaces/USB/class/ccid/ccid.c
  • interfaces/USB/class/ccid/ccid.h
  • interfaces/USB/class/ccid/usbd_ccid.c
  • interfaces/USB/class/ctaphid/ctaphid.c
  • interfaces/USB/class/ctaphid/ctaphid.h
  • interfaces/USB/class/ctaphid/usbd_ctaphid.c
  • interfaces/USB/class/ctaphid/usbd_ctaphid.h
  • interfaces/USB/class/kbdhid/kbdhid.c
  • interfaces/USB/class/kbdhid/kbdhid.h
  • interfaces/USB/class/webusb/webusb.c
  • interfaces/USB/core/inc/usbd_core.h
  • interfaces/USB/core/inc/usbd_ctlreq.h
  • interfaces/USB/core/inc/usbd_def.h
  • interfaces/USB/core/inc/usbd_ioreq.h
  • interfaces/USB/core/src/usbd_core.c
  • interfaces/USB/core/src/usbd_ctlreq.c
  • interfaces/USB/core/src/usbd_ioreq.c
  • interfaces/USB/device/usb_device.c
  • interfaces/USB/device/usb_device.h
  • interfaces/USB/device/usbd_canokey.c
  • interfaces/USB/device/usbd_canokey.h
  • interfaces/USB/device/usbd_desc.c
  • littlefs
  • scripts/gen_ctap_get_info.py
  • scripts/gen_git_rev_header.cmake
  • scripts/gen_virt_card_git_rev_header.cmake
  • src/apdu.c
  • src/applets.c
  • src/common.c
  • src/device.c
  • src/fs.c
  • src/key.c
  • src/pin.c
  • src/pke.c
  • src/platform-config.c
  • test-real/.gitignore
  • test-real/macos-common.sh
  • test-real/pinentry-mock
  • test-real/test-macos-gpg.sh
  • test-real/test-macos-piv.sh
  • test-real/test-macos.sh
  • test-real/test-piv.sh
  • test-real/test-webusb.py
  • test-via-pcsc/Dockerfile
  • test-via-pcsc/Dockerfile.fido-local
  • test-via-pcsc/admin_test.go
  • test-via-pcsc/build_fido_tests.sh
  • test-via-pcsc/build_gpg.sh
  • test-via-pcsc/fido2_SM2_COSE_key.patch
  • test-via-pcsc/fido2_retry_ctap2_init.patch
  • test-via-pcsc/install_fido_tests.sh
  • test-via-pcsc/install_gpg.sh
  • test-via-pcsc/ndef_test.go
  • test-via-pcsc/oath_test.go
  • test-via-pcsc/openpgp_test.go
  • test-via-pcsc/piv-go-aes192.patch
  • test-via-pcsc/piv_test.go
  • test-via-pcsc/run-fido-ci-local.sh
  • test-via-pcsc/run-nontouch-tests.sh
  • test/CMakeLists.txt
  • test/piv_attestation_fixture.h
  • test/test_apdu.c
  • test/test_core_helpers.c
  • test/test_kbdhid.c
  • test/test_key.c
  • test/test_oath.c
  • test/test_openpgp.c
  • test/test_piv.c
  • tinycbor
  • virt-card/device-sim.c
  • virt-card/fabrication.c
  • virt-card/fabrication.h
  • virt-card/fido-hid-over-udp.c
  • virt-card/git-rev.h.in
  • virt-card/ifdhandler.c
  • virt-card/usb-dummy.c
  • virt-card/usb-dummy.h

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


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

Comment @coderabbitai help to get the list of available commands.

@dangfan dangfan closed this Sep 1, 2026
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