Skip to content

Moves fingerprint enrollments behind the Fingerprint API - #844

Open
nishat-06 wants to merge 1 commit into
google:developfrom
nishat-06:uv-listed-templates
Open

nishat-06 wants to merge 1 commit into
google:developfrom
nishat-06:uv-listed-templates

Conversation

@nishat-06

@nishat-06 nishat-06 commented Nov 19, 2026 •

Copy link
Copy Markdown

Built-in UV accepts any finger the sensor matches. The applet identifies against every template on the FPC2534 (Identify::new(None)) and drops the template ID that IdentifyResult::Match returns, so the library can't tell an enrolled finger from a template OpenSK doesn't store. The sensor holds such a template when it finishes an enrollment that OpenSK never records: after enrollBegin, the finger is touched until the sensor completes the enrollment and cancelCurrentEnrollment is sent next (Enroll::abort only aborts a running enrollment, so a finished one stays on the sensor), or the device loses power before the template ID is stored. That finger passes built-in UV whenever at least one stored finger exists. It isn't listed by enumerateEnrollments, removeEnrollment can't delete it, and it survives authenticatorReset.

Reworked as the third option from #844: the environment owns both the templates and their metadata, so there is no one-to-one invariant left on the library side (this also covers #846 and #840).

  • Fingerprint gains init, list_enrollments and set_friendly_name, and remove_enrollment deletes the enrollment as well as the template. Capturing the last sample enrolls the template, and the implementation deletes it from the sensor if it can't store the enrollment. check_fingerprint only matches enrolled templates.
  • api::fingerprint::helper implements that storage on top of Persist, the way the key store helper does, keeping the template IDs and friendly names in keys::TEMPLATE_INFOS. Persist loses its five fingerprint methods and the library no longer touches the store for this.
  • The Wasefire environment stores enrollments through the helper, compares the matched template from IdentifyResult::Match against them, and deletes templates that are not enrolled in init. It can't restrict identification to a set of templates, since Identify::new takes a single optional template ID.
  • The test environment does the same, with the store shared between TestEnv and TestFingerprint, so it mirrors a real environment and the helper is covered by the library tests.

Since the trait changes, other Env implementations need to implement the three new methods and keep the metadata with the templates.

