Migrate to SQLCipher for messages/cache

Quite a few other fixes, including:
  - Sending to contact with no avatar yet (not synced from mobile)
  - Left pane doesn't update quickly or at all on new message
  - Left pane doesn't show sent or error status

Also:
 - Contributing.md: Ensure set of linux dev dependencies is complete
This commit is contained in:
Scott Nonnenberg 2018-07-26 18:13:56 -07:00
parent fc461c82ce
commit 3105b77475
29 changed files with 2006 additions and 716 deletions

67
main.js
View file

@ -4,6 +4,7 @@ const path = require('path');
const url = require('url');
const os = require('os');
const fs = require('fs');
const crypto = require('crypto');
const _ = require('lodash');
const pify = require('pify');
@ -23,7 +24,9 @@ const {
const packageJson = require('./package.json');
const Attachments = require('./app/attachments');
const sql = require('./app/sql');
const sqlChannels = require('./app/sql_channel');
const attachmentChannel = require('./app/attachment_channel');
const autoUpdate = require('./app/auto_update');
const createTrayIcon = require('./app/tray_icon');
const GlobalErrors = require('./app/global_errors');
@ -596,44 +599,48 @@ app.on('ready', async () => {
installPermissionsHandler({ session, userConfig });
// NOTE: Temporarily allow `then` until we convert the entire file to `async` / `await`:
/* eslint-disable more/no-then */
let loggingSetupError;
logging
.initialize()
.catch(error => {
loggingSetupError = error;
})
.then(async () => {
/* eslint-enable more/no-then */
logger = logging.getLogger();
logger.info('app ready');
try {
await logging.initialize();
} catch (error) {
loggingSetupError = error;
}
if (loggingSetupError) {
logger.error('Problem setting up logging', loggingSetupError.stack);
}
logger = logging.getLogger();
logger.info('app ready');
if (!locale) {
const appLocale =
process.env.NODE_ENV === 'test' ? 'en' : app.getLocale();
locale = loadLocale({ appLocale, logger });
}
if (loggingSetupError) {
logger.error('Problem setting up logging', loggingSetupError.stack);
}
console.log('Ensure attachments directory exists');
await Attachments.ensureDirectory(userDataPath);
if (!locale) {
const appLocale = process.env.NODE_ENV === 'test' ? 'en' : app.getLocale();
locale = loadLocale({ appLocale, logger });
}
ready = true;
await attachmentChannel.initialize({ configDir: userDataPath });
autoUpdate.initialize(getMainWindow, locale.messages);
let key = userConfig.get('key');
if (!key) {
// https://www.zetetic.net/sqlcipher/sqlcipher-api/#key
key = crypto.randomBytes(32).toString('hex');
userConfig.set('key', key);
}
createWindow();
await sql.initialize({ configDir: userDataPath, key });
await sqlChannels.initialize({ userConfig });
if (usingTrayIcon) {
tray = createTrayIcon(getMainWindow, locale.messages);
}
ready = true;
setupMenu();
});
autoUpdate.initialize(getMainWindow, locale.messages);
createWindow();
if (usingTrayIcon) {
tray = createTrayIcon(getMainWindow, locale.messages);
}
setupMenu();
});
function setupMenu(options) {