From 78389440c0f264d0c0e628b7271f1255d6030ea1 Mon Sep 17 00:00:00 2001 From: Mikunj Date: Tue, 3 Mar 2020 15:17:30 +1100 Subject: [PATCH] Update sqlcipher to 4.2.0. --- app/global_errors.js | 3 +++ app/sql.js | 19 +++++++++++++++++++ package.json | 4 +++- yarn.lock | 18 +++++++++--------- 4 files changed, 34 insertions(+), 10 deletions(-) diff --git a/app/global_errors.js b/app/global_errors.js index 85ddee387..16d54327f 100644 --- a/app/global_errors.js +++ b/app/global_errors.js @@ -10,6 +10,9 @@ let quitText = 'Quit'; let copyErrorAndQuitText = 'Copy error and quit'; function handleError(prefix, error) { + if (console._error) { + console._error(`${prefix}:`, Errors.toLogFormat(error)); + } console.error(`${prefix}:`, Errors.toLogFormat(error)); if (app.isReady()) { diff --git a/app/sql.js b/app/sql.js index 29f19027d..478ec44d3 100644 --- a/app/sql.js +++ b/app/sql.js @@ -231,6 +231,15 @@ async function getSQLCipherVersion(instance) { } } +async function getSQLIntegrityCheck(instance) { + const row = await instance.get('PRAGMA cipher_integrity_check;'); + if (row) { + return row.cipher_integrity_check; + } + + return null; +} + const HEX_KEY = /[^0-9A-Fa-f]/; async function setupSQLCipher(instance, { key }) { // If the key isn't hex then we need to derive a hex key from it @@ -239,6 +248,9 @@ async function setupSQLCipher(instance, { key }) { // https://www.zetetic.net/sqlcipher/sqlcipher-api/#key const value = deriveKey ? `'${key}'` : `"x'${key}'"`; await instance.run(`PRAGMA key = ${value};`); + + // https://www.zetetic.net/blog/2018/11/30/sqlcipher-400-release/#compatability-sqlcipher-4-0-0 + await instance.run('PRAGMA cipher_migrate;'); } async function setSQLPassword(password) { @@ -1071,6 +1083,13 @@ async function initialize({ configDir, key, messages, passwordAttempt }) { db = promisified; // test database + + const result = await getSQLIntegrityCheck(db); + if (result) { + console.log('Database integrity check failed:', result); + throw new Error(`Integrity check failed: ${result}`); + } + await getMessageCount(); } catch (error) { if (passwordAttempt) { diff --git a/package.json b/package.json index 206065e8d..ef1bad9b6 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ "ready": "yarn clean-transpile && yarn grunt && yarn lint-full && yarn test-node && yarn test-electron && yarn lint-deps" }, "dependencies": { - "@journeyapps/sqlcipher": "https://github.com/scottnonnenberg-signal/node-sqlcipher.git#2e28733b61640556b0272a3bfc78b0357daf71e6", + "@journeyapps/sqlcipher": "https://github.com/scottnonnenberg-signal/node-sqlcipher.git#b10f232fac62ba7f8775c9e086bb5558fe7d948b", "@sindresorhus/is": "0.8.0", "@types/dompurify": "^2.0.0", "@types/rc-slider": "^8.6.5", @@ -316,6 +316,8 @@ "node_modules/socks/build/client/*.js", "node_modules/smart-buffer/build/*.js", "!node_modules/@journeyapps/sqlcipher/deps/*", + "!node_modules/@journeyapps/sqlcipher/build/*", + "!node_modules/@journeyapps/sqlcipher/lib/binding/node-*", "!build/*.js" ] } diff --git a/yarn.lock b/yarn.lock index dc8d73cae..b7a8a3a0e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -27,12 +27,12 @@ ajv "^6.1.0" ajv-keywords "^3.1.0" -"@journeyapps/sqlcipher@https://github.com/scottnonnenberg-signal/node-sqlcipher.git#2e28733b61640556b0272a3bfc78b0357daf71e6": - version "3.2.1" - resolved "https://github.com/scottnonnenberg-signal/node-sqlcipher.git#2e28733b61640556b0272a3bfc78b0357daf71e6" +"@journeyapps/sqlcipher@https://github.com/scottnonnenberg-signal/node-sqlcipher.git#b10f232fac62ba7f8775c9e086bb5558fe7d948b": + version "4.0.0" + resolved "https://github.com/scottnonnenberg-signal/node-sqlcipher.git#b10f232fac62ba7f8775c9e086bb5558fe7d948b" dependencies: - nan "^2.10.0" - node-pre-gyp "^0.10.0" + nan "^2.12.1" + node-pre-gyp "^0.11.0" "@protobufjs/aspromise@^1.1.1", "@protobufjs/aspromise@^1.1.2": version "1.1.2" @@ -6806,10 +6806,10 @@ node-libs-browser@^2.0.0: util "^0.11.0" vm-browserify "^1.0.1" -node-pre-gyp@^0.10.0: - version "0.10.3" - resolved "https://registry.yarnpkg.com/node-pre-gyp/-/node-pre-gyp-0.10.3.tgz#3070040716afdc778747b61b6887bf78880b80fc" - integrity sha512-d1xFs+C/IPS8Id0qPTZ4bUT8wWryfR/OzzAFxweG+uLN85oPzyo2Iw6bVlLQ/JOdgNonXLCoRyqDzDWq4iw72A== +node-pre-gyp@^0.11.0: + version "0.11.0" + resolved "https://registry.yarnpkg.com/node-pre-gyp/-/node-pre-gyp-0.11.0.tgz#db1f33215272f692cd38f03238e3e9b47c5dd054" + integrity sha512-TwWAOZb0j7e9eGaf9esRx3ZcLaE5tQ2lvYy1pb5IAaG1a2e2Kv5Lms1Y4hpj+ciXJRofIxxlt5haeQ/2ANeE0Q== dependencies: detect-libc "^1.0.2" mkdirp "^0.5.1"