Secrets and the keyring
Where passwords, tokens and private links are kept, and the one file they may go to instead.
Passwords, tokens, API keys and private links never go into data.json or config.json. They go to the system's keyring, through src/secrets.rs.
The keyring#
| System | Store | Crate |
|---|---|---|
| Linux | the Secret Service (GNOME Keyring, KWallet) over D-Bus | zbus-secret-service-keyring-store |
| Windows | the Credential Manager | windows-native-keyring-store |
| macOS | the Keychain | apple-native-keyring-store |
Entries are kept under the service name katlendar. Entries left under the old name kalendar are moved over.
| Key | Holds |
|---|---|
account:<id> | an account's password, refresh token or session |
feed:<id> | a subscribed calendar's private link |
maps:google | the person's Google Maps API key (see Maps) |
For Google, the entry is a small JSON value with the refresh token and the client secret. For Proton, it is the session and what opens its keys, never the password.
Calls#
secrets::set, get and delete all take allow_file. They may block while the keyring asks to be unlocked, so call them on a background thread.
When there is no keyring#
Some Linux desktops run no Secret Service. Then the app says so, and Settings › Calendars offers a box: "Keep passwords in a file when no keyring is running". It sets plaintext_secrets.
The file is secrets.json, beside data.json. On Linux and macOS it is written with mode 0600, so only its owner can read it. A secret is kept in one place only: when the keyring works again, the copy in the file is removed.
Private links#
Some calendar links are secrets themselves: anyone with the link can read the calendar. Proton's feed links are one such kind, and ics::is_proton spots them. Such a calendar gets url_secret set, its link goes to the keyring under feed:<id>, and data.json holds keyring: in its place. At start, syncing::keep_private_links reads those links back from the keyring, and moves a Proton link that is still in data.json into it.
Testing#
cargo test keyring_round_trip -- --ignored
This writes, reads and deletes a real keyring entry. It is ignored by default, so a plain cargo test never touches the keyring.
Rules#
- Never log or print a secret, not even in an error.
- Never put one in a URL that gets logged, such as a query string.
- A new kind of secret gets its own key name in
secrets.rs.