Closed Bug 2071247 Opened 2 months ago Closed 1 month ago

Integrate EncryptorDecryptor for rust credit card store

Categories

(Toolkit :: Form Autofill, task, P2)

task

Tracking

()

RESOLVED FIXED
160 Branch
Tracking Status
firefox160 --- fixed

People

(Reporter: dimi, Assigned: dimi)

References

(Blocks 2 open bugs)

Details

Attachments

(3 external files, 1 obsolete file)

No description provided.

The Rust store now holds an EncryptorDecryptor, so it owns the key and decides
what counts as undecryptable. The adapter's crypto sites go through the store
instead of OSKeyStore; a number encrypted under any other key would read back
as an unreadable card. Reading one becomes decryptNumber(), the single place
this store decrypts.

RustAutofillStore opens the store with a key held in NSS's key4.db under its
own name, distinct from logins', and supplies the primary password through a
PrimaryPasswordAuthenticator modelled on passwordmgr's. Both stores keep keys
in the same key4.db, so the prompt is shared: this one declines while
LoginHelper.requestReauth holds the token logged out, and announces the
outcome on the topics passwordmgr's callers already wait on.

A cancelled prompt and data that will not decrypt arrive as the same crypto
error, so the handler records which it was and decryptNumber turns a
cancellation back into NS_ERROR_ABORT, which is what crypto-SDR and the JSON
store report and what callers branch on.

Cards written under OSKeyStore no longer read back. The JSON records they were
copied from are still there -- the migration never wipes its source -- but
nothing re-runs the copy on its own, so recovering them needs the profile put
back on the JSON store first. No profile is in that position: the pref is off
on every channel.

The Rust store encrypts with a key of its own, so which key reads a card back
depends on which store wrote it and cc-number-encrypted can no longer be
handed straight to OSKeyStore.

Both credit card collections grow decryptNumber(), and the three consumers that
decrypted for themselves -- filling a form, opening the edit dialog, and
revealing a card in the sidebar -- ask the collection they read the record
from. For the JSON store that is OSKeyStore as before, re-authentication and
its telemetry trigger included; for the Rust store re-authentication is a step
of its own, its key not being the one the OS prompt guards, and it asks not to
be handed an OS key store key it would never read.

FormAutofillSection is bundled for iOS, where importing the storage would drag
the whole store in with it, so the parent passes the decryption in rather than
the section reaching for it.

The migration itself is unchanged: it already crossed the number in the clear.
What moves is which key each side uses. #creditCardKeysAvailable asks about
both now: reading the source does not cover the Rust store's key, which the
copy needs to write with, and a primary password answered mid-copy would spend
one of the three attempts the migration gets.

A browser test covers what the xpcshell ones cannot: filling a form is the only
path that takes the ciphertext the receiving store wrote and asks for the
number back. It saves a card in JSON, migrates it, fills it, captures a new one
against the Rust store, resubmits a stored card to check it is recognised
rather than duplicated, and switches back. Its own directory, since a manifest
sets prefs for all of its tests and the address suite has to keep running
without this one turned on.

Depends on D325372

The store's key lives in NSS, so a profile with a primary password set cannot
read it until the user supplies one. P1 left that case declining rather than
prompting; this is the prompt, and everything that has to hold still around it.

The prompt itself is passwordmgr's, shown from a PrimaryPasswordAuthenticator
modelled on RustLoginStorageAuthenticator. Both stores keep keys in the same
key4.db and the token is global, so unlocking for one unlocks the other: this
announces the outcome on the topics passwordmgr's callers already wait on, and
declines while LoginHelper.requestReauth holds the token deliberately logged
out rather than answering its prompt for it.

A declined prompt and data that will not decrypt reach JS as the same crypto
error. The handler records which it was and the adapter turns a cancellation
back into NS_ERROR_ABORT, which is what crypto-SDR and the JSON store report
and what callers already branch on: an edit dialog returns rather than opening
with a blank number, and a merge that needed the stored number refuses instead
of quietly dropping it. getDuplicateRecords gives up on the first one rather
than asking again for every remaining card.

The migration settles the key up front, the way LoginStorageMigrator does. A
prompt answered mid-copy would otherwise spend one of the three attempts the
migration gets, and three spent attempts cost it for good.

Still missing, and tracked separately: this store's prompts are untelemetered,
and uiBusy has no shared owner, so passwordmgr cannot see that a prompt of
ours is already on screen.

Depends on D325373

