|
| 1 | +# KeePass Integration |
| 2 | + |
| 3 | +The KeePass integration in iNiR provides a secure, fast, and visually integrated way to manage your passwords directly from the shell. |
| 4 | + |
| 5 | +## Architecture |
| 6 | + |
| 7 | +The system consists of three layers: |
| 8 | + |
| 9 | +1. **Backend Script (`scripts/quickshell-keepass`)**: A robust wrapper around `keepassxc-cli`. It handles the core logic, error reporting, and secure password caching using the system keyring. |
| 10 | +2. **Service (`services/KeePass.qml`)**: A background service that manages the database state (unlocked/locked), handles automated background locking via a timer, and exposes IPC targets. |
| 11 | +3. **UI Panel (`modules/keepass/KeepassPanel.qml`)**: A material-style overlay following the "SnowArch" aesthetic, providing search, entry management, and timer controls. |
| 12 | + |
| 13 | +## Features |
| 14 | + |
| 15 | +### Secure Caching |
| 16 | +Unlike standard scripts that might save passwords in plain text or volatile files, iNiR uses the **Secret Service API** (`secret-tool`). |
| 17 | +- The vault password is stored in your session keyring (Gnome Keyring or KWallet). |
| 18 | +- Each cache item is **scoped to its vault path**, so vaults with different master passwords never feed each other a stale password. |
| 19 | +- The cache is automatically cleared when the timer expires, when manually locked, and on shell start (the shell always starts locked, so no master password lingers after a crash or a previous session). |
| 20 | +- **No-keyring fallback**: if no Secret Service is reachable, the password is kept in memory for the session instead, so copy/reveal keep working (probed at startup via `quickshell-keepass check-keyring`). |
| 21 | + |
| 22 | +### Smart Timer System |
| 23 | +The integration features a persistent background timer: |
| 24 | +- **Interactive Slider**: Set the unlock duration (from 1 minute to 4 hours) before unlocking. |
| 25 | +- **Title Bar Badge**: A live countdown timer (`MM:SS`) is visible in the title bar when the database is open. |
| 26 | +- **Visual Progress**: A subtle progress bar inside the badge shows the remaining time relative to the initial setting. |
| 27 | +- **Critical Alerts**: The timer turns **red** when less than 30 seconds remain. |
| 28 | +- **Quick Reset**: Click the timer badge in the title bar to instantly reset the time to the maximum duration without re-entering the password. |
| 29 | + |
| 30 | +### Integrated UI |
| 31 | +- **Auto-Focus**: Opening the panel automatically focuses the password field or the search field. |
| 32 | +- **Pill Style**: All UI elements (selections, buttons, list items) use the "pill" shape and colors harmonized with your system theme (`colPrimary`). |
| 33 | +- **High Contrast**: Text automatically inverts (`colOnPrimary`) when inside a selected "pill" for maximum readability. |
| 34 | +- **Keyboard Friendly**: Fully navigable via keyboard. `Tab` cycles only between inputs and list; `Enter` selects or saves. |
| 35 | + |
| 36 | +## Configuration |
| 37 | + |
| 38 | +Configure the vault location in `~/.config/illogical-impulse/config.json`: |
| 39 | + |
| 40 | +```json |
| 41 | +"keepass": { |
| 42 | + "vaultDir": "/path/to/your/vaults", |
| 43 | + "cacheTtl": 300 |
| 44 | +} |
| 45 | +``` |
| 46 | + |
| 47 | +- `keepass.vaultDir`: directory containing your `.kdbx` vaults (defaults to `~/.local/share/keepassqs`). |
| 48 | +- `keepass.cacheTtl`: how long (in seconds) the vault stays unlocked before it auto-locks and clears the cached password (defaults to `300`). Settable from the in-panel slider or the **Settings → Services → KeePass** section; both persist here. |
| 49 | + |
| 50 | +Quickshell hot-reloads the config, so the panel picks up changes on the next toggle. The picker lists all `.kdbx` files found in that directory, and new vaults can be created from the UI. The word-based generator uses the wordlist from the active UI locale (via `Translation.tr("keepass_wordlist")`). |
| 51 | + |
| 52 | +## Usage |
| 53 | + |
| 54 | +### Commands |
| 55 | +- `inir keepass toggle`: Opens or closes the KeePass panel. |
| 56 | +- `inir keepass add`: Opens the panel in "Add Entry" mode, automatically pasting the primary selection into the password field. |
| 57 | + |
| 58 | +### Keyboard Shortcuts |
| 59 | + |
| 60 | +Default bindings (from `scripts/lib/ipc-registry.sh`): |
| 61 | +- `Super+P`: toggle the panel |
| 62 | +- `Super+Ctrl+P`: open the panel in "Add Entry" mode with the primary selection pre-filled |
| 63 | + |
| 64 | +Inside the panel: |
| 65 | +- `Enter` on the password field: unlock the vault |
| 66 | +- Start typing (in entries tab): focuses the search field |
| 67 | +- `Down` / `Up`: navigate the entry list or vault picker list; in the entry list the highlighted entry is auto-selected (its detail card opens as you move); `Up` at the top of the entry list returns focus to search |
| 68 | +- `Enter` on a highlighted entry: copy its password to the clipboard (no double-press — the entry is already selected) |
| 69 | +- `Enter` on a highlighted vault (picker tab): open the unlock screen for it |
| 70 | +- `Left` / `Right`: cycle through the three tabs — picker → entries → add — when the vault is unlocked |
| 71 | +- `Tab`: enter the form fields on the create-vault or add-entry tabs (focus starts outside the fields so the arrows remain free for tab cycling) |
| 72 | +- **Hold `Alt`**: reveal the selected entry's password while held — releasing hides it again (avoids moving keyboard focus away from the list) |
| 73 | +- `Escape`: close the entry detail, or close the panel if no entry is open |
| 74 | + |
| 75 | +## Security Model |
| 76 | +1. **Locking**: The database is locked and the keyring cache is cleared immediately when the timer reaches zero or the "Lock" button is pressed. The cache is also wiped on shell start, so a cached password never outlives the session that created it. |
| 77 | +2. **Transparency**: Real error messages from `keepassxc-cli` (e.g., "Database locked by another process") are displayed directly in the UI for better diagnostics. |
| 78 | +3. **Clipboard**: Passwords copied to the clipboard are automatically cleared from the `cliphist` history after a short delay (if `cliphist` is active). |
| 79 | + |
| 80 | +## Troubleshooting |
| 81 | + |
| 82 | +Set `KP_DEBUG=1` to trace every keyring decision (cache hit/miss, store, clear, stdin fallback) so you can confirm operations go through the keyring with no silent fallbacks. The trace is off by default and has zero overhead when unset. |
| 83 | + |
| 84 | +```sh |
| 85 | +# Enable for the running shell, then watch the trace |
| 86 | +systemctl --user set-environment KP_DEBUG=1 && inir restart |
| 87 | +tail -F "${XDG_RUNTIME_DIR:-/tmp}/quickshell-keepass-debug.log" |
| 88 | +# Disable again |
| 89 | +systemctl --user unset-environment KP_DEBUG && inir restart |
| 90 | +``` |
| 91 | + |
| 92 | +Override the log location with `KP_DEBUG_LOG=/path/to/file`. The trace never records secret values, only which code path ran. |
0 commit comments