Accounts, credentials, per-account settings and signatures lived in the same libremail.db that SQLCipher encrypts under the auth-bound passphrase when app-lock + encrypted-cache are on. A genuine key invalidation (biometric re-enrollment or lock removal/re-add) made that file undecryptable, and the "clear + re-sync" recovery wiped the accounts and stored credentials along with the mail cache, dropping the user into onboarding (issue #111). Move those four tables into a new plaintext AccountDatabase (libremail-accounts.db) that is never bound to the auth key. Credentials stay AES-GCM sealed at the column level by the surviving non-auth KeystoreCrypto master key, so the only secret never touches disk in the clear. A cache-key invalidation now wipes only libremail.db; the user stays signed in. - AccountDatabase (v1) + AccountDatabaseModule; the cache DB drops to v15 via MIGRATION_14_15. DAOs are unchanged and re-provided from the new DB, so no injection site changes. - AccountDataMigrator performs the one-time cross-DB copy at startup, before Room opens either database. It attaches the cache (with its resolved passphrase, so an encrypted source is handled) and copies with INSERT OR IGNORE. It is crash-safe and idempotent: the source is dropped only by MIGRATION_14_15 after the copy, a re-run never duplicates or overwrites, and it runs after the clear-pending wipe so an unrecoverable cache degrades to "nothing to move" instead of blocking. - Exported schemas for both databases; MigrationTest asserts the account rows/backfills survive to v14 then are dropped at v15, plus a dedicated 14->15 test. AccountDataMigratorTest covers the plaintext + encrypted copy, idempotency, a DDL-vs-Room drift guard, and end-to-end survival of a simulated cache wipe. Closes #111 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
234 lines
6.9 KiB
JSON
234 lines
6.9 KiB
JSON
{
|
|
"formatVersion": 1,
|
|
"database": {
|
|
"version": 1,
|
|
"identityHash": "f2bbe80e572de72f50869b14aca4c4bb",
|
|
"entities": [
|
|
{
|
|
"tableName": "accounts",
|
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `email` TEXT NOT NULL, `displayName` TEXT NOT NULL, `authType` TEXT NOT NULL, `imap_host` TEXT NOT NULL, `imap_port` INTEGER NOT NULL, `imap_security` TEXT NOT NULL, `smtp_host` TEXT NOT NULL, `smtp_port` INTEGER NOT NULL, `smtp_security` TEXT NOT NULL, PRIMARY KEY(`id`))",
|
|
"fields": [
|
|
{
|
|
"fieldPath": "id",
|
|
"columnName": "id",
|
|
"affinity": "TEXT",
|
|
"notNull": true
|
|
},
|
|
{
|
|
"fieldPath": "email",
|
|
"columnName": "email",
|
|
"affinity": "TEXT",
|
|
"notNull": true
|
|
},
|
|
{
|
|
"fieldPath": "displayName",
|
|
"columnName": "displayName",
|
|
"affinity": "TEXT",
|
|
"notNull": true
|
|
},
|
|
{
|
|
"fieldPath": "authType",
|
|
"columnName": "authType",
|
|
"affinity": "TEXT",
|
|
"notNull": true
|
|
},
|
|
{
|
|
"fieldPath": "imap.host",
|
|
"columnName": "imap_host",
|
|
"affinity": "TEXT",
|
|
"notNull": true
|
|
},
|
|
{
|
|
"fieldPath": "imap.port",
|
|
"columnName": "imap_port",
|
|
"affinity": "INTEGER",
|
|
"notNull": true
|
|
},
|
|
{
|
|
"fieldPath": "imap.security",
|
|
"columnName": "imap_security",
|
|
"affinity": "TEXT",
|
|
"notNull": true
|
|
},
|
|
{
|
|
"fieldPath": "smtp.host",
|
|
"columnName": "smtp_host",
|
|
"affinity": "TEXT",
|
|
"notNull": true
|
|
},
|
|
{
|
|
"fieldPath": "smtp.port",
|
|
"columnName": "smtp_port",
|
|
"affinity": "INTEGER",
|
|
"notNull": true
|
|
},
|
|
{
|
|
"fieldPath": "smtp.security",
|
|
"columnName": "smtp_security",
|
|
"affinity": "TEXT",
|
|
"notNull": true
|
|
}
|
|
],
|
|
"primaryKey": {
|
|
"autoGenerate": false,
|
|
"columnNames": [
|
|
"id"
|
|
]
|
|
}
|
|
},
|
|
{
|
|
"tableName": "credentials",
|
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`accountId` TEXT NOT NULL, `encryptedSecret` TEXT NOT NULL, PRIMARY KEY(`accountId`))",
|
|
"fields": [
|
|
{
|
|
"fieldPath": "accountId",
|
|
"columnName": "accountId",
|
|
"affinity": "TEXT",
|
|
"notNull": true
|
|
},
|
|
{
|
|
"fieldPath": "encryptedSecret",
|
|
"columnName": "encryptedSecret",
|
|
"affinity": "TEXT",
|
|
"notNull": true
|
|
}
|
|
],
|
|
"primaryKey": {
|
|
"autoGenerate": false,
|
|
"columnNames": [
|
|
"accountId"
|
|
]
|
|
}
|
|
},
|
|
{
|
|
"tableName": "account_settings",
|
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`accountId` TEXT NOT NULL, `signature` TEXT NOT NULL, `signatureEnabled` INTEGER NOT NULL, `notificationsEnabled` INTEGER NOT NULL, `retentionCount` INTEGER, `retentionMonths` INTEGER, PRIMARY KEY(`accountId`), FOREIGN KEY(`accountId`) REFERENCES `accounts`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
|
|
"fields": [
|
|
{
|
|
"fieldPath": "accountId",
|
|
"columnName": "accountId",
|
|
"affinity": "TEXT",
|
|
"notNull": true
|
|
},
|
|
{
|
|
"fieldPath": "signature",
|
|
"columnName": "signature",
|
|
"affinity": "TEXT",
|
|
"notNull": true
|
|
},
|
|
{
|
|
"fieldPath": "signatureEnabled",
|
|
"columnName": "signatureEnabled",
|
|
"affinity": "INTEGER",
|
|
"notNull": true
|
|
},
|
|
{
|
|
"fieldPath": "notificationsEnabled",
|
|
"columnName": "notificationsEnabled",
|
|
"affinity": "INTEGER",
|
|
"notNull": true
|
|
},
|
|
{
|
|
"fieldPath": "retentionCount",
|
|
"columnName": "retentionCount",
|
|
"affinity": "INTEGER"
|
|
},
|
|
{
|
|
"fieldPath": "retentionMonths",
|
|
"columnName": "retentionMonths",
|
|
"affinity": "INTEGER"
|
|
}
|
|
],
|
|
"primaryKey": {
|
|
"autoGenerate": false,
|
|
"columnNames": [
|
|
"accountId"
|
|
]
|
|
},
|
|
"foreignKeys": [
|
|
{
|
|
"table": "accounts",
|
|
"onDelete": "CASCADE",
|
|
"onUpdate": "NO ACTION",
|
|
"columns": [
|
|
"accountId"
|
|
],
|
|
"referencedColumns": [
|
|
"id"
|
|
]
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"tableName": "signatures",
|
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `accountId` TEXT NOT NULL, `name` TEXT NOT NULL, `contentHtml` TEXT NOT NULL, `isDefault` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`accountId`) REFERENCES `accounts`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
|
|
"fields": [
|
|
{
|
|
"fieldPath": "id",
|
|
"columnName": "id",
|
|
"affinity": "TEXT",
|
|
"notNull": true
|
|
},
|
|
{
|
|
"fieldPath": "accountId",
|
|
"columnName": "accountId",
|
|
"affinity": "TEXT",
|
|
"notNull": true
|
|
},
|
|
{
|
|
"fieldPath": "name",
|
|
"columnName": "name",
|
|
"affinity": "TEXT",
|
|
"notNull": true
|
|
},
|
|
{
|
|
"fieldPath": "contentHtml",
|
|
"columnName": "contentHtml",
|
|
"affinity": "TEXT",
|
|
"notNull": true
|
|
},
|
|
{
|
|
"fieldPath": "isDefault",
|
|
"columnName": "isDefault",
|
|
"affinity": "INTEGER",
|
|
"notNull": true
|
|
}
|
|
],
|
|
"primaryKey": {
|
|
"autoGenerate": false,
|
|
"columnNames": [
|
|
"id"
|
|
]
|
|
},
|
|
"indices": [
|
|
{
|
|
"name": "index_signatures_accountId",
|
|
"unique": false,
|
|
"columnNames": [
|
|
"accountId"
|
|
],
|
|
"orders": [],
|
|
"createSql": "CREATE INDEX IF NOT EXISTS `index_signatures_accountId` ON `${TABLE_NAME}` (`accountId`)"
|
|
}
|
|
],
|
|
"foreignKeys": [
|
|
{
|
|
"table": "accounts",
|
|
"onDelete": "CASCADE",
|
|
"onUpdate": "NO ACTION",
|
|
"columns": [
|
|
"accountId"
|
|
],
|
|
"referencedColumns": [
|
|
"id"
|
|
]
|
|
}
|
|
]
|
|
}
|
|
],
|
|
"setupQueries": [
|
|
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
|
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'f2bbe80e572de72f50869b14aca4c4bb')"
|
|
]
|
|
}
|
|
} |