SNJS 1.0.2 and accompanying refactor to cryptoManager
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { isDesktopApplication } from '@/utils';
|
||||
import { PrivilegesManager } from '@/services/privilegesManager';
|
||||
import template from '%/directives/account-menu.pug';
|
||||
import { SNJS } from 'snjs';
|
||||
import { cryptoManager } from 'snjs';
|
||||
|
||||
export class AccountMenu {
|
||||
constructor() {
|
||||
@@ -326,9 +326,9 @@ export class AccountMenu {
|
||||
}
|
||||
|
||||
if(data.auth_params) {
|
||||
SNJS.crypto.computeEncryptionKeysForUser(password, data.auth_params).then((keys) => {
|
||||
cryptoManager.computeEncryptionKeysForUser(password, data.auth_params).then((keys) => {
|
||||
try {
|
||||
SNJS.itemTransformer.decryptMultipleItems(data.items, keys, false) /* throws = false as we don't want to interrupt all decryption if just one fails */
|
||||
cryptoManager.decryptMultipleItems(data.items, keys, false) /* throws = false as we don't want to interrupt all decryption if just one fails */
|
||||
.then(() => {
|
||||
// delete items enc_item_key since the user's actually key will do the encrypting once its passed off
|
||||
data.items.forEach(function(item){
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { SNJS } from 'snjs';
|
||||
import { cryptoManager } from 'snjs';
|
||||
import template from '%/directives/password-wizard.pug';
|
||||
|
||||
export class PasswordWizard {
|
||||
@@ -213,7 +213,7 @@ export class PasswordWizard {
|
||||
// Ensure value for current password matches what's saved
|
||||
let authParams = await authManager.getAuthParams();
|
||||
let password = $scope.formData.currentPassword;
|
||||
SNJS.crypto.computeEncryptionKeysForUser(password, authParams).then(async (keys) => {
|
||||
cryptoManager.computeEncryptionKeysForUser(password, authParams).then(async (keys) => {
|
||||
let success = keys.mk === (await authManager.keys()).mk;
|
||||
if(success) {
|
||||
this.currentServerPw = keys.pw;
|
||||
@@ -241,7 +241,7 @@ export class PasswordWizard {
|
||||
|
||||
let currentServerPw = this.currentServerPw;
|
||||
|
||||
let results = await SNJS.crypto.generateInitialKeysAndAuthParamsForUser(authManager.user.email, newUserPassword);
|
||||
let results = await cryptoManager.generateInitialKeysAndAuthParamsForUser(authManager.user.email, newUserPassword);
|
||||
let newKeys = results.keys;
|
||||
let newAuthParams = results.authParams;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { SNJS, SNComponent, SFItem, SFModelManager } from 'snjs';
|
||||
import { cryptoManager, SNComponent, SFItem, SFModelManager } from 'snjs';
|
||||
import template from '%/directives/revision-preview-modal.pug';
|
||||
|
||||
export class RevisionPreviewModal {
|
||||
@@ -33,7 +33,7 @@ export class RevisionPreviewModal {
|
||||
// but then generate new uuid for note as not to save changes to original, if editor makes changes.
|
||||
$scope.note.uuid = $scope.uuid;
|
||||
let editorForNote = componentManager.editorForNote($scope.note);
|
||||
$scope.note.uuid = SNJS.crypto.generateUUIDSync();
|
||||
$scope.note.uuid = cryptoManager.crypto.generateUUIDSync();
|
||||
|
||||
if(editorForNote) {
|
||||
// Create temporary copy, as a lot of componentManager is uuid based,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import _ from 'lodash';
|
||||
import angular from 'angular';
|
||||
import { Action, SFModelManager, SFItemParams, SNJS } from 'snjs';
|
||||
import { Action, SFModelManager, SFItemParams, cryptoManager } from 'snjs';
|
||||
|
||||
export class ActionsManager {
|
||||
|
||||
@@ -85,7 +85,7 @@ export class ActionsManager {
|
||||
let handleResponseDecryption = async (response, keys, merge) => {
|
||||
var item = response.item;
|
||||
|
||||
await SNJS.itemTransformer.decryptItem(item, keys);
|
||||
await cryptoManager.decryptItem(item, keys);
|
||||
|
||||
if(!item.errorDecrypting) {
|
||||
if(merge) {
|
||||
@@ -115,7 +115,7 @@ export class ActionsManager {
|
||||
}
|
||||
triedPasswords.push(passwordCandidate);
|
||||
|
||||
var keyResults = await SNJS.crypto.computeEncryptionKeysForUser(passwordCandidate, response.auth_params);
|
||||
var keyResults = await cryptoManager.computeEncryptionKeysForUser(passwordCandidate, response.auth_params);
|
||||
if(!keyResults) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import angular from 'angular';
|
||||
import { StorageManager } from './storageManager';
|
||||
import { SNJS, SFItem, SFPredicate, SFAuthManager } from 'snjs';
|
||||
import { cryptoManager, SFItem, SFPredicate, SFAuthManager } from 'snjs';
|
||||
|
||||
export class AuthManager extends SFAuthManager {
|
||||
/* @ngInject */
|
||||
@@ -112,7 +112,7 @@ export class AuthManager extends SFAuthManager {
|
||||
|
||||
async verifyAccountPassword(password) {
|
||||
let authParams = await this.getAuthParams();
|
||||
let keys = await SNJS.crypto.computeEncryptionKeysForUser(password, authParams);
|
||||
let keys = await cryptoManager.computeEncryptionKeysForUser(password, authParams);
|
||||
let success = keys.mk === (await this.keys()).mk;
|
||||
return success;
|
||||
}
|
||||
@@ -122,7 +122,7 @@ export class AuthManager extends SFAuthManager {
|
||||
return false;
|
||||
}
|
||||
|
||||
let latest = SNJS.version();
|
||||
let latest = cryptoManager.version();
|
||||
let updateAvailable = await this.protocolVersion() !== latest;
|
||||
if(updateAvailable !== this.securityUpdateAvailable) {
|
||||
this.securityUpdateAvailable = updateAvailable;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import _ from 'lodash';
|
||||
import { isDesktopApplication } from '@/utils';
|
||||
import { StorageManager } from './storageManager';
|
||||
import { SNJS } from 'snjs';
|
||||
import { cryptoManager } from 'snjs';
|
||||
|
||||
const MillisecondsPerSecond = 1000;
|
||||
|
||||
@@ -88,7 +88,7 @@ export class PasscodeManager {
|
||||
async verifyPasscode(passcode) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
var params = this.passcodeAuthParams();
|
||||
let keys = await SNJS.crypto.computeEncryptionKeysForUser(passcode, params);
|
||||
let keys = await cryptoManager.computeEncryptionKeysForUser(passcode, params);
|
||||
if(keys.pw !== params.hash) {
|
||||
resolve(false);
|
||||
} else {
|
||||
@@ -99,7 +99,7 @@ export class PasscodeManager {
|
||||
|
||||
unlock(passcode, callback) {
|
||||
var params = this.passcodeAuthParams();
|
||||
SNJS.crypto.computeEncryptionKeysForUser(passcode, params).then((keys) => {
|
||||
cryptoManager.computeEncryptionKeysForUser(passcode, params).then((keys) => {
|
||||
if(keys.pw !== params.hash) {
|
||||
callback(false);
|
||||
return;
|
||||
@@ -115,9 +115,9 @@ export class PasscodeManager {
|
||||
}
|
||||
|
||||
setPasscode(passcode, callback) {
|
||||
var uuid = SNJS.crypto.generateUUIDSync();
|
||||
var uuid = cryptoManager.crypto.generateUUIDSync();
|
||||
|
||||
SNJS.crypto.generateInitialKeysAndAuthParamsForUser(uuid, passcode).then((results) => {
|
||||
cryptoManager.generateInitialKeysAndAuthParamsForUser(uuid, passcode).then((results) => {
|
||||
let keys = results.keys;
|
||||
let authParams = results.authParams;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { SNJS, SNEncryptedStorage, SFStorageManager , SFItemParams } from 'snjs';
|
||||
import { cryptoManager, SNEncryptedStorage, SFStorageManager , SFItemParams } from 'snjs';
|
||||
|
||||
export class MemoryStorage {
|
||||
constructor() {
|
||||
@@ -119,7 +119,7 @@ export class StorageManager extends SFStorageManager {
|
||||
}
|
||||
|
||||
if(vaultKey === StorageManager.FixedEncrypted || (!vaultKey && this.itemsStorageMode === StorageManager.FixedEncrypted)) {
|
||||
this.writeEncryptedStorageToDisk();
|
||||
return this.writeEncryptedStorageToDisk();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,21 +157,20 @@ export class StorageManager extends SFStorageManager {
|
||||
this.encryptedStorageAuthParams = authParams;
|
||||
}
|
||||
|
||||
writeEncryptedStorageToDisk() {
|
||||
async writeEncryptedStorageToDisk() {
|
||||
var encryptedStorage = new SNEncryptedStorage();
|
||||
// Copy over totality of current storage
|
||||
encryptedStorage.content.storage = this.storageAsHash();
|
||||
|
||||
// Save new encrypted storage in Fixed storage
|
||||
var params = new SFItemParams(encryptedStorage, this.encryptedStorageKeys, this.encryptedStorageAuthParams);
|
||||
params.paramsForSync().then((syncParams) => {
|
||||
this.setItem("encryptedStorage", JSON.stringify(syncParams), StorageManager.Fixed);
|
||||
})
|
||||
const syncParams = await params.paramsForSync();
|
||||
this.setItem("encryptedStorage", JSON.stringify(syncParams), StorageManager.Fixed);
|
||||
}
|
||||
|
||||
async decryptStorage() {
|
||||
var stored = JSON.parse(this.getItemSync("encryptedStorage", StorageManager.Fixed));
|
||||
await SNJS.itemTransformer.decryptItem(stored, this.encryptedStorageKeys);
|
||||
await cryptoManager.decryptItem(stored, this.encryptedStorageKeys);
|
||||
var encryptedStorage = new SNEncryptedStorage(stored);
|
||||
|
||||
for(var key of Object.keys(encryptedStorage.content.storage)) {
|
||||
|
||||
Reference in New Issue
Block a user