Item auth_params

This commit is contained in:
Mo Bitar
2018-07-06 23:35:32 -05:00
parent 6fe08106ed
commit 7339c7c77f
9 changed files with 13 additions and 30 deletions

View File

@@ -75,12 +75,12 @@ angular.module('app')
syncManager.setKeyRequestHandler(async () => {
let offline = authManager.offline();
let version = offline ? passcodeManager.protocolVersion() : await authManager.protocolVersion();
let auth_params = offline ? passcodeManager.passcodeAuthParams() : await authManager.getAuthParams();
let keys = offline ? passcodeManager.keys() : await authManager.keys();
return {
keys: keys,
offline: offline,
version: version
auth_params: auth_params
}
});

View File

@@ -204,6 +204,7 @@ angular.module('app')
this.createNewNote();
return;
}
this.selectedNote = note;
note.conflict_of = null; // clear conflict
this.selectionMade()(note);

View File

@@ -173,7 +173,7 @@ class PasswordWizard {
}
// Ensure value for current password matches what's saved
let authParams = authManager.getAuthParams();
let authParams = await authManager.getAuthParams();
let password = $scope.formData.currentPassword;
SFJS.crypto.computeEncryptionKeysForUser(password, authParams).then(async (keys) => {
let success = keys.mk === (await authManager.keys()).mk;

View File

@@ -179,7 +179,7 @@ class ActionsManager {
if(decrypted) {
keys = null;
}
var itemParams = new SFItemParams(item, keys, await this.authManager.protocolVersion());
var itemParams = new SFItemParams(item, keys, await this.authManager.getAuthParams());
return itemParams.paramsForExtension();
}

View File

@@ -17,14 +17,12 @@ class ArchiveManager {
if(this.authManager.offline() && this.passcodeManager.hasPasscode()) {
keys = this.passcodeManager.keys();
authParams = this.passcodeManager.passcodeAuthParams();
protocolVersion = authParams.version;
} else {
keys = await this.authManager.keys();
authParams = this.authManager.getAuthParams();
protocolVersion = await this.authManager.protocolVersion();
authParams = await this.authManager.getAuthParams();
}
}
this.__itemsData(keys, authParams, protocolVersion).then((data) => {
this.__itemsData(keys, authParams).then((data) => {
this.__downloadData(data, `SN Archive - ${new Date()}.txt`);
// download as zipped plain text files
@@ -39,8 +37,8 @@ class ArchiveManager {
Private
*/
async __itemsData(keys, authParams, protocolVersion) {
let data = await this.modelManager.getAllItemsJSONData(keys, authParams, protocolVersion);
async __itemsData(keys, authParams) {
let data = await this.modelManager.getAllItemsJSONData(keys, authParams);
let blobData = new Blob([data], {type: 'text/json'});
return blobData;
}

View File

@@ -49,15 +49,8 @@ class AuthManager extends SFAuthManager {
}
}
getAuthParams() {
if(!this._authParams) {
this._authParams = JSON.parse(this.storageManager.getItemSync("auth_params"));
}
return this._authParams;
}
async protocolVersion() {
var authParams = this.getAuthParams();
var authParams = await this.getAuthParams();
if(authParams && authParams.version) {
return authParams.version;
}

View File

@@ -134,17 +134,14 @@ class DesktopManager {
if(this.authManager.offline() && this.passcodeManager.hasPasscode()) {
keys = this.passcodeManager.keys();
authParams = this.passcodeManager.passcodeAuthParams();
protocolVersion = authParams.version;
} else {
keys = await this.authManager.keys();
authParams = this.authManager.getAuthParams();
protocolVersion = await this.authManager.protocolVersion();
authParams = await this.authManager.getAuthParams();
}
this.modelManager.getAllItemsJSONData(
keys,
authParams,
protocolVersion,
true /* return null on empty */
).then((data) => {
callback(data);

View File

@@ -154,7 +154,7 @@ class StorageManager extends SFStorageManager {
encryptedStorage.content.storage = this.storageAsHash();
// Save new encrypted storage in Fixed storage
var params = new SFItemParams(encryptedStorage, this.encryptedStorageKeys, this.encryptedStorageAuthParams.version);
var params = new SFItemParams(encryptedStorage, this.encryptedStorageKeys, this.encryptedStorageAuthParams);
params.paramsForSync().then((syncParams) => {
this.setItem("encryptedStorage", JSON.stringify(syncParams), StorageManager.Fixed);
})

View File

@@ -373,10 +373,6 @@ describe("syncing", () => {
let authManager = Factory.globalAuthManager();
let syncManager = new SFSyncManager(modelManager, Factory.globalStorageManager(), Factory.globalHttpManager());
syncManager.setEventHandler(() => {
})
syncManager.setKeyRequestHandler(async () => {
return {
keys: await authManager.keys(),
@@ -392,7 +388,7 @@ describe("syncing", () => {
})
}
it.only('syncing a note many times does not cause duplication', async () => {
it('syncing a note many times does not cause duplication', async () => {
modelManager.resetLocalMemory();
let pair = createRelatedNoteTagPair();
let noteParams = pair[0];
@@ -421,8 +417,6 @@ describe("syncing", () => {
let syncManager = new SFSyncManager(modelManager, Factory.globalStorageManager(), Factory.globalHttpManager());
syncManager.setEventHandler(() => {})
// be offline
syncManager.setKeyRequestHandler(async () => {
return {