application-services icon indicating copy to clipboard operation
application-services copied to clipboard

expose Logins keydb structs constructors

Open jo opened this issue 6 months ago • 6 comments

Pull Request checklist

  • Breaking changes: This PR follows our breaking change policy
    • [x] 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
  • [x] 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.
  • [x] Tests: This PR includes thorough tests or an explanation of why it does not
  • [x] 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
  • [x] Dependencies: This PR follows our dependency management guidelines
    • Any new dependencies are accompanied by a summary of the due diligence applied in selecting them.

jo avatar Jun 19 '25 10:06 jo

Is there anything else I need to consider to get the following code to work in the JavaScript Login Storage Adapter? Or do I still need factory methods? And does this already work with the Foreign Trait in JavaScript, and in this way or else?

class LoginStorageAuthenticator extends PrimaryPasswordAuthenticator {
  // init () {
  //   super()
  //   return new LoginStorageAuthenticator()
  // }

  async getPrimaryPassword() {
    console.log("LoginStorageAuthenticator: get primary password");
    console.log("TBD")
    return "secure"
  }

  onAuthenticationSuccess() {
    console.log("LoginStorageAuthenticator: authentication success!");
  }
  
  onAuthenticationFailure() {
    console.error("LoginStorageAuthenticator: authentication failure!");
  } 
} 

// then, later
const authenticator = new LoginStorageAuthenticator;
const keyManager = NssKeyManager.init(authenticator);
const encdec = ManagedEncryptorDecryptor.init(keyManager);
const path = `${Services.dirsvc.get("ProfD", Ci.nsIFile).path}/logins.db`;
const store = LoginStore.init(path, encdec);

jo avatar Jun 19 '25 11:06 jo

Is that not working, or are you just checking if it should work? I'd think it should, but that's a naive opinion as I've not done that before, partly because the capability has only recently been added (until recently we only supported callback interfaces)

mhammond avatar Jun 20 '25 00:06 mhammond

Currently it is not working, mostly due to the missing constructor exports I think.

jo avatar Jun 20 '25 09:06 jo

So at least this patch is needed. What I'm curious is especially the Foreign Trait handling - can we just extend a class with it?

jo avatar Jun 20 '25 09:06 jo

const encdec = ManagedEncryptorDecryptor.init(keyManager);

I think this line may not work. NssKeyManager implements KeyManager in Rust, but UniFFI doesn't yet have the capabilities to auto convert it into a dyn KeyManager like you can do in Rust.

I think you may need to add another NssKeyManager method to do that. I think you just need to get the signature right and Rust will make the conversion itself. Something like this should work:

pub fn into_dyn_key_manage(self: Arc<Self>) -> Arc<dyn KeyManager> {
   self
}

I could easily be missing something and you might need a couple tries to get everything right. I'd recommend taking the git commit from this PR, vendoring it into moz-central / generating the UniFFI bindings, and testing yourself if the JS works or not.

bendk avatar Jun 20 '25 14:06 bendk

Thank you @bendk for your hints! I will link mc against this pr and try locally before continuing.

jo avatar Jun 20 '25 15:06 jo