From 13dc29cda6edb1ca3a56fd1902f235fe785804af Mon Sep 17 00:00:00 2001 From: Edward Lee Date: Wed, 2 Dec 2009 17:25:14 -0800 Subject: [PATCH] Bug 531005 - Sync is not working after update IWeaveCrypto.unwrapSymmetricKey NS_ERROR_FAILURE Check that the cryptometa is unwrappable when syncing; if not purge the key and data and make a new crypto record. --- services/sync/modules/engines.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/services/sync/modules/engines.js b/services/sync/modules/engines.js index 0e24e9fc1dc5..d48e975e44a8 100644 --- a/services/sync/modules/engines.js +++ b/services/sync/modules/engines.js @@ -349,7 +349,26 @@ SyncEngine.prototype = { _syncStartup: function SyncEngine__syncStartup() { this._log.debug("Ensuring server crypto records are there"); + // Try getting/unwrapping the crypto record let meta = CryptoMetas.get(this.cryptoMetaURL); + if (meta) { + try { + let pubkey = PubKeys.getDefaultKey(); + let privkey = PrivKeys.get(pubkey.privateKeyUri); + meta.getKey(privkey, ID.get("WeaveCryptoID")); + } + catch(ex) { + // Remove traces of this bad cryptometa + this._log.debug("Purging bad data after failed unwrap crypto: " + ex); + CryptoMetas.del(this.cryptoMetaURL); + meta = null; + + // Remove any potentially tained data + new Resource(this.engineURL).delete(); + } + } + + // Generate a new crypto record if (!meta) { let symkey = Svc.Crypto.generateRandomKey(); let pubkey = PubKeys.getDefaultKey();