option names now follow camelCase

This commit is contained in:
azivner
2018-04-02 21:47:46 -04:00
parent 429d3f518e
commit c6c76ba360
26 changed files with 77 additions and 63 deletions

View File

@@ -20,8 +20,8 @@ async function anonymize() {
await db.run("UPDATE note_revisions SET title = 'title', content = 'text'");
await db.run("UPDATE branches SET prefix = 'prefix' WHERE prefix IS NOT NULL");
await db.run(`UPDATE options SET value = 'anonymized' WHERE name IN
('document_secret', 'encrypted_data_key', 'password_verification_hash',
'password_verification_salt', 'password_derived_key_salt')`);
('documentSecret', 'encryptedDataKey', 'passwordVerificationHash',
'passwordVerificationSalt', 'passwordDerivedKeySalt')`);
await db.run("VACUUM");
await db.close();

View File

@@ -7,7 +7,7 @@ const APP_DB_VERSION = 81;
module.exports = {
app_version: packageJson.version,
db_version: APP_DB_VERSION,
dbVersion: APP_DB_VERSION,
build_date: build.build_date,
build_revision: build.build_revision
};

View File

@@ -11,7 +11,7 @@ const cls = require('./cls');
async function regularBackup() {
const now = new Date();
const lastBackupDate = dateUtils.parseDateTime(await optionService.getOption('last_backup_date'));
const lastBackupDate = dateUtils.parseDateTime(await optionService.getOption('lastBackupDate'));
console.log(lastBackupDate);
@@ -32,7 +32,7 @@ async function backupNow() {
log.info("Created backup at " + backupFile);
await optionService.setOption('last_backup_date', dateUtils.nowDate());
await optionService.setOption('lastBackupDate', dateUtils.nowDate());
});
}

View File

@@ -20,7 +20,7 @@ async function changePassword(currentPassword, newPassword) {
await sql.doInTransaction(async () => {
await passwordEncryptionService.setDataKey(newPassword, decryptedDataKey);
await optionService.setOption('password_verification_hash', newPasswordVerificationKey);
await optionService.setOption('passwordVerificationHash', newPasswordVerificationKey);
});
return {

View File

@@ -66,7 +66,7 @@ async function sendMessageToAllClients(message) {
async function sendPing(client, lastSentSyncId) {
const syncData = await sql.getRows("SELECT * FROM sync WHERE id > ?", [lastSentSyncId]);
const lastSyncedPush = await optionService.getOption('last_synced_push');
const lastSyncedPush = await optionService.getOption('lastSyncedPush');
const changesToPushCount = await sql.getValue("SELECT COUNT(*) FROM sync WHERE id > ?", [lastSyncedPush]);

View File

@@ -12,7 +12,7 @@ async function migrate() {
// backup before attempting migration
await backupService.backupNow();
const currentDbVersion = parseInt(await optionService.getOption('db_version'));
const currentDbVersion = parseInt(await optionService.getOption('dbVersion'));
fs.readdirSync(resourceDir.MIGRATIONS_DIR).forEach(file => {
const match = file.match(/([0-9]{4})__([a-zA-Z0-9_ ]+)\.(sql|js)/);
@@ -63,7 +63,7 @@ async function migrate() {
throw new Error("Unknown migration type " + mig.type);
}
await optionService.setOption("db_version", mig.dbVersion);
await optionService.setOption("dbVersion", mig.dbVersion);
});

View File

@@ -4,13 +4,13 @@ const optionService = require('./options');
const scrypt = require('scrypt');
async function getVerificationHash(password) {
const salt = await optionService.getOption('password_verification_salt');
const salt = await optionService.getOption('passwordVerificationSalt');
return getScryptHash(password, salt);
}
async function getPasswordDerivedKey(password) {
const salt = await optionService.getOption('password_derived_key_salt');
const salt = await optionService.getOption('passwordDerivedKeySalt');
return getScryptHash(password, salt);
}

View File

@@ -165,7 +165,7 @@ async function saveNoteRevision(note) {
const labelsMap = await note.getLabelMap();
const now = new Date();
const noteRevisionSnapshotTimeInterval = parseInt(await optionService.getOption('note_revision_snapshot_time_interval'));
const noteRevisionSnapshotTimeInterval = parseInt(await optionService.getOption('noteRevisionSnapshotTimeInterval'));
const revisionCutoff = dateUtils.dateStr(new Date(now.getTime() - noteRevisionSnapshotTimeInterval * 1000));

View File

@@ -47,24 +47,24 @@ async function createOption(name, value, isSynced) {
}
async function initOptions(startNotePath) {
await createOption('document_id', utils.randomSecureToken(16), false);
await createOption('document_secret', utils.randomSecureToken(16), false);
await createOption('documentId', utils.randomSecureToken(16), false);
await createOption('documentSecret', utils.randomSecureToken(16), false);
await createOption('username', '', true);
await createOption('password_verification_hash', '', true);
await createOption('password_verification_salt', '', true);
await createOption('password_derived_key_salt', '', true);
await createOption('encrypted_data_key', '', true);
await createOption('encrypted_data_key_iv', '', true);
await createOption('passwordVerificationHash', '', true);
await createOption('passwordVerificationSalt', '', true);
await createOption('passwordDerivedKeySalt', '', true);
await createOption('encryptedDataKey', '', true);
await createOption('encryptedDataKey_iv', '', true);
await createOption('start_note_path', startNotePath, false);
await createOption('protected_session_timeout', 600, true);
await createOption('note_revision_snapshot_time_interval', 600, true);
await createOption('last_backup_date', dateUtils.nowDate(), false);
await createOption('db_version', appInfo.db_version, false);
await createOption('startNotePath', startNotePath, false);
await createOption('protectedSessionTimeout', 600, true);
await createOption('noteRevisionSnapshotTimeInterval', 600, true);
await createOption('lastBackupDate', dateUtils.nowDate(), false);
await createOption('dbVersion', appInfo.dbVersion, false);
await createOption('last_synced_pull', appInfo.db_version, false);
await createOption('last_synced_push', 0, false);
await createOption('lastSyncedPull', appInfo.dbVersion, false);
await createOption('lastSyncedPush', 0, false);
}
module.exports = {

View File

@@ -6,7 +6,7 @@ const dataEncryptionService = require('./data_encryption');
async function verifyPassword(password) {
const givenPasswordHash = utils.toBase64(await myScryptService.getVerificationHash(password));
const dbPasswordHash = await optionService.getOption('password_verification_hash');
const dbPasswordHash = await optionService.getOption('passwordVerificationHash');
return givenPasswordHash === dbPasswordHash;
}
@@ -16,20 +16,20 @@ async function setDataKey(password, plainTextDataKey) {
const encryptedDataKeyIv = utils.randomString(16);
await optionService.setOption('encrypted_data_key_iv', encryptedDataKeyIv);
await optionService.setOption('encryptedDataKeyIv', encryptedDataKeyIv);
const buffer = Buffer.from(plainTextDataKey);
const newEncryptedDataKey = dataEncryptionService.encrypt(passwordDerivedKey, encryptedDataKeyIv, buffer);
await optionService.setOption('encrypted_data_key', newEncryptedDataKey);
await optionService.setOption('encryptedDataKey', newEncryptedDataKey);
}
async function getDataKey(password) {
const passwordDerivedKey = await myScryptService.getPasswordDerivedKey(password);
const encryptedDataKeyIv = await optionService.getOption('encrypted_data_key_iv');
const encryptedDataKey = await optionService.getOption('encrypted_data_key');
const encryptedDataKeyIv = await optionService.getOption('encryptedDataKeyIv');
const encryptedDataKey = await optionService.getOption('encryptedDataKey');
const decryptedDataKey = dataEncryptionService.decrypt(passwordDerivedKey, encryptedDataKeyIv, encryptedDataKey);

View File

@@ -76,12 +76,12 @@ function setDbReadyAsResolved() {
}
async function isDbUpToDate() {
const dbVersion = parseInt(await sql.getValue("SELECT value FROM options WHERE name = 'db_version'"));
const dbVersion = parseInt(await sql.getValue("SELECT value FROM options WHERE name = 'dbVersion'"));
const upToDate = dbVersion >= appInfo.db_version;
const upToDate = dbVersion >= appInfo.dbVersion;
if (!upToDate) {
log.info("App db version is " + appInfo.db_version + ", while db version is " + dbVersion + ". Migration needed.");
log.info("App db version is " + appInfo.dbVersion + ", while db version is " + dbVersion + ". Migration needed.");
}
return upToDate;

View File

@@ -71,14 +71,14 @@ async function sync() {
async function login() {
const timestamp = dateUtils.nowDate();
const documentSecret = await optionService.getOption('document_secret');
const documentSecret = await optionService.getOption('documentSecret');
const hash = utils.hmac(documentSecret, timestamp);
const syncContext = { cookieJar: rp.jar() };
const resp = await syncRequest(syncContext, 'POST', '/api/login/sync', {
timestamp: timestamp,
dbVersion: appInfo.db_version,
dbVersion: appInfo.dbVersion,
hash: hash
});
@@ -92,11 +92,11 @@ async function login() {
}
async function getLastSyncedPull() {
return parseInt(await optionService.getOption('last_synced_pull'));
return parseInt(await optionService.getOption('lastSyncedPull'));
}
async function setLastSyncedPull(syncId) {
await optionService.setOption('last_synced_pull', syncId);
await optionService.setOption('lastSyncedPull', syncId);
}
async function pullSync(syncContext) {
@@ -163,11 +163,11 @@ async function pullSync(syncContext) {
}
async function getLastSyncedPush() {
return parseInt(await optionService.getOption('last_synced_push'));
return parseInt(await optionService.getOption('lastSyncedPush'));
}
async function setLastSyncedPush(lastSyncedPush) {
await optionService.setOption('last_synced_push', lastSyncedPush);
await optionService.setOption('lastSyncedPush', lastSyncedPush);
}
async function pushSync(syncContext) {

View File

@@ -56,7 +56,7 @@ async function addEntitySync(entityName, entityId, sourceId) {
if (!syncSetup.isSyncSetup) {
// this is because the "server" instances shouldn't have outstanding pushes
// useful when you fork the DB for new "client" instance, it won't try to sync the whole DB
await sql.execute("UPDATE options SET value = (SELECT MAX(id) FROM sync) WHERE name IN('last_synced_push', 'last_synced_pull')");
await sql.execute("UPDATE options SET value = (SELECT MAX(id) FROM sync) WHERE name IN('lastSyncedPush', 'lastSyncedPull')");
}
}