SNJS 1.0.2 and accompanying refactor to cryptoManager
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import { isDesktopApplication } from '@/utils';
|
import { isDesktopApplication } from '@/utils';
|
||||||
import { PrivilegesManager } from '@/services/privilegesManager';
|
import { PrivilegesManager } from '@/services/privilegesManager';
|
||||||
import template from '%/directives/account-menu.pug';
|
import template from '%/directives/account-menu.pug';
|
||||||
import { SNJS } from 'snjs';
|
import { cryptoManager } from 'snjs';
|
||||||
|
|
||||||
export class AccountMenu {
|
export class AccountMenu {
|
||||||
constructor() {
|
constructor() {
|
||||||
@@ -326,9 +326,9 @@ export class AccountMenu {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(data.auth_params) {
|
if(data.auth_params) {
|
||||||
SNJS.crypto.computeEncryptionKeysForUser(password, data.auth_params).then((keys) => {
|
cryptoManager.computeEncryptionKeysForUser(password, data.auth_params).then((keys) => {
|
||||||
try {
|
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(() => {
|
.then(() => {
|
||||||
// delete items enc_item_key since the user's actually key will do the encrypting once its passed off
|
// delete items enc_item_key since the user's actually key will do the encrypting once its passed off
|
||||||
data.items.forEach(function(item){
|
data.items.forEach(function(item){
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { SNJS } from 'snjs';
|
import { cryptoManager } from 'snjs';
|
||||||
import template from '%/directives/password-wizard.pug';
|
import template from '%/directives/password-wizard.pug';
|
||||||
|
|
||||||
export class PasswordWizard {
|
export class PasswordWizard {
|
||||||
@@ -213,7 +213,7 @@ export class PasswordWizard {
|
|||||||
// Ensure value for current password matches what's saved
|
// Ensure value for current password matches what's saved
|
||||||
let authParams = await authManager.getAuthParams();
|
let authParams = await authManager.getAuthParams();
|
||||||
let password = $scope.formData.currentPassword;
|
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;
|
let success = keys.mk === (await authManager.keys()).mk;
|
||||||
if(success) {
|
if(success) {
|
||||||
this.currentServerPw = keys.pw;
|
this.currentServerPw = keys.pw;
|
||||||
@@ -241,7 +241,7 @@ export class PasswordWizard {
|
|||||||
|
|
||||||
let currentServerPw = this.currentServerPw;
|
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 newKeys = results.keys;
|
||||||
let newAuthParams = results.authParams;
|
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';
|
import template from '%/directives/revision-preview-modal.pug';
|
||||||
|
|
||||||
export class RevisionPreviewModal {
|
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.
|
// but then generate new uuid for note as not to save changes to original, if editor makes changes.
|
||||||
$scope.note.uuid = $scope.uuid;
|
$scope.note.uuid = $scope.uuid;
|
||||||
let editorForNote = componentManager.editorForNote($scope.note);
|
let editorForNote = componentManager.editorForNote($scope.note);
|
||||||
$scope.note.uuid = SNJS.crypto.generateUUIDSync();
|
$scope.note.uuid = cryptoManager.crypto.generateUUIDSync();
|
||||||
|
|
||||||
if(editorForNote) {
|
if(editorForNote) {
|
||||||
// Create temporary copy, as a lot of componentManager is uuid based,
|
// Create temporary copy, as a lot of componentManager is uuid based,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import angular from 'angular';
|
import angular from 'angular';
|
||||||
import { Action, SFModelManager, SFItemParams, SNJS } from 'snjs';
|
import { Action, SFModelManager, SFItemParams, cryptoManager } from 'snjs';
|
||||||
|
|
||||||
export class ActionsManager {
|
export class ActionsManager {
|
||||||
|
|
||||||
@@ -85,7 +85,7 @@ export class ActionsManager {
|
|||||||
let handleResponseDecryption = async (response, keys, merge) => {
|
let handleResponseDecryption = async (response, keys, merge) => {
|
||||||
var item = response.item;
|
var item = response.item;
|
||||||
|
|
||||||
await SNJS.itemTransformer.decryptItem(item, keys);
|
await cryptoManager.decryptItem(item, keys);
|
||||||
|
|
||||||
if(!item.errorDecrypting) {
|
if(!item.errorDecrypting) {
|
||||||
if(merge) {
|
if(merge) {
|
||||||
@@ -115,7 +115,7 @@ export class ActionsManager {
|
|||||||
}
|
}
|
||||||
triedPasswords.push(passwordCandidate);
|
triedPasswords.push(passwordCandidate);
|
||||||
|
|
||||||
var keyResults = await SNJS.crypto.computeEncryptionKeysForUser(passwordCandidate, response.auth_params);
|
var keyResults = await cryptoManager.computeEncryptionKeysForUser(passwordCandidate, response.auth_params);
|
||||||
if(!keyResults) {
|
if(!keyResults) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import angular from 'angular';
|
import angular from 'angular';
|
||||||
import { StorageManager } from './storageManager';
|
import { StorageManager } from './storageManager';
|
||||||
import { SNJS, SFItem, SFPredicate, SFAuthManager } from 'snjs';
|
import { cryptoManager, SFItem, SFPredicate, SFAuthManager } from 'snjs';
|
||||||
|
|
||||||
export class AuthManager extends SFAuthManager {
|
export class AuthManager extends SFAuthManager {
|
||||||
/* @ngInject */
|
/* @ngInject */
|
||||||
@@ -112,7 +112,7 @@ export class AuthManager extends SFAuthManager {
|
|||||||
|
|
||||||
async verifyAccountPassword(password) {
|
async verifyAccountPassword(password) {
|
||||||
let authParams = await this.getAuthParams();
|
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;
|
let success = keys.mk === (await this.keys()).mk;
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
@@ -122,7 +122,7 @@ export class AuthManager extends SFAuthManager {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
let latest = SNJS.version();
|
let latest = cryptoManager.version();
|
||||||
let updateAvailable = await this.protocolVersion() !== latest;
|
let updateAvailable = await this.protocolVersion() !== latest;
|
||||||
if(updateAvailable !== this.securityUpdateAvailable) {
|
if(updateAvailable !== this.securityUpdateAvailable) {
|
||||||
this.securityUpdateAvailable = updateAvailable;
|
this.securityUpdateAvailable = updateAvailable;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { isDesktopApplication } from '@/utils';
|
import { isDesktopApplication } from '@/utils';
|
||||||
import { StorageManager } from './storageManager';
|
import { StorageManager } from './storageManager';
|
||||||
import { SNJS } from 'snjs';
|
import { cryptoManager } from 'snjs';
|
||||||
|
|
||||||
const MillisecondsPerSecond = 1000;
|
const MillisecondsPerSecond = 1000;
|
||||||
|
|
||||||
@@ -88,7 +88,7 @@ export class PasscodeManager {
|
|||||||
async verifyPasscode(passcode) {
|
async verifyPasscode(passcode) {
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
var params = this.passcodeAuthParams();
|
var params = this.passcodeAuthParams();
|
||||||
let keys = await SNJS.crypto.computeEncryptionKeysForUser(passcode, params);
|
let keys = await cryptoManager.computeEncryptionKeysForUser(passcode, params);
|
||||||
if(keys.pw !== params.hash) {
|
if(keys.pw !== params.hash) {
|
||||||
resolve(false);
|
resolve(false);
|
||||||
} else {
|
} else {
|
||||||
@@ -99,7 +99,7 @@ export class PasscodeManager {
|
|||||||
|
|
||||||
unlock(passcode, callback) {
|
unlock(passcode, callback) {
|
||||||
var params = this.passcodeAuthParams();
|
var params = this.passcodeAuthParams();
|
||||||
SNJS.crypto.computeEncryptionKeysForUser(passcode, params).then((keys) => {
|
cryptoManager.computeEncryptionKeysForUser(passcode, params).then((keys) => {
|
||||||
if(keys.pw !== params.hash) {
|
if(keys.pw !== params.hash) {
|
||||||
callback(false);
|
callback(false);
|
||||||
return;
|
return;
|
||||||
@@ -115,9 +115,9 @@ export class PasscodeManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setPasscode(passcode, callback) {
|
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 keys = results.keys;
|
||||||
let authParams = results.authParams;
|
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 {
|
export class MemoryStorage {
|
||||||
constructor() {
|
constructor() {
|
||||||
@@ -119,7 +119,7 @@ export class StorageManager extends SFStorageManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(vaultKey === StorageManager.FixedEncrypted || (!vaultKey && this.itemsStorageMode === StorageManager.FixedEncrypted)) {
|
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;
|
this.encryptedStorageAuthParams = authParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
writeEncryptedStorageToDisk() {
|
async writeEncryptedStorageToDisk() {
|
||||||
var encryptedStorage = new SNEncryptedStorage();
|
var encryptedStorage = new SNEncryptedStorage();
|
||||||
// Copy over totality of current storage
|
// Copy over totality of current storage
|
||||||
encryptedStorage.content.storage = this.storageAsHash();
|
encryptedStorage.content.storage = this.storageAsHash();
|
||||||
|
|
||||||
// Save new encrypted storage in Fixed storage
|
// Save new encrypted storage in Fixed storage
|
||||||
var params = new SFItemParams(encryptedStorage, this.encryptedStorageKeys, this.encryptedStorageAuthParams);
|
var params = new SFItemParams(encryptedStorage, this.encryptedStorageKeys, this.encryptedStorageAuthParams);
|
||||||
params.paramsForSync().then((syncParams) => {
|
const syncParams = await params.paramsForSync();
|
||||||
this.setItem("encryptedStorage", JSON.stringify(syncParams), StorageManager.Fixed);
|
this.setItem("encryptedStorage", JSON.stringify(syncParams), StorageManager.Fixed);
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async decryptStorage() {
|
async decryptStorage() {
|
||||||
var stored = JSON.parse(this.getItemSync("encryptedStorage", StorageManager.Fixed));
|
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);
|
var encryptedStorage = new SNEncryptedStorage(stored);
|
||||||
|
|
||||||
for(var key of Object.keys(encryptedStorage.content.storage)) {
|
for(var key of Object.keys(encryptedStorage.content.storage)) {
|
||||||
|
|||||||
10
dist/javascripts/app.js
vendored
10
dist/javascripts/app.js
vendored
File diff suppressed because one or more lines are too long
2
dist/javascripts/app.js.map
vendored
2
dist/javascripts/app.js.map
vendored
File diff suppressed because one or more lines are too long
6
package-lock.json
generated
6
package-lock.json
generated
@@ -8687,9 +8687,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"snjs": {
|
"snjs": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/snjs/-/snjs-1.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/snjs/-/snjs-1.0.2.tgz",
|
||||||
"integrity": "sha512-Md+K/qt0k2MQYWLbZDAOIjaVF6XbGE56CqpAWr0gV+u0XlBd5G6xMVVxOH9qO96H5ILEOG/oESNzchwChxQfqg==",
|
"integrity": "sha512-ciTP0YALhV7BMJ4B5m5gHnn3hDwGtpEniKd6/WUobKvgA365rCc0GboiYTCj07LY21I9mVq1seDSZT3bSkM15w==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"lodash": "^4.17.15"
|
"lodash": "^4.17.15"
|
||||||
|
|||||||
@@ -44,7 +44,7 @@
|
|||||||
"mocha": "^6.2.2",
|
"mocha": "^6.2.2",
|
||||||
"serve-static": "^1.14.1",
|
"serve-static": "^1.14.1",
|
||||||
"sn-stylekit": "2.0.20",
|
"sn-stylekit": "2.0.20",
|
||||||
"snjs": "1.0.1",
|
"snjs": "1.0.2",
|
||||||
"webpack": "^4.41.3",
|
"webpack": "^4.41.3",
|
||||||
"webpack-cli": "^3.3.10"
|
"webpack-cli": "^3.3.10"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -4,14 +4,14 @@ import '../vendor/chai-as-promised-built.js';
|
|||||||
import '../../../vendor/assets/javascripts/lodash/lodash.custom.js';
|
import '../../../vendor/assets/javascripts/lodash/lodash.custom.js';
|
||||||
|
|
||||||
import LocalStorageManager from './localStorageManager.js';
|
import LocalStorageManager from './localStorageManager.js';
|
||||||
const sf_default = new StandardNotes();
|
const sf_default = new SNCryptoManager();
|
||||||
SFItem.AppDomain = "org.standardnotes.sn";
|
SFItem.AppDomain = "org.standardnotes.sn";
|
||||||
|
|
||||||
var _globalStorageManager = null;
|
var _globalStorageManager = null;
|
||||||
var _globalHttpManager = null;
|
var _globalHttpManager = null;
|
||||||
var _globalAuthManager = null;
|
var _globalAuthManager = null;
|
||||||
var _globalModelManager = null;
|
var _globalModelManager = null;
|
||||||
var _globalStandardNotes = null;
|
var _globalCryptoManager = null;
|
||||||
|
|
||||||
export default class Factory {
|
export default class Factory {
|
||||||
|
|
||||||
@@ -47,9 +47,9 @@ export default class Factory {
|
|||||||
return _globalModelManager;
|
return _globalModelManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
static globalStandardNotes() {
|
static globalCryptoManager() {
|
||||||
if(_globalStandardNotes == null) { _globalStandardNotes = new StandardNotes(); }
|
if(_globalCryptoManager == null) { _globalCryptoManager = new SNCryptoManager(); }
|
||||||
return _globalStandardNotes;
|
return _globalCryptoManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
static createModelManager() {
|
static createModelManager() {
|
||||||
@@ -62,7 +62,7 @@ export default class Factory {
|
|||||||
|
|
||||||
static createItemParams() {
|
static createItemParams() {
|
||||||
var params = {
|
var params = {
|
||||||
uuid: SNJS.crypto.generateUUIDSync(),
|
uuid: cryptoManager.crypto.generateUUIDSync(),
|
||||||
content_type: "Note",
|
content_type: "Note",
|
||||||
content: {
|
content: {
|
||||||
title: "hello",
|
title: "hello",
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ var expect = chai.expect;
|
|||||||
|
|
||||||
const getNoteParams = () => {
|
const getNoteParams = () => {
|
||||||
var params = {
|
var params = {
|
||||||
uuid: SNJS.crypto.generateUUIDSync(),
|
uuid: cryptoManager.crypto.generateUUIDSync(),
|
||||||
content_type: "Note",
|
content_type: "Note",
|
||||||
content: {
|
content: {
|
||||||
title: "hello",
|
title: "hello",
|
||||||
@@ -22,7 +22,7 @@ const getNoteParams = () => {
|
|||||||
const createRelatedNoteTagPair = () => {
|
const createRelatedNoteTagPair = () => {
|
||||||
let noteParams = getNoteParams();
|
let noteParams = getNoteParams();
|
||||||
let tagParams = {
|
let tagParams = {
|
||||||
uuid: SNJS.crypto.generateUUIDSync(),
|
uuid: cryptoManager.crypto.generateUUIDSync(),
|
||||||
content_type: "Tag",
|
content_type: "Tag",
|
||||||
content: {
|
content: {
|
||||||
title: "thoughts",
|
title: "thoughts",
|
||||||
@@ -441,8 +441,8 @@ describe("syncing", () => {
|
|||||||
var totalItemCount = 0;
|
var totalItemCount = 0;
|
||||||
|
|
||||||
beforeEach((done) => {
|
beforeEach((done) => {
|
||||||
var email = Factory.globalStandardNotes().crypto.generateUUIDSync();
|
var email = Factory.globalCryptoManager().crypto.generateUUIDSync();
|
||||||
var password = Factory.globalStandardNotes().crypto.generateUUIDSync();
|
var password = Factory.globalCryptoManager().crypto.generateUUIDSync();
|
||||||
Factory.globalStorageManager().clearAllData().then(() => {
|
Factory.globalStorageManager().clearAllData().then(() => {
|
||||||
Factory.newRegisteredUser(email, password).then((user) => {
|
Factory.newRegisteredUser(email, password).then((user) => {
|
||||||
done();
|
done();
|
||||||
|
|||||||
Reference in New Issue
Block a user