Skip to content

FXCM-2273: Refactor login/encryption code into a new support crate - #7542

Open
oskirby wants to merge 25 commits into
mozilla:mainfrom
oskirby:fxcm-2274-add-encryption-crate
Open

FXCM-2273: Refactor login/encryption code into a new support crate#7542
oskirby wants to merge 25 commits into
mozilla:mainfrom
oskirby:fxcm-2274-add-encryption-crate

Conversation

@oskirby

@oskirby oskirby commented Aug 13, 2026

Copy link
Copy Markdown

This attempts to refactor the credential encryption code and move it into it's own support crate so that it can be re-used by other modules in the a-s ecosystem, and is a prerequisite for supporting encrypted autofill (eg: to store things like payment details).

There were some changes made to the uniffi API to enable this work, but logically there should be no meaningful changes to the API, and it should be compatible with no changes to the consumers of this code. It's a bit unclear to me how serious these changes are, and whether they constitute an API change. The changes include:

  • The encryption-related types and traits are moved out of logins.udl and into a new crate encryption.udl.
  • The encryption-related types and traits that were moved, are re-export by logins.udl as external types.
  • The return type is changed from a LoginsApiError to an EncryptionApiError.
  • The constructor for the NSSKeyManager type now takes a key_name parameter, though as far as I can tell, the NSSKeyManager was never acually exposed by uniffi.

Related JIRA Issues:

Pull Request checklist

  • Breaking changes: This PR follows our breaking change policy
    • This PR follows the breaking change policy:
      • This PR has no breaking API changes, or
      • There are corresponding PRs for our consumer applications that resolve the breaking changes and have been approved
  • Quality: This PR builds and tests run cleanly
    • Note:
      • For changes that need extra cross-platform testing, consider adding [ci full] to the PR title.
      • If this pull request includes a breaking change, consider cutting a new release after merging.
  • Tests: This PR includes thorough tests or an explanation of why it does not
  • Changelog: This PR includes a changelog entry in CHANGELOG.md or an explanation of why it does not need one
    • Any breaking changes to Swift or Kotlin binding APIs are noted explicitly
  • Dependencies: This PR follows our dependency management guidelines
    • Any new dependencies are accompanied by a summary of the due diligence applied in selecting them.

@oskirby
oskirby force-pushed the fxcm-2274-add-encryption-crate branch 3 times, most recently from 27fea06 to 042d197 Compare August 14, 2026 00:13
@oskirby
oskirby marked this pull request as ready for review August 14, 2026 23:19
@oskirby
oskirby force-pushed the fxcm-2274-add-encryption-crate branch from aa20b6c to 26697cb Compare August 17, 2026 08:26
jo
jo previously requested changes Aug 17, 2026

@jo jo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you very much for this work!

I think that - contrary to our expectations - this represents a breaking change for Android and Swift users, since error handling has changed and the moved import. Therefore, accompanying pull requests for mobile applications would be necessary 😬 see https://github.com/mozilla/application-services/blob/main/docs/howtos/breaking-changes.md

And could you add a CHANGELOG entry?

Comment thread examples/sync-pass/src/sync-pass.rs Outdated
Comment thread megazords/full/src/lib.rs
Comment thread components/support/encryption/uniffi.toml
Comment thread components/support/encryption/android/build.gradle Outdated
Comment thread components/support/encryption/android/build.gradle Outdated
Comment thread components/logins/src/logins.udl Outdated
Comment thread components/logins/src/logins.udl Outdated
Comment on lines +160 to +161
[External = "encryption"]
typedef interface StaticKeyManager;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can go, too afaik, ...

Comment thread components/logins/src/logins.udl Outdated
Comment thread components/logins/src/logins.udl Outdated
bytes decrypt(bytes ciphertext);
};
[External = "encryption"]
typedef trait EncryptorDecryptor;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I am not sure but this might be

typedef trait_with_foreign EncryptorDecryptor;

Comment thread components/logins/src/logins.udl Outdated
bytes get_key();
};
[External = "encryption"]
typedef trait KeyManager;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

and this

typedef trait_with_foreign KeyManager;

@jo

jo commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

@oskirby #7535 has landed, which introduces a key cache - could you port this in here as well?

@oskirby

oskirby commented Aug 18, 2026

Copy link
Copy Markdown
Author

@oskirby #7535 has landed, which introduces a key cache - could you port this in here as well?

Yep, I'll rebase my work to pick that up.

@mergify
mergify Bot dismissed jo’s stale review August 18, 2026 14:04

The pull request has been modified, dismissing previous reviews.

@oskirby
oskirby force-pushed the fxcm-2274-add-encryption-crate branch 2 times, most recently from a6af9f0 to 8706813 Compare August 18, 2026 14:23
@oskirby
oskirby force-pushed the fxcm-2274-add-encryption-crate branch from 8706813 to 88f8453 Compare August 19, 2026 08:44
@oskirby
oskirby force-pushed the fxcm-2274-add-encryption-crate branch from 88f8453 to 51cb1fa Compare August 19, 2026 08:47

@mhammond mhammond left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

just a quick driveby, but this looks great!

Ok(encryption::create_canary(text, key)?)
}

pub fn check_canary(canary: &str, text: &str, key: &str) -> ApiResult<bool> {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

#[handle_error(Error)] here?

@@ -0,0 +1,30 @@
[package]
name = "encryption"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't like this name, it's too generic and kinda competes with rc_crypto for things generically called "encryption". I think we need some qualification here. Not sure what it might be - something likelogins-encryption, but clearly you are intending to make it more generic than that. I've no great ideas but maybe we can bike-shed?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I agree, and I am open to suggestions as well.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I think something along the lines of 'credential-cryptography` would better represent the intended purpose of this crate, but that is a bit of a lengthy name.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

still a fan of enc_dec and renaming EncryptorDecryptor to EncDec

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm good with either of those options. enc_dec has the advantage of matching exactly how it is used. Happy to leave this decision to y'all!

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