mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
make sure records always have a data field that represents their state (e.g. for serialization); add some pki routines (createKeypair); add incoming/outgoing queue to NewEngine
This commit is contained in:
parent
43d4c7b865
commit
7091144051
@ -62,6 +62,7 @@ CryptoWrapper.prototype = {
|
||||
|
||||
_CryptoWrap_init: function CryptoWrap_init(uri, authenticator) {
|
||||
this._WBORec_init(uri, authenticator);
|
||||
this.data.payload = "";
|
||||
},
|
||||
|
||||
_encrypt: function CryptoWrap__encrypt(passphrase) {
|
||||
@ -114,6 +115,11 @@ CryptoMeta.prototype = {
|
||||
|
||||
_CryptoMeta_init: function CryptoMeta_init(uri, authenticator) {
|
||||
this._WBORec_init(uri, authenticator);
|
||||
this.data.payload = {
|
||||
salt: null,
|
||||
iv: null,
|
||||
keyring: {}
|
||||
};
|
||||
},
|
||||
|
||||
get salt() this.data.payload.salt,
|
||||
@ -138,7 +144,7 @@ CryptoMeta.prototype = {
|
||||
wrappedKey = this.data.payload.keyring[relUri];
|
||||
}
|
||||
if (!wrappedKey)
|
||||
throw "keyring doesn't contain a key for " + pubKeyUrl;
|
||||
throw "keyring doesn't contain a key for " + pubKeyUri;
|
||||
|
||||
let crypto = Cc["@labs.mozilla.com/Weave/Crypto;1"].
|
||||
createInstance(Ci.IWeaveCrypto);
|
||||
|
@ -61,26 +61,35 @@ function PubKey(uri, authenticator) {
|
||||
}
|
||||
PubKey.prototype = {
|
||||
__proto__: WBORecord.prototype,
|
||||
_logName: "Record.PubKey",
|
||||
|
||||
_PubKey_init: function PubKey_init(uri, authenticator) {
|
||||
this._WBORec_init(uri, authenticator);
|
||||
this.data.payload = {
|
||||
type: "pubkey",
|
||||
key_data: null,
|
||||
private_key: null
|
||||
};
|
||||
},
|
||||
|
||||
get keyData() {
|
||||
if (!this.data)
|
||||
return null;
|
||||
return this.data.payload.key_data;
|
||||
get keyData() this.data.payload.key_data,
|
||||
set keyData(value) {
|
||||
this.data.payload.key_data = value;
|
||||
},
|
||||
get _privateKeyUri() this.data.payload.private_key,
|
||||
set _privateKeyUri(value) {
|
||||
this.data.payload.private_key = value;
|
||||
},
|
||||
|
||||
get privateKeyUri() {
|
||||
if (!this.data)
|
||||
return null;
|
||||
// resolve
|
||||
let uri = this.uri.resolve(this.data.payload.private_key);
|
||||
let uri = this.uri.resolve(this._privateKeyUri);
|
||||
if (uri)
|
||||
return Utils.makeURI(uri);
|
||||
// does not resolve, return raw (this uri type might not be able to resolve)
|
||||
return Utils.makeURI(this.data.payload.private_key);
|
||||
return Utils.makeURI(this._privateKeyUri);
|
||||
}
|
||||
};
|
||||
|
||||
@ -89,15 +98,24 @@ function PrivKey(uri, authenticator) {
|
||||
}
|
||||
PrivKey.prototype = {
|
||||
__proto__: WBORecord.prototype,
|
||||
_logName: "Record.PrivKey",
|
||||
|
||||
_PrivKey_init: function PrivKey_init(uri, authenticator) {
|
||||
this._WBORec_init(uri, authenticator);
|
||||
this.data.payload = {
|
||||
type: "privkey",
|
||||
key_data: null,
|
||||
private_key: null
|
||||
};
|
||||
},
|
||||
|
||||
get keyData() {
|
||||
if (!this.data)
|
||||
return null;
|
||||
return this.data.payload.key_data;
|
||||
get keyData() this.data.payload.key_data,
|
||||
set keyData(value) {
|
||||
this.data.payload.key_data = value;
|
||||
},
|
||||
get _publicKeyUri() this.payload.public_key,
|
||||
set _publicKeyUri(value) {
|
||||
this.data.payload.public_key = value;
|
||||
},
|
||||
|
||||
get privateKeyUri() {
|
||||
@ -108,14 +126,15 @@ PrivKey.prototype = {
|
||||
if (!this.data)
|
||||
return null;
|
||||
// resolve
|
||||
let uri = this.uri.resolve(this.data.payload.public_key);
|
||||
let uri = this.uri.resolve(this._publicKeyUri);
|
||||
if (uri)
|
||||
return Utils.makeURI(uri);
|
||||
// does not resolve, return raw (this uri type might not be able to resolve)
|
||||
return Utils.makeURI(this.data.payload.public_key);
|
||||
return Utils.makeURI(this._publicKeyUri);
|
||||
}
|
||||
};
|
||||
|
||||
// XXX unused/unfinished
|
||||
function SymKey(keyData, wrapped) {
|
||||
this._init(keyData, wrapped);
|
||||
}
|
||||
@ -147,7 +166,7 @@ PubKeyManager.prototype = {
|
||||
_keyType: PubKey,
|
||||
_logName: "PubKeyManager",
|
||||
|
||||
get defaultKeyUri() this._defaultKeyUrl,
|
||||
get defaultKeyUri() this._defaultKeyUri,
|
||||
set defaultKeyUri(value) { this._defaultKeyUri = value; },
|
||||
|
||||
_getDefaultKey: function KeyMgr__getDefaultKey() {
|
||||
@ -159,6 +178,18 @@ PubKeyManager.prototype = {
|
||||
return this._getDefaultKey.async(this, onComplete);
|
||||
},
|
||||
|
||||
createKeypair: function KeyMgr_createKeypair() {
|
||||
let pubOut = {}, privOut = {};
|
||||
let cryptoSvc = Cc["@labs.mozilla.com/Weave/Crypto;1"].
|
||||
getService(Ci.IWeaveCrypto);
|
||||
cryptoSvc.generateKeypair("my passphrase", salt, iv, pubOut, privOut);
|
||||
let pubkey = new PubKey();
|
||||
let privkey = new PrivKey();
|
||||
pubkey.keyData = pubOut.value;
|
||||
privkey.keyData = privOut.value;
|
||||
return {pubkey: pubkey, privkey: privkey};
|
||||
},
|
||||
|
||||
_init: function KeyMgr__init() {
|
||||
this._log = Log4Moz.repository.getLogger(this._logName);
|
||||
this._keys = {};
|
||||
@ -167,21 +198,18 @@ PubKeyManager.prototype = {
|
||||
|
||||
_import: function KeyMgr__import(url) {
|
||||
let self = yield;
|
||||
let ret = null;
|
||||
|
||||
this._log.trace("Importing key: " + (url.spec? url.spec : url));
|
||||
|
||||
try {
|
||||
let key = new this._keyType(url);
|
||||
let foo = yield key.get(self.cb);
|
||||
yield key.get(self.cb);
|
||||
this.set(url, key);
|
||||
ret = key;
|
||||
self.done(key);
|
||||
} catch (e) {
|
||||
this._log.debug("Failed to import key: " + e);
|
||||
// don't do anything else, we'll just return null
|
||||
self.done(null);
|
||||
}
|
||||
|
||||
self.done(ret);
|
||||
},
|
||||
import: function KeyMgr_import(onComplete, url) {
|
||||
this._import.async(this, onComplete, url);
|
||||
|
@ -57,5 +57,19 @@ WBORecord.prototype = {
|
||||
_WBORec_init: function WBORec_init(uri, authenticator) {
|
||||
this._init(uri, authenticator);
|
||||
this.pushFilter(new JsonFilter());
|
||||
this.data = {
|
||||
modified: "2454725.98283", // FIXME
|
||||
payload: {}
|
||||
};
|
||||
},
|
||||
|
||||
get modified() this.data.modified,
|
||||
set modified(value) {
|
||||
this.data.modified = value;
|
||||
},
|
||||
|
||||
get payload() this.data.payload,
|
||||
set payload(value) {
|
||||
this.data.payload = value;
|
||||
}
|
||||
};
|
||||
|
@ -11,10 +11,10 @@
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Bookmarks Sync.
|
||||
* The Original Code is Weave.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mozilla.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2007
|
||||
* Portions created by the Initial Developer are Copyright (C) 2008
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
|
@ -246,8 +246,37 @@ function NewEngine() {}
|
||||
NewEngine.prototype = {
|
||||
__proto__: Engine.prototype,
|
||||
|
||||
get lastSync() Utils.prefs.getCharPref(this.name + ".lastSync"),
|
||||
set lastSync(value) {
|
||||
Utils.prefs.setCharPref(this.name + ".lastSync", value);
|
||||
},
|
||||
|
||||
_incoming: null,
|
||||
get incoming() {
|
||||
if (!this._incoming)
|
||||
this._incoming = [];
|
||||
return this._incoming;
|
||||
},
|
||||
|
||||
_outgoing: null,
|
||||
get outgoing() {
|
||||
if (!this._outgoing)
|
||||
this._outgoing = [];
|
||||
return this._outgoing;
|
||||
},
|
||||
|
||||
_sync: function NewEngine__sync() {
|
||||
let self = yield;
|
||||
// find new items from server, place into incoming queue
|
||||
|
||||
// if snapshot-based, generate outgoing queue
|
||||
|
||||
// apply incoming queue one by one
|
||||
|
||||
// upload new/changed items from our outgoing queue
|
||||
foreach (this.outgoing) {
|
||||
// ...
|
||||
}
|
||||
self.done();
|
||||
}
|
||||
};
|
||||
@ -475,7 +504,7 @@ function BlobEngine() {
|
||||
// we don't call it here because it requires serverPrefix to be set
|
||||
}
|
||||
BlobEngine.prototype = {
|
||||
__proto__: new Engine(),
|
||||
__proto__: Engine.prototype,
|
||||
|
||||
get _profileID() {
|
||||
return ClientData.GUID;
|
||||
|
@ -109,42 +109,40 @@ Resource.prototype = {
|
||||
this._uri.spec = value;
|
||||
},
|
||||
|
||||
get data() {
|
||||
return this._data;
|
||||
},
|
||||
_data: null,
|
||||
get data() this._data,
|
||||
set data(value) {
|
||||
this._dirty = true;
|
||||
this._data = value;
|
||||
},
|
||||
|
||||
get lastRequest() { return this._lastRequest; },
|
||||
get downloaded() { return this._downloaded; },
|
||||
get dirty() { return this._dirty; },
|
||||
_lastRequest: null,
|
||||
_downloaded: false,
|
||||
_dirty: false,
|
||||
get lastRequest() this._lastRequest,
|
||||
get downloaded() this._downloaded,
|
||||
get dirty() this._dirty,
|
||||
|
||||
_filters: null,
|
||||
pushFilter: function Res_pushFilter(filter) {
|
||||
if (!this._filters)
|
||||
this._filters = [];
|
||||
this._filters.push(filter);
|
||||
},
|
||||
|
||||
popFilter: function Res_popFilter() {
|
||||
return this._filters.pop();
|
||||
},
|
||||
|
||||
clearFilters: function Res_clearFilters() {
|
||||
this._filters = [];
|
||||
},
|
||||
|
||||
_init: function Res__init(uri, authenticator) {
|
||||
this._log = Log4Moz.repository.getLogger(this._logName);
|
||||
if (typeof uri == 'string')
|
||||
uri = Utils.makeURI(uri);
|
||||
this._uri = uri;
|
||||
this._authenticator = authenticator;
|
||||
this._headers = {'Content-type': 'text/plain'};
|
||||
this._data = null;
|
||||
this._downloaded = false;
|
||||
this._dirty = false;
|
||||
this._filters = [];
|
||||
this._lastRequest = null;
|
||||
this._log = Log4Moz.repository.getLogger(this._logName);
|
||||
},
|
||||
|
||||
_createRequest: function Res__createRequest(op, onRequestFinished) {
|
||||
@ -198,7 +196,7 @@ Resource.prototype = {
|
||||
|
||||
if ("PUT" == action) {
|
||||
for each (let filter in this._filters) {
|
||||
data = yield filter.beforePUT.async(filter, self.cb, data);
|
||||
data = yield filter.beforePUT.async(filter, self.cb, data, this);
|
||||
}
|
||||
}
|
||||
|
||||
@ -224,7 +222,7 @@ Resource.prototype = {
|
||||
this._data = this._lastRequest.responseText;
|
||||
let filters = this._filters.slice(); // reverse() mutates, so we copy
|
||||
for each (let filter in filters.reverse()) {
|
||||
this._data = yield filter.afterGET.async(filter, self.cb, this._data);
|
||||
this._data = yield filter.afterGET.async(filter, self.cb, this._data, this);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -270,7 +268,7 @@ Resource.prototype = {
|
||||
|
||||
|
||||
function JsonFilter() {
|
||||
this._log = Log4Moz.repository.getLogger("Service.JsonFilter");
|
||||
this._log = Log4Moz.repository.getLogger("Net.JsonFilter");
|
||||
}
|
||||
JsonFilter.prototype = {
|
||||
get _json() {
|
||||
|
Loading…
Reference in New Issue
Block a user