Blocks: 2073416
Attachment #9641024 - Attachment description: WIP: Bug 2071247 - P1. Encrypt credit card numbers with the store's own key r=joschmidt → Bug 2071247 - P1. Encrypt credit card numbers with the store's own key r=joschmidt
Attachment #9641025 - Attachment description: WIP: Bug 2071247 - P2. Read credit card numbers through the store that holds them r=joschmidt → Bug 2071247 - P2. Read credit card numbers through the store that holds them r=joschmidt
Attachment #9641128 - Attachment description: WIP: Bug 2071247 - P3. Prompt for the primary password when the store's key needs it r=joschmidt → Bug 2071247 - P3. Prompt for the primary password when the store's key needs it r=joschmidt
Blocks: 2074007
Attachment #9641024 - Attachment description: Bug 2071247 - P1. Encrypt credit card numbers with the store's own key r=joschmidt → Bug 2071247 - P1. Hand credit card numbers to the store that encrypts them r?joschmidt
Attachment #9641025 - Attachment description: Bug 2071247 - P2. Read credit card numbers through the store that holds them r=joschmidt → Bug 2071247 - P2. Read credit card numbers through the store that holds them r?joschmidt
Attachment #9641128 - Attachment description: Bug 2071247 - P3. Prompt for the primary password when the store's key needs it r=joschmidt → Bug 2071247 - P3. Prompt for the primary password when the store's key needs it r?joschmidt

Local vendor of application-services draft pull request #7573 (head
54fc561bfe), its four commits applied onto the revision the tree already
vendors, 7585e03e2. It moves autofill's credit card encryption onto the
db-crypto crate: Store::new() takes an EncryptorDecryptor, and the record API
carries the card number in cleartext, which the store encrypts and derives the
last four digits from. A number the key cannot read fails the read. It also
removes the key-based encrypt_string() and decrypt_string(), which nothing can
call once no consumer holds ciphertext.

The NSS store constructor is behind the crate's new keydb feature, which the
uniffi-bindgen-gecko-js components crate turns on as it already does for
db-crypto. Both store constructors are declared AsyncWrapped, since each does
the same database work as Store's own constructor, and the two new key manager
helpers Sync, alongside create_autofill_key().

This must not land. It carries a draft pull request, and should be dropped as
soon as a real vendor bump carries it in.

Attachment #9641024 - Attachment description: Bug 2071247 - P1. Hand credit card numbers to the store that encrypts them r?joschmidt → Bug 2071247 - P2. Hand credit card numbers to the store that encrypts them r?joschmidt
Attachment #9641025 - Attachment description: Bug 2071247 - P2. Read credit card numbers through the store that holds them r?joschmidt → Bug 2071247 - P3. Read credit card numbers through the store that holds them r?joschmidt
Attachment #9641128 - Attachment description: Bug 2071247 - P3. Prompt for the primary password when the store's key needs it r?joschmidt → Bug 2071247 - P4. Prompt for the primary password when the store's key needs it r?joschmidt
Attachment #9654780 - Attachment description: Bug 2071247 - P1. Vendor the autofill EncryptorDecryptor from application-services DO NOT MERGE r=joschmidt → Bug 2071247 - P1. Vendor the autofill EncryptorDecryptor from application-services r=joschmidt
Pushed by dlee@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/7263e6cd3725 https://hg.mozilla.org/integration/autoland/rev/aef603e1b41d P1. Vendor the autofill EncryptorDecryptor from application-services r=joschmidt,credential-management-reviewers https://github.com/mozilla-firefox/firefox/commit/a220e1f5e5af https://hg.mozilla.org/integration/autoland/rev/a934ff59f7fd P2. Hand credit card numbers to the store that encrypts them r=joschmidt,credential-management-reviewers https://github.com/mozilla-firefox/firefox/commit/0b9b15c6cfa2 https://hg.mozilla.org/integration/autoland/rev/761e23e95635 P3. Read credit card numbers through the store that holds them r=joschmidt,credential-management-reviewers
Status: ASSIGNED → RESOLVED
Closed: 1 month ago
Resolution: --- → FIXED
Target Milestone: --- → 160 Branch
Blocks: 2080074

Comment on attachment 9641128 [details]
Bug 2071247 - P4. Prompt for the primary password when the store's key needs it r?joschmidt

Revision D325418 was moved to bug 2080074. Setting attachment 9641128 [details] to obsolete.

Attachment #9641128 - Attachment is obsolete: true
QA Whiteboard: [qa-triage-done-c161/b160]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: