mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-28 13:21:28 +00:00
Bug 618335: normalize old-style 20-char sync keys. r=philiKON
This commit is contained in:
parent
b0e9d01a0a
commit
801dd50f93
@ -1310,10 +1310,25 @@ let Utils = {
|
||||
normalizePassphrase: function normalizePassphrase(pp) {
|
||||
// Short var name... have you seen the lines below?!
|
||||
pp = pp.toLowerCase();
|
||||
if (pp.length == 31 && [1, 7, 13, 19, 25].every(function(i) pp[i] == '-'))
|
||||
|
||||
// 20-char sync key.
|
||||
if (pp.length == 23 &&
|
||||
[5, 11, 17].every(function(i) pp[i] == '-')) {
|
||||
|
||||
return pp.slice(0, 5) + pp.slice(6, 11)
|
||||
+ pp.slice(12, 17) + pp.slice(18, 23);
|
||||
}
|
||||
|
||||
// "Modern" 26-char key.
|
||||
if (pp.length == 31 &&
|
||||
[1, 7, 13, 19, 25].every(function(i) pp[i] == '-')) {
|
||||
|
||||
return pp.slice(0, 1) + pp.slice(2, 7)
|
||||
+ pp.slice(8, 13) + pp.slice(14, 19)
|
||||
+ pp.slice(20, 25) + pp.slice(26, 31);
|
||||
}
|
||||
|
||||
// Something else -- just return.
|
||||
return pp;
|
||||
},
|
||||
|
||||
|
43
services/sync/tests/unit/test_upgrade_old_sync_key.js
Normal file
43
services/sync/tests/unit/test_upgrade_old_sync_key.js
Normal file
@ -0,0 +1,43 @@
|
||||
Cu.import("resource://services-sync/constants.js");
|
||||
Cu.import("resource://services-sync/main.js");
|
||||
var btoa = Cu.import("resource://services-sync/util.js").btoa;
|
||||
|
||||
// Test upgrade of a dashed old-style sync key.
|
||||
function run_test() {
|
||||
const PBKDF2_KEY_BYTES = 16;
|
||||
initTestLogging("Trace");
|
||||
|
||||
let passphrase = "abcde-abcde-abcde-abcde";
|
||||
do_check_false(Utils.isPassphrase(passphrase));
|
||||
|
||||
let normalized = Utils.normalizePassphrase(passphrase);
|
||||
_("Normalized: " + normalized);
|
||||
|
||||
// Still not a modern passphrase...
|
||||
do_check_false(Utils.isPassphrase(normalized));
|
||||
|
||||
// ... but different.
|
||||
do_check_neq(normalized, passphrase);
|
||||
do_check_eq(normalized, "abcdeabcdeabcdeabcde");
|
||||
|
||||
// Now run through the upgrade.
|
||||
Weave.Service.syncID = "1234567890";
|
||||
Weave.Service.passphrase = normalized; // UI normalizes.
|
||||
do_check_false(Utils.isPassphrase(Weave.Service.passphrase));
|
||||
Weave.Service.upgradeSyncKey(Weave.Service.syncID);
|
||||
let upgraded = Weave.Service.passphrase;
|
||||
_("Upgraded: " + upgraded);
|
||||
do_check_true(Utils.isPassphrase(upgraded));
|
||||
|
||||
// Now let's verify that it's been derived correctly, from the normalized
|
||||
// version, and the encoded sync ID.
|
||||
_("Sync ID: " + Weave.Service.syncID);
|
||||
let derivedKeyStr =
|
||||
Utils.derivePresentableKeyFromPassphrase(normalized,
|
||||
btoa(Weave.Service.syncID),
|
||||
PBKDF2_KEY_BYTES, true);
|
||||
_("Derived: " + derivedKeyStr);
|
||||
|
||||
// Success!
|
||||
do_check_eq(derivedKeyStr, upgraded);
|
||||
}
|
@ -44,11 +44,15 @@ function run_test() {
|
||||
"a-bcdef-ghijk-mnpab-cdefg-");
|
||||
// Cuts off.
|
||||
do_check_eq(Utils.hyphenatePartialPassphrase("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa").length, 31);
|
||||
|
||||
|
||||
|
||||
_("Normalize passphrase recognizes hyphens.");
|
||||
do_check_eq(Utils.normalizePassphrase(hyphenated), pp);
|
||||
|
||||
_("Normalizing 20-char passphrases.");
|
||||
do_check_eq(Utils.normalizePassphrase("abcde-abcde-abcde-abcde"),
|
||||
"abcdeabcdeabcdeabcde");
|
||||
do_check_eq(Utils.normalizePassphrase("a-bcde-abcde-abcde-abcde"),
|
||||
"a-bcde-abcde-abcde-abcde");
|
||||
|
||||
_("Passphrase strength calculated according to the NIST algorithm.");
|
||||
do_check_eq(Utils.passphraseStrength(""), 0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user