Startup: integrity_check in addition to cipher_integrity_check
This commit is contained in:
parent
8ccb89310b
commit
2a7cfd9776
1 changed files with 24 additions and 5 deletions
29
app/sql.js
29
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;');
|
const row = await instance.get('PRAGMA cipher_integrity_check;');
|
||||||
if (row) {
|
if (row) {
|
||||||
return row.cipher_integrity_check;
|
return row.cipher_integrity_check;
|
||||||
|
@ -223,6 +223,15 @@ async function getSQLIntegrityCheck(instance) {
|
||||||
return null;
|
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) {
|
async function migrateSchemaVersion(instance) {
|
||||||
const userVersion = await getUserVersion(instance);
|
const userVersion = await getUserVersion(instance);
|
||||||
if (userVersion > 0) {
|
if (userVersion > 0) {
|
||||||
|
@ -1262,10 +1271,20 @@ async function initialize({ configDir, key, messages }) {
|
||||||
|
|
||||||
// test database
|
// test database
|
||||||
|
|
||||||
const result = await getSQLIntegrityCheck(promisified);
|
const cipherIntegrityResult = await getSQLCipherIntegrityCheck(promisified);
|
||||||
if (result) {
|
if (cipherIntegrityResult) {
|
||||||
console.log('Database integrity check failed:', result);
|
console.log(
|
||||||
throw new Error(`Integrity check failed: ${result}`);
|
'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
|
// At this point we can allow general access to the database
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue