Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Desktop: Use Electron safeStorage for keychain support #10535

Draft
wants to merge 17 commits into
base: dev
Choose a base branch
from

Conversation

personalizedrefrigerator
Copy link
Collaborator

@personalizedrefrigerator personalizedrefrigerator commented Jun 3, 2024

Summary

This PR uses Electron safeStorage when available and falls back to keytar.

On desktop, fixes #8829.
May also fix #10526.

This pull request:

  1. Adds keychain support on Linux.
  2. This may help address a keychain-related bug (from my very limited testing).

The CLI app doesn't have access to Electron APIs, and so will still need to use keytar after this pull request.

To-do

  • Decide where to store encrypted settings. Using KvStore.
    • Electron's safeStorage doesn't seem to provide key-value storage. Instead, it provides methods that encrypt or decrypt data.
    • Currently, encrypted secure settings are stored in the settings table, using the encryptedValue. key prefix. For example, a setting with key sync.6.password would have its encrypted value stored as encryptedValue.sync.6.password.
    • It could make sense to store these settings separately from the database (e.g. in an encrypted-settings.json file). This could make it clear that these settings need special care when creating a backup of Joplin (if backing up by copying the database). It would also avoid reusing the existing settings table.
  • Decide whether this should be enabled for all platforms initially, or just Linux.
  • Migrations
    • On Linux, keychain.supported needs to be reset to -1 on existing installs for the keychain check to be re-run (allowing the keychain to be used).
    • Migrate existing settings away from keytar?
    • Migrate existing unencrypted settings to safeStorage.
  • Test on more platforms.
    • Windows
    • MacOS

Testing

So far, limited manual testing has been done on Ubuntu 24.04:

  1. Run Setting.resetKey('keychain.supported') from Joplin's development tools, then restart Joplin.
  2. Restart Joplin
  3. Open Joplin's devtools (if not already open -- I tested in development mode) and search for key.
  4. Verify that KeychainService: check was already done - skipping. Supported: 1 appears in the console.
  5. Change the password for the backup plugin and save.
  6. Verify that no new errors are logged to the console.

Additional manual testing will be necessary on Windows and MacOS.

@personalizedrefrigerator personalizedrefrigerator marked this pull request as draft June 3, 2024 16:50
@djsudduth
Copy link

djsudduth commented Jun 3, 2024

@personalizedrefrigerator - thx for this pull! Glad to see this change. But, keytar needs to eventually be replaced in the CLI somehow since it's repo has been archived.

Before this pull request, Linux systems lacked keychain support. This
commit adds a migration that resets `keychain.supported` to -1, allowing
the keychain support check to be re-run.

At present, this migration just re-runs the keychain support check. It
does not remove or modify existing secure settings previously stored
in the database.
@laurent22 laurent22 added the v3.1 label Jun 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Plugins: settings fields that are secure are unable to be set on keychain Find alternative to keytar package
3 participants