encrypt stored webdav password

This commit is contained in:
antelle 2016-03-19 15:43:50 +03:00
parent 90b51376b9
commit 6c930f9ac6
3 changed files with 47 additions and 4 deletions

View File

@ -379,7 +379,6 @@ var AppModel = Backbone.Model.extend({
name: params.name,
storage: params.storage,
path: params.path,
opts: params.opts,
keyFileName: params.keyFileName
});
var that = this;
@ -408,6 +407,7 @@ var AppModel = Backbone.Model.extend({
Storage.cache.save(cacheId, null, params.fileData);
}
var rev = params.rev || fileInfo && fileInfo.get('rev');
that.setFileOpts(file, params.opts);
that.addToLastOpenFiles(file, rev);
that.addFile(file);
that.fileOpened(file);
@ -442,7 +442,7 @@ var AppModel = Backbone.Model.extend({
name: file.get('name'),
storage: file.get('storage'),
path: file.get('path'),
opts: file.get('opts'),
opts: this.getStoreOpts(file),
modified: file.get('modified'),
editState: file.getLocalEditState(),
rev: rev,
@ -460,6 +460,21 @@ var AppModel = Backbone.Model.extend({
this.fileInfos.save();
},
getStoreOpts: function(file) {
var opts = file.get('opts'), storage = file.get('storage');
if (Storage[storage]&& Storage[storage].fileOptsToStoreOpts && opts) {
return Storage[storage].fileOptsToStoreOpts(opts, file);
}
return null;
},
setFileOpts: function(file, opts) {
var storage = file.get('storage');
if (Storage[storage]&& Storage[storage].storeOptsToFileOpts && opts) {
file.set('opts', Storage[storage].storeOptsToFileOpts(opts));
}
},
fileOpened: function(file) {
var that = this;
if (file.get('storage') === 'file') {
@ -514,7 +529,7 @@ var AppModel = Backbone.Model.extend({
name: file.get('name'),
storage: file.get('storage'),
path: file.get('path'),
opts: file.get('opts'),
opts: this.getStoreOpts(file),
modified: file.get('modified'),
editState: null,
rev: null,

View File

@ -102,6 +102,34 @@ var StorageWebDav = {
});
},
fileOptsToStoreOpts: function(opts, file) {
var result = {user: opts.user, encpass: opts.encpass};
if (opts.password) {
var fileId = file.get('id');
var password = opts.password;
var encpass = '';
for (var i = 0; i < password.length; i++) {
encpass += String.fromCharCode(password.charCodeAt(i) ^ fileId.charCodeAt(i % fileId.length));
}
result.encpass = btoa(encpass);
}
return result;
},
storeOptsToFileOpts: function(opts, file) {
var result = {user: opts.user, password: opts.password};
if (opts.encpass) {
var fileId = file.get('id');
var encpass = atob(opts.encpass);
var password = '';
for (var i = 0; i < encpass.length; i++) {
password += String.fromCharCode(encpass.charCodeAt(i) ^ fileId.charCodeAt(i % fileId.length));
}
opts.password = password;
}
return result;
},
_request: function(config, callback) {
if (config.rev) {
logger.debug(config.op, config.path, config.rev);

View File

@ -600,7 +600,7 @@ var OpenView = Backbone.View.extend({
var storage = Storage[config.storage];
this.storageWaitId = Math.random();
var path = config.path;
var opts = _.omit(config, 'path');
var opts = _.omit(config, ['path', 'storage']);
var req = {
waitId: this.storageWaitId,
storage: config.storage,