зеркало из https://github.com/mozilla/gecko-dev.git
get crypto working with FileEngine
This commit is contained in:
Родитель
dea3f0cad7
Коммит
3cc3c36b0b
|
@ -509,10 +509,10 @@ FileEngine.prototype = {
|
||||||
|
|
||||||
_initialUpload: function FileEngine__initialUpload() {
|
_initialUpload: function FileEngine__initialUpload() {
|
||||||
let self = yield;
|
let self = yield;
|
||||||
|
yield this._keys.initialize(self.cb, this.engineId);
|
||||||
this._file.data = {};
|
this._file.data = {};
|
||||||
yield this._merge.async(this, self.cb);
|
yield this._merge.async(this, self.cb);
|
||||||
yield this._file.put(self.cb, this._file.data);
|
yield this._file.put(self.cb, this._file.data);
|
||||||
// put keychain
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// NOTE: Assumes this._file has latest server data
|
// NOTE: Assumes this._file has latest server data
|
||||||
|
@ -536,16 +536,16 @@ FileEngine.prototype = {
|
||||||
if (!(yield DAV.MKCOL(this.serverPrefix, self.cb)))
|
if (!(yield DAV.MKCOL(this.serverPrefix, self.cb)))
|
||||||
throw "Could not create remote folder";
|
throw "Could not create remote folder";
|
||||||
|
|
||||||
if ("none" != Utils.prefs.getCharPref("encryption"))
|
|
||||||
yield this._keys.getKeyAndIV(self.cb, this.engineId);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if ("none" != Utils.prefs.getCharPref("encryption"))
|
||||||
|
yield this._keys.getKeyAndIV(self.cb, this.engineId);
|
||||||
yield this._file.get(self.cb);
|
yield this._file.get(self.cb);
|
||||||
yield this._merge.async(this, self.cb);
|
yield this._merge.async(this, self.cb);
|
||||||
yield this._file.put(self.cb, this._file.data);
|
yield this._file.put(self.cb, this._file.data);
|
||||||
|
|
||||||
} catch (e if e.status == 404) {
|
} catch (e if e.status == 404) {
|
||||||
this._initialUpload.async(this, self.cb);
|
|
||||||
this._log.info("Initial upload to server");
|
this._log.info("Initial upload to server");
|
||||||
|
yield this._initialUpload.async(this, self.cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
this._log.info("Sync complete");
|
this._log.info("Sync complete");
|
||||||
|
|
|
@ -350,8 +350,7 @@ CryptoFilter.prototype = {
|
||||||
let self = yield;
|
let self = yield;
|
||||||
this._log.debug("Encrypting data");
|
this._log.debug("Encrypting data");
|
||||||
this._os.notifyObservers(null, "weave:service:sync:status", "status.encrypting");
|
this._os.notifyObservers(null, "weave:service:sync:status", "status.encrypting");
|
||||||
Crypto.encryptData.async(Crypto, self.cb, data, this._identity);
|
let ret = yield Crypto.encryptData.async(Crypto, self.cb, data, this._identity);
|
||||||
let ret = yield;
|
|
||||||
self.done(ret);
|
self.done(ret);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -359,8 +358,7 @@ CryptoFilter.prototype = {
|
||||||
let self = yield;
|
let self = yield;
|
||||||
this._log.debug("Decrypting data");
|
this._log.debug("Decrypting data");
|
||||||
this._os.notifyObservers(null, "weave:service:sync:status", "status.decrypting");
|
this._os.notifyObservers(null, "weave:service:sync:status", "status.decrypting");
|
||||||
Crypto.decryptData.async(Crypto, self.cb, data, this.identity);
|
let ret = yield Crypto.decryptData.async(Crypto, self.cb, data, this._identity);
|
||||||
let ret = yield;
|
|
||||||
self.done(ret);
|
self.done(ret);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -374,12 +372,37 @@ Keychain.prototype = {
|
||||||
this.__proto__.__proto__._init.call(this, prefix + "keys.json");
|
this.__proto__.__proto__._init.call(this, prefix + "keys.json");
|
||||||
this.pushFilter(new JsonFilter());
|
this.pushFilter(new JsonFilter());
|
||||||
},
|
},
|
||||||
|
_initialize: function Keychain__initialize(identity) {
|
||||||
|
let self = yield;
|
||||||
|
let wrappedSymkey;
|
||||||
|
|
||||||
|
if ("none" != Utils.prefs.getCharPref("encryption")) {
|
||||||
|
this._os.notifyObservers(null, "weave:service:sync:status", "status.generating-random-key");
|
||||||
|
|
||||||
|
yield Crypto.randomKeyGen.async(Crypto, self.cb, identity);
|
||||||
|
|
||||||
|
// Wrap (encrypt) this key with the user's public key.
|
||||||
|
let idRSA = ID.get('WeaveCryptoID');
|
||||||
|
this._os.notifyObservers(null, "weave:service:sync:status", "status.encrypting-key");
|
||||||
|
wrappedSymkey = yield Crypto.wrapKey.async(Crypto, self.cb,
|
||||||
|
identity.bulkKey, idRSA);
|
||||||
|
}
|
||||||
|
|
||||||
|
let keys = {ring: {}, bulkIV: identity.bulkIV};
|
||||||
|
this._os.notifyObservers(null, "weave:service:sync:status", "status.uploading-key");
|
||||||
|
keys.ring[identity.username] = wrappedSymkey;
|
||||||
|
yield this.put(self.cb, keys);
|
||||||
|
},
|
||||||
|
initialize: function Keychain_initialize(onComplete, identity) {
|
||||||
|
this._initialize.async(this, onComplete, identity);
|
||||||
|
},
|
||||||
_getKeyAndIV: function Keychain__getKeyAndIV(identity) {
|
_getKeyAndIV: function Keychain__getKeyAndIV(identity) {
|
||||||
let self = yield;
|
let self = yield;
|
||||||
|
|
||||||
this._os.notifyObservers(null, "weave:service:sync:status", "status.downloading-keyring");
|
this._os.notifyObservers(null, "weave:service:sync:status", "status.downloading-keyring");
|
||||||
this.get(self.cb);
|
|
||||||
yield;
|
yield this.get(self.cb);
|
||||||
|
|
||||||
if (!this.data || !this.data.ring || !this.data.ring[identity.username])
|
if (!this.data || !this.data.ring || !this.data.ring[identity.username])
|
||||||
throw "Keyring does not contain a key for this user";
|
throw "Keyring does not contain a key for this user";
|
||||||
|
|
||||||
|
@ -415,7 +438,7 @@ RemoteStore.prototype = {
|
||||||
},
|
},
|
||||||
|
|
||||||
get keys() {
|
get keys() {
|
||||||
let keys = new Keychain(this.serverPrefix);
|
let keys = new Keychain(this.serverPrefix, this.engineId);
|
||||||
this.__defineGetter__("keys", function() keys);
|
this.__defineGetter__("keys", function() keys);
|
||||||
return keys;
|
return keys;
|
||||||
},
|
},
|
||||||
|
@ -481,26 +504,8 @@ RemoteStore.prototype = {
|
||||||
// FIXME: add 'metadata' arg here like appendDelta's
|
// FIXME: add 'metadata' arg here like appendDelta's
|
||||||
_initialize: function RStore__initialize(snapshot) {
|
_initialize: function RStore__initialize(snapshot) {
|
||||||
let self = yield;
|
let self = yield;
|
||||||
let wrappedSymkey;
|
|
||||||
|
|
||||||
if ("none" != Utils.prefs.getCharPref("encryption")) {
|
|
||||||
this._os.notifyObservers(null, "weave:service:sync:status", "status.generating-random-key");
|
|
||||||
|
|
||||||
Crypto.randomKeyGen.async(Crypto, self.cb, this.engineId);
|
|
||||||
yield;
|
|
||||||
|
|
||||||
// Wrap (encrypt) this key with the user's public key.
|
|
||||||
let idRSA = ID.get('WeaveCryptoID');
|
|
||||||
this._os.notifyObservers(null, "weave:service:sync:status", "status.encrypting-key");
|
|
||||||
wrappedSymkey = yield Crypto.wrapKey.async(Crypto, self.cb,
|
|
||||||
this.engineId.bulkKey, idRSA);
|
|
||||||
}
|
|
||||||
|
|
||||||
let keys = {ring: {}, bulkIV: this.engineId.bulkIV};
|
|
||||||
this._os.notifyObservers(null, "weave:service:sync:status", "status.uploading-key");
|
|
||||||
keys.ring[this.engineId.username] = wrappedSymkey;
|
|
||||||
yield this.keys.put(self.cb, keys);
|
|
||||||
|
|
||||||
|
yield this.keys.initialize(self.cb, this.engineId);
|
||||||
this._os.notifyObservers(null, "weave:service:sync:status", "status.uploading-snapshot");
|
this._os.notifyObservers(null, "weave:service:sync:status", "status.uploading-snapshot");
|
||||||
yield this._snapshot.put(self.cb, snapshot.data);
|
yield this._snapshot.put(self.cb, snapshot.data);
|
||||||
//yield this._deltas.put(self.cb, []);
|
//yield this._deltas.put(self.cb, []);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче