sonda/migrations/sqlite/0034_device_passwords.sql
tgiachi 010f2e5057 feat: a password for each app or device
A person can make a password for each app that connects to their server, in
Settings, Apps and devices. The secret is shown once, can be taken back, and
is for the music API of other apps only: it cannot sign in or change the
account. Secrets are kept sealed (AES-256-GCM, key derived from the jwt secret)
because token login needs them in clear, and a hash finds a device by its key.

- migration 0034 device_passwords (sqlite, postgres)
- internal/devices service, storage repo
- GET/POST /me/devices, DELETE /me/devices/{id}, in the OpenAPI spec
- Settings section with copy and remove
2026-11-16 09:15:25 +01:00

16 lines
827 B
SQL

-- The passwords a person makes for the apps and devices that connect to their server (OpenSubsonic clients). A password
-- opens the music API and nothing else. Token login needs the secret itself, so it is kept sealed (sealed), and a hash of
-- it (key_hash) finds the device of an API key.
CREATE TABLE device_passwords (
id INTEGER PRIMARY KEY,
user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
name TEXT NOT NULL,
key_hash TEXT NOT NULL,
sealed BLOB NOT NULL,
created_at INTEGER NOT NULL, -- unix seconds
last_used_at INTEGER -- unix seconds, NULL until it is used
);
CREATE UNIQUE INDEX idx_device_passwords_key ON device_passwords(key_hash);
CREATE INDEX idx_device_passwords_user ON device_passwords(user_id);