Bug 1508825 - Enable ESLint for dom/crypto (manual changes) r=Standard8,Ehsan

Differential Revision: https://phabricator.services.mozilla.com/D13694

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Volodymyr Klymenko ext:(%3E) 2018-12-14 22:54:56 +00:00
parent fbb0aae478
commit 92c4139a6d
17 changed files with 97 additions and 118 deletions

View file

@ -182,7 +182,6 @@ dom/cache/test/mochitest/**
dom/cache/test/xpcshell/** dom/cache/test/xpcshell/**
dom/canvas/** dom/canvas/**
dom/console/** dom/console/**
dom/crypto/**
dom/encoding/** dom/encoding/**
dom/events/** dom/events/**
dom/fetch/** dom/fetch/**

View file

@ -2,6 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// This file expects utils.js to be included in its scope
/* import-globals-from ./util.js */
var MOCHITEST = false; var MOCHITEST = false;
function Test(name, test) { function Test(name, test) {
@ -34,7 +36,9 @@ function Test(name, test) {
}; };
this.complete = function(result) { this.complete = function(result) {
if (MOCHITEST) { ok(result, this.name); } if (MOCHITEST) {
ok(result, this.name);
}
// Note the end time // Note the end time
this.endTime = new Date(); this.endTime = new Date();
@ -60,28 +64,30 @@ function Test(name, test) {
// Print the name of the test // Print the name of the test
if (this.name) { if (this.name) {
this.row[0].innerHTML = this.name; this.row[0].textContent = this.name;
var that = this; var that = this;
this.row[0].onclick = function() { that.run(); }; this.row[0].onclick = function() {
that.run();
};
} else { } else {
this.row[0] = ""; this.row[0] = "";
} }
// Print the result of the test // Print the result of the test
if (this.result == true) { if (this.result === true) {
this.row[1].className = "pass"; this.row[1].className = "pass";
this.row[1].innerHTML = "PASS"; this.row[1].innerHTML = "PASS";
} else if (this.result == false) { } else if (this.result === false) {
this.row[1].className = "fail"; this.row[1].className = "fail";
this.row[1].innerHTML = "FAIL"; this.row[1].innerHTML = "FAIL";
} else { } else {
// this.row[1].innerHTML = ""; // this.row[1].innerHTML = "";
this.row[1].innerHTML = this.result; this.row[1].textContent = this.result;
} }
// Print the elapsed time, if known // Print the elapsed time, if known
if (this.startTime && this.endTime) { if (this.startTime && this.endTime) {
this.row[2].innerHTML = (this.endTime - this.startTime) + " ms"; this.row[2].textContent = (this.endTime - this.startTime) + " ms";
} else { } else {
this.row[2].innerHTML = ""; this.row[2].innerHTML = "";
} }
@ -143,13 +149,13 @@ var TestArray = {
updateSummary() { updateSummary() {
this.pass = this.fail = this.pending = 0; this.pass = this.fail = this.pending = 0;
for (var i = 0; i < this.tests.length; ++i) { for (var i = 0; i < this.tests.length; ++i) {
if (this.tests[i].result == true) this.pass++; if (this.tests[i].result === true) this.pass++;
if (this.tests[i].result == false) this.fail++; if (this.tests[i].result === false) this.fail++;
if (this.tests[i].result == null) this.pending++; if (this.tests[i].result == null) this.pending++;
} }
this.passSpan.innerHTML = this.pass; this.passSpan.textContent = this.pass;
this.failSpan.innerHTML = this.fail; this.failSpan.textContent = this.fail;
this.pendingSpan.innerHTML = this.pending; this.pendingSpan.textContent = this.pending;
}, },
load() { load() {
@ -182,7 +188,9 @@ var TestArray = {
this.updateSummary(); this.updateSummary();
var i = this.currTest++; var i = this.currTest++;
if (i >= this.tests.length) { if (i >= this.tests.length) {
if (MOCHITEST) { SimpleTest.finish(); } if (MOCHITEST) {
SimpleTest.finish();
}
return; return;
} }
@ -195,16 +203,20 @@ var TestArray = {
}; };
if (window.addEventListener) { if (window.addEventListener) {
window.addEventListener("load", function() { TestArray.load(); } ); window.addEventListener("load", function() {
TestArray.load();
});
} else { } else {
window.attachEvent("onload", function() { TestArray.load(); } ); window.attachEvent("onload", function() {
TestArray.load();
});
} }
function start() { function start() {
TestArray.run(); TestArray.run();
} }
MOCHITEST = ("SimpleTest" in window); MOCHITEST = "SimpleTest" in window;
if (MOCHITEST) { if (MOCHITEST) {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
SimpleTest.requestLongerTimeout(2); SimpleTest.requestLongerTimeout(2);

View file

@ -2,7 +2,9 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
tv = { // This file expects utils.js to be included in its scope
/* import-globals-from ./util.js */
let tv = {
raw: util.hex2abv("f3095c4fe5e299477643c2310b44f0aa"), raw: util.hex2abv("f3095c4fe5e299477643c2310b44f0aa"),
// this key had an inappropriate length (18 octets) // this key had an inappropriate length (18 octets)

View file

@ -2,6 +2,10 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* eslint-env worker */
// This file expects utils.js to be included in its scope
/* import-globals-from ./util.js */
importScripts("util.js"); importScripts("util.js");
importScripts("test-vectors.js"); importScripts("test-vectors.js");
@ -34,6 +38,7 @@ function error(test) {
} }
onmessage = function(msg) { onmessage = function(msg) {
// eslint-disable-next-line no-eval
var test = eval("(" + msg.data + ")"); var test = eval("(" + msg.data + ")");
try { try {

View file

@ -26,7 +26,6 @@
TestArray.addTest( TestArray.addTest(
"Test for presence of WebCrypto API methods", "Test for presence of WebCrypto API methods",
function() { function() {
var that = this;
this.complete( this.complete(
exists(window.crypto.subtle) && exists(window.crypto.subtle) &&
exists(window.crypto.subtle.encrypt) && exists(window.crypto.subtle.encrypt) &&
@ -630,11 +629,6 @@ TestArray.addTest(
x, tv.aes_ctr_dec.data); x, tv.aes_ctr_dec.data);
} }
function decrypt(x) {
return decrypt(x, new Uint8Array(15))
.catch(function() { return decrypt(x, new Uint8Array(17)); });
}
crypto.subtle.importKey("raw", tv.aes_ctr_dec.key, "AES-CTR", false, ["decrypt"]) crypto.subtle.importKey("raw", tv.aes_ctr_dec.key, "AES-CTR", false, ["decrypt"])
.then(doDecrypt) .then(doDecrypt)
.then( .then(
@ -1004,7 +998,6 @@ TestArray.addTest(
function() { function() {
var that = this; var that = this;
var alg = { name: "RSASSA-PKCS1-v1_5", hash: "SHA-256" }; var alg = { name: "RSASSA-PKCS1-v1_5", hash: "SHA-256" };
var use = ["sign", "verify"];
function doVerify(x) { function doVerify(x) {
return crypto.subtle.verify(alg.name, x, tv.rsassa.sig_fail, tv.rsassa.data); return crypto.subtle.verify(alg.name, x, tv.rsassa.sig_fail, tv.rsassa.data);
@ -1103,7 +1096,7 @@ TestArray.addTest(
error(that)(); error(that)();
} }
Promise.all([p1, p2, p3]).then(complete(that, keys => { return Promise.all([p1, p2, p3]).then(complete(that, keys => {
return keys.every(key => { return keys.every(key => {
if (key instanceof CryptoKey) { if (key instanceof CryptoKey) {
return checkPrototypes(key, "CryptoKey"); return checkPrototypes(key, "CryptoKey");

View file

@ -21,7 +21,6 @@
<script>/* <![CDATA[*/ <script>/* <![CDATA[*/
"use strict"; "use strict";
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
TestArray.addTest( TestArray.addTest(
"Generate a DH key", "Generate a DH key",
@ -68,11 +67,7 @@ TestArray.addTest(
}; };
function doDerive(x) { function doDerive(x) {
var alg = { return crypto.subtle.deriveBits({ name: "DH", public: x.publicKey }, x.privateKey, 128);
name: "DH",
public: x.publicKey,
};
return crypto.subtle.deriveBits(alg, x.privateKey, 128);
} }
crypto.subtle.generateKey(alg, false, ["deriveBits"]) crypto.subtle.generateKey(alg, false, ["deriveBits"])
@ -218,8 +213,7 @@ TestArray.addTest(
} }
function doDerive(pubKey) { function doDerive(pubKey) {
var alg = {name: "DH", public: pubKey}; return crypto.subtle.deriveBits({name: "DH", public: pubKey}, privKey, 128);
return crypto.subtle.deriveBits(alg, privKey, 128);
} }
crypto.subtle.generateKey(alg, false, ["deriveBits"]) crypto.subtle.generateKey(alg, false, ["deriveBits"])

View file

@ -62,8 +62,7 @@ TestArray.addTest(
function doDerive(n) { function doDerive(n) {
return function(x) { return function(x) {
var alg = { name: "ECDH", public: pair.publicKey }; return crypto.subtle.deriveBits({ name: "ECDH", public: pair.publicKey }, pair.privateKey, n * 8);
return crypto.subtle.deriveBits(alg, pair.privateKey, n * 8);
}; };
} }
@ -165,8 +164,7 @@ TestArray.addTest(
function setPriv(x) { privKey = x; } function setPriv(x) { privKey = x; }
function doDerive() { function doDerive() {
var alg = { name: "ECDH", public: pubKey }; return crypto.subtle.deriveBits({ name: "ECDH", public: pubKey }, privKey, tv.ecdh_p256.secret.byteLength * 8);
return crypto.subtle.deriveBits(alg, privKey, tv.ecdh_p256.secret.byteLength * 8);
} }
Promise.all([ Promise.all([
@ -191,8 +189,7 @@ TestArray.addTest(
function setPriv(x) { privKey = x; } function setPriv(x) { privKey = x; }
function doDerive() { function doDerive() {
var alg = { name: "ECDH", public: pubKey }; return crypto.subtle.deriveBits({ name: "ECDH", public: pubKey }, privKey, tv.ecdh_p384.secret.byteLength * 8);
return crypto.subtle.deriveBits(alg, privKey, tv.ecdh_p384.secret.byteLength * 8);
} }
Promise.all([ Promise.all([
@ -217,8 +214,7 @@ TestArray.addTest(
function setPriv(x) { privKey = x; } function setPriv(x) { privKey = x; }
function doDerive() { function doDerive() {
var alg = { name: "ECDH", public: pubKey }; return crypto.subtle.deriveBits({ name: "ECDH", public: pubKey }, privKey, tv.ecdh_p521.secret.byteLength * 8);
return crypto.subtle.deriveBits(alg, privKey, tv.ecdh_p521.secret.byteLength * 8);
} }
Promise.all([ Promise.all([
@ -342,8 +338,7 @@ TestArray.addTest(
function setPriv(x) { privKey = x; } function setPriv(x) { privKey = x; }
function doDerive() { function doDerive() {
var alg = { name: "ECDH", public: pubKey }; return crypto.subtle.deriveKey({ name: "ECDH", public: pubKey }, privKey, algDerived, false, ["sign", "verify"])
return crypto.subtle.deriveKey(alg, privKey, algDerived, false, ["sign", "verify"])
.then(function(x) { .then(function(x) {
if (!hasKeyFields(x)) { if (!hasKeyFields(x)) {
throw "Invalid key; missing field(s)"; throw "Invalid key; missing field(s)";
@ -406,6 +401,7 @@ TestArray.addTest(
if (keys.length) { if (keys.length) {
return nextKey(); return nextKey();
} }
return Promise.resolve();
}); });
} }
@ -425,8 +421,7 @@ TestArray.addTest(
function setPriv(x) { privKey = x; } function setPriv(x) { privKey = x; }
function doDerive() { function doDerive() {
var alg = { name: "ECDH", public: pubKey }; return crypto.subtle.deriveBits({ name: "ECDH", public: pubKey }, privKey, tv.ecdh_p256.secret.byteLength * 8);
return crypto.subtle.deriveBits(alg, privKey, tv.ecdh_p256.secret.byteLength * 8);
} }
Promise.all([ Promise.all([
@ -462,7 +457,6 @@ TestArray.addTest(
function() { function() {
var that = this; var that = this;
var alg = { name: "ECDH", namedCurve: "P-256" }; var alg = { name: "ECDH", namedCurve: "P-256" };
var tvs = tv.ecdh_p256_negative.raw_bad;
crypto.subtle.importKey("raw", tv, alg, false, ["deriveBits"]) crypto.subtle.importKey("raw", tv, alg, false, ["deriveBits"])
.then(error(that), complete(that)); .then(error(that), complete(that));
@ -475,7 +469,6 @@ TestArray.addTest(
function() { function() {
var that = this; var that = this;
var alg = { name: "ECDH", namedCurve: "P-256" }; var alg = { name: "ECDH", namedCurve: "P-256" };
var tvs = tv.ecdh_p256.raw;
crypto.subtle.importKey("unknown", tv, alg, false, ["deriveBits"]) crypto.subtle.importKey("unknown", tv, alg, false, ["deriveBits"])
.then(error(that), complete(that)); .then(error(that), complete(that));
@ -488,7 +481,6 @@ TestArray.addTest(
function() { function() {
var that = this; var that = this;
var alg = { name: "ECDH", namedCurve: "P-256" }; var alg = { name: "ECDH", namedCurve: "P-256" };
var tvs = tv.ecdh_p256_negative.raw_short;
crypto.subtle.importKey("raw", tv, alg, false, ["deriveBits"]) crypto.subtle.importKey("raw", tv, alg, false, ["deriveBits"])
.then(error(that), complete(that)); .then(error(that), complete(that));
@ -501,7 +493,6 @@ TestArray.addTest(
function() { function() {
var that = this; var that = this;
var alg = { name: "ECDH", namedCurve: "P-256" }; var alg = { name: "ECDH", namedCurve: "P-256" };
var tvs = tv.ecdh_p256_negative.raw_long;
crypto.subtle.importKey("raw", tv, alg, false, ["deriveBits"]) crypto.subtle.importKey("raw", tv, alg, false, ["deriveBits"])
.then(error(that), complete(that)); .then(error(that), complete(that));
@ -514,7 +505,6 @@ TestArray.addTest(
function() { function() {
var that = this; var that = this;
var alg = { name: "ECDH", namedCurve: "P-256" }; var alg = { name: "ECDH", namedCurve: "P-256" };
var tvs = tv.ecdh_p256_negative.raw_compressed;
crypto.subtle.importKey("raw", tv, alg, false, ["deriveBits"]) crypto.subtle.importKey("raw", tv, alg, false, ["deriveBits"])
.then(error(that), complete(that)); .then(error(that), complete(that));
@ -533,8 +523,7 @@ TestArray.addTest(
function setPriv(x) { privKey = x; } function setPriv(x) { privKey = x; }
function doDerive() { function doDerive() {
var alg = { name: "ECDH", public: pubKey }; return crypto.subtle.deriveBits({ name: "ECDH", public: pubKey }, privKey, tv.ecdh_p256.secret.byteLength * 8);
return crypto.subtle.deriveBits(alg, privKey, tv.ecdh_p256.secret.byteLength * 8);
} }
Promise.all([ Promise.all([

View file

@ -135,10 +135,6 @@ TestArray.addTest(
var that = this; var that = this;
var alg = { name: "ECDSA", namedCurve: "P-256", hash: "SHA-256" }; var alg = { name: "ECDSA", namedCurve: "P-256", hash: "SHA-256" };
function doVerify(x) {
return crypto.subtle.verify(alg, x, tv.ecdsa_verify.sig, tv.ecdsa_verify.data);
}
crypto.subtle.importKey("jwk", tv.ecdsa_bad.pub_jwk, alg, true, ["verify"]) crypto.subtle.importKey("jwk", tv.ecdsa_bad.pub_jwk, alg, true, ["verify"])
.then(error(that), complete(that)); .then(error(that), complete(that));
} }

View file

@ -146,23 +146,27 @@ TestArray.addTest(
function() { function() {
var that = this; var that = this;
var tests = tv.hkdf.slice(); var tests = tv.hkdf.slice();
if (!tests.length) {
error(that)("No tests found");
return;
}
function next() { function next() {
if (!tests.length) { if (!tests.length) {
return; return Promise.resolve();
} }
var test = tests.shift(); var test = tests.shift();
var {key, data} = test; var {key} = test;
return crypto.subtle.importKey("raw", key, "HKDF", false, ["deriveBits"]) return crypto.subtle.importKey("raw", key, "HKDF", false, ["deriveBits"])
.then(function(key) { .then(function(baseKey) {
return crypto.subtle.deriveBits({ return crypto.subtle.deriveBits({
name: "HKDF", name: "HKDF",
hash: test.prf, hash: test.prf,
salt: test.salt, salt: test.salt,
info: test.info, info: test.info,
}, key, test.data.byteLength * 8); }, baseKey, test.data.byteLength * 8);
}) })
.then(function(data) { .then(function(data) {
if (!util.memcmp(data, test.data)) { if (!util.memcmp(data, test.data)) {

View file

@ -29,23 +29,21 @@ TestArray.addTest(
var alg = { name: "hmac", hash: {name: "sHa-256"} }; var alg = { name: "hmac", hash: {name: "sHa-256"} };
function doGenerateAesKey() { function doGenerateAesKey() {
var alg = { name: "AES-gcm", length: 192 }; return crypto.subtle.generateKey({ name: "AES-gcm", length: 192 }, false, ["encrypt"]);
return crypto.subtle.generateKey(alg, false, ["encrypt"]);
} }
function doGenerateRsaOaepKey() { function doGenerateRsaOaepKey() {
var alg = { var algo = {
name: "rsa-OAEP", name: "rsa-OAEP",
hash: "sha-1", hash: "sha-1",
modulusLength: 2048, modulusLength: 2048,
publicExponent: new Uint8Array([0x01, 0x00, 0x01]), publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
}; };
return crypto.subtle.generateKey(alg, false, ["encrypt", "decrypt"]); return crypto.subtle.generateKey(algo, false, ["encrypt", "decrypt"]);
} }
function doGenerateRsaSsaPkcs1Key() { function doGenerateRsaSsaPkcs1Key() {
var alg = { name: "RSASSA-pkcs1-V1_5", hash: "SHA-1" }; return crypto.subtle.importKey("pkcs8", tv.pkcs8, { name: "RSASSA-pkcs1-V1_5", hash: "SHA-1" }, true, ["sign"]);
return crypto.subtle.importKey("pkcs8", tv.pkcs8, alg, true, ["sign"]);
} }
crypto.subtle.generateKey(alg, false, ["sign"]) crypto.subtle.generateKey(alg, false, ["sign"])

View file

@ -76,13 +76,13 @@ TestArray.addTest(
throw "Invalid key; missing field(s)"; throw "Invalid key; missing field(s)";
} }
var alg = { var algo = {
name: "PBKDF2", name: "PBKDF2",
hash: "SHA-1", hash: "SHA-1",
salt: tv.pbkdf2_sha1.salt, salt: tv.pbkdf2_sha1.salt,
iterations: tv.pbkdf2_sha1.iterations, iterations: tv.pbkdf2_sha1.iterations,
}; };
return crypto.subtle.deriveBits(alg, x, tv.pbkdf2_sha1.length); return crypto.subtle.deriveBits(algo, x, tv.pbkdf2_sha1.length);
} }
function fail(x) { console.log("failing"); error(that)(x); } function fail(x) { console.log("failing"); error(that)(x); }
@ -104,13 +104,13 @@ TestArray.addTest(
throw "Invalid key; missing field(s)"; throw "Invalid key; missing field(s)";
} }
var alg = { var algo = {
name: "PBKDF2", name: "PBKDF2",
hash: "SHA-1", hash: "SHA-1",
salt: tv.pbkdf2_sha1.salt, salt: tv.pbkdf2_sha1.salt,
iterations: tv.pbkdf2_sha1.iterations, iterations: tv.pbkdf2_sha1.iterations,
}; };
return crypto.subtle.deriveBits(alg, x, tv.pbkdf2_sha1.length); return crypto.subtle.deriveBits(algo, x, tv.pbkdf2_sha1.length);
} }
function fail(x) { console.log("failing"); error(that)(x); } function fail(x) { console.log("failing"); error(that)(x); }
@ -133,7 +133,7 @@ TestArray.addTest(
throw "Invalid key; missing field(s)"; throw "Invalid key; missing field(s)";
} }
var alg = { var algo = {
name: "PBKDF2", name: "PBKDF2",
hash: "SHA-1", hash: "SHA-1",
salt: tv.pbkdf2_sha1.salt, salt: tv.pbkdf2_sha1.salt,
@ -145,17 +145,17 @@ TestArray.addTest(
hash: {name: "SHA-1"}, hash: {name: "SHA-1"},
}; };
return crypto.subtle.deriveKey(alg, x, algDerived, false, ["sign", "verify"]) return crypto.subtle.deriveKey(algo, x, algDerived, false, ["sign", "verify"])
.then(function(x) { .then(function(y) {
if (!hasKeyFields(x)) { if (!hasKeyFields(y)) {
throw "Invalid key; missing field(s)"; throw "Invalid key; missing field(s)";
} }
if (x.algorithm.length != 512) { if (y.algorithm.length != 512) {
throw "Invalid key; incorrect length"; throw "Invalid key; incorrect length";
} }
return x; return y;
}); });
} }
@ -217,13 +217,13 @@ TestArray.addTest(
throw "Invalid key; missing field(s)"; throw "Invalid key; missing field(s)";
} }
var alg = { var algo = {
name: "PBKDF2", name: "PBKDF2",
hash: "SHA-256", hash: "SHA-256",
salt: tv.pbkdf2_sha256.salt, salt: tv.pbkdf2_sha256.salt,
iterations: tv.pbkdf2_sha256.iterations, iterations: tv.pbkdf2_sha256.iterations,
}; };
return crypto.subtle.deriveBits(alg, x, tv.pbkdf2_sha256.length); return crypto.subtle.deriveBits(algo, x, tv.pbkdf2_sha256.length);
} }
function fail(x) { console.log("failing"); error(that)(x); } function fail(x) { console.log("failing"); error(that)(x); }
@ -246,13 +246,13 @@ TestArray.addTest(
throw "Invalid key; missing field(s)"; throw "Invalid key; missing field(s)";
} }
var alg = { var algo = {
name: "PBKDF2", name: "PBKDF2",
hash: "SHA-256", hash: "SHA-256",
salt: tv.pbkdf2_sha256_no_pwd.salt, salt: tv.pbkdf2_sha256_no_pwd.salt,
iterations: tv.pbkdf2_sha256_no_pwd.iterations, iterations: tv.pbkdf2_sha256_no_pwd.iterations,
}; };
return crypto.subtle.deriveBits(alg, x, tv.pbkdf2_sha256_no_pwd.length); return crypto.subtle.deriveBits(algo, x, tv.pbkdf2_sha256_no_pwd.length);
} }
function fail(x) { console.log("failing"); error(that)(x); } function fail(x) { console.log("failing"); error(that)(x); }

View file

@ -33,7 +33,6 @@ TestArray.addTest(
var privKey, pubKey; var privKey, pubKey;
var alg = {name: "RSA-OAEP", hash: "SHA-1"}; var alg = {name: "RSA-OAEP", hash: "SHA-1"};
var privKey, pubKey;
function setPriv(x) { privKey = x; } function setPriv(x) { privKey = x; }
function setPub(x) { pubKey = x; } function setPub(x) { pubKey = x; }
function doEncrypt() { function doEncrypt() {
@ -112,7 +111,7 @@ TestArray.addTest(
"RSA-OAEP input data length checks (2048-bit key)", "RSA-OAEP input data length checks (2048-bit key)",
function() { function() {
var that = this; var that = this;
var privKey, pubKey; var pubKey;
var alg = { var alg = {
name: "RSA-OAEP", name: "RSA-OAEP",
hash: "SHA-1", hash: "SHA-1",
@ -120,8 +119,7 @@ TestArray.addTest(
publicExponent: new Uint8Array([0x01, 0x00, 0x01]), publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
}; };
var privKey, pubKey; function setKey(x) { pubKey = x.publicKey; }
function setKey(x) { pubKey = x.publicKey; privKey = x.privateKey; }
function doEncrypt(n) { function doEncrypt(n) {
console.log("entered encrypt(" + n + ")"); console.log("entered encrypt(" + n + ")");
return function() { return function() {

View file

@ -58,12 +58,10 @@ TestArray.addTest(
var data = crypto.getRandomValues(new Uint8Array(128)); var data = crypto.getRandomValues(new Uint8Array(128));
function setKey(x) { pubKey = x.publicKey; privKey = x.privateKey; } function setKey(x) { pubKey = x.publicKey; privKey = x.privateKey; }
function doSign() { function doSign() {
var alg = {name: "RSA-PSS", saltLength: 32}; return crypto.subtle.sign({name: "RSA-PSS", saltLength: 32}, privKey, data);
return crypto.subtle.sign(alg, privKey, data);
} }
function doVerify(x) { function doVerify(x) {
var alg = {name: "RSA-PSS", saltLength: 32}; return crypto.subtle.verify({name: "RSA-PSS", saltLength: 32}, pubKey, x, data);
return crypto.subtle.verify(alg, pubKey, x, data);
} }
crypto.subtle.generateKey(alg, false, ["sign", "verify"]) crypto.subtle.generateKey(alg, false, ["sign", "verify"])
@ -83,8 +81,7 @@ TestArray.addTest(
var vec = tv.rsapss; var vec = tv.rsapss;
function doVerify(x) { function doVerify(x) {
var alg = {name: "RSA-PSS", saltLength: vec.saltLength}; return crypto.subtle.verify({name: "RSA-PSS", saltLength: vec.saltLength}, x, vec.sig, vec.data);
return crypto.subtle.verify(alg, x, vec.sig, vec.data);
} }
crypto.subtle.importKey("spki", vec.spki, alg, false, ["verify"]) crypto.subtle.importKey("spki", vec.spki, alg, false, ["verify"])
@ -102,17 +99,17 @@ TestArray.addTest(
var vec = tv.rsapss; var vec = tv.rsapss;
function doVerify(x) { function doVerify(x) {
var alg = {name: "RSA-PSS", saltLength: vec.saltLength}; var algo = {name: "RSA-PSS", saltLength: vec.saltLength};
var clone1 = new Uint8Array(vec.data); var clone1 = new Uint8Array(vec.data);
var clone2 = new Uint8Array(vec.data); var clone2 = new Uint8Array(vec.data);
clone1[clone1.byteLength - 1] ^= 1; clone1[clone1.byteLength - 1] ^= 1;
clone2[0] ^= 1; clone2[0] ^= 1;
return Promise.all([ return Promise.all([
crypto.subtle.verify(alg, x, vec.sig, clone1), crypto.subtle.verify(algo, x, vec.sig, clone1),
crypto.subtle.verify(alg, x, vec.sig, clone2), crypto.subtle.verify(algo, x, vec.sig, clone2),
crypto.subtle.verify(alg, x, vec.sig, vec.data.slice(1)), crypto.subtle.verify(algo, x, vec.sig, vec.data.slice(1)),
crypto.subtle.verify(alg, x, vec.sig, vec.data.slice(0, vec.data.byteLength - 1)), crypto.subtle.verify(algo, x, vec.sig, vec.data.slice(0, vec.data.byteLength - 1)),
]); ]);
} }
@ -131,8 +128,7 @@ TestArray.addTest(
var alg = {name: "RSA-PSS", hash: "SHA-1"}; var alg = {name: "RSA-PSS", hash: "SHA-1"};
function doVerify(x) { function doVerify(x) {
var alg = {name: "RSA-PSS", saltLength: tv.rsapss.saltLength}; return crypto.subtle.verify({name: "RSA-PSS", saltLength: tv.rsapss.saltLength}, x, tv.rsapss.sig, tv.rsapss.data);
return crypto.subtle.verify(alg, x, tv.rsapss.sig, tv.rsapss.data);
} }
crypto.subtle.importKey("jwk", tv.rsapss.jwk_pub, alg, false, ["verify"]) crypto.subtle.importKey("jwk", tv.rsapss.jwk_pub, alg, false, ["verify"])
@ -172,12 +168,10 @@ TestArray.addTest(
var privKey, pubKey; var privKey, pubKey;
function setKeys([pub, priv]) { pubKey = pub; privKey = priv; } function setKeys([pub, priv]) { pubKey = pub; privKey = priv; }
function doSign() { function doSign() {
var alg = {name: "RSA-PSS", saltLength: tv.rsapss.saltLength}; return crypto.subtle.sign({name: "RSA-PSS", saltLength: tv.rsapss.saltLength}, privKey, tv.rsapss.data);
return crypto.subtle.sign(alg, privKey, tv.rsapss.data);
} }
function doVerify(x) { function doVerify(x) {
var alg = {name: "RSA-PSS", saltLength: tv.rsapss.saltLength}; return crypto.subtle.verify({name: "RSA-PSS", saltLength: tv.rsapss.saltLength}, pubKey, x, tv.rsapss.data);
return crypto.subtle.verify(alg, pubKey, x, tv.rsapss.data);
} }
var spki = var spki =
@ -203,12 +197,10 @@ TestArray.addTest(
var privKey, pubKey; var privKey, pubKey;
function setKeys([pub, priv]) { pubKey = pub; privKey = priv; } function setKeys([pub, priv]) { pubKey = pub; privKey = priv; }
function doSign() { function doSign() {
var alg = {name: "RSA-PSS", saltLength: tv.rsapss.saltLength}; return crypto.subtle.sign({name: "RSA-PSS", saltLength: tv.rsapss.saltLength}, privKey, tv.rsapss.data);
return crypto.subtle.sign(alg, privKey, tv.rsapss.data);
} }
function doVerify(x) { function doVerify(x) {
var alg = {name: "RSA-PSS", saltLength: tv.rsapss.saltLength}; return crypto.subtle.verify({name: "RSA-PSS", saltLength: tv.rsapss.saltLength}, pubKey, x, tv.rsapss.data);
return crypto.subtle.verify(alg, pubKey, x, tv.rsapss.data);
} }
var spki = var spki =
@ -341,16 +333,14 @@ TestArray.addTest(
function setKey(x) { pubKey = x.publicKey; privKey = x.privateKey; } function setKey(x) { pubKey = x.publicKey; privKey = x.privateKey; }
function doSignTwice() { function doSignTwice() {
var alg = {name: "RSA-PSS", saltLength: 0};
return Promise.all([ return Promise.all([
crypto.subtle.sign(alg, privKey, data), crypto.subtle.sign({name: "RSA-PSS", saltLength: 0}, privKey, data),
crypto.subtle.sign(alg, privKey, data), crypto.subtle.sign({name: "RSA-PSS", saltLength: 0}, privKey, data),
]); ]);
} }
function doVerify(x) { function doVerify(x) {
var alg = {name: "RSA-PSS", saltLength: 0}; return crypto.subtle.verify({name: "RSA-PSS", saltLength: 0}, pubKey, x, data);
return crypto.subtle.verify(alg, pubKey, x, data);
} }
crypto.subtle.generateKey(alg, false, ["sign", "verify"]) crypto.subtle.generateKey(alg, false, ["sign", "verify"])

View file

@ -42,8 +42,7 @@ TestArray.addTest(
crypto.subtle.generateKey(alg, false, ["encrypt", "decrypt"]).then(key => { crypto.subtle.generateKey(alg, false, ["encrypt", "decrypt"]).then(key => {
// Wait for ciphertext, check and decrypt. // Wait for ciphertext, check and decrypt.
worker.addEventListener("message", ({data: ciphertext}) => { worker.addEventListener("message", ({data: ciphertext}) => {
var alg = { name: "AES-GCM", iv: nonce }; crypto.subtle.decrypt({ name: "AES-GCM", iv: nonce }, key, ciphertext)
crypto.subtle.decrypt(alg, key, ciphertext)
.then(memcmp_complete(that, data), error(that)); .then(memcmp_complete(that, data), error(that));
}); });

View file

@ -98,7 +98,7 @@ TestArray.addTest(
iv: tv.key_wrap_known_answer.wrapping_iv, iv: tv.key_wrap_known_answer.wrapping_iv,
tagLength: 128, tagLength: 128,
}; };
var key, wrappingKey; var wrappingKey;
function doUnwrap(k) { function doUnwrap(k) {
wrappingKey = k; wrappingKey = k;

View file

@ -39,9 +39,9 @@
frame.remove(); frame.remove();
// Load the test app again to retrieve stored keys. // Load the test app again to retrieve stored keys.
createMozBrowserFrame((frame, result) => { createMozBrowserFrame((recFrame, recResult) => {
is(result, "ok", "retrieved keys successfully"); is(recResult, "ok", "retrieved keys successfully");
frame.remove(); recFrame.remove();
SimpleTest.finish(); SimpleTest.finish();
}); });
}); });

View file

@ -105,7 +105,7 @@ function shallowArrayEquals(x, y) {
return false; return false;
} }
for (i in x) { for (let i in x) {
if (x[i] != y[i]) { if (x[i] != y[i]) {
return false; return false;
} }