mirror of https://github.com/keeweb/keeweb.git
encrypt stored webdav password
This commit is contained in:
parent
90b51376b9
commit
6c930f9ac6
|
@ -379,7 +379,6 @@ var AppModel = Backbone.Model.extend({
|
||||||
name: params.name,
|
name: params.name,
|
||||||
storage: params.storage,
|
storage: params.storage,
|
||||||
path: params.path,
|
path: params.path,
|
||||||
opts: params.opts,
|
|
||||||
keyFileName: params.keyFileName
|
keyFileName: params.keyFileName
|
||||||
});
|
});
|
||||||
var that = this;
|
var that = this;
|
||||||
|
@ -408,6 +407,7 @@ var AppModel = Backbone.Model.extend({
|
||||||
Storage.cache.save(cacheId, null, params.fileData);
|
Storage.cache.save(cacheId, null, params.fileData);
|
||||||
}
|
}
|
||||||
var rev = params.rev || fileInfo && fileInfo.get('rev');
|
var rev = params.rev || fileInfo && fileInfo.get('rev');
|
||||||
|
that.setFileOpts(file, params.opts);
|
||||||
that.addToLastOpenFiles(file, rev);
|
that.addToLastOpenFiles(file, rev);
|
||||||
that.addFile(file);
|
that.addFile(file);
|
||||||
that.fileOpened(file);
|
that.fileOpened(file);
|
||||||
|
@ -442,7 +442,7 @@ var AppModel = Backbone.Model.extend({
|
||||||
name: file.get('name'),
|
name: file.get('name'),
|
||||||
storage: file.get('storage'),
|
storage: file.get('storage'),
|
||||||
path: file.get('path'),
|
path: file.get('path'),
|
||||||
opts: file.get('opts'),
|
opts: this.getStoreOpts(file),
|
||||||
modified: file.get('modified'),
|
modified: file.get('modified'),
|
||||||
editState: file.getLocalEditState(),
|
editState: file.getLocalEditState(),
|
||||||
rev: rev,
|
rev: rev,
|
||||||
|
@ -460,6 +460,21 @@ var AppModel = Backbone.Model.extend({
|
||||||
this.fileInfos.save();
|
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) {
|
fileOpened: function(file) {
|
||||||
var that = this;
|
var that = this;
|
||||||
if (file.get('storage') === 'file') {
|
if (file.get('storage') === 'file') {
|
||||||
|
@ -514,7 +529,7 @@ var AppModel = Backbone.Model.extend({
|
||||||
name: file.get('name'),
|
name: file.get('name'),
|
||||||
storage: file.get('storage'),
|
storage: file.get('storage'),
|
||||||
path: file.get('path'),
|
path: file.get('path'),
|
||||||
opts: file.get('opts'),
|
opts: this.getStoreOpts(file),
|
||||||
modified: file.get('modified'),
|
modified: file.get('modified'),
|
||||||
editState: null,
|
editState: null,
|
||||||
rev: null,
|
rev: null,
|
||||||
|
|
|
@ -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) {
|
_request: function(config, callback) {
|
||||||
if (config.rev) {
|
if (config.rev) {
|
||||||
logger.debug(config.op, config.path, config.rev);
|
logger.debug(config.op, config.path, config.rev);
|
||||||
|
|
|
@ -600,7 +600,7 @@ var OpenView = Backbone.View.extend({
|
||||||
var storage = Storage[config.storage];
|
var storage = Storage[config.storage];
|
||||||
this.storageWaitId = Math.random();
|
this.storageWaitId = Math.random();
|
||||||
var path = config.path;
|
var path = config.path;
|
||||||
var opts = _.omit(config, 'path');
|
var opts = _.omit(config, ['path', 'storage']);
|
||||||
var req = {
|
var req = {
|
||||||
waitId: this.storageWaitId,
|
waitId: this.storageWaitId,
|
||||||
storage: config.storage,
|
storage: config.storage,
|
||||||
|
|
Loading…
Reference in New Issue