Skip to content

Repair gnome-keyring plaintext keyrings rejected by gnome-keyring 50 - #13014

Closed
LinuxGamerUK wants to merge 1 commit into
omacom:quattrofrom
LinuxGamerUK:fix/gnome-keyring-plaintext-repair
Closed

LinuxGamerUK wants to merge 1 commit into
omacom:quattrofrom
LinuxGamerUK:fix/gnome-keyring-plaintext-repair

Conversation

@LinuxGamerUK

Copy link
Copy Markdown

Fixes the data-loss mechanism reported in #5105.

Problem

gnome-keyring 50 writes textual secrets with g_key_file_set_value(), which does not escape newlines. Any secret containing a raw newline (JSON with embedded PEM blocks, pretty-printed tokens) produces a plaintext keyring file the daemon cannot parse again. On the next start it logs:

keyring was in an invalid or unrecognized format: ~/.local/share/keyrings/<name>.keyring

silently drops the collection, and creates a fresh empty default. Browsers lose Safe Storage, SSO tokens vanish, and users perceive a full password wipe. The old file stays on disk, so the data is recoverable.

  • Write path: generate_item() in gkm-secret-textual.c uses g_key_file_set_value() for valid-UTF-8 secrets (no escaping); hex binary-secret= for non-UTF-8.
  • Read path: GKeyFile parse; a raw newline inside a value breaks the parse and the whole collection is discarded.
  • Empty-password keyrings always use the plaintext format, so this hits typical single-user desktop installs.

The migration

One-shot, idempotent, offline (no D-Bus / daemon restart needed):

  1. Scans ~/.local/share/keyrings/*.keyring for plaintext files whose structure the daemon will reject (group-aware: [keyring], [N], [N:attributeK], [N:aclK] key sets from the writer source).
  2. Backs the file up under ~/.local/share/keyrings/backup-<timestamp>/.
  3. Repairs in place by GKeyFile-escaping multi-line values (\n, \r, \t, \\) into single lines. The reader unescapes them, so secrets survive byte-exact.

After repair, the daemon simply re-adopts the file on next start - same collection name, same items, same default pointer. No re-import, no prompts.

Testing

  • Synthetic corrupt keyring (multi-line textual + binary-hex secrets): migration repairs it; a fresh gnome-keyring-daemon re-adopts the file; secret-tool lookup round-trips both secret types byte-exact.
  • A real-world corrupt keyring captured from an affected machine (5 items incl. a browser Safe Storage key): repaired and re-adopted; all 5 items readable, Safe Storage key byte-identical.
  • Empty $HOME and already-valid files: no-op; rerun is a no-op (idempotent).
  • Repairs that would not produce a strictly valid file are skipped with the original left untouched (never makes data worse).

Security notes

  • The migration only ever rewrites files under the user's own ~/.local/share/keyrings/, creates a backup before touching anything, and never prints secret material.
  • Upstream follow-up to file with GNOME (write-path escaping / read-path tolerance); this migration shields existing installs meanwhile.

@Irfrit

Irfrit commented Sep 23, 2026

Copy link
Copy Markdown

omacom/omarchy-pkgs#248

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.

2 participants