test_perform_built_in_uv_unenrolled_template leaves a template on the sensor without enrolling it and checks that built-in UV rejects it, test_init_removes_unenrolled_template checks that init deletes it, and test_enrollment_database_full now checks that a template the environment couldn't enroll is gone from the sensor.

  • Local tests pass (every check in run_desktop_tests.sh except cargo audit, which I don't have installed; no dependencies changed)
  • Tested against boards
    • Nordic nRF52840 DK
    • Nordic nRF52840 Dongle
    • Makerdiary nRF52840 MDK USB Dongle
  • Appropriate changes to README are included in PR

@kaczmarczyck kaczmarczyck left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I wonder where this problem should be solved.
The problem is that the assumed invariant between template ID storage and fingerprint template storage is broken. You are working on this in #846, but there might be more problems.
This PR wants to solve it in the library. It could also be a problem for the Env implementation. Or even the OS might need to help by either cleaning up fingerprints when installing OpenSK, or otherwise helping us enforce the invariant.

@ia0 Opinions?

@ia0

ia0 commented Nov 24, 2026

Copy link
Copy Markdown
Member

I can see at least 3 options:

  • The environment doesn't provide any isolation or helpers. The library is responsible to only look at fingerprints it understands.
  • The environment provides isolation but no helpers. The library only needs to maintain a one-to-one matching between the fingerprints in the environment and their metadata in the store.
  • The environment provides both isolation and helpers. The library doesn't need to use the store for metadata. The enviroment provides some amount of storage for metadata for each registered fingerprints. Deleting a fingerprint automatically deletes its metadata, so there's no one-to-one mapping invariant on the library side.

If the third option is possible, in my opinion it's the cleanest. The library is simpler and we can provide helpers (like we do for other APIs) to implement the environment using some keys in the storage.

@nishat-06

Copy link
Copy Markdown
Author

Option 3 looks possible with the API that is already there. matcher::list_templates() returns the template IDs of every finger on the sensor, and runner-nordic implements it for the FPC2534, so the environment can keep the metadata (today just the friendly name) keyed by template ID and reconcile it against the sensor list: a template with no metadata is a leftover, and metadata with no template is a stale entry. Reconciling once in init and deleting the leftovers there means the library never sees an unregistered finger, and the one-to-one invariant that #846 is about goes away.

One constraint on the isolation: Identify::new takes a single optional template ID, not a set, so identification cannot be restricted to the registered fingers. It has to be either the reconcile-and-delete above or a check on the matched template ID, which is what this PR does in the library.

I am happy to rework this as option 3: move listing and friendly names behind the Fingerprint API with a storage-backed helper for environments that want one, and drop the template IDs from Persist. Want me to take it that way, or keep the library-side check here while that lands?

@kaczmarczyck

Copy link
Copy Markdown
Collaborator

I agree that the invariant is not clean. Option 3 should be powerful enough, and ideally we don't need to put too much CTAP logic into the helper.
@nishat-06 If you want to take it, I appreciate it!

Built-in UV accepted any finger the sensor matched. The applet identifies
against every template on the FPC2534 (Identify::new(None)) and dropped
the template ID that IdentifyResult::Match returns, so the library could
not tell an enrolled finger from a template OpenSK doesn't store. The
sensor holds such a template when it finishes an enrollment that OpenSK
never records: after enrollBegin, the finger is touched until the sensor
completes the enrollment and cancelCurrentEnrollment is sent next
(Enroll::abort only aborts a running enrollment, so a finished one stays
on the sensor), or the device loses power before the template ID is
stored. That finger passed built-in UV whenever at least one stored
finger existed, was not listed by enumerateEnrollments, could not be
deleted with removeEnrollment, and survived authenticatorReset.

The root cause is the invariant between the template IDs in the store and
the templates on the sensor, which the library maintained on its own. The
environment now owns both, so there is no invariant left to break:

- Fingerprint gains init, list_enrollments and set_friendly_name, and
  remove_enrollment deletes the enrollment as well as the template.
  Capturing the last sample enrolls the template, and the implementation
  deletes it from the sensor if it can't store the enrollment.
  check_fingerprint only matches enrolled templates.
- api::fingerprint::helper implements that storage on top of Persist, the
  way the key store helper does, keeping the template IDs and friendly
  names in keys::TEMPLATE_INFOS. Persist loses the five fingerprint
  methods and the library no longer uses the store for this.
- The Wasefire environment stores enrollments through the helper,
  compares the matched template from IdentifyResult::Match against them,
  and deletes templates that are not enrolled in init.
- The test environment does the same with a store shared between TestEnv
  and TestFingerprint, so it mirrors a real environment.

test_perform_built_in_uv_unenrolled_template leaves a template on the
sensor without enrolling it and checks that built-in UV rejects it,
test_init_removes_unenrolled_template checks that init deletes it, and
test_enrollment_database_full now checks that a template the environment
couldn't enroll is gone from the sensor.
@nishat-06 nishat-06 changed the title Accepts built-in UV only for stored fingerprint templates Moves fingerprint enrollments behind the Fingerprint API Nov 29, 2026
@nishat-06

Copy link
Copy Markdown
Author

Reworked as option 3, so the environment owns the templates and their metadata. Fingerprint gained init, list_enrollments and set_friendly_name, remove_enrollment now deletes the enrollment as well as the template, capturing the last sample enrolls it (and deletes it from the sensor if the enrollment doesn't fit), and check_fingerprint only matches enrolled templates. Persist lost its five fingerprint methods and the library doesn't touch the store for this anymore.

The helper in api::fingerprint::helper is only storage on top of Persist, same shape as the key store helper: list, insert, remove, set a friendly name, and ask whether a template ID is enrolled. Nothing CTAP specific in it beyond the status codes the trait already documents.

One constraint on the isolation: Identify::new takes a single optional template ID, so identification can't be restricted to the enrolled set. The Wasefire environment compares the matched ID from IdentifyResult::Match against the store instead, and init deletes templates the sensor holds without an enrollment, so a leftover doesn't keep its slot forever. The test environment shares the store with TestFingerprint and does the same, which also puts the helper under the library tests.

With the invariant gone, #846 isn't needed, so I'm happy to close it if you agree.

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.

3 participants