Update sqlcipher to 4.2.0.

pull/945/head
Mikunj 5 years ago
parent 488c0b4e08
commit 78389440c0

@ -10,6 +10,9 @@ let quitText = 'Quit';
let copyErrorAndQuitText = 'Copy error and quit'; let copyErrorAndQuitText = 'Copy error and quit';
function handleError(prefix, error) { function handleError(prefix, error) {
if (console._error) {
console._error(`${prefix}:`, Errors.toLogFormat(error));
}
console.error(`${prefix}:`, Errors.toLogFormat(error)); console.error(`${prefix}:`, Errors.toLogFormat(error));
if (app.isReady()) { if (app.isReady()) {

@ -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]/; const HEX_KEY = /[^0-9A-Fa-f]/;
async function setupSQLCipher(instance, { key }) { async function setupSQLCipher(instance, { key }) {
// If the key isn't hex then we need to derive a hex key from it // 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 // https://www.zetetic.net/sqlcipher/sqlcipher-api/#key
const value = deriveKey ? `'${key}'` : `"x'${key}'"`; const value = deriveKey ? `'${key}'` : `"x'${key}'"`;
await instance.run(`PRAGMA key = ${value};`); 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) { async function setSQLPassword(password) {
@ -1071,6 +1083,13 @@ async function initialize({ configDir, key, messages, passwordAttempt }) {
db = promisified; db = promisified;
// test database // 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(); await getMessageCount();
} catch (error) { } catch (error) {
if (passwordAttempt) { if (passwordAttempt) {

@ -61,7 +61,7 @@
"ready": "yarn clean-transpile && yarn grunt && yarn lint-full && yarn test-node && yarn test-electron && yarn lint-deps" "ready": "yarn clean-transpile && yarn grunt && yarn lint-full && yarn test-node && yarn test-electron && yarn lint-deps"
}, },
"dependencies": { "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", "@sindresorhus/is": "0.8.0",
"@types/dompurify": "^2.0.0", "@types/dompurify": "^2.0.0",
"@types/rc-slider": "^8.6.5", "@types/rc-slider": "^8.6.5",
@ -316,6 +316,8 @@
"node_modules/socks/build/client/*.js", "node_modules/socks/build/client/*.js",
"node_modules/smart-buffer/build/*.js", "node_modules/smart-buffer/build/*.js",
"!node_modules/@journeyapps/sqlcipher/deps/*", "!node_modules/@journeyapps/sqlcipher/deps/*",
"!node_modules/@journeyapps/sqlcipher/build/*",
"!node_modules/@journeyapps/sqlcipher/lib/binding/node-*",
"!build/*.js" "!build/*.js"
] ]
} }

@ -27,12 +27,12 @@
ajv "^6.1.0" ajv "^6.1.0"
ajv-keywords "^3.1.0" ajv-keywords "^3.1.0"
"@journeyapps/sqlcipher@https://github.com/scottnonnenberg-signal/node-sqlcipher.git#2e28733b61640556b0272a3bfc78b0357daf71e6": "@journeyapps/sqlcipher@https://github.com/scottnonnenberg-signal/node-sqlcipher.git#b10f232fac62ba7f8775c9e086bb5558fe7d948b":
version "3.2.1" version "4.0.0"
resolved "https://github.com/scottnonnenberg-signal/node-sqlcipher.git#2e28733b61640556b0272a3bfc78b0357daf71e6" resolved "https://github.com/scottnonnenberg-signal/node-sqlcipher.git#b10f232fac62ba7f8775c9e086bb5558fe7d948b"
dependencies: dependencies:
nan "^2.10.0" nan "^2.12.1"
node-pre-gyp "^0.10.0" node-pre-gyp "^0.11.0"
"@protobufjs/aspromise@^1.1.1", "@protobufjs/aspromise@^1.1.2": "@protobufjs/aspromise@^1.1.1", "@protobufjs/aspromise@^1.1.2":
version "1.1.2" version "1.1.2"
@ -6806,10 +6806,10 @@ node-libs-browser@^2.0.0:
util "^0.11.0" util "^0.11.0"
vm-browserify "^1.0.1" vm-browserify "^1.0.1"
node-pre-gyp@^0.10.0: node-pre-gyp@^0.11.0:
version "0.10.3" version "0.11.0"
resolved "https://registry.yarnpkg.com/node-pre-gyp/-/node-pre-gyp-0.10.3.tgz#3070040716afdc778747b61b6887bf78880b80fc" resolved "https://registry.yarnpkg.com/node-pre-gyp/-/node-pre-gyp-0.11.0.tgz#db1f33215272f692cd38f03238e3e9b47c5dd054"
integrity sha512-d1xFs+C/IPS8Id0qPTZ4bUT8wWryfR/OzzAFxweG+uLN85oPzyo2Iw6bVlLQ/JOdgNonXLCoRyqDzDWq4iw72A== integrity sha512-TwWAOZb0j7e9eGaf9esRx3ZcLaE5tQ2lvYy1pb5IAaG1a2e2Kv5Lms1Y4hpj+ciXJRofIxxlt5haeQ/2ANeE0Q==
dependencies: dependencies:
detect-libc "^1.0.2" detect-libc "^1.0.2"
mkdirp "^0.5.1" mkdirp "^0.5.1"

Loading…
Cancel
Save