michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: Cu.import("resource://services-sync/constants.js"); michael@0: Cu.import("resource://services-sync/service.js"); michael@0: Cu.import("resource://services-sync/util.js"); michael@0: Cu.import("resource://testing-common/services/sync/utils.js"); michael@0: michael@0: // Test upgrade of a dashed old-style sync key. michael@0: function run_test() { michael@0: const PBKDF2_KEY_BYTES = 16; michael@0: initTestLogging("Trace"); michael@0: ensureLegacyIdentityManager(); michael@0: michael@0: let passphrase = "abcde-abcde-abcde-abcde"; michael@0: do_check_false(Utils.isPassphrase(passphrase)); michael@0: michael@0: let normalized = Utils.normalizePassphrase(passphrase); michael@0: _("Normalized: " + normalized); michael@0: michael@0: // Still not a modern passphrase... michael@0: do_check_false(Utils.isPassphrase(normalized)); michael@0: michael@0: // ... but different. michael@0: do_check_neq(normalized, passphrase); michael@0: do_check_eq(normalized, "abcdeabcdeabcdeabcde"); michael@0: michael@0: // Now run through the upgrade. michael@0: Service.identity.account = "johndoe"; michael@0: Service.syncID = "1234567890"; michael@0: Service.identity.syncKey = normalized; // UI normalizes. michael@0: do_check_false(Utils.isPassphrase(Service.identity.syncKey)); michael@0: Service.upgradeSyncKey(Service.syncID); michael@0: let upgraded = Service.identity.syncKey; michael@0: _("Upgraded: " + upgraded); michael@0: do_check_true(Utils.isPassphrase(upgraded)); michael@0: michael@0: // Now let's verify that it's been derived correctly, from the normalized michael@0: // version, and the encoded sync ID. michael@0: _("Sync ID: " + Service.syncID); michael@0: let derivedKeyStr = michael@0: Utils.derivePresentableKeyFromPassphrase(normalized, michael@0: btoa(Service.syncID), michael@0: PBKDF2_KEY_BYTES, true); michael@0: _("Derived: " + derivedKeyStr); michael@0: michael@0: // Success! michael@0: do_check_eq(derivedKeyStr, upgraded); michael@0: }