diff --git a/app/sql.js b/app/sql.js index ffe263faa..e1dacbf6b 100644 --- a/app/sql.js +++ b/app/sql.js @@ -214,7 +214,7 @@ async function getSQLCipherVersion(instance) { } } -async function getSQLIntegrityCheck(instance) { +async function getSQLCipherIntegrityCheck(instance) { const row = await instance.get('PRAGMA cipher_integrity_check;'); if (row) { return row.cipher_integrity_check; @@ -223,6 +223,15 @@ async function getSQLIntegrityCheck(instance) { return null; } +async function getSQLIntegrityCheck(instance) { + const row = await instance.get('PRAGMA integrity_check;'); + if (row && row.integrity_check !== 'ok') { + return row.integrity_check; + } + + return null; +} + async function migrateSchemaVersion(instance) { const userVersion = await getUserVersion(instance); if (userVersion > 0) { @@ -1262,10 +1271,20 @@ async function initialize({ configDir, key, messages }) { // test database - const result = await getSQLIntegrityCheck(promisified); - if (result) { - console.log('Database integrity check failed:', result); - throw new Error(`Integrity check failed: ${result}`); + const cipherIntegrityResult = await getSQLCipherIntegrityCheck(promisified); + if (cipherIntegrityResult) { + console.log( + 'Database cipher integrity check failed:', + cipherIntegrityResult + ); + throw new Error( + `Cipher integrity check failed: ${cipherIntegrityResult}` + ); + } + const integrityResult = await getSQLIntegrityCheck(promisified); + if (integrityResult) { + console.log('Database integrity check failed:', integrityResult); + throw new Error(`Integrity check failed: ${integrityResult}`); } // At this point we can allow general access to the database