зеркало из https://github.com/mozilla/gecko-dev.git
Bug 627097: Audit usage of js-ctypes in Sync/WeaveCrypto. r=philiKON
This commit is contained in:
Родитель
8f4afe2745
Коммит
74df0a04ca
|
@ -8,6 +8,21 @@ try {
|
|||
.getService(Ci.IWeaveCrypto);
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
|
||||
if ("makeSECItem" in cryptoSvc) // Only for js-ctypes WeaveCrypto.
|
||||
test_makeSECItem();
|
||||
|
||||
if (this.gczeal) {
|
||||
_("Running crypto tests with gczeal(2).");
|
||||
gczeal(2);
|
||||
}
|
||||
test_bug_617650();
|
||||
test_encrypt_decrypt();
|
||||
if (this.gczeal)
|
||||
gczeal(0);
|
||||
}
|
||||
|
||||
function multiple_decrypts(iterations) {
|
||||
let iv = cryptoSvc.generateRandomIV();
|
||||
let key = cryptoSvc.generateRandomKey();
|
||||
|
@ -45,12 +60,7 @@ function test_makeSECItem() {
|
|||
do_check_eq(intData[i], "abcdefghi".charCodeAt(i));
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
|
||||
if ("makeSECItem" in cryptoSvc) // Only for js-ctypes WeaveCrypto.
|
||||
test_makeSECItem();
|
||||
|
||||
test_bug_617650();
|
||||
function test_encrypt_decrypt() {
|
||||
|
||||
// First, do a normal run with expected usage... Generate a random key and
|
||||
// iv, encrypt and decrypt a string.
|
||||
|
|
|
@ -9,6 +9,11 @@ try {
|
|||
}
|
||||
|
||||
function run_test() {
|
||||
if (this.gczeal) {
|
||||
_("Running crypto random tests with gczeal(2).");
|
||||
gczeal(2);
|
||||
}
|
||||
|
||||
// Test salt generation.
|
||||
var salt;
|
||||
|
||||
|
@ -69,4 +74,7 @@ function run_test() {
|
|||
do_check_neq(keydata, keydata2); // sanity check for randomness
|
||||
iv = cryptoSvc.generateRandomIV();
|
||||
do_check_eq(iv.length, 24);
|
||||
|
||||
if (this.gczeal)
|
||||
gczeal(0);
|
||||
}
|
||||
|
|
|
@ -11,6 +11,13 @@ try {
|
|||
Cu.import("resource://services-sync/util.js");
|
||||
|
||||
function run_test() {
|
||||
if (this.gczeal) {
|
||||
_("Running deriveKey tests with gczeal(2).");
|
||||
gczeal(2);
|
||||
} else {
|
||||
_("Running deriveKey tests with default gczeal.");
|
||||
}
|
||||
|
||||
var iv = cryptoSvc.generateRandomIV();
|
||||
var der_passphrase = "secret phrase";
|
||||
var der_salt = "RE5YUHpQcGl3bg=="; // btoa("DNXPzPpiwn")
|
||||
|
@ -37,12 +44,6 @@ function run_test() {
|
|||
_("Derived key in base64: " + der_key);
|
||||
do_check_eq(cryptoSvc.decrypt(cryptoSvc.encrypt("bacon", der_key, iv), der_key, iv), "bacon");
|
||||
|
||||
// Test the equivalence of our NSS and JS versions.
|
||||
// Will only work on FF4, of course.
|
||||
do_check_eq(
|
||||
Utils.deriveEncodedKeyFromPassphrase(der_passphrase, der_salt, 16, false),
|
||||
Utils.deriveEncodedKeyFromPassphrase(der_passphrase, der_salt, 16, true));
|
||||
|
||||
// Base64, 16-byte output.
|
||||
var der_key = Utils.deriveEncodedKeyFromPassphrase(der_passphrase, der_salt, 16);
|
||||
_("Derived key in base64: " + der_key);
|
||||
|
@ -58,4 +59,15 @@ function run_test() {
|
|||
do_check_eq(b32key.length, 26);
|
||||
do_check_eq(hyphenated.length, 31); // 1 char, plus 5 groups of 5, hyphenated = 5 + (5*5) + 1 = 31.
|
||||
do_check_eq(hyphenated, "9-5wmnu-95tqc-78z2h-amkbw-izqzi");
|
||||
|
||||
if (this.gczeal)
|
||||
gczeal(0);
|
||||
|
||||
// Test the equivalence of our NSS and JS versions.
|
||||
// Will only work on FF4, of course.
|
||||
// Note that we don't add gczeal here: the pure-JS implementation is
|
||||
// astonishingly slow, and this check takes five minutes to run.
|
||||
do_check_eq(
|
||||
Utils.deriveEncodedKeyFromPassphrase(der_passphrase, der_salt, 16, false),
|
||||
Utils.deriveEncodedKeyFromPassphrase(der_passphrase, der_salt, 16, true));
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче