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

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Volodymyr Klymenko ext:(%3E) 2018-12-14 00:44:52 +00:00
Родитель 7e0f4b06eb
Коммит fbb0aae478
21 изменённых файлов: 448 добавлений и 448 удалений

Просмотреть файл

@ -17,7 +17,7 @@
let request = indexedDB.open("keystore", 1);
request.onerror = err(reject);
request.onsuccess = function (event) {
request.onsuccess = function(event) {
db = event.target.result;
resolve();
};
@ -38,11 +38,11 @@
transaction.onabort = err(reject);
transaction.onerror = err(reject);
transaction.oncomplete = function () {
transaction.oncomplete = function() {
resolve(key);
};
});
};
}
function retrieveKey() {
return new Promise((resolve, reject) => {
@ -52,7 +52,7 @@
cursor.onerror = err(reject);
cursor.onabort = err(reject);
cursor.onsuccess = function (event) {
cursor.onsuccess = function(event) {
try {
let result = event.target.result;
resolve(result && result.value);
@ -68,7 +68,7 @@
name: "RSASSA-PKCS1-v1_5",
hash: "SHA-256",
modulusLength: 1024,
publicExponent: new Uint8Array([0x01, 0x00, 0x01])
publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
};
return crypto.subtle.generateKey(algorithm, true, ["sign", "verify"]);

Просмотреть файл

@ -62,7 +62,7 @@ function Test(name, test) {
if (this.name) {
this.row[0].innerHTML = this.name;
var that = this;
this.row[0].onclick = function() { that.run(); }
this.row[0].onclick = function() { that.run(); };
} else {
this.row[0] = "";
}
@ -75,12 +75,12 @@ function Test(name, test) {
this.row[1].className = "fail";
this.row[1].innerHTML = "FAIL";
} else {
//this.row[1].innerHTML = "";
// this.row[1].innerHTML = "";
this.row[1].innerHTML = this.result;
}
// 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";
} else {
this.row[2].innerHTML = "";
@ -128,7 +128,7 @@ var TestArray = {
currTest: 0,
worker: new Worker("test-worker.js"),
addTest: function(name, testFn) {
addTest(name, testFn) {
// Give it a reference to the array
var test = new Test(name, testFn);
test.ta = this;
@ -140,19 +140,19 @@ var TestArray = {
this.tests.push(new WorkerTest(this.worker, name, testFn));
},
updateSummary: function() {
updateSummary() {
this.pass = this.fail = this.pending = 0;
for (var i=0; i<this.tests.length; ++i) {
if (this.tests[i].result == true) this.pass++;
for (var i = 0; i < this.tests.length; ++i) {
if (this.tests[i].result == true) this.pass++;
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.failSpan.innerHTML = this.fail;
this.pendingSpan.innerHTML = this.pending;
},
load: function() {
load() {
// Grab reference to table and summary numbers
this.table = document.getElementById("results");
this.passSpan = document.getElementById("passN");
@ -161,7 +161,7 @@ var TestArray = {
// Populate everything initially
this.updateSummary();
for (var i=0; i<this.tests.length; ++i) {
for (var i = 0; i < this.tests.length; ++i) {
var tr = document.createElement("tr");
tr.id = "test" + i;
tr.appendChild(document.createElement("td"));
@ -173,12 +173,12 @@ var TestArray = {
}
},
run: function() {
run() {
this.currTest = 0;
this.runNextTest();
},
runNextTest: function() {
runNextTest() {
this.updateSummary();
var i = this.currTest++;
if (i >= this.tests.length) {
@ -189,10 +189,10 @@ var TestArray = {
var self = this;
this.tests[i].oncomplete = function() {
self.runNextTest();
}
};
this.tests[i].run();
}
}
},
};
if (window.addEventListener) {
window.addEventListener("load", function() { TestArray.load(); } );
@ -218,25 +218,25 @@ function error(test) {
console.log("ERROR :: " + x);
test.complete(false);
throw x;
}
};
}
function complete(test, valid) {
return function(x) {
console.log("COMPLETE")
console.log("COMPLETE");
console.log(x);
if (valid) {
test.complete(valid(x));
} else {
test.complete(true);
}
}
};
}
function memcmp_complete(test, value) {
return function(x) {
console.log("COMPLETE")
console.log("COMPLETE");
console.log(x);
test.memcmp_complete(value, x);
}
};
}

Просмотреть файл

@ -105,7 +105,7 @@ tv = {
"feffe9928665731c6d6a8f9467308308"),
key_jwk: {
kty: "oct",
k: "_v_pkoZlcxxtao-UZzCDCP7_6ZKGZXMcbWqPlGcwgwg"
k: "_v_pkoZlcxxtao-UZzCDCP7_6ZKGZXMcbWqPlGcwgwg",
},
iv: util.hex2abv("9313225df88406e555909c5aff5269aa" +
"6a7a9538534f7da1e4c303d2a318a728" +
@ -295,7 +295,7 @@ tv = {
dq: "Gos485j6cSBJiY1_t57gp3ZoeRKZzfoJ78DlB6yyHtdDAe9b_Ui-RV6utuFng" +
"lWCdYCo5OjhQVHRUQqCo_LnKQ",
qi: "JxVqukEm0kqB86Uoy_sn9WiG-ECp9uhuF6RLlP6TGVhLjiL93h5aLjvYqluo2" +
"FhBlOshkKz4MrhH8To9JKefTQ"
"FhBlOshkKz4MrhH8To9JKefTQ",
},
spki: util.hex2abv(
"30819f300d06092a864886f70d010101050003818d0030818902818100a56e4a" +
@ -516,7 +516,7 @@ tv = {
"8442e03da015b136e543f7ab07c0c13e4225b8de8cce25d4f6eb8400f81f7e18" +
"33b7ee6e334d370964ca79fdb872b4d75223b5eeb08101591fb532d155a6de87"
),
saltLength: 20
saltLength: 20,
},
// [SigVerPSS_186-3.rsp] from
@ -541,7 +541,7 @@ tv = {
"d2ab24f789b3464c5c43a256bbc1d692cf7f04801dac5bb401a4a03ab7d5728a" +
"860c19e1a4dc797ca542c8203cec2e601eb0c51f567f2eda022b0b9ebddeeefa"
),
saltLength: 10
saltLength: 10,
},
// [SigVerPSS_186-3.rsp] from
@ -566,7 +566,7 @@ tv = {
"9b41cdbd530c69d17cdbc84bc6b9830fc7dc8e1b2412cfe06dcf8c1a0cc3453f" +
"93f25ebf10cb0c90334fac573f449138616e1a194c67f44efac34cc07a526267"
),
saltLength: 10
saltLength: 10,
},
// [SigVerPSS_186-3.rsp] from
@ -591,7 +591,7 @@ tv = {
"6551cdf93197e9f8fb048044473ab41a801e9f7fc983c62b324361dade9f71a6" +
"5952bd35c59faaa4d6ff462f68a6c4ec0b428aa47336f2178aeb276136563b7d"
),
saltLength: 10
saltLength: 10,
},
key_wrap_known_answer: {
@ -599,7 +599,7 @@ tv = {
wrapping_key: util.hex2abv("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b"),
wrapping_iv: util.hex2abv("0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c"),
wrapped_key: util.hex2abv("9ed0283a9a2b7e4292ebc5135e6342cc" +
"8a7f65802a1f6fd41bd3251c4da0c138")
"8a7f65802a1f6fd41bd3251c4da0c138"),
},
// AES Key Wrap
@ -609,14 +609,14 @@ tv = {
wrapping_key: {
kty: "oct",
alg: "A256KW",
k: "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8"
k: "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8",
},
key: {
kty: "oct",
k: "ABEiM0RVZneImaq7zN3u_w"
k: "ABEiM0RVZneImaq7zN3u_w",
},
wrapped_key: util.hex2abv("64e8c3f9ce0f5ba263e9777905818a2a"+
"93c8191e7d6e8ae7")
wrapped_key: util.hex2abv("64e8c3f9ce0f5ba263e9777905818a2a" +
"93c8191e7d6e8ae7"),
},
// RFC 6070 <http://tools.ietf.org/html/rfc6070>
@ -632,8 +632,8 @@ tv = {
jwk: {
kty: "oct",
k: "cGFzc3dvcmRQQVNTV09SRHBhc3N3b3Jk"
}
k: "cGFzc3dvcmRQQVNTV09SRHBhc3N3b3Jk",
},
},
// https://stackoverflow.com/questions/5130513/pbkdf2-hmac-sha2-test-vectors
@ -646,7 +646,7 @@ tv = {
derived: util.hex2abv(
"348c89dbcbd32b2f32d814b8116e84cf2b17347ebc1800181c4e2a1fb8dd53e1" +
"c635518c7dac47e9"
)
),
},
pbkdf2_sha256_no_salt: {
@ -656,7 +656,7 @@ tv = {
iterations: 1,
derived: util.hex2abv(
"ef29dd382fa66a83a95be7ccfb71f1ccfee494977855a4c260d90c2f8c91e062")
"ef29dd382fa66a83a95be7ccfb71f1ccfee494977855a4c260d90c2f8c91e062"),
},
pbkdf2_sha256_no_pwd: {
@ -666,7 +666,7 @@ tv = {
iterations: 1,
derived: util.hex2abv(
"1635fa0f0542cc84f51207ff6cad5284aee3b0264faa55868eca95a7efd2335c")
"1635fa0f0542cc84f51207ff6cad5284aee3b0264faa55868eca95a7efd2335c"),
},
broken_pkcs8: {
@ -684,7 +684,7 @@ tv = {
"fd6d95e9cefcb0745763cddf564c87bcf4ba7928e74fd6a3080481f588d535e4" +
"c026b58a21e1e5ec412ff241b436043e29173f1dc6cb943c09742de989547288" +
"0416021442c6ee70beb7465928a1efe692d2281b8f7b53d6"
)
),
},
// KASValidityTest_ECCEphemeralUnified_NOKC_ZZOnly_init.fax [EC]
@ -694,7 +694,7 @@ tv = {
kty: "EC",
crv: "P-256",
x: "XOe4bjsyZgQD5jcS7wmY3q4QJ_rsPBvp92-TTf61jpg",
y: "9M8HWzlAXdHxresJAQftz7K0ljc52HZ54wVssFV9Ct8"
y: "9M8HWzlAXdHxresJAQftz7K0ljc52HZ54wVssFV9Ct8",
},
jwk_priv: {
@ -702,7 +702,7 @@ tv = {
crv: "P-256",
d: "qq_LEzeJpR00KM5DQvL2MNtJcbi0KcGVcoPIHNnwm2A",
x: "FNwJHA-FwnSx5tKXFV_iLN408gbKUHRV06WnQlzTdN4",
y: "is9pWAaneK4RdxmdLfsq5IwizDmUS2w8OGS99sKm3ek"
y: "is9pWAaneK4RdxmdLfsq5IwizDmUS2w8OGS99sKm3ek",
},
// vector with algorithm = id-ecDH
@ -726,7 +726,7 @@ tv = {
secret: util.hex2abv(
"35669cd5c244ba6c1ea89b8802c3d1db815cd769979072e6556eb98548c65f7d"
)
),
},
// KASValidityTest_ECCEphemeralUnified_NOKC_ZZOnly_init.fax [ED]
@ -736,7 +736,7 @@ tv = {
kty: "EC",
crv: "P-384",
x: "YoV6fhCph4kyt7sUkqiZOtbRs0rF6etPqlnrn1nzSB95NElaw4uTK7Pn2nlFFqqH",
y: "bf3tRz6icq3-W6hhmoqDTBKjdOQUJ5xHr5kX4X-h5MZk_P_nCrG3IUVl1SAbhWDw"
y: "bf3tRz6icq3-W6hhmoqDTBKjdOQUJ5xHr5kX4X-h5MZk_P_nCrG3IUVl1SAbhWDw",
},
jwk_priv: {
@ -744,13 +744,13 @@ tv = {
crv: "P-384",
d: "RT8f0pRw4CL1Tgk4rwuNnNbFoQBNTTBkr7WVLLm4fDA3boYZpNB_t-rbMVLx0CRp",
x: "_XwhXRnOzEfCsWIRCz3QLClaDkigQFvXmqYNdh_7vJdADykPbfGi1VgAu3XJdXoD",
y: "S1P_FBCXYGE-5VPvTCRnFT7bPIPmUPV9qKTM24TQFYEUgIDfzCLsyGCWK-rhP6jU"
y: "S1P_FBCXYGE-5VPvTCRnFT7bPIPmUPV9qKTM24TQFYEUgIDfzCLsyGCWK-rhP6jU",
},
secret: util.hex2abv(
"a3d28aa18f905a48a5f166b4ddbf5f6b499e43858ccdd80b869946aba2c5d461" +
"db6a1e5b1137687801878ff0f8d9a7b3"
)
),
},
// KASValidityTest_ECCEphemeralUnified_NOKC_ZZOnly_init.fax [EE]
@ -762,7 +762,7 @@ tv = {
x: "AeCLgRZ-BPqfhq4jt409-E26VHW5l29q74cHbIbQiS_-Gcqdo-087jHdPXUksGpr" +
"Nyp_RcTZd94t3peXzQziQIqo",
y: "AZIAp8QVnU9hBOkLScv0dy540uGtBWHkWj4DGh-Exh4iWZ0E-YBS8-HVx2eB-nfG" +
"AGEy4-BzfpFFlfidOS1Tg77J"
"AGEy4-BzfpFFlfidOS1Tg77J",
},
jwk_priv: {
@ -773,14 +773,14 @@ tv = {
x: "AcD_6Eb4A-8QdUM70c6F0WthN1kvV4fohS8QHbod6B4y1ZDU54mQuCR-3IBjcV1c" +
"oh18uxbyUn5szMuCgjZUiD0y",
y: "AU3WKJffztkhAQetBXaLvUSIHa87HMn8vZFB04lWipH-SrsrAu_4N-6iam0OD4EJ" +
"0kOMH8iEh7yuivaKsFRzm2-m"
"0kOMH8iEh7yuivaKsFRzm2-m",
},
secret: util.hex2abv(
"00561eb17d856552c21b8cbe7d3d60d1ea0db738b77d4050fa2dbd0773edc395" +
"09854d9e30e843964ed3fd303339e338f31289120a38f94e9dc9ff7d4b3ea8f2" +
"5e01"
)
),
},
// Some test vectors that we should fail to import.
@ -790,21 +790,21 @@ tv = {
kty: "EC",
crv: "P-123",
x: "XOe4bjsyZgQD5jcS7wmY3q4QJ_rsPBvp92-TTf61jpg",
y: "9M8HWzlAXdHxresJAQftz7K0ljc52HZ54wVssFV9Ct8"
y: "9M8HWzlAXdHxresJAQftz7K0ljc52HZ54wVssFV9Ct8",
},
// The crv parameter is missing.
jwk_missing_crv: {
kty: "EC",
x: "XOe4bjsyZgQD5jcS7wmY3q4QJ_rsPBvp92-TTf61jpg",
y: "9M8HWzlAXdHxresJAQftz7K0ljc52HZ54wVssFV9Ct8"
y: "9M8HWzlAXdHxresJAQftz7K0ljc52HZ54wVssFV9Ct8",
},
// The X coordinate is missing.
jwk_missing_x: {
kty: "EC",
crv: "P-256",
y: "9M8HWzlAXdHxresJAQftz7K0ljc52HZ54wVssFV9Ct8"
y: "9M8HWzlAXdHxresJAQftz7K0ljc52HZ54wVssFV9Ct8",
},
// The Y coordinate is missing.
@ -836,7 +836,7 @@ tv = {
raw_compressed: util.hex2abv(
"025ce7b86e3b32660403e63712ef0998deae1027faec3c1be9f76f934dfeb58e" +
"98f4cf075b39405dd1f1adeb090107edcfb2b4963739d87679e3056cb0557d0adf"
)
),
},
// NIST ECDSA test vectors
@ -882,7 +882,7 @@ tv = {
"99e4bc72fd79d28a380f8d4b4c919ac290d248c37983ba05aea42e2dd79fdd33e8" +
"0087488c859a96fea266ea13bf6d114c429b163be97a57559086edb64aed4a1859" +
"4b46fb9efc7fd25d8b2de8f09ca0587f54bd287299f47b2ff124aac56600000000"
)
),
},
ecdsa_bad: {
@ -892,8 +892,8 @@ tv = {
"x": "BhOH_WuVkU6IX5Eu37tfsnRlUCfyFsQJHKg-GTNnQP2B" +
"rt_gR_UbQr32gWESEBPg1VsRehTkMD-SbI3rt3p_2q0B",
"y": "AUNouOdGgHsraPNhXNeNdhpGTd15GPyN9R0iWWL98ePc" +
"JD4mUQD/DsEzNZ4zLkTdSa/Y5fOP6GEzVzQy0zwC+goD"
}
"JD4mUQD/DsEzNZ4zLkTdSa/Y5fOP6GEzVzQy0zwC+goD",
},
},
// RFC 2409 <http://tools.ietf.org/html/rfc2409#section-6.2>
@ -952,7 +952,7 @@ tv = {
"7a08b0c7c509110b9e7c6dbc961ca4360362d3dbcffc5bf2bb7207e0a5922f77" +
"cf5464b316aa49fb62b338ebcdb30bf573d07b663bb7777b69d6317df0a4f636" +
"ba3d9acbf9e8ac"
)
),
},
// Taken from appendix A of RFC 5869.
@ -969,8 +969,8 @@ tv = {
),
jwk: {
kty: "oct",
k: "CwsLCwsLCwsLCwsLCwsLCwsLCwsLCw"
}
k: "CwsLCwsLCwsLCwsLCwsLCwsLCwsLCw",
},
},
{
prf: "SHA-256",
@ -993,7 +993,7 @@ tv = {
"b11e398dc80327a1c8e7f78c596a49344f012eda2d4efad8a050cc4c19afa97c" +
"59045a99cac7827271cb41c65e590e09da3275600c2f09b8367793a9aca3db71" +
"cc30c58179ec3e87c14c01d5c1f3434f1d87"
)
),
},
{
prf: "SHA-256",
@ -1003,7 +1003,7 @@ tv = {
data: util.hex2abv(
"8da4e775a563c18f715f802a063c5a31b8a11f5c5ee1879ec3454e5f3c738d2d" +
"9d201395faa4b61a96c8"
)
),
},
{
prf: "SHA-1",
@ -1013,7 +1013,7 @@ tv = {
data: util.hex2abv(
"085a01ea1b10f36933068b56efa5ad81a4f14b822f5b091568a9cdd4f155fda2" +
"c22e422478d305f3f896"
)
),
},
{
prf: "SHA-1",
@ -1036,7 +1036,7 @@ tv = {
"0bd770a74d1160f7c9f12cd5912a06ebff6adcae899d92191fe4305673ba2ffe" +
"8fa3f1a4e5ad79f3f334b3b202b2173c486ea37ce3d397ed034c7f9dfeb15c5e" +
"927336d0441f4c4300e2cff0d0900b52d3b4"
)
),
},
{
prf: "SHA-1",
@ -1046,7 +1046,7 @@ tv = {
data: util.hex2abv(
"0ac1af7002b3d761d1e55298da9d0506b9ae52057220a306e07b6b87e8df21d0" +
"ea00033de03984d34918"
)
),
},
{
prf: "SHA-1",
@ -1056,7 +1056,7 @@ tv = {
data: util.hex2abv(
"2c91117204d745f3500d636a62f64f0ab3bae548aa53d423b0d1f27ebba6f5e5" +
"673a081d70cce7acfc48"
)
}
]
}
),
},
],
};

Просмотреть файл

@ -22,18 +22,18 @@ function complete(test, valid) {
}
function memcmp_complete(test, value) {
return function (x) {
return function(x) {
finish(util.memcmp(x, value));
};
}
function error(test) {
return function (x) {
return function(x) {
throw x;
};
}
onmessage = function (msg) {
onmessage = function(msg) {
var test = eval("(" + msg.data + ")");
try {

Просмотреть файл

@ -19,7 +19,7 @@
<!-- General testing framework -->
<script src="./test-array.js"></script>
<script>/*<![CDATA[*/
<script>/* <![CDATA[*/
"use strict";
// -----------------------------------------------------------------------------
@ -51,7 +51,7 @@ TestArray.addTest(
var alg = {
get name() {
throw "Oh no, no name!";
}
},
};
crypto.subtle.importKey("raw", tv.raw, alg, true, ["encrypt"])
@ -60,7 +60,7 @@ TestArray.addTest(
complete(that, function(x) { return true; })
);
}
)
);
// -----------------------------------------------------------------------------
TestArray.addTest(
@ -77,7 +77,7 @@ TestArray.addTest(
(x.type != "secret") ||
(!x.extractable) ||
(x.usages.length != 1) ||
(x.usages[0] != 'encrypt')){
(x.usages[0] != "encrypt")) {
throw "Invalid key: incorrect key data";
}
return crypto.subtle.exportKey("raw", x);
@ -116,7 +116,7 @@ TestArray.addTest(
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f]);
var u32 = new Uint32Array(u8.buffer, 8, 4);
var out = u8.subarray(8, 24)
var out = u8.subarray(8, 24);
function doExport(x) {
return crypto.subtle.exportKey("raw", x);
@ -145,7 +145,7 @@ TestArray.addTest(
(x.type != "private") ||
(!x.extractable) ||
(x.usages.length != 1) ||
(x.usages[0] != 'sign')){
(x.usages[0] != "sign")) {
throw "Invalid key: incorrect key data";
}
return crypto.subtle.exportKey("pkcs8", x);
@ -179,7 +179,7 @@ TestArray.addTest(
var that = this;
var alg = {
name: "RSASSA-PKCS1-v1_5",
hash: "SHA-256"
hash: "SHA-256",
};
function doExport(x) {
@ -191,7 +191,7 @@ TestArray.addTest(
(x.type != "public") ||
(!x.extractable) ||
(x.usages.length != 1) ||
(x.usages[0] != 'verify')){
(x.usages[0] != "verify")) {
throw "Invalid key: incorrect key data";
}
return crypto.subtle.exportKey("spki", x);
@ -213,7 +213,7 @@ TestArray.addTest(
var that = this;
var alg = {
name: "RSASSA-PKCS1-v1_5",
hash: "SHA-256"
hash: "SHA-256",
};
crypto.subtle.importKey("spki", tv.negative_spki, alg, true, ["encrypt"])
@ -267,7 +267,7 @@ TestArray.addTest(
req.onupgradeneeded = function(e) {
db = e.target.result;
db.createObjectStore(dbstore, {keyPath: "id"});
}
};
req.onsuccess = doPut;
}
@ -291,7 +291,7 @@ TestArray.addTest(
});
}
crypto.subtle.importKey("raw", tv.raw, alg, false, ['encrypt'])
crypto.subtle.importKey("raw", tv.raw, alg, false, ["encrypt"])
.then(doIndexedDB, error(that));
}
);
@ -391,7 +391,7 @@ TestArray.addTest(
name: "RSASSA-PKCS1-v1_5",
hash: "SHA-256",
modulusLength: 1024,
publicExponent: new Uint8Array([0x01, 0x00, 0x01])
publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
};
crypto.subtle.generateKey(alg, false, ["sign", "verify"]).then(
complete(that, function(x) {
@ -424,7 +424,7 @@ TestArray.addTest(
name: "RSASSA-PKCS1-v1_5",
hash: "SHA-256",
modulusLength: 2299, // NSS does not like this key length
publicExponent: new Uint8Array([0x01, 0x00, 0x01])
publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
};
crypto.subtle.generateKey(alg, false, ["sign"])
@ -459,7 +459,7 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"AES-CBC encrypt",
function () {
function() {
var that = this;
function doEncrypt(x) {
@ -468,7 +468,7 @@ TestArray.addTest(
x, tv.aes_cbc_enc.data);
}
crypto.subtle.importKey("raw", tv.aes_cbc_enc.key, "AES-CBC", false, ['encrypt'])
crypto.subtle.importKey("raw", tv.aes_cbc_enc.key, "AES-CBC", false, ["encrypt"])
.then(doEncrypt)
.then(
memcmp_complete(that, tv.aes_cbc_enc.result),
@ -480,21 +480,21 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"AES-CBC encrypt with wrong IV size",
function () {
function() {
var that = this;
function encrypt(x, iv) {
return crypto.subtle.encrypt(
{ name: "AES-CBC", iv: iv },
{ name: "AES-CBC", iv },
x, tv.aes_cbc_enc.data);
}
function doEncrypt(x) {
return encrypt(x, new Uint8Array(15))
.catch(function () { return encrypt(new Uint8Array(17)); });
.catch(function() { return encrypt(new Uint8Array(17)); });
}
crypto.subtle.importKey("raw", tv.aes_cbc_enc.key, "AES-CBC", false, ['encrypt'])
crypto.subtle.importKey("raw", tv.aes_cbc_enc.key, "AES-CBC", false, ["encrypt"])
.then(doEncrypt)
.then(
error(that),
@ -506,7 +506,7 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"AES-CBC decrypt",
function () {
function() {
var that = this;
function doDecrypt(x) {
@ -515,7 +515,7 @@ TestArray.addTest(
x, tv.aes_cbc_dec.data);
}
crypto.subtle.importKey("raw", tv.aes_cbc_dec.key, "AES-CBC", false, ['decrypt'])
crypto.subtle.importKey("raw", tv.aes_cbc_dec.key, "AES-CBC", false, ["decrypt"])
.then(doDecrypt)
.then(
memcmp_complete(that, tv.aes_cbc_dec.result),
@ -527,21 +527,21 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"AES-CBC decrypt with wrong IV size",
function () {
function() {
var that = this;
function decrypt(x, iv) {
return crypto.subtle.decrypt(
{ name: "AES-CBC", iv: iv },
{ name: "AES-CBC", iv },
x, tv.aes_cbc_dec.data);
}
function doDecrypt(x) {
return decrypt(x, new Uint8Array(15))
.catch(function () { return decrypt(x, new Uint8Array(17)); });
.catch(function() { return decrypt(x, new Uint8Array(17)); });
}
crypto.subtle.importKey("raw", tv.aes_cbc_dec.key, "AES-CBC", false, ['decrypt'])
crypto.subtle.importKey("raw", tv.aes_cbc_dec.key, "AES-CBC", false, ["decrypt"])
.then(doDecrypt)
.then(
error(that),
@ -553,7 +553,7 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"AES-CTR encryption",
function () {
function() {
var that = this;
function doEncrypt(x) {
@ -562,7 +562,7 @@ TestArray.addTest(
x, tv.aes_ctr_enc.data);
}
crypto.subtle.importKey("raw", tv.aes_ctr_enc.key, "AES-CTR", false, ['encrypt'])
crypto.subtle.importKey("raw", tv.aes_ctr_enc.key, "AES-CTR", false, ["encrypt"])
.then(doEncrypt)
.then(
memcmp_complete(that, tv.aes_ctr_enc.result),
@ -574,7 +574,7 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"AES-CTR encryption with wrong IV size",
function () {
function() {
var that = this;
function encrypt(x, iv) {
@ -585,10 +585,10 @@ TestArray.addTest(
function doEncrypt(x) {
return encrypt(x, new Uint8Array(15))
.catch(function () { return encrypt(x, new Uint8Array(17)); });
.catch(function() { return encrypt(x, new Uint8Array(17)); });
}
crypto.subtle.importKey("raw", tv.aes_ctr_enc.key, "AES-CTR", false, ['encrypt'])
crypto.subtle.importKey("raw", tv.aes_ctr_enc.key, "AES-CTR", false, ["encrypt"])
.then(doEncrypt)
.then(
error(that),
@ -600,7 +600,7 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"AES-CTR decryption",
function () {
function() {
var that = this;
function doDecrypt(x) {
@ -609,7 +609,7 @@ TestArray.addTest(
x, tv.aes_ctr_dec.data);
}
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(
memcmp_complete(that, tv.aes_ctr_dec.result),
@ -621,7 +621,7 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"AES-CTR decryption with wrong IV size",
function () {
function() {
var that = this;
function doDecrypt(x, iv) {
@ -632,10 +632,10 @@ TestArray.addTest(
function decrypt(x) {
return decrypt(x, new Uint8Array(15))
.catch(function () { return decrypt(x, new Uint8Array(17)); });
.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(
error(that),
@ -647,7 +647,7 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"AES-GCM encryption",
function () {
function() {
var that = this;
function doEncrypt(x) {
@ -656,12 +656,12 @@ TestArray.addTest(
name: "AES-GCM",
iv: tv.aes_gcm_enc.iv,
additionalData: tv.aes_gcm_enc.adata,
tagLength: 128
tagLength: 128,
},
x, tv.aes_gcm_enc.data);
}
crypto.subtle.importKey("raw", tv.aes_gcm_enc.key, "AES-GCM", false, ['encrypt'])
crypto.subtle.importKey("raw", tv.aes_gcm_enc.key, "AES-GCM", false, ["encrypt"])
.then(doEncrypt)
.then(
memcmp_complete(that, tv.aes_gcm_enc.result),
@ -673,7 +673,7 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"AES-GCM decryption",
function () {
function() {
var that = this;
function doDecrypt(x) {
@ -682,12 +682,12 @@ TestArray.addTest(
name: "AES-GCM",
iv: tv.aes_gcm_dec.iv,
additionalData: tv.aes_gcm_dec.adata,
tagLength: 128
tagLength: 128,
},
x, tv.aes_gcm_dec.data);
}
crypto.subtle.importKey("raw", tv.aes_gcm_dec.key, "AES-GCM", false, ['decrypt'])
crypto.subtle.importKey("raw", tv.aes_gcm_dec.key, "AES-GCM", false, ["decrypt"])
.then(doDecrypt)
.then(
memcmp_complete(that, tv.aes_gcm_dec.result),
@ -699,7 +699,7 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"AES-GCM decryption, failing authentication check",
function () {
function() {
var that = this;
function doDecrypt(x) {
@ -708,12 +708,12 @@ TestArray.addTest(
name: "AES-GCM",
iv: tv.aes_gcm_dec_fail.iv,
additionalData: tv.aes_gcm_dec_fail.adata,
tagLength: 128
tagLength: 128,
},
x, tv.aes_gcm_dec_fail.data);
}
crypto.subtle.importKey("raw", tv.aes_gcm_dec_fail.key, "AES-GCM", false, ['decrypt'])
crypto.subtle.importKey("raw", tv.aes_gcm_dec_fail.key, "AES-GCM", false, ["decrypt"])
.then(doDecrypt)
.then(
error(that),
@ -725,20 +725,20 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"AES-GCM encryption, fail with a zero-length IV",
function () {
function() {
var that = this;
var alg = {
name: "AES-GCM",
iv: new Uint8Array(),
additionalData: tv.aes_gcm_enc.adata,
tagLength: 128
tagLength: 128,
};
function doEncrypt(x) {
return crypto.subtle.encrypt(alg, x, tv.aes_gcm_enc.data);
}
crypto.subtle.importKey("raw", tv.aes_gcm_enc.key, "AES-GCM", false, ['encrypt'])
crypto.subtle.importKey("raw", tv.aes_gcm_enc.key, "AES-GCM", false, ["encrypt"])
.then(doEncrypt)
.then(error(that), complete(that));
}
@ -747,20 +747,20 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"AES-GCM encryption, accept an all-zero IV (1 byte)",
function () {
function() {
var that = this;
var alg = {
name: "AES-GCM",
iv: new Uint8Array(1),
additionalData: tv.aes_gcm_enc.adata,
tagLength: 128
tagLength: 128,
};
function doEncrypt(x) {
return crypto.subtle.encrypt(alg, x, tv.aes_gcm_enc.data);
}
crypto.subtle.importKey("raw", tv.aes_gcm_enc.key, "AES-GCM", false, ['encrypt'])
crypto.subtle.importKey("raw", tv.aes_gcm_enc.key, "AES-GCM", false, ["encrypt"])
.then(doEncrypt)
.then(complete(that), error(that));
}
@ -769,20 +769,20 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"AES-GCM encryption, accept an all-zero IV (12 bytes)",
function () {
function() {
var that = this;
var alg = {
name: "AES-GCM",
iv: new Uint8Array(12),
additionalData: tv.aes_gcm_enc.adata,
tagLength: 128
tagLength: 128,
};
function doEncrypt(x) {
return crypto.subtle.encrypt(alg, x, tv.aes_gcm_enc.data);
}
crypto.subtle.importKey("raw", tv.aes_gcm_enc.key, "AES-GCM", false, ['encrypt'])
crypto.subtle.importKey("raw", tv.aes_gcm_enc.key, "AES-GCM", false, ["encrypt"])
.then(doEncrypt)
.then(complete(that), error(that));
}
@ -791,20 +791,20 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"AES-GCM encryption, accept an all-zero IV (16 bytes)",
function () {
function() {
var that = this;
var alg = {
name: "AES-GCM",
iv: new Uint8Array(16),
additionalData: tv.aes_gcm_enc.adata,
tagLength: 128
tagLength: 128,
};
function doEncrypt(x) {
return crypto.subtle.encrypt(alg, x, tv.aes_gcm_enc.data);
}
crypto.subtle.importKey("raw", tv.aes_gcm_enc.key, "AES-GCM", false, ['encrypt'])
crypto.subtle.importKey("raw", tv.aes_gcm_enc.key, "AES-GCM", false, ["encrypt"])
.then(doEncrypt)
.then(complete(that), error(that));
}
@ -817,14 +817,14 @@ TestArray.addTest(
var that = this;
var alg = {
name: "HMAC",
hash: "SHA-256"
}
hash: "SHA-256",
};
function doSign(x) {
return crypto.subtle.sign("HMAC", x, tv.hmac_sign.data);
}
crypto.subtle.importKey("raw", tv.hmac_sign.key, alg, false, ['sign'])
crypto.subtle.importKey("raw", tv.hmac_sign.key, alg, false, ["sign"])
.then(doSign)
.then(
memcmp_complete(that, tv.hmac_sign.result),
@ -840,14 +840,14 @@ TestArray.addTest(
var that = this;
var alg = {
name: "HMAC",
hash: "SHA-256"
}
hash: "SHA-256",
};
function doVerify(x) {
return crypto.subtle.verify("HMAC", x, tv.hmac_verify.sig, tv.hmac_verify.data);
}
crypto.subtle.importKey("raw", tv.hmac_verify.key, alg, false, ['verify'])
crypto.subtle.importKey("raw", tv.hmac_verify.key, alg, false, ["verify"])
.then(doVerify)
.then(
complete(that, function(x) { return !!x; }),
@ -863,15 +863,15 @@ TestArray.addTest(
var that = this;
var alg = {
name: "HMAC",
hash: "SHA-256"
}
hash: "SHA-256",
};
function doVerify(x) {
return crypto.subtle.verify("HMAC", x, tv.hmac_verify.sig_fail,
tv.hmac_verify.data);
}
crypto.subtle.importKey("raw", tv.hmac_verify.key, alg, false, ['verify'])
crypto.subtle.importKey("raw", tv.hmac_verify.key, alg, false, ["verify"])
.then(doVerify)
.then(
complete(that, function(x) { return !x; }),
@ -887,15 +887,15 @@ TestArray.addTest(
var that = this;
var alg = {
name: "HMAC",
hash: "SHA-256"
}
hash: "SHA-256",
};
function doVerify(x) {
return crypto.subtle.verify("HMAC", x, tv.hmac_verify.sig,
tv.hmac_verify.data);
}
crypto.subtle.importKey("raw", tv.hmac_verify.key, alg, false, ['encrypt'])
crypto.subtle.importKey("raw", tv.hmac_verify.key, alg, false, ["encrypt"])
.then(doVerify)
.then(
error(that),
@ -907,7 +907,7 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"RSASSA/SHA-1 signature",
function () {
function() {
var that = this;
var alg = { name: "RSASSA-PKCS1-v1_5", hash: "SHA-1" };
@ -915,7 +915,7 @@ TestArray.addTest(
return crypto.subtle.sign(alg.name, x, tv.rsassa.data);
}
crypto.subtle.importKey("pkcs8", tv.rsassa.pkcs8, alg, false, ['sign'])
crypto.subtle.importKey("pkcs8", tv.rsassa.pkcs8, alg, false, ["sign"])
.then( doSign )
.then( memcmp_complete(that, tv.rsassa.sig1), error(that) );
}
@ -924,7 +924,7 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"RSASSA verification (SHA-1)",
function () {
function() {
var that = this;
var alg = { name: "RSASSA-PKCS1-v1_5", hash: "SHA-1" };
@ -932,7 +932,7 @@ TestArray.addTest(
return crypto.subtle.verify(alg.name, x, tv.rsassa.sig1, tv.rsassa.data);
}
crypto.subtle.importKey("spki", tv.rsassa.spki, alg, false, ['verify'])
crypto.subtle.importKey("spki", tv.rsassa.spki, alg, false, ["verify"])
.then( doVerify )
.then(
complete(that, function(x) { return x; }),
@ -944,7 +944,7 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"RSASSA verification (SHA-1), failing verification",
function () {
function() {
var that = this;
var alg = { name: "RSASSA-PKCS1-v1_5", hash: "SHA-1" };
@ -952,7 +952,7 @@ TestArray.addTest(
return crypto.subtle.verify(alg.name, x, tv.rsassa.sig_fail, tv.rsassa.data);
}
crypto.subtle.importKey("spki", tv.rsassa.spki, alg, false, ['verify'])
crypto.subtle.importKey("spki", tv.rsassa.spki, alg, false, ["verify"])
.then( doVerify )
.then(
complete(that, function(x) { return !x; }),
@ -964,7 +964,7 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"RSASSA/SHA-256 signature",
function () {
function() {
var that = this;
var alg = { name: "RSASSA-PKCS1-v1_5", hash: "SHA-256" };
@ -972,7 +972,7 @@ TestArray.addTest(
return crypto.subtle.sign(alg.name, x, tv.rsassa.data);
}
crypto.subtle.importKey("pkcs8", tv.rsassa.pkcs8, alg, false, ['sign'])
crypto.subtle.importKey("pkcs8", tv.rsassa.pkcs8, alg, false, ["sign"])
.then( doSign )
.then( memcmp_complete(that, tv.rsassa.sig256), error(that) );
}
@ -981,7 +981,7 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"RSASSA verification (SHA-256)",
function () {
function() {
var that = this;
var alg = { name: "RSASSA-PKCS1-v1_5", hash: "SHA-256" };
@ -989,7 +989,7 @@ TestArray.addTest(
return crypto.subtle.verify(alg.name, x, tv.rsassa.sig256, tv.rsassa.data);
}
crypto.subtle.importKey("spki", tv.rsassa.spki, alg, false, ['verify'])
crypto.subtle.importKey("spki", tv.rsassa.spki, alg, false, ["verify"])
.then( doVerify )
.then(
complete(that, function(x) { return x; }),
@ -1001,16 +1001,16 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"RSASSA verification (SHA-256), failing verification",
function () {
function() {
var that = this;
var alg = { name: "RSASSA-PKCS1-v1_5", hash: "SHA-256" };
var use = ['sign', 'verify'];
var use = ["sign", "verify"];
function doVerify(x) {
return crypto.subtle.verify(alg.name, x, tv.rsassa.sig_fail, tv.rsassa.data);
}
crypto.subtle.importKey("spki", tv.rsassa.spki, alg, false, ['verify'])
crypto.subtle.importKey("spki", tv.rsassa.spki, alg, false, ["verify"])
.then( doVerify )
.then(
complete(that, function(x) { return !x; }),
@ -1026,7 +1026,7 @@ TestArray.addTest(
var that = this;
crypto.subtle.digest("SHA-256", tv.sha256.data)
.then(complete(that, function (x) {
.then(complete(that, function(x) {
return x instanceof ArrayBuffer;
}), error(that));
}
@ -1035,7 +1035,7 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"Ensure that importing an invalid key doesn't crash",
function () {
function() {
var that = this;
// TODO Change the algorithm to "DH" once we support it.
var alg = {name: "RSA-OAEP", hash: "SHA-1"};
@ -1082,12 +1082,12 @@ TestArray.addTest(
name: "RSA-PSS",
hash: "SHA-1",
modulusLength: 1024,
publicExponent: new Uint8Array([0x01, 0x00, 0x01])
publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
};
function checkPrototypes(obj, type) {
return obj.__proto__ != window[type].prototype &&
obj.__proto__ == frames[0][type].prototype
obj.__proto__ == frames[0][type].prototype;
}
var p1 = crypto.subtle.importKey.call(
@ -1115,7 +1115,7 @@ TestArray.addTest(
}), error(that));
}
);
/*]]>*/</script>
/* ]]>*/</script>
</head>
<body>

Просмотреть файл

@ -19,7 +19,7 @@
<!-- General testing framework -->
<script src="./test-array.js"></script>
<script>/*<![CDATA[*/
<script>/* <![CDATA[*/
"use strict";
// -----------------------------------------------------------------------------
@ -30,7 +30,7 @@ TestArray.addTest(
var alg = {
name: "DH",
prime: tv.dh.prime,
generator: new Uint8Array([0x02])
generator: new Uint8Array([0x02]),
};
crypto.subtle.generateKey(alg, false, ["deriveKey", "deriveBits"]).then(
complete(that, function(x) {
@ -64,20 +64,20 @@ TestArray.addTest(
var alg = {
name: "DH",
prime: tv.dh.prime,
generator: new Uint8Array([0x02])
generator: new Uint8Array([0x02]),
};
function doDerive(x) {
var alg = {
name: "DH",
public: x.publicKey
public: x.publicKey,
};
return crypto.subtle.deriveBits(alg, x.privateKey, 128);
}
crypto.subtle.generateKey(alg, false, ["deriveBits"])
.then(doDerive, error(that))
.then(complete(that, function (x) {
.then(complete(that, function(x) {
return x.byteLength == 16;
}), error(that));
}
@ -96,7 +96,7 @@ TestArray.addTest(
var alg = {
name: "DH",
prime: tv.dh.prime,
generator: new Uint8Array([0x02])
generator: new Uint8Array([0x02]),
};
return crypto.subtle.generateKey(alg, false, ["deriveBits"]);
}
@ -106,9 +106,9 @@ TestArray.addTest(
name: "RSA-OAEP",
hash: "SHA-256",
modulusLength: 2048,
publicExponent: new Uint8Array([0x01, 0x00, 0x01])
publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
};
return crypto.subtle.generateKey(alg, false, ["encrypt"])
return crypto.subtle.generateKey(alg, false, ["encrypt"]);
}
function doDerive() {
@ -138,7 +138,7 @@ TestArray.addTest(
var alg = {
name: "DH",
prime: tv.dh.prime,
generator: new Uint8Array([0x02])
generator: new Uint8Array([0x02]),
};
return crypto.subtle.generateKey(alg, false, ["deriveBits"]);
}
@ -147,7 +147,7 @@ TestArray.addTest(
var alg = {
name: "DH",
prime: tv.dh.prime2,
generator: new Uint8Array([0x02])
generator: new Uint8Array([0x02]),
};
return crypto.subtle.generateKey(alg, false, ["deriveBits"]);
}
@ -156,7 +156,7 @@ TestArray.addTest(
var alg = {
name: "DH",
prime: tv.dh.prime,
generator: new Uint8Array([0x03])
generator: new Uint8Array([0x03]),
};
return crypto.subtle.generateKey(alg, false, ["deriveBits"]);
}
@ -181,12 +181,12 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"Raw import/export of a public DH key",
function () {
function() {
var that = this;
var alg = {
name: "DH",
prime: tv.dh_nist.prime,
generator: tv.dh_nist.gen
generator: tv.dh_nist.gen,
};
function doExport(x) {
@ -207,7 +207,7 @@ TestArray.addTest(
var alg = {
name: "DH",
prime: tv.dh_nist.prime,
generator: tv.dh_nist.gen
generator: tv.dh_nist.gen,
};
var privKey;
@ -226,7 +226,7 @@ TestArray.addTest(
.then(setPriv, error(that))
.then(doImport, error(that))
.then(doDerive, error(that))
.then(complete(that, function (x) {
.then(complete(that, function(x) {
return x.byteLength == 16;
}), error(that));
}
@ -247,7 +247,7 @@ TestArray.addTest(
.then(memcmp_complete(that, tv.dh_nist.spki), error(that));
}
);
/*]]>*/</script>
/* ]]>*/</script>
</head>
<body>

Просмотреть файл

@ -19,7 +19,7 @@
<!-- General testing framework -->
<script src="./test-array.js"></script>
<script>/*<![CDATA[*/
<script>/* <![CDATA[*/
"use strict";
// -----------------------------------------------------------------------------
@ -61,16 +61,16 @@ TestArray.addTest(
function setKeyPair(x) { pair = x; }
function doDerive(n) {
return function (x) {
return function(x) {
var alg = { name: "ECDH", public: pair.publicKey };
return crypto.subtle.deriveBits(alg, pair.privateKey, n * 8);
}
};
}
crypto.subtle.generateKey(alg, false, ["deriveBits"])
.then(setKeyPair, error(that))
.then(doDerive(2), error(that))
.then(function (x) {
.then(function(x) {
// Deriving less bytes works.
if (x.byteLength != 2) {
throw "should have derived two bytes";
@ -101,9 +101,9 @@ TestArray.addTest(
name: "RSA-OAEP",
hash: "SHA-256",
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(alg, false, ["encrypt", "decrypt"]);
}
function doDerive() {
@ -156,7 +156,7 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"JWK import an ECDH public and private key and derive bits (P-256)",
function () {
function() {
var that = this;
var alg = { name: "ECDH" };
@ -173,7 +173,7 @@ TestArray.addTest(
crypto.subtle.importKey("jwk", tv.ecdh_p256.jwk_priv, alg, false, ["deriveBits"])
.then(setPriv, error(that)),
crypto.subtle.importKey("jwk", tv.ecdh_p256.jwk_pub, alg, false, ["deriveBits"])
.then(setPub, error(that))
.then(setPub, error(that)),
]).then(doDerive, error(that))
.then(memcmp_complete(that, tv.ecdh_p256.secret), error(that));
}
@ -182,7 +182,7 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"JWK import an ECDH public and private key and derive bits (P-384)",
function () {
function() {
var that = this;
var alg = { name: "ECDH" };
@ -199,7 +199,7 @@ TestArray.addTest(
crypto.subtle.importKey("jwk", tv.ecdh_p384.jwk_priv, alg, false, ["deriveBits"])
.then(setPriv, error(that)),
crypto.subtle.importKey("jwk", tv.ecdh_p384.jwk_pub, alg, false, ["deriveBits"])
.then(setPub, error(that))
.then(setPub, error(that)),
]).then(doDerive, error(that))
.then(memcmp_complete(that, tv.ecdh_p384.secret), error(that));
}
@ -208,7 +208,7 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"JWK import an ECDH public and private key and derive bits (P-521)",
function () {
function() {
var that = this;
var alg = { name: "ECDH" };
@ -225,7 +225,7 @@ TestArray.addTest(
crypto.subtle.importKey("jwk", tv.ecdh_p521.jwk_priv, alg, false, ["deriveBits"])
.then(setPriv, error(that)),
crypto.subtle.importKey("jwk", tv.ecdh_p521.jwk_pub, alg, false, ["deriveBits"])
.then(setPub, error(that))
.then(setPub, error(that)),
]).then(doDerive, error(that))
.then(memcmp_complete(that, tv.ecdh_p521.secret), error(that));
}
@ -234,7 +234,7 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"JWK import/export roundtrip with ECDH (P-256)",
function () {
function() {
var that = this;
var alg = { name: "ECDH" };
@ -253,9 +253,9 @@ TestArray.addTest(
crypto.subtle.importKey("jwk", tv.ecdh_p256.jwk_priv, alg, true, ["deriveBits"])
.then(setPriv, error(that)),
crypto.subtle.importKey("jwk", tv.ecdh_p256.jwk_pub, alg, true, ["deriveBits"])
.then(setPub, error(that))
.then(setPub, error(that)),
]).then(doExportPub, error(that))
.then(function (x) {
.then(function(x) {
var tp = tv.ecdh_p256.jwk_pub;
if ((tp.kty != x.kty) &&
(tp.crv != x.crv) &&
@ -265,7 +265,7 @@ TestArray.addTest(
}
}, error(that))
.then(doExportPriv, error(that))
.then(complete(that, function (x) {
.then(complete(that, function(x) {
var tp = tv.ecdh_p256.jwk_priv;
return (tp.kty == x.kty) &&
(tp.crv == x.crv) &&
@ -279,15 +279,15 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"Test that importing bad JWKs fails",
function () {
function() {
var that = this;
var alg = { name: "ECDH" };
var tvs = tv.ecdh_p256_negative;
function doTryImport(jwk) {
return function () {
return function() {
return crypto.subtle.importKey("jwk", jwk, alg, false, ["deriveBits"]);
}
};
}
doTryImport(tvs.jwk_bad_crv)()
@ -301,13 +301,13 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"JWK export of a newly generated ECDH private key",
function () {
function() {
var that = this;
var alg = { name: "ECDH", namedCurve: "P-256" };
var reBase64URL = /^[a-zA-Z0-9_-]+$/;
function doExportToJWK(x) {
return crypto.subtle.exportKey("jwk", x.privateKey)
return crypto.subtle.exportKey("jwk", x.privateKey);
}
crypto.subtle.generateKey(alg, true, ["deriveKey", "deriveBits"])
@ -315,14 +315,14 @@ TestArray.addTest(
.then(
complete(that, function(x) {
return x.ext &&
x.kty == 'EC' &&
x.crv == 'P-256' &&
x.kty == "EC" &&
x.crv == "P-256" &&
reBase64URL.test(x.x) &&
reBase64URL.test(x.y) &&
reBase64URL.test(x.d) &&
x.x.length == 43 && // 32 octets, base64-encoded
x.y.length == 43 && // 32 octets, base64-encoded
shallowArrayEquals(x.key_ops, ['deriveKey', 'deriveBits']);
shallowArrayEquals(x.key_ops, ["deriveKey", "deriveBits"]);
}),
error(that)
);
@ -344,7 +344,7 @@ TestArray.addTest(
function doDerive() {
var alg = { name: "ECDH", public: pubKey };
return crypto.subtle.deriveKey(alg, privKey, algDerived, false, ["sign", "verify"])
.then(function (x) {
.then(function(x) {
if (!hasKeyFields(x)) {
throw "Invalid key; missing field(s)";
}
@ -361,7 +361,7 @@ TestArray.addTest(
function doSignAndVerify(x) {
var data = crypto.getRandomValues(new Uint8Array(1024));
return crypto.subtle.sign("HMAC", x, data)
.then(function (sig) {
.then(function(sig) {
return crypto.subtle.verify("HMAC", x, sig, data);
});
}
@ -370,7 +370,7 @@ TestArray.addTest(
crypto.subtle.importKey("jwk", tv.ecdh_p521.jwk_priv, alg, false, ["deriveKey"])
.then(setPriv),
crypto.subtle.importKey("jwk", tv.ecdh_p521.jwk_pub, alg, false, ["deriveKey"])
.then(setPub)
.then(setPub),
]).then(doDerive)
.then(doSignAndVerify)
.then(complete(that, x => x), error(that));
@ -380,7 +380,7 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"SPKI import/export of public ECDH keys (P-256)",
function () {
function() {
var that = this;
var alg = { name: "ECDH" };
var keys = ["spki", "spki_id_ecpk"];
@ -398,7 +398,7 @@ TestArray.addTest(
var imported = doImport(key);
var derived = imported.then(doExport);
return derived.then(function (x) {
return derived.then(function(x) {
if (!util.memcmp(x, tv.ecdh_p256.spki)) {
throw "exported key is invalid";
}
@ -416,7 +416,7 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"SPKI/JWK import ECDH keys (P-256) and derive a known secret",
function () {
function() {
var that = this;
var alg = { name: "ECDH" };
@ -433,7 +433,7 @@ TestArray.addTest(
crypto.subtle.importKey("spki", tv.ecdh_p256.spki, alg, false, ["deriveBits"])
.then(setPub),
crypto.subtle.importKey("jwk", tv.ecdh_p256.jwk_priv, alg, false, ["deriveBits"])
.then(setPriv)
.then(setPriv),
]).then(doDerive)
.then(memcmp_complete(that, tv.ecdh_p256.secret), error(that));
}
@ -442,7 +442,7 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"Raw import/export of a public ECDH key (P-256)",
function () {
function() {
var that = this;
var alg = { name: "ECDH", namedCurve: "P-256" };
@ -459,7 +459,7 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"Test that importing bad raw ECDH keys fails",
function () {
function() {
var that = this;
var alg = { name: "ECDH", namedCurve: "P-256" };
var tvs = tv.ecdh_p256_negative.raw_bad;
@ -472,7 +472,7 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"Test that importing ECDH keys with an unknown format fails",
function () {
function() {
var that = this;
var alg = { name: "ECDH", namedCurve: "P-256" };
var tvs = tv.ecdh_p256.raw;
@ -485,7 +485,7 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"Test that importing too short raw ECDH keys fails",
function () {
function() {
var that = this;
var alg = { name: "ECDH", namedCurve: "P-256" };
var tvs = tv.ecdh_p256_negative.raw_short;
@ -498,7 +498,7 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"Test that importing too long raw ECDH keys fails",
function () {
function() {
var that = this;
var alg = { name: "ECDH", namedCurve: "P-256" };
var tvs = tv.ecdh_p256_negative.raw_long;
@ -511,7 +511,7 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"Test that importing compressed raw ECDH keys fails",
function () {
function() {
var that = this;
var alg = { name: "ECDH", namedCurve: "P-256" };
var tvs = tv.ecdh_p256_negative.raw_compressed;
@ -524,7 +524,7 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"RAW/JWK import ECDH keys (P-256) and derive a known secret",
function () {
function() {
var that = this;
var alg = { name: "ECDH", namedCurve: "P-256" };
@ -541,12 +541,12 @@ TestArray.addTest(
crypto.subtle.importKey("raw", tv.ecdh_p256.raw, alg, false, ["deriveBits"])
.then(setPub),
crypto.subtle.importKey("jwk", tv.ecdh_p256.jwk_priv, alg, false, ["deriveBits"])
.then(setPriv)
.then(setPriv),
]).then(doDerive)
.then(memcmp_complete(that, tv.ecdh_p256.secret), error(that));
}
);
/*]]>*/</script>
/* ]]>*/</script>
</head>
<body>

Просмотреть файл

@ -19,7 +19,7 @@
<!-- General testing framework -->
<script src="./test-array.js"></script>
<script>/*<![CDATA[*/
<script>/* <![CDATA[*/
"use strict";
// -----------------------------------------------------------------------------
@ -43,7 +43,7 @@ TestArray.addTest(
(x.privateKey.type == "private") &&
!x.privateKey.extractable &&
(x.privateKey.usages.length == 1) &&
(x.privateKey.usages[0] == "sign")
(x.privateKey.usages[0] == "sign");
}),
error(that)
);
@ -63,7 +63,7 @@ TestArray.addTest(
crypto.subtle.importKey("jwk", tv.ecdsa_verify.pub_jwk, alg, true, ["verify"])
.then(doVerify)
.then(complete(that, x => x), error(that))
.then(complete(that, x => x), error(that));
}
);
@ -79,10 +79,10 @@ TestArray.addTest(
.then(pair => Promise.all([
crypto.subtle.sign(alg, pair.privateKey, msg),
crypto.subtle.exportKey("spki", pair.publicKey)
.then(spki => crypto.subtle.importKey("spki", spki, alg, false, ["verify"]))
.then(spki => crypto.subtle.importKey("spki", spki, alg, false, ["verify"])),
]))
.then(sigAndKey => crypto.subtle.verify(alg, sigAndKey[1], sigAndKey[0], msg))
.then(complete(that, x => x), error(that))
.then(complete(that, x => x), error(that));
}
);
@ -100,7 +100,7 @@ TestArray.addTest(
crypto.subtle.importKey("jwk", tv.ecdsa_verify.pub_jwk, alg, true, ["verify"])
.then(doVerify)
.then(complete(that, x => !x), error(that))
.then(complete(that, x => !x), error(that));
}
);
@ -124,7 +124,7 @@ TestArray.addTest(
crypto.subtle.generateKey(alg, true, ["sign", "verify"])
.then(doSign)
.then(doVerify)
.then(complete(that, x => x), error(that))
.then(complete(that, x => x), error(that));
}
);
@ -140,14 +140,14 @@ TestArray.addTest(
}
crypto.subtle.importKey("jwk", tv.ecdsa_bad.pub_jwk, alg, true, ["verify"])
.then(error(that), complete(that))
.then(error(that), complete(that));
}
);
// -----------------------------------------------------------------------------
TestArray.addTest(
"Raw import/export of a public ECDSA key (P-521)",
function () {
function() {
var that = this;
var alg = { name: "ECDSA", namedCurve: "P-521", hash: "SHA-512" };
@ -174,11 +174,11 @@ TestArray.addTest(
crypto.subtle.importKey("raw", tv.ecdsa_verify.raw, alg, true, ["verify"])
.then(doVerify)
.then(complete(that, x => x), error(that))
.then(complete(that, x => x), error(that));
}
);
/*]]>*/</script>
/* ]]>*/</script>
</head>
<body>

Просмотреть файл

@ -19,7 +19,7 @@
<!-- General testing framework -->
<script src="./test-array.js"></script>
<script>/*<![CDATA[*/
<script>/* <![CDATA[*/
"use strict";
// -----------------------------------------------------------------------------
@ -33,7 +33,7 @@ TestArray.addTest(
name: "HKDF",
hash: "SHA-256",
salt: new Uint8Array(),
info: new Uint8Array()
info: new Uint8Array(),
};
crypto.subtle.importKey("raw", key, "HKDF", false, ["deriveBits"])
@ -53,7 +53,7 @@ TestArray.addTest(
name: "HKDF",
hash: "SHA-256",
salt: new Uint8Array(),
info: new Uint8Array()
info: new Uint8Array(),
};
crypto.subtle.importKey("raw", key, "HKDF", false, ["deriveBits"])
@ -75,7 +75,7 @@ TestArray.addTest(
name: "HKDF",
hash: "SHA-256",
salt: new Uint8Array(),
info: new Uint8Array()
info: new Uint8Array(),
};
function deriveBits(x) {
@ -103,7 +103,7 @@ TestArray.addTest(
name: "HKDF",
hash: "HMAC",
salt: new Uint8Array(),
info: new Uint8Array()
info: new Uint8Array(),
};
function deriveBits(x) {
@ -126,7 +126,7 @@ TestArray.addTest(
name: "HKDF",
hash: "HMAC",
salt: new Uint8Array(),
info: new Uint8Array()
info: new Uint8Array(),
};
function deriveBits(x) {
@ -156,15 +156,15 @@ TestArray.addTest(
var {key, data} = test;
return crypto.subtle.importKey("raw", key, "HKDF", false, ["deriveBits"])
.then(function (key) {
.then(function(key) {
return crypto.subtle.deriveBits({
name: "HKDF",
hash: test.prf,
salt: test.salt,
info: test.info
info: test.info,
}, key, test.data.byteLength * 8);
})
.then(function (data) {
.then(function(data) {
if (!util.memcmp(data, test.data)) {
throw new Error("derived bits don't match expected value");
}
@ -188,7 +188,7 @@ TestArray.addTest(
name: "HKDF",
hash: test.prf,
salt: test.salt,
info: test.info
info: test.info,
};
crypto.subtle.importKey("jwk", test.jwk, "HKDF", false, ["deriveBits"])
@ -219,7 +219,7 @@ TestArray.addTest(
name: "HKDF",
hash: "SHA-256",
salt: new Uint8Array(),
info: new Uint8Array()
info: new Uint8Array(),
}, rawKey, 4);
})
.then(derivedBits => {
@ -276,7 +276,7 @@ TestArray.addTest(
name: "HKDF",
hash: "SHA-256",
salt: new Uint8Array(),
info: new Uint8Array()
info: new Uint8Array(),
};
function deriveKey(x) {
@ -286,7 +286,7 @@ TestArray.addTest(
crypto.subtle.importKey("raw", key, "HKDF", false, ["deriveKey"])
.then(deriveKey)
.then(complete(that), error(that))
.then(complete(that), error(that));
}
);
@ -301,7 +301,7 @@ TestArray.addTest(
name: "HKDF",
hash: "SHA-256",
salt: new Uint8Array(),
info: new Uint8Array()
info: new Uint8Array(),
};
function deriveKey(x) {
@ -310,11 +310,11 @@ TestArray.addTest(
crypto.subtle.importKey("raw", key, "HKDF", false, ["deriveKey"])
.then(deriveKey)
.then(error(that), complete(that))
.then(error(that), complete(that));
}
);
/*]]>*/</script>
/* ]]>*/</script>
</head>
<body>

Просмотреть файл

@ -10,13 +10,13 @@
<!-- General testing framework -->
<script src="./test-array.js"></script>
<script>/*<![CDATA[*/
<script>/* <![CDATA[*/
"use strict";
// -----------------------------------------------------------------------------
TestArray.addTest(
"Import the same ECDSA key multiple times and ensure that it can be used.",
function () {
function() {
var alg = { name: "ECDSA", namedCurve: "P-256", hash: "SHA-256" };
crypto.subtle.generateKey(alg, true, ["sign", "verify"])
.then(function(keyPair) {
@ -50,12 +50,12 @@ TestArray.addTest(
// means we can't factor out common code here.
TestArray.addTest(
"Import the same RSA key multiple times and ensure that it can be used.",
function () {
function() {
var alg = {
name: "RSASSA-PKCS1-v1_5",
modulusLength: 2048,
publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
hash: "SHA-256"
hash: "SHA-256",
};
crypto.subtle.generateKey(alg, true, ["sign", "verify"])
.then(function(keyPair) {
@ -82,7 +82,7 @@ TestArray.addTest(
}), error(this));
}
);
/*]]>*/</script>
/* ]]>*/</script>
</head>
<body>

Просмотреть файл

@ -19,13 +19,13 @@
<!-- General testing framework -->
<script src="./test-array.js"></script>
<script>/*<![CDATA[*/
<script>/* <![CDATA[*/
"use strict";
// -----------------------------------------------------------------------------
TestArray.addTest(
"JWK import and use of an AES-GCM key",
function () {
function() {
var that = this;
function doEncrypt(x) {
@ -34,12 +34,12 @@ TestArray.addTest(
name: "AES-GCM",
iv: tv.aes_gcm_enc.iv,
additionalData: tv.aes_gcm_enc.adata,
tagLength: 128
tagLength: 128,
},
x, tv.aes_gcm_enc.data);
}
crypto.subtle.importKey("jwk", tv.aes_gcm_enc.key_jwk, "AES-GCM", false, ['encrypt'])
crypto.subtle.importKey("jwk", tv.aes_gcm_enc.key_jwk, "AES-GCM", false, ["encrypt"])
.then(doEncrypt)
.then(
memcmp_complete(that, tv.aes_gcm_enc.result),
@ -51,7 +51,7 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"JWK import and use of an RSASSA-PKCS1-v1_5 private key",
function () {
function() {
var that = this;
var alg = { name: "RSASSA-PKCS1-v1_5", hash: "SHA-256" };
@ -60,7 +60,7 @@ TestArray.addTest(
}
function fail(x) { console.log(x); error(that); }
crypto.subtle.importKey("jwk", tv.rsassa.jwk_priv, alg, false, ['sign'])
crypto.subtle.importKey("jwk", tv.rsassa.jwk_priv, alg, false, ["sign"])
.then( doSign, fail )
.then( memcmp_complete(that, tv.rsassa.sig256), fail );
}
@ -69,7 +69,7 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"JWK import and use of an RSASSA-PKCS1-v1_5 public key",
function () {
function() {
var that = this;
var alg = { name: "RSASSA-PKCS1-v1_5", hash: "SHA-256" };
@ -78,7 +78,7 @@ TestArray.addTest(
}
function fail(x) { error(that); }
crypto.subtle.importKey("jwk", tv.rsassa.jwk_pub, alg, false, ['verify'])
crypto.subtle.importKey("jwk", tv.rsassa.jwk_pub, alg, false, ["verify"])
.then( doVerify, fail )
.then(
complete(that, function(x) { return x; }),
@ -89,7 +89,7 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"JWK import failure on incomplete RSA private key (missing 'qi')",
function () {
function() {
var that = this;
var alg = { name: "RSA-OAEP", hash: "SHA-256" };
var jwk = {
@ -103,7 +103,7 @@ TestArray.addTest(
dq: tv.rsassa.jwk_priv.dq,
};
crypto.subtle.importKey("jwk", jwk, alg, true, ['encrypt', 'decrypt'])
crypto.subtle.importKey("jwk", jwk, alg, true, ["encrypt", "decrypt"])
.then( error(that), complete(that) );
}
);
@ -111,12 +111,12 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"JWK import failure on algorithm mismatch",
function () {
function() {
var that = this;
var alg = "AES-GCM";
var jwk = { k: "c2l4dGVlbiBieXRlIGtleQ", alg: "A256GCM" };
crypto.subtle.importKey("jwk", jwk, alg, true, ['encrypt', 'decrypt'])
crypto.subtle.importKey("jwk", jwk, alg, true, ["encrypt", "decrypt"])
.then( error(that), complete(that) );
}
);
@ -124,12 +124,12 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"JWK import failure on usages mismatch",
function () {
function() {
var that = this;
var alg = "AES-GCM";
var jwk = { k: "c2l4dGVlbiBieXRlIGtleQ", key_ops: ['encrypt'] };
var jwk = { k: "c2l4dGVlbiBieXRlIGtleQ", key_ops: ["encrypt"] };
crypto.subtle.importKey("jwk", jwk, alg, true, ['encrypt', 'decrypt'])
crypto.subtle.importKey("jwk", jwk, alg, true, ["encrypt", "decrypt"])
.then( error(that), complete(that) );
}
);
@ -137,12 +137,12 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"JWK import failure on extractable mismatch",
function () {
function() {
var that = this;
var alg = "AES-GCM";
var jwk = { k: "c2l4dGVlbiBieXRlIGtleQ", ext: false };
crypto.subtle.importKey("jwk", jwk, alg, true, ['encrypt'])
crypto.subtle.importKey("jwk", jwk, alg, true, ["encrypt"])
.then( error(that), complete(that) );
}
);
@ -150,7 +150,7 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"JWK export of a symmetric key",
function () {
function() {
var that = this;
var alg = "AES-GCM";
var jwk = { k: "c2l4dGVlbiBieXRlIGtleQ", kty: "oct" };
@ -159,17 +159,17 @@ TestArray.addTest(
return crypto.subtle.exportKey("jwk", k);
}
crypto.subtle.importKey("jwk", jwk, alg, true, ['encrypt', 'decrypt'])
crypto.subtle.importKey("jwk", jwk, alg, true, ["encrypt", "decrypt"])
.then(doExport)
.then(
complete(that, function(x) {
return hasBaseJwkFields(x) &&
hasFields(x, ['k']) &&
x.kty == 'oct' &&
x.alg == 'A128GCM' &&
hasFields(x, ["k"]) &&
x.kty == "oct" &&
x.alg == "A128GCM" &&
x.ext &&
shallowArrayEquals(x.key_ops, ['encrypt','decrypt']) &&
x.k == jwk.k
shallowArrayEquals(x.key_ops, ["encrypt", "decrypt"]) &&
x.k == jwk.k;
}),
error(that)
);
@ -179,7 +179,7 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"JWK import/export of an RSA private key",
function () {
function() {
var jwk = tv.rsassa.jwk_priv;
var that = this;
@ -189,21 +189,21 @@ TestArray.addTest(
return crypto.subtle.exportKey("jwk", k);
}
crypto.subtle.importKey("jwk", jwk, alg, true, ['sign'])
crypto.subtle.importKey("jwk", jwk, alg, true, ["sign"])
.then(doExport)
.then(
complete(that, function(x) {
return hasBaseJwkFields(x) &&
hasFields(x, ['n', 'e', 'd', 'p', 'q', 'dp', 'dq', 'qi']) &&
x.kty == 'RSA' &&
x.alg == 'RS256' &&
hasFields(x, ["n", "e", "d", "p", "q", "dp", "dq", "qi"]) &&
x.kty == "RSA" &&
x.alg == "RS256" &&
x.ext &&
shallowArrayEquals(x.key_ops, ['sign']) &&
x.n == jwk.n &&
x.e == jwk.e &&
x.d == jwk.d &&
x.p == jwk.p &&
x.q == jwk.q &&
shallowArrayEquals(x.key_ops, ["sign"]) &&
x.n == jwk.n &&
x.e == jwk.e &&
x.d == jwk.d &&
x.p == jwk.p &&
x.q == jwk.q &&
x.dp == jwk.dp &&
x.dq == jwk.dq &&
x.qi == jwk.qi;
@ -216,7 +216,7 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"JWK import/export of an RSA private key where p < q",
function () {
function() {
var jwk = tv.rsassa.jwk_priv_pLTq;
var that = this;
@ -226,21 +226,21 @@ TestArray.addTest(
return crypto.subtle.exportKey("jwk", k);
}
crypto.subtle.importKey("jwk", jwk, alg, true, ['sign'])
crypto.subtle.importKey("jwk", jwk, alg, true, ["sign"])
.then(doExport)
.then(
complete(that, function(x) {
return hasBaseJwkFields(x) &&
hasFields(x, ['n', 'e', 'd', 'p', 'q', 'dp', 'dq', 'qi']) &&
x.kty == 'RSA' &&
x.alg == 'RS256' &&
hasFields(x, ["n", "e", "d", "p", "q", "dp", "dq", "qi"]) &&
x.kty == "RSA" &&
x.alg == "RS256" &&
x.ext &&
shallowArrayEquals(x.key_ops, ['sign']) &&
x.n == jwk.n &&
x.e == jwk.e &&
x.d == jwk.d &&
x.p == jwk.p &&
x.q == jwk.q &&
shallowArrayEquals(x.key_ops, ["sign"]) &&
x.n == jwk.n &&
x.e == jwk.e &&
x.d == jwk.d &&
x.p == jwk.p &&
x.q == jwk.q &&
x.dp == jwk.dp &&
x.dq == jwk.dq &&
x.qi == jwk.qi;
@ -253,7 +253,7 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"JWK export of an RSA public key",
function () {
function() {
var that = this;
var alg = { name: "RSASSA-PKCS1-v1_5", hash: "SHA-256" };
var jwk = tv.rsassa.jwk_pub;
@ -262,19 +262,19 @@ TestArray.addTest(
return crypto.subtle.exportKey("jwk", k);
}
crypto.subtle.importKey("jwk", jwk, alg, true, ['verify'])
crypto.subtle.importKey("jwk", jwk, alg, true, ["verify"])
.then(doExport)
.then(
complete(that, function(x) {
window.jwk_pub = x;
return hasBaseJwkFields(x) &&
hasFields(x, ['n', 'e']) &&
x.kty == 'RSA' &&
x.alg == 'RS256' &&
hasFields(x, ["n", "e"]) &&
x.kty == "RSA" &&
x.alg == "RS256" &&
x.ext &&
shallowArrayEquals(x.key_ops, ['verify']) &&
x.n == jwk.n &&
x.e == jwk.e;
shallowArrayEquals(x.key_ops, ["verify"]) &&
x.n == jwk.n &&
x.e == jwk.e;
}),
error(that)
);
@ -285,30 +285,30 @@ TestArray.addTest(
TestArray.addTest(
"Check JWK parameters on generated ECDSA key pair",
function() {
crypto.subtle.generateKey({name: 'ECDSA', namedCurve: 'P-256'}, true, ['sign', 'verify'])
crypto.subtle.generateKey({name: "ECDSA", namedCurve: "P-256"}, true, ["sign", "verify"])
.then(pair => Promise.all([
crypto.subtle.exportKey('jwk', pair.privateKey),
crypto.subtle.exportKey('jwk', pair.publicKey)
crypto.subtle.exportKey("jwk", pair.privateKey),
crypto.subtle.exportKey("jwk", pair.publicKey),
]))
.then(
complete(this, function(x) {
var priv = x[0];
var pub = x[1];
var pubIsSubsetOfPriv = Object.keys(pub)
.filter(k => k !== 'key_ops') // key_ops is the only complex attr
.filter(k => k !== "key_ops") // key_ops is the only complex attr
.reduce((all, k) => all && pub[k] === priv[k], true);
// Can't use hasBaseJwkFields() because EC keys don't get "alg":
// "alg" matches curve to hash, but WebCrypto keys are more flexible.
return hasFields(pub, ['kty', 'crv', 'key_ops', 'ext']) &&
pub.kty === 'EC' &&
pub.crv === 'P-256' &&
return hasFields(pub, ["kty", "crv", "key_ops", "ext"]) &&
pub.kty === "EC" &&
pub.crv === "P-256" &&
pub.ext &&
typeof(pub.x) === 'string' &&
typeof(pub.y) === 'string' &&
shallowArrayEquals(pub.key_ops, ['verify']) &&
typeof(pub.x) === "string" &&
typeof(pub.y) === "string" &&
shallowArrayEquals(pub.key_ops, ["verify"]) &&
pubIsSubsetOfPriv &&
shallowArrayEquals(priv.key_ops, ['sign']) &&
typeof(priv.d) === 'string';
shallowArrayEquals(priv.key_ops, ["sign"]) &&
typeof(priv.d) === "string";
}),
error(this));
}
@ -319,20 +319,20 @@ TestArray.addTest(
"Check key_ops parameter on an unusable RSA public key",
function() {
var parameters = {
name: 'RSASSA-PKCS1-v1_5',
name: "RSASSA-PKCS1-v1_5",
modulusLength: 1024,
publicExponent: new Uint8Array([1, 0, 1]),
hash: 'SHA-256'
hash: "SHA-256",
};
// The public key generated here will have no usages and will therefore
// have an empty key_ops list.
crypto.subtle.generateKey(parameters, true, ['sign'])
.then(pair => crypto.subtle.exportKey('jwk', pair.publicKey))
crypto.subtle.generateKey(parameters, true, ["sign"])
.then(pair => crypto.subtle.exportKey("jwk", pair.publicKey))
.then(complete(this, x => x.key_ops.length === 0),
error(this));
}
);
/*]]>*/</script>
/* ]]>*/</script>
</head>
<body>

Просмотреть файл

@ -19,7 +19,7 @@
<!-- General testing framework -->
<script src="./test-array.js"></script>
<script>/*<![CDATA[*/
<script>/* <![CDATA[*/
"use strict";
TestArray.addTest(
@ -38,7 +38,7 @@ TestArray.addTest(
name: "rsa-OAEP",
hash: "sha-1",
modulusLength: 2048,
publicExponent: new Uint8Array([0x01, 0x00, 0x01])
publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
};
return crypto.subtle.generateKey(alg, false, ["encrypt", "decrypt"]);
}
@ -56,7 +56,7 @@ TestArray.addTest(
}
);
/*]]>*/</script>
/* ]]>*/</script>
</head>
<body>

Просмотреть файл

@ -19,7 +19,7 @@
<!-- General testing framework -->
<script src="./test-array.js"></script>
<script>/*<![CDATA[*/
<script>/* <![CDATA[*/
"use strict";
// -----------------------------------------------------------------------------
@ -80,7 +80,7 @@ TestArray.addTest(
name: "PBKDF2",
hash: "SHA-1",
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);
}
@ -108,7 +108,7 @@ TestArray.addTest(
name: "PBKDF2",
hash: "SHA-1",
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);
}
@ -137,16 +137,16 @@ TestArray.addTest(
name: "PBKDF2",
hash: "SHA-1",
salt: tv.pbkdf2_sha1.salt,
iterations: tv.pbkdf2_sha1.iterations
iterations: tv.pbkdf2_sha1.iterations,
};
var algDerived = {
name: "HMAC",
hash: {name: "SHA-1"}
hash: {name: "SHA-1"},
};
return crypto.subtle.deriveKey(alg, x, algDerived, false, ["sign", "verify"])
.then(function (x) {
.then(function(x) {
if (!hasKeyFields(x)) {
throw "Invalid key; missing field(s)";
}
@ -163,7 +163,7 @@ TestArray.addTest(
var data = new Uint8Array(1024);
return crypto.subtle.sign("HMAC", x, data)
.then(function (sig) {
.then(function(sig) {
return crypto.subtle.verify("HMAC", x, sig, data);
});
}
@ -188,7 +188,7 @@ TestArray.addTest(
name: "PBKDF2",
hash: "SHA-1",
salt: tv.pbkdf2_sha1.salt,
iterations: tv.pbkdf2_sha1.iterations
iterations: tv.pbkdf2_sha1.iterations,
};
var algDerived = {name: "HMAC", hash: "SHA-1", length: 128};
@ -198,7 +198,7 @@ TestArray.addTest(
var password = crypto.getRandomValues(new Uint8Array(8));
crypto.subtle.importKey("raw", password, "PBKDF2", false, ["deriveKey"])
.then(doDerive)
.then(complete(that, function (x) {
.then(complete(that, function(x) {
return hasKeyFields(x) && x.algorithm.length == 128;
}), error(that));
}
@ -221,7 +221,7 @@ TestArray.addTest(
name: "PBKDF2",
hash: "SHA-256",
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);
}
@ -250,7 +250,7 @@ TestArray.addTest(
name: "PBKDF2",
hash: "SHA-256",
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);
}
@ -279,7 +279,7 @@ TestArray.addTest(
name: "PBKDF2",
hash: "SHA-256",
salt: new Uint8Array(0),
iterations: tv.pbkdf2_sha256_no_salt.iterations
iterations: tv.pbkdf2_sha256_no_salt.iterations,
};
return crypto.subtle.deriveBits(deriveAlg, x, tv.pbkdf2_sha256_no_salt.length);
}
@ -290,7 +290,7 @@ TestArray.addTest(
.then( memcmp_complete(that, tv.pbkdf2_sha256_no_salt.derived), fail );
}
);
/*]]>*/</script>
/* ]]>*/</script>
</head>
<body>

Просмотреть файл

@ -19,7 +19,7 @@
<!-- General testing framework -->
<script src="./test-array.js"></script>
<script>/*<![CDATA[*/
<script>/* <![CDATA[*/
"use strict";
// Generating 2048-bit keys takes some time.
@ -28,7 +28,7 @@ SimpleTest.requestLongerTimeout(2);
// -----------------------------------------------------------------------------
TestArray.addTest(
"RSA-OAEP encrypt/decrypt round-trip",
function () {
function() {
var that = this;
var privKey, pubKey;
var alg = {name: "RSA-OAEP", hash: "SHA-1"};
@ -44,10 +44,10 @@ TestArray.addTest(
}
Promise.all([
crypto.subtle.importKey("pkcs8", tv.rsaoaep.pkcs8, alg, false, ['decrypt'])
crypto.subtle.importKey("pkcs8", tv.rsaoaep.pkcs8, alg, false, ["decrypt"])
.then(setPriv, error(that)),
crypto.subtle.importKey("spki", tv.rsaoaep.spki, alg, false, ['encrypt'])
.then(setPub, error(that))
crypto.subtle.importKey("spki", tv.rsaoaep.spki, alg, false, ["encrypt"])
.then(setPub, error(that)),
]).then(doEncrypt, error(that))
.then(doDecrypt, error(that))
.then(
@ -60,13 +60,13 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"RSA-OAEP key generation and encrypt/decrypt round-trip (SHA-256)",
function () {
function() {
var that = this;
var alg = {
name: "RSA-OAEP",
hash: "SHA-256",
modulusLength: 2048,
publicExponent: new Uint8Array([0x01, 0x00, 0x01])
publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
};
var privKey, pubKey, data = crypto.getRandomValues(new Uint8Array(128));
@ -78,7 +78,7 @@ TestArray.addTest(
return crypto.subtle.decrypt(alg, privKey, x);
}
crypto.subtle.generateKey(alg, false, ['encrypt', 'decrypt'])
crypto.subtle.generateKey(alg, false, ["encrypt", "decrypt"])
.then(setKey, error(that))
.then(doEncrypt, error(that))
.then(doDecrypt, error(that))
@ -92,7 +92,7 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"RSA-OAEP decryption known answer",
function () {
function() {
var that = this;
var alg = {name: "RSA-OAEP", hash: "SHA-1"};
@ -101,7 +101,7 @@ TestArray.addTest(
}
function fail() { error(that); }
crypto.subtle.importKey("pkcs8", tv.rsaoaep.pkcs8, alg, false, ['decrypt'])
crypto.subtle.importKey("pkcs8", tv.rsaoaep.pkcs8, alg, false, ["decrypt"])
.then( doDecrypt, fail )
.then( memcmp_complete(that, tv.rsaoaep.data), fail );
}
@ -110,26 +110,26 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"RSA-OAEP input data length checks (2048-bit key)",
function () {
function() {
var that = this;
var privKey, pubKey;
var alg = {
name: "RSA-OAEP",
hash: "SHA-1",
modulusLength: 2048,
publicExponent: new Uint8Array([0x01, 0x00, 0x01])
publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
};
var privKey, pubKey;
function setKey(x) { pubKey = x.publicKey; privKey = x.privateKey; }
function doEncrypt(n) {
console.log("entered encrypt("+ n +")");
return function () {
console.log("entered encrypt(" + n + ")");
return function() {
return crypto.subtle.encrypt(alg, pubKey, new Uint8Array(n));
}
};
}
crypto.subtle.generateKey(alg, false, ['encrypt', 'decrypt'])
crypto.subtle.generateKey(alg, false, ["encrypt", "decrypt"])
.then(setKey, error(that))
.then(doEncrypt(214), error(that))
.then(doEncrypt(215), error(that))
@ -140,11 +140,11 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"RSA-OAEP key import with invalid hash",
function () {
function() {
var that = this;
var alg = {name: "RSA-OAEP", hash: "SHA-123"};
crypto.subtle.importKey("pkcs8", tv.rsaoaep.pkcs8, alg, false, ['decrypt'])
crypto.subtle.importKey("pkcs8", tv.rsaoaep.pkcs8, alg, false, ["decrypt"])
.then(error(that), complete(that));
}
);
@ -152,13 +152,13 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"Test that RSA-OAEP encrypt/decrypt accepts strings as AlgorithmIdentifiers",
function () {
function() {
var that = this;
var alg = {
name: "RSA-OAEP",
hash: "SHA-256",
modulusLength: 2048,
publicExponent: new Uint8Array([0x01, 0x00, 0x01])
publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
};
var privKey, pubKey, data = crypto.getRandomValues(new Uint8Array(128));
@ -177,7 +177,7 @@ TestArray.addTest(
.then(memcmp_complete(that, data), error(that));
}
);
/*]]>*/</script>
/* ]]>*/</script>
</head>
<body>

Просмотреть файл

@ -19,7 +19,7 @@
<!-- General testing framework -->
<script src="./test-array.js"></script>
<script>/*<![CDATA[*/
<script>/* <![CDATA[*/
"use strict";
// Generating 2048-bit keys takes some time.
@ -28,13 +28,13 @@ SimpleTest.requestLongerTimeout(2);
// -----------------------------------------------------------------------------
TestArray.addTest(
"RSA-PSS key generation (SHA-1, 1024-bit)",
function () {
function() {
var that = this;
var alg = {
name: "RSA-PSS",
hash: "SHA-1",
modulusLength: 1024,
publicExponent: new Uint8Array([0x01, 0x00, 0x01])
publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
};
crypto.subtle.generateKey(alg, false, ["sign", "verify"])
@ -45,13 +45,13 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"RSA-PSS key generation and sign/verify round-trip (SHA-256, 2048-bit)",
function () {
function() {
var that = this;
var alg = {
name: "RSA-PSS",
hash: "SHA-256",
modulusLength: 2048,
publicExponent: new Uint8Array([0x01, 0x00, 0x01])
publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
};
var privKey, pubKey;
@ -70,14 +70,14 @@ TestArray.addTest(
.then(setKey, error(that))
.then(doSign, error(that))
.then(doVerify, error(that))
.then(complete(that, x => x), error(that))
.then(complete(that, x => x), error(that));
}
);
// -----------------------------------------------------------------------------
TestArray.addTest(
"RSA-PSS verify known signature (SHA-1, 1024-bit)",
function () {
function() {
var that = this;
var alg = {name: "RSA-PSS", hash: "SHA-1"};
var vec = tv.rsapss;
@ -96,7 +96,7 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"Test invalid RSA-PSS signatures",
function () {
function() {
var that = this;
var alg = {name: "RSA-PSS", hash: "SHA-1"};
var vec = tv.rsapss;
@ -126,7 +126,7 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"RSA-PSS verify known signature (SHA-1, 1024-bit, JWK)",
function () {
function() {
var that = this;
var alg = {name: "RSA-PSS", hash: "SHA-1"};
@ -144,7 +144,7 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"RSA-PSS verify known signatures (SHA-1 to SHA-512, 1024-bit)",
function () {
function() {
var that = this;
function verifyCase(hash, tv) {
@ -165,7 +165,7 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"RSA-PSS import SPKI/PKCS#8 keys and sign/verify (SHA-1, 1024-bit)",
function () {
function() {
var that = this;
var alg = {name: "RSA-PSS", hash: "SHA-1"};
@ -196,7 +196,7 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"RSA-PSS import JWK keys and sign/verify (SHA-1, 1024-bit)",
function () {
function() {
var that = this;
var alg = {name: "RSA-PSS", hash: "SHA-1"};
@ -227,7 +227,7 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"RSA-PSS SPKI import/export (SHA-1, 1024-bit)",
function () {
function() {
var that = this;
var alg = {name: "RSA-PSS", hash: "SHA-1"};
@ -244,7 +244,7 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"RSA-PSS PKCS#8 import/export (SHA-1, 1024-bit)",
function () {
function() {
var that = this;
var alg = {name: "RSA-PSS", hash: "SHA-1"};
@ -261,7 +261,7 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"RSA-PSS JWK export a public key",
function () {
function() {
var that = this;
var alg = {name: "RSA-PSS", hash: "SHA-1"};
var jwk = tv.rsapss.jwk_pub;
@ -291,7 +291,7 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"RSA-PSS JWK export a private key",
function () {
function() {
var that = this;
var alg = {name: "RSA-PSS", hash: "SHA-1"};
var jwk = tv.rsapss.jwk_priv;
@ -327,13 +327,13 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"Deterministic RSA-PSS signatures with saltLength=0 (SHA-256, 2048-bit)",
function () {
function() {
var that = this;
var alg = {
name: "RSA-PSS",
hash: "SHA-256",
modulusLength: 2048,
publicExponent: new Uint8Array([0x01, 0x00, 0x01])
publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
};
var privKey, pubKey;
@ -344,7 +344,7 @@ TestArray.addTest(
var alg = {name: "RSA-PSS", saltLength: 0};
return Promise.all([
crypto.subtle.sign(alg, privKey, data),
crypto.subtle.sign(alg, privKey, data)
crypto.subtle.sign(alg, privKey, data),
]);
}
@ -364,10 +364,10 @@ TestArray.addTest(
return sig1;
}, error(that))
.then(doVerify, error(that))
.then(complete(that, x => x), error(that))
.then(complete(that, x => x), error(that));
}
);
/*]]>*/</script>
/* ]]>*/</script>
</head>
<body>

Просмотреть файл

@ -19,7 +19,7 @@
<!-- General testing framework -->
<script src="./test-array.js"></script>
<script>/*<![CDATA[*/
<script>/* <![CDATA[*/
"use strict";
// Generating 2048-bit keys takes some time.
@ -33,23 +33,23 @@ TestArray.addTest(
name: "RSA-OAEP",
hash: "SHA-256",
modulusLength: 2048,
publicExponent: new Uint8Array([0x01, 0x00, 0x01])
publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
};
function generateKey(usages) {
return crypto.subtle.generateKey(alg, false, usages);
}
generateKey(["encrypt", "decrypt"]).then(function () {
generateKey(["encrypt", "decrypt"]).then(function() {
return generateKey(["encrypt"]);
}).then(function () {
}).then(function() {
return generateKey(["decrypt"]);
}).then(function () {
return generateKey(["sign"])
}).then(function() {
return generateKey(["sign"]);
}, error(that)).then(error(that), complete(that));
}
);
/*]]>*/</script>
/* ]]>*/</script>
</head>
<body>

Просмотреть файл

@ -19,7 +19,7 @@
<!-- General testing framework -->
<script src="./test-array.js"></script>
<script>/*<![CDATA[*/
<script>/* <![CDATA[*/
"use strict";
// -----------------------------------------------------------------------------
@ -113,7 +113,7 @@ TestArray.addTest(
name: "PBKDF2",
hash: "SHA-1",
salt: crypto.getRandomValues(new Uint8Array(8)),
iterations: 4096
iterations: 4096,
};
crypto.subtle.importKey("raw", key, "PBKDF2", true, ["deriveBits"])
@ -134,7 +134,7 @@ TestArray.addTest(
name: "HKDF",
hash: "SHA-256",
salt: new Uint8Array(),
info: new Uint8Array()
info: new Uint8Array(),
};
crypto.subtle.importKey("raw", key, "HKDF", false, ["deriveBits"])
@ -155,7 +155,7 @@ TestArray.addTest(
name: "RSA-OAEP",
hash: "SHA-256",
modulusLength: 2048,
publicExponent: new Uint8Array([1, 0, 1])
publicExponent: new Uint8Array([1, 0, 1]),
};
crypto.subtle.generateKey(alg, true, ["encrypt", "decrypt"])
@ -179,7 +179,7 @@ TestArray.addTest(
name: "RSASSA-PKCS1-v1_5",
hash: "SHA-256",
modulusLength: 2048,
publicExponent: new Uint8Array([1, 0, 1])
publicExponent: new Uint8Array([1, 0, 1]),
};
crypto.subtle.generateKey(alg, true, ["sign", "verify"])
@ -204,7 +204,7 @@ TestArray.addTest(
hash: "SHA-256",
modulusLength: 2048,
publicExponent: new Uint8Array([1, 0, 1]),
saltLength: 20
saltLength: 20,
};
crypto.subtle.generateKey(alg, true, ["sign", "verify"])
@ -218,7 +218,7 @@ TestArray.addTest(
);
// -----------------------------------------------------------------------------
/*TestArray.addTest(
/* TestArray.addTest(
"Structured Cloning: DH",
function() {
var that = this;
@ -235,7 +235,7 @@ TestArray.addTest(
);*/
// -----------------------------------------------------------------------------
/*TestArray.addTest(
/* TestArray.addTest(
"Structured Cloning: ECDH",
function() {
var that = this;
@ -252,7 +252,7 @@ TestArray.addTest(
);*/
// -----------------------------------------------------------------------------
/*TestArray.addTest(
/* TestArray.addTest(
"Structured Cloning: ECDSA",
function() {
var that = this;
@ -268,7 +268,7 @@ TestArray.addTest(
.then(complete(that), error(that));
}
);*/
/*]]>*/</script>
/* ]]>*/</script>
</head>
<body>

Просмотреть файл

@ -19,13 +19,13 @@
<!-- General testing framework -->
<script src="./test-array.js"></script>
<script>/*<![CDATA[*/
<script>/* <![CDATA[*/
"use strict";
// -----------------------------------------------------------------------------
TestArray.addTest(
"Send a CryptoKey to a Worker and use it to encrypt data",
function () {
function() {
var worker = new Worker(`data:text/plain,
onmessage = ({data: {key, data, nonce}}) => {
var alg = { name: "AES-GCM", iv: nonce };
@ -56,7 +56,7 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"Get a CryptoKey from a Worker and encrypt/decrypt data",
function () {
function() {
var worker = new Worker(`data:text/plain,
var alg = { name: "AES-GCM", length: 128 };
crypto.subtle.generateKey(alg, false, ["encrypt", "decrypt"])
@ -83,7 +83,7 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"Web crypto in terminating Worker",
function () {
function() {
var worker = new Worker(`data:text/plain,
function infiniteEncrypt(key, data, nonce) {
var alg = { name: "AES-GCM", iv: nonce };
@ -122,7 +122,7 @@ TestArray.addTest(
});
}
);
/*]]>*/</script>
/* ]]>*/</script>
</head>
<body>

Просмотреть файл

@ -19,25 +19,25 @@
<!-- General testing framework -->
<script src="./test-array.js"></script>
<script>/*<![CDATA[*/
<script>/* <![CDATA[*/
"use strict";
// -----------------------------------------------------------------------------
TestArray.addTest(
"Key wrap known answer, using AES-GCM",
function () {
function() {
var that = this;
var alg = {
name: "AES-GCM",
iv: tv.key_wrap_known_answer.wrapping_iv,
tagLength: 128
tagLength: 128,
};
var key, wrappingKey;
function doImport(k) {
wrappingKey = k;
return crypto.subtle.importKey("raw", tv.key_wrap_known_answer.key,
alg, true, ['encrypt', 'decrypt']);
alg, true, ["encrypt", "decrypt"]);
}
function doWrap(k) {
key = k;
@ -45,7 +45,7 @@ TestArray.addTest(
}
crypto.subtle.importKey("raw", tv.key_wrap_known_answer.wrapping_key,
alg, false, ['wrapKey'])
alg, false, ["wrapKey"])
.then(doImport, error(that))
.then(doWrap, error(that))
.then(
@ -58,19 +58,19 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"Key wrap failing on non-extractable key",
function () {
function() {
var that = this;
var alg = {
name: "AES-GCM",
iv: tv.key_wrap_known_answer.wrapping_iv,
tagLength: 128
tagLength: 128,
};
var key, wrappingKey;
function doImport(k) {
wrappingKey = k;
return crypto.subtle.importKey("raw", tv.key_wrap_known_answer.key,
alg, false, ['encrypt', 'decrypt']);
alg, false, ["encrypt", "decrypt"]);
}
function doWrap(k) {
key = k;
@ -78,7 +78,7 @@ TestArray.addTest(
}
crypto.subtle.importKey("raw", tv.key_wrap_known_answer.wrapping_key,
alg, false, ['wrapKey'])
alg, false, ["wrapKey"])
.then(doImport, error(that))
.then(doWrap, error(that))
.then(
@ -91,12 +91,12 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"Key unwrap known answer, using AES-GCM",
function () {
function() {
var that = this;
var alg = {
name: "AES-GCM",
iv: tv.key_wrap_known_answer.wrapping_iv,
tagLength: 128
tagLength: 128,
};
var key, wrappingKey;
@ -105,7 +105,7 @@ TestArray.addTest(
return crypto.subtle.unwrapKey(
"raw", tv.key_wrap_known_answer.wrapped_key,
wrappingKey, alg,
"AES-GCM", true, ['encrypt', 'decrypt']
"AES-GCM", true, ["encrypt", "decrypt"]
);
}
function doExport(k) {
@ -113,7 +113,7 @@ TestArray.addTest(
}
crypto.subtle.importKey("raw", tv.key_wrap_known_answer.wrapping_key,
alg, false, ['unwrapKey'])
alg, false, ["unwrapKey"])
.then(doUnwrap, error(that))
.then(doExport, error(that))
.then(
@ -126,17 +126,17 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"Key wrap/unwrap round-trip, using RSA-OAEP",
function () {
function() {
var that = this;
var oaep = {
name: "RSA-OAEP",
hash: "SHA-256"
hash: "SHA-256",
};
var gcm = {
name: "AES-GCM",
iv: tv.aes_gcm_enc.iv,
additionalData: tv.aes_gcm_enc.adata,
tagLength: 128
tagLength: 128,
};
var unwrapKey;
@ -148,7 +148,7 @@ TestArray.addTest(
}
function doUnwrap(wrappedKey) {
return crypto.subtle.unwrapKey("raw", wrappedKey, unwrapKey, oaep,
gcm, false, ['encrypt']);
gcm, false, ["encrypt"]);
}
function doEncrypt(aesKey) {
return crypto.subtle.encrypt(gcm, aesKey, tv.aes_gcm_enc.data);
@ -163,9 +163,9 @@ TestArray.addTest(
// 4. Compute HMAC
// 5. Check HMAC value
Promise.all([
crypto.subtle.importKey("raw", tv.aes_gcm_enc.key, gcm, true, ['encrypt']),
crypto.subtle.importKey("spki", tv.rsaoaep.spki, oaep, true, ['wrapKey']),
crypto.subtle.importKey("pkcs8", tv.rsaoaep.pkcs8, oaep, false, ['unwrapKey'])
crypto.subtle.importKey("raw", tv.aes_gcm_enc.key, gcm, true, ["encrypt"]),
crypto.subtle.importKey("spki", tv.rsaoaep.spki, oaep, true, ["wrapKey"]),
crypto.subtle.importKey("pkcs8", tv.rsaoaep.pkcs8, oaep, false, ["unwrapKey"]),
])
.then(doWrap, error(that))
.then(doUnwrap, error(that))
@ -180,7 +180,7 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"JWK wrap/unwrap round-trip, with AES-GCM",
function () {
function() {
var that = this;
var genAlg = { name: "HMAC", hash: "SHA-384", length: 512 };
var wrapAlg = { name: "AES-GCM", iv: tv.aes_gcm_enc.iv };
@ -195,17 +195,17 @@ TestArray.addTest(
function doUnwrap(wrappedKey) {
return crypto.subtle.unwrapKey("jwk", wrappedKey, wrapKey, wrapAlg,
{ name: "HMAC", hash: "SHA-384"},
true, ['sign', 'verify']);
true, ["sign", "verify"]);
}
Promise.all([
crypto.subtle.importKey("jwk", tv.aes_gcm_enc.key_jwk,
"AES-GCM", false, ['wrapKey','unwrapKey'])
"AES-GCM", false, ["wrapKey", "unwrapKey"])
.then(function(x) { wrapKey = x; }),
crypto.subtle.generateKey(genAlg, true, ['sign', 'verify'])
crypto.subtle.generateKey(genAlg, true, ["sign", "verify"])
.then(function(x) { originalKey = x; return x; })
.then(doExport)
.then(function(x) { originalKeyJwk = x; })
.then(function(x) { originalKeyJwk = x; }),
])
.then(doWrap)
.then(doUnwrap)
@ -222,7 +222,7 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"AES-KW known answer",
function () {
function() {
var that = this;
function doWrap(keys) {
@ -233,9 +233,9 @@ TestArray.addTest(
Promise.all([
crypto.subtle.importKey("jwk", tv.aes_kw.wrapping_key,
"AES-KW", false, ['wrapKey']),
"AES-KW", false, ["wrapKey"]),
crypto.subtle.importKey("jwk", tv.aes_kw.key,
"AES-GCM", true, ['encrypt'])
"AES-GCM", true, ["encrypt"]),
])
.then(doWrap)
.then(
@ -249,7 +249,7 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"AES-KW unwrap failure on tampered key data",
function () {
function() {
var that = this;
var tamperedWrappedKey = new Uint8Array(tv.aes_kw.wrapped_key);
tamperedWrappedKey[5] ^= 0xFF;
@ -257,11 +257,11 @@ TestArray.addTest(
function doUnwrap(wrapKey) {
return crypto.subtle.unwrapKey("raw", tamperedWrappedKey, wrapKey,
"AES-KW", "AES-GCM",
true, ['encrypt', 'decrypt']);
true, ["encrypt", "decrypt"]);
}
crypto.subtle.importKey("jwk", tv.aes_kw.wrapping_key,
"AES-KW", false, ['unwrapKey'])
"AES-KW", false, ["unwrapKey"])
.then(doUnwrap)
.then(error(that), complete(that));
}
@ -270,7 +270,7 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"AES-KW wrap/unwrap round-trip",
function () {
function() {
var that = this;
var genAlg = { name: "HMAC", hash: "SHA-384", length: 512 };
var wrapKey, originalKey, originalKeyJwk;
@ -284,17 +284,17 @@ TestArray.addTest(
function doUnwrap(wrappedKey) {
return crypto.subtle.unwrapKey("raw", wrappedKey, wrapKey,
"AES-KW", { name: "HMAC", hash: "SHA-384"},
true, ['sign', 'verify']);
true, ["sign", "verify"]);
}
Promise.all([
crypto.subtle.importKey("jwk", tv.aes_kw.wrapping_key,
"AES-KW", false, ['wrapKey','unwrapKey'])
"AES-KW", false, ["wrapKey", "unwrapKey"])
.then(function(x) { wrapKey = x; }),
crypto.subtle.generateKey(genAlg, true, ['sign'])
crypto.subtle.generateKey(genAlg, true, ["sign"])
.then(function(x) { originalKey = x; return x; })
.then(doExport)
.then(function(x) { originalKeyJwk = x; })
.then(function(x) { originalKeyJwk = x; }),
])
.then(doWrap)
.then(doUnwrap)
@ -311,7 +311,7 @@ TestArray.addTest(
// -----------------------------------------------------------------------------
TestArray.addTest(
"JWK unwrap attempt on bogus data should error out",
function () {
function() {
// Largely cribbed from the "JWK wrap/unwrap round-trip, with AES-GCM" test
var that = this;
var wrapAlg = { name: "AES-GCM", iv: tv.aes_gcm_enc.iv };
@ -324,11 +324,11 @@ TestArray.addTest(
function doUnwrap(wrappedKey) {
return crypto.subtle.unwrapKey("jwk", wrappedKey, wrapKey, wrapAlg,
{name: "HMAC", hash: "SHA-384"},
true, ['sign', 'verify']);
true, ["sign", "verify"]);
}
crypto.subtle.importKey("jwk", tv.aes_gcm_enc.key_jwk,
"AES-GCM", false, ['encrypt','unwrapKey'])
"AES-GCM", false, ["encrypt", "unwrapKey"])
.then(function(x) { wrapKey = x; })
.then(doBogusWrap, error(that))
.then(doUnwrap, error(that))
@ -339,7 +339,7 @@ TestArray.addTest(
}
);
/*]]>*/</script>
/* ]]>*/</script>
</head>
<body>

Просмотреть файл

@ -47,12 +47,12 @@
});
}
addEventListener("load", function () {
addEventListener("load", function() {
SpecialPowers.addPermission("browser", true, document);
SpecialPowers.pushPrefEnv({set: [
["dom.ipc.browser_frames.oop_by_default", true],
["dom.mozBrowserFramesEnabled", true],
["network.disable.ipc.security", true]
["network.disable.ipc.security", true],
]}, runTest);
});
</script>

Просмотреть файл

@ -11,7 +11,7 @@ var util = {
var yb = new Uint8Array(y);
if (x.byteLength !== y.byteLength) { return false; }
for (var i=0; i<xb.byteLength; ++i) {
for (var i = 0; i < xb.byteLength; ++i) {
if (xb[i] !== yb[i]) {
return false;
}
@ -23,7 +23,7 @@ var util = {
abv2hex: function util_abv2hex(abv) {
var b = new Uint8Array(abv);
var hex = "";
for (var i=0; i <b.length; ++i) {
for (var i = 0; i < b.length; ++i) {
var zeropad = (b[i] < 0x10) ? "0" : "";
hex += zeropad + b[i].toString(16);
}
@ -37,13 +37,13 @@ var util = {
}
var abv = new Uint8Array(hex.length / 2);
for (var i=0; i<abv.length; ++i) {
abv[i] = parseInt(hex.substr(2*i, 2), 16);
for (var i = 0; i < abv.length; ++i) {
abv[i] = parseInt(hex.substr(2 * i, 2), 16);
}
return abv;
},
clone: function (obj) {
clone(obj) {
return new Promise(resolve => {
let {port1, port2} = new MessageChannel();
@ -55,7 +55,7 @@ var util = {
});
},
cloneExportCompareKeys: function (key) {
cloneExportCompareKeys(key) {
return util.clone(key).then(clone => {
var exports = [];
@ -79,7 +79,7 @@ var util = {
return clone;
});
});
}
},
};
function exists(x) {
@ -89,7 +89,7 @@ function exists(x) {
function hasFields(object, fields) {
return fields
.map(x => exists(object[x]))
.reduce((x,y) => (x && y));
.reduce((x, y) => (x && y));
}
function hasKeyFields(x) {