Commit df32d58c authored by ap@apple.com's avatar ap@apple.com

Update WebCrypto tests

https://bugs.webkit.org/show_bug.cgi?id=124388

Reviewed by Anders Carlsson.

Updated tests for newer common.js. Changed some tests from just dumping results
to comparing them to known expected ones. Fixed a syntax error in
aes-cbc-invalid-length.html, so it now actually runs.

* crypto/subtle/resources/common.js: Update to a new version from Blink, because
it's much nicer than the old one, and it's good to be compatible at test level.
Moved crypto.subtle definition from webkitSubtle here to avoid repeating it in all
tests. Added a quick and dirty Promise.all implementation.

* crypto/subtle/aes-cbc-192-encrypt-decrypt-expected.txt:
* crypto/subtle/aes-cbc-192-encrypt-decrypt.html:
* crypto/subtle/aes-cbc-256-encrypt-decrypt-expected.txt:
* crypto/subtle/aes-cbc-256-encrypt-decrypt.html:
* crypto/subtle/aes-cbc-encrypt-decrypt-expected.txt:
* crypto/subtle/aes-cbc-encrypt-decrypt-with-padding-expected.txt:
* crypto/subtle/aes-cbc-encrypt-decrypt-with-padding.html:
* crypto/subtle/aes-cbc-encrypt-decrypt.html:
* crypto/subtle/aes-cbc-generate-key.html:
* crypto/subtle/aes-cbc-import-jwk-expected.txt:
* crypto/subtle/aes-cbc-import-jwk.html:
* crypto/subtle/aes-cbc-invalid-length-expected.txt:
* crypto/subtle/aes-cbc-invalid-length.html:
* crypto/subtle/aes-cbc-wrong-key-class.html:
* crypto/subtle/aes-export-key-expected.txt:
* crypto/subtle/aes-export-key.html:
* crypto/subtle/argument-conversion-expected.txt:
* crypto/subtle/argument-conversion.html:
* crypto/subtle/hmac-export-key-expected.txt:
* crypto/subtle/hmac-export-key.html:
* crypto/subtle/hmac-generate-key.html:
* crypto/subtle/hmac-import-jwk-expected.txt:
* crypto/subtle/hmac-import-jwk.html:
* crypto/subtle/hmac-sign-verify-empty-key-expected.txt:
* crypto/subtle/hmac-sign-verify-empty-key.html:
* crypto/subtle/hmac-sign-verify-expected.txt:
* crypto/subtle/hmac-sign-verify.html:
* crypto/subtle/import-jwk-expected.txt:
* crypto/subtle/import-jwk.html:
* crypto/subtle/rsassa-pkcs1-v1_5-generate-key-expected.txt:
* crypto/subtle/rsassa-pkcs1-v1_5-generate-key.html:
* crypto/subtle/rsassa-pkcs1-v1_5-import-jwk-expected.txt:
* crypto/subtle/rsassa-pkcs1-v1_5-import-jwk.html:
* crypto/subtle/rsassa-pkcs1-v1_5-sign-verify-expected.txt:
* crypto/subtle/rsassa-pkcs1-v1_5-sign-verify.html:
* crypto/subtle/sha-1-expected.txt:
* crypto/subtle/sha-1.html:
* crypto/subtle/sha-224-expected.txt:
* crypto/subtle/sha-224.html:
* crypto/subtle/sha-256-expected.txt:
* crypto/subtle/sha-256.html:
* crypto/subtle/sha-384-expected.txt:
* crypto/subtle/sha-384.html:
* crypto/subtle/sha-512-expected.txt:
* crypto/subtle/sha-512.html:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@159327 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent d9eb969a
2013-11-14 Alexey Proskuryakov <ap@apple.com>
Update WebCrypto tests
https://bugs.webkit.org/show_bug.cgi?id=124388
Reviewed by Anders Carlsson.
Updated tests for newer common.js. Changed some tests from just dumping results
to comparing them to known expected ones. Fixed a syntax error in
aes-cbc-invalid-length.html, so it now actually runs.
* crypto/subtle/resources/common.js: Update to a new version from Blink, because
it's much nicer than the old one, and it's good to be compatible at test level.
Moved crypto.subtle definition from webkitSubtle here to avoid repeating it in all
tests. Added a quick and dirty Promise.all implementation.
* crypto/subtle/aes-cbc-192-encrypt-decrypt-expected.txt:
* crypto/subtle/aes-cbc-192-encrypt-decrypt.html:
* crypto/subtle/aes-cbc-256-encrypt-decrypt-expected.txt:
* crypto/subtle/aes-cbc-256-encrypt-decrypt.html:
* crypto/subtle/aes-cbc-encrypt-decrypt-expected.txt:
* crypto/subtle/aes-cbc-encrypt-decrypt-with-padding-expected.txt:
* crypto/subtle/aes-cbc-encrypt-decrypt-with-padding.html:
* crypto/subtle/aes-cbc-encrypt-decrypt.html:
* crypto/subtle/aes-cbc-generate-key.html:
* crypto/subtle/aes-cbc-import-jwk-expected.txt:
* crypto/subtle/aes-cbc-import-jwk.html:
* crypto/subtle/aes-cbc-invalid-length-expected.txt:
* crypto/subtle/aes-cbc-invalid-length.html:
* crypto/subtle/aes-cbc-wrong-key-class.html:
* crypto/subtle/aes-export-key-expected.txt:
* crypto/subtle/aes-export-key.html:
* crypto/subtle/argument-conversion-expected.txt:
* crypto/subtle/argument-conversion.html:
* crypto/subtle/hmac-export-key-expected.txt:
* crypto/subtle/hmac-export-key.html:
* crypto/subtle/hmac-generate-key.html:
* crypto/subtle/hmac-import-jwk-expected.txt:
* crypto/subtle/hmac-import-jwk.html:
* crypto/subtle/hmac-sign-verify-empty-key-expected.txt:
* crypto/subtle/hmac-sign-verify-empty-key.html:
* crypto/subtle/hmac-sign-verify-expected.txt:
* crypto/subtle/hmac-sign-verify.html:
* crypto/subtle/import-jwk-expected.txt:
* crypto/subtle/import-jwk.html:
* crypto/subtle/rsassa-pkcs1-v1_5-generate-key-expected.txt:
* crypto/subtle/rsassa-pkcs1-v1_5-generate-key.html:
* crypto/subtle/rsassa-pkcs1-v1_5-import-jwk-expected.txt:
* crypto/subtle/rsassa-pkcs1-v1_5-import-jwk.html:
* crypto/subtle/rsassa-pkcs1-v1_5-sign-verify-expected.txt:
* crypto/subtle/rsassa-pkcs1-v1_5-sign-verify.html:
* crypto/subtle/sha-1-expected.txt:
* crypto/subtle/sha-1.html:
* crypto/subtle/sha-224-expected.txt:
* crypto/subtle/sha-224.html:
* crypto/subtle/sha-256-expected.txt:
* crypto/subtle/sha-256.html:
* crypto/subtle/sha-384-expected.txt:
* crypto/subtle/sha-384.html:
* crypto/subtle/sha-512-expected.txt:
* crypto/subtle/sha-512.html:
2013-11-14 Victor Costan <costan@gmail.com>
XMLSerializer escapes < > & correctly inside <script> and <style> tags.
......
......@@ -10,7 +10,7 @@ PASS key.algorithm.name is 'aes-cbc'
PASS key.algorithm.length is 192
PASS key.usages is ['encrypt', 'decrypt']
Using the key to encrypt plaintext...
PASS byteArrayToHexString(new Uint8Array(encryptionResult)) is '[4f 02 1d b2 43 bc 63 3d 71 78 18 3a 9f a0 71 e8 b4 d9 ad a9 ad 7d ed f4 e5 e7 38 76 3f 69 14 5a 57 1b 24 20 12 fb 7a e0 7f a9 ba ac 3d f1 02 e0 08 b0 e2 79 88 59 88 81 d9 20 a9 e6 4f 56 15 cd 61 2c cd 79 22 4b 35 09 35 d4 5d d6 a9 8f 81 76]'
PASS bytesToHexString(new Uint8Array(encryptionResult)) is '4f021db243bc633d7178183a9fa071e8b4d9ada9ad7dedf4e5e738763f69145a571b242012fb7ae07fa9baac3df102e008b0e27988598881d920a9e64f5615cd612ccd79224b350935d45dd6a98f8176'
Decrypting it back...
PASS new Uint8Array(decryptionResult) is plaintext
PASS successfullyParsed is true
......
......@@ -13,12 +13,9 @@ description("Test AES-CBC encrypt and decrypt functions with a 256 bit key.");
jsTestIsAsync = true;
if (!window.subtle)
window.crypto.subtle = window.crypto.webkitSubtle;
var keyData = hexToArrayBuffer("8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b");
var iv = hexToArrayBuffer("000102030405060708090a0b0c0d0e0f");
var plaintext = hexToArrayBuffer("6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc1191a0a52eff69f2445df4f9b17ad2b417be66c3710");
var keyData = hexStringToUint8Array("8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b");
var iv = hexStringToUint8Array("000102030405060708090a0b0c0d0e0f");
var plaintext = hexStringToUint8Array("6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc1191a0a52eff69f2445df4f9b17ad2b417be66c3710");
var extractable = true;
debug("Importing a raw AES key from string literal...");
......@@ -34,7 +31,7 @@ crypto.subtle.importKey("raw", keyData, "aes-cbc", extractable, ["encrypt", "dec
return crypto.subtle.encrypt({name: "aes-cbc", iv: iv}, key, [plaintext]);
}).then(function(result) {
encryptionResult = result;
shouldBe("byteArrayToHexString(new Uint8Array(encryptionResult))", "'[4f 02 1d b2 43 bc 63 3d 71 78 18 3a 9f a0 71 e8 b4 d9 ad a9 ad 7d ed f4 e5 e7 38 76 3f 69 14 5a 57 1b 24 20 12 fb 7a e0 7f a9 ba ac 3d f1 02 e0 08 b0 e2 79 88 59 88 81 d9 20 a9 e6 4f 56 15 cd 61 2c cd 79 22 4b 35 09 35 d4 5d d6 a9 8f 81 76]'");
shouldBe("bytesToHexString(new Uint8Array(encryptionResult))", "'4f021db243bc633d7178183a9fa071e8b4d9ada9ad7dedf4e5e738763f69145a571b242012fb7ae07fa9baac3df102e008b0e27988598881d920a9e64f5615cd612ccd79224b350935d45dd6a98f8176'");
debug("Decrypting it back...");
return crypto.subtle.decrypt({name: "aes-cbc", iv: iv}, key, [result]);
......
......@@ -10,7 +10,7 @@ PASS key.algorithm.name is 'aes-cbc'
PASS key.algorithm.length is 256
PASS key.usages is ['encrypt', 'decrypt']
Using the key to encrypt plaintext...
PASS byteArrayToHexString(new Uint8Array(encryptionResult)) is '[f5 8c 4c 04 d6 e5 f1 ba 77 9e ab fb 5f 7b fb d6 9c fc 4e 96 7e db 80 8d 67 9f 77 7b c6 70 2c 7d 39 f2 33 69 a9 d9 ba cf a5 30 e2 63 04 23 14 61 b2 eb 05 e2 c3 9b e9 fc da 6c 19 07 8c 6a 9d 1b 3f 46 17 96 d6 b0 d6 b2 e0 c2 a7 2b 4d 80 e6 44]'
PASS bytesToHexString(new Uint8Array(encryptionResult)) is 'f58c4c04d6e5f1ba779eabfb5f7bfbd69cfc4e967edb808d679f777bc6702c7d39f23369a9d9bacfa530e26304231461b2eb05e2c39be9fcda6c19078c6a9d1b3f461796d6b0d6b2e0c2a72b4d80e644'
Decrypting it back...
PASS new Uint8Array(decryptionResult) is plaintext
PASS successfullyParsed is true
......
......@@ -13,12 +13,9 @@ description("Test AES-CBC encrypt and decrypt functions with a 256 bit key.");
jsTestIsAsync = true;
if (!window.subtle)
window.crypto.subtle = window.crypto.webkitSubtle;
var keyData = hexToArrayBuffer("603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4");
var iv = hexToArrayBuffer("000102030405060708090a0b0c0d0e0f");
var plaintext = hexToArrayBuffer("6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc1191a0a52eff69f2445df4f9b17ad2b417be66c3710");
var keyData = hexStringToUint8Array("603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4");
var iv = hexStringToUint8Array("000102030405060708090a0b0c0d0e0f");
var plaintext = hexStringToUint8Array("6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc1191a0a52eff69f2445df4f9b17ad2b417be66c3710");
var extractable = true;
debug("Importing a raw AES key from string literal...");
......@@ -34,7 +31,7 @@ crypto.subtle.importKey("raw", keyData, "aes-cbc", extractable, ["encrypt", "dec
return crypto.subtle.encrypt({name: "aes-cbc", iv: iv}, key, [plaintext]);
}).then(function(result) {
encryptionResult = result;
shouldBe("byteArrayToHexString(new Uint8Array(encryptionResult))", "'[f5 8c 4c 04 d6 e5 f1 ba 77 9e ab fb 5f 7b fb d6 9c fc 4e 96 7e db 80 8d 67 9f 77 7b c6 70 2c 7d 39 f2 33 69 a9 d9 ba cf a5 30 e2 63 04 23 14 61 b2 eb 05 e2 c3 9b e9 fc da 6c 19 07 8c 6a 9d 1b 3f 46 17 96 d6 b0 d6 b2 e0 c2 a7 2b 4d 80 e6 44]'");
shouldBe("bytesToHexString(new Uint8Array(encryptionResult))", "'f58c4c04d6e5f1ba779eabfb5f7bfbd69cfc4e967edb808d679f777bc6702c7d39f23369a9d9bacfa530e26304231461b2eb05e2c39be9fcda6c19078c6a9d1b3f461796d6b0d6b2e0c2a72b4d80e644'");
debug("Decrypting it back...");
return crypto.subtle.decrypt({name: "aes-cbc", iv: iv}, key, [result]);
......
......@@ -10,7 +10,7 @@ PASS key.algorithm.name is 'aes-cbc'
PASS key.algorithm.length is 128
PASS key.usages is ['encrypt', 'decrypt']
Using the key to encrypt plaintext...
PASS byteArrayToHexString(new Uint8Array(encryptionResult)) is '[76 49 ab ac 81 19 b2 46 ce e9 8e 9b 12 e9 19 7d 50 86 cb 9b 50 72 19 ee 95 db 11 3a 91 76 78 b2 73 be d6 b8 e3 c1 74 3b 71 16 e6 9e 22 22 95 16 3f f1 ca a1 68 1f ac 09 12 0e ca 30 75 86 e1 a7 8c b8 28 07 23 0e 13 21 d3 fa e0 0d 18 cc 20 12]'
PASS bytesToHexString(new Uint8Array(encryptionResult)) is '7649abac8119b246cee98e9b12e9197d5086cb9b507219ee95db113a917678b273bed6b8e3c1743b7116e69e222295163ff1caa1681fac09120eca307586e1a78cb82807230e1321d3fae00d18cc2012'
Decrypting it back...
PASS new Uint8Array(decryptionResult) is plaintext
Testing initialization vector bindings...
......
......@@ -10,7 +10,7 @@ PASS key.algorithm.name is 'aes-cbc'
PASS key.algorithm.length is 128
PASS key.usages is ['encrypt', 'decrypt']
Using the key to encrypt plaintext...
= [63 01 99 c5 f2 02 cc 71 67 bb 84 c6 c7 2b 34 9d]
PASS bytesToHexString(new Uint8Array(cyphertext)) is '630199c5f202cc7167bb84c6c72b349d'
Decrypting it back...
PASS new Uint8Array(decryptionResult) is plaintext
PASS successfullyParsed is true
......
......@@ -13,12 +13,9 @@ description("Test AES-CBC encrypt and decrypt functions on a plaintext that is n
jsTestIsAsync = true;
if (!window.subtle)
window.crypto.subtle = window.crypto.webkitSubtle;
var keyData = hexToArrayBuffer("2b7e151628aed2a6abf7158809cf4f3c");
var iv = hexToArrayBuffer("000102030405060708090a0b0c0d0e0f");
var plaintext = asciiToArrayBuffer("test");
var keyData = hexStringToUint8Array("2b7e151628aed2a6abf7158809cf4f3c");
var iv = hexStringToUint8Array("000102030405060708090a0b0c0d0e0f");
var plaintext = asciiToUint8Array("test");
var extractable = true;
debug("Importing a raw AES key from string literal...");
......@@ -33,7 +30,8 @@ crypto.subtle.importKey("raw", keyData, "aes-cbc", extractable, ["encrypt", "dec
debug("Using the key to encrypt plaintext...");
return crypto.subtle.encrypt({name: "aes-cbc", iv: iv}, key, [plaintext]);
}).then(function(result) {
printAcceptedResult(result);
cyphertext = result;
shouldBe("bytesToHexString(new Uint8Array(cyphertext))", "'630199c5f202cc7167bb84c6c72b349d'");
debug("Decrypting it back...");
return crypto.subtle.decrypt({name: "aes-cbc", iv: iv}, key, [result]);
......
......@@ -13,12 +13,9 @@ description("Test AES-CBC encrypt and decrypt functions.");
jsTestIsAsync = true;
if (!window.subtle)
window.crypto.subtle = window.crypto.webkitSubtle;
var keyData = hexToArrayBuffer("2b7e151628aed2a6abf7158809cf4f3c");
var iv = hexToArrayBuffer("000102030405060708090a0b0c0d0e0f");
var plaintext = hexToArrayBuffer("6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc1191a0a52eff69f2445df4f9b17ad2b417be66c3710");
var keyData = hexStringToUint8Array("2b7e151628aed2a6abf7158809cf4f3c");
var iv = hexStringToUint8Array("000102030405060708090a0b0c0d0e0f");
var plaintext = hexStringToUint8Array("6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc1191a0a52eff69f2445df4f9b17ad2b417be66c3710");
var extractable = true;
debug("Importing a raw AES key from string literal...");
......@@ -34,7 +31,7 @@ crypto.subtle.importKey("raw", keyData, "aes-cbc", extractable, ["encrypt", "dec
return crypto.subtle.encrypt({name: "aes-cbc", iv: iv}, key, [plaintext]);
}).then(function(result) {
encryptionResult = result;
shouldBe("byteArrayToHexString(new Uint8Array(encryptionResult))", "'[76 49 ab ac 81 19 b2 46 ce e9 8e 9b 12 e9 19 7d 50 86 cb 9b 50 72 19 ee 95 db 11 3a 91 76 78 b2 73 be d6 b8 e3 c1 74 3b 71 16 e6 9e 22 22 95 16 3f f1 ca a1 68 1f ac 09 12 0e ca 30 75 86 e1 a7 8c b8 28 07 23 0e 13 21 d3 fa e0 0d 18 cc 20 12]'");
shouldBe("bytesToHexString(new Uint8Array(encryptionResult))", "'7649abac8119b246cee98e9b12e9197d5086cb9b507219ee95db113a917678b273bed6b8e3c1743b7116e69e222295163ff1caa1681fac09120eca307586e1a78cb82807230e1321d3fae00d18cc2012'");
debug("Decrypting it back...");
return crypto.subtle.decrypt({name: "aes-cbc", iv: iv}, key, [result]);
......
......@@ -13,9 +13,6 @@ description("Test generating an AES key using AES-CBC algorithm.");
jsTestIsAsync = true;
if (!window.subtle)
window.crypto.subtle = window.crypto.webkitSubtle;
var extractable = true;
shouldThrow('crypto.subtle.generateKey("aes-cbc", extractable, ["encrypt", "decrypt"])');
......
......@@ -12,7 +12,7 @@ PASS key.algorithm.length is 192
PASS key.usages is ["encrypt"]
Using the key to encrypt plaintext...
PASS byteArrayToHexString(new Uint8Array(encryptionResult)) is '[4f 02 1d b2 43 bc 63 3d 71 78 18 3a 9f a0 71 e8 b4 d9 ad a9 ad 7d ed f4 e5 e7 38 76 3f 69 14 5a 57 1b 24 20 12 fb 7a e0 7f a9 ba ac 3d f1 02 e0 08 b0 e2 79 88 59 88 81 d9 20 a9 e6 4f 56 15 cd 61 2c cd 79 22 4b 35 09 35 d4 5d d6 a9 8f 81 76]'
PASS bytesToHexString(new Uint8Array(encryptionResult)) is '4f021db243bc633d7178183a9fa071e8b4d9ada9ad7dedf4e5e738763f69145a571b242012fb7ae07fa9baac3df102e008b0e27988598881d920a9e64f5615cd612ccd79224b350935d45dd6a98f8176'
PASS successfullyParsed is true
TEST COMPLETE
......
......@@ -13,13 +13,10 @@ description("Test importing a JWK key for AES-CBC.");
jsTestIsAsync = true;
if (!window.subtle)
window.crypto.subtle = window.crypto.webkitSubtle;
var extractable = true;
var iv = hexToArrayBuffer("000102030405060708090a0b0c0d0e0f");
var plaintext = hexToArrayBuffer("6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc1191a0a52eff69f2445df4f9b17ad2b417be66c3710");
var iv = hexStringToUint8Array("000102030405060708090a0b0c0d0e0f");
var plaintext = hexStringToUint8Array("6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc1191a0a52eff69f2445df4f9b17ad2b417be66c3710");
var jwkKey = {
"kty": "oct",
......@@ -29,7 +26,7 @@ var jwkKey = {
"k": "jnOw99oOZFLIEPMrgJB55WL46tJSLGt7"
};
var jwkKeyAsArrayBuffer = asciiToArrayBuffer(JSON.stringify(jwkKey));
var jwkKeyAsArrayBuffer = asciiToUint8Array(JSON.stringify(jwkKey));
debug("Importing a key...\n");
crypto.subtle.importKey("jwk", jwkKeyAsArrayBuffer, null, false, ["encrypt"]).then(function(result) {
......@@ -45,7 +42,7 @@ crypto.subtle.importKey("jwk", jwkKeyAsArrayBuffer, null, false, ["encrypt"]).th
return crypto.subtle.encrypt({name: "aes-cbc", iv: iv}, key, [plaintext]);
}).then(function(result) {
encryptionResult = result;
shouldBe("byteArrayToHexString(new Uint8Array(encryptionResult))", "'[4f 02 1d b2 43 bc 63 3d 71 78 18 3a 9f a0 71 e8 b4 d9 ad a9 ad 7d ed f4 e5 e7 38 76 3f 69 14 5a 57 1b 24 20 12 fb 7a e0 7f a9 ba ac 3d f1 02 e0 08 b0 e2 79 88 59 88 81 d9 20 a9 e6 4f 56 15 cd 61 2c cd 79 22 4b 35 09 35 d4 5d d6 a9 8f 81 76]'");
shouldBe("bytesToHexString(new Uint8Array(encryptionResult))", "'4f021db243bc633d7178183a9fa071e8b4d9ada9ad7dedf4e5e738763f69145a571b242012fb7ae07fa9baac3df102e008b0e27988598881d920a9e64f5615cd612ccd79224b350935d45dd6a98f8176'");
finishJSTest();
});
</script>
......
CONSOLE MESSAGE: line 38: SyntaxError: Unexpected identifier 'finishJSTest'. Expected ')' to end a argument list.
FAIL successfullyParsed should be true (of type boolean). Was undefined (of type undefined).
Test an unsupported AES key length.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
Importing a raw AES key from string literal...
PASS key.type is 'secret'
PASS key.extractable is true
PASS key.algorithm.name is 'aes-cbc'
PASS key.algorithm.length is 176
PASS key.usages is ['encrypt', 'decrypt']
Using the key to encrypt plaintext...
Failed, as expected. Note that the spec doesn't appear to clearly define which step should fail.
PASS successfullyParsed is true
TEST COMPLETE
......@@ -13,12 +13,9 @@ description("Test an unsupported AES key length.");
jsTestIsAsync = true;
if (!window.subtle)
window.crypto.subtle = window.crypto.webkitSubtle;
var keyData = hexToArrayBuffer("8e73b0f7da0e6452c810f32b809079e562f8ead2522c");
var iv = hexToArrayBuffer("000102030405060708090a0b0c0d0e0f");
var plaintext = hexToArrayBuffer("6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc1191a0a52eff69f2445df4f9b17ad2b417be66c3710");
var keyData = hexStringToUint8Array("8e73b0f7da0e6452c810f32b809079e562f8ead2522c");
var iv = hexStringToUint8Array("000102030405060708090a0b0c0d0e0f");
var plaintext = hexStringToUint8Array("6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc1191a0a52eff69f2445df4f9b17ad2b417be66c3710");
var extractable = true;
debug("Importing a raw AES key from string literal...");
......@@ -33,7 +30,7 @@ crypto.subtle.importKey("raw", keyData, "aes-cbc", extractable, ["encrypt", "dec
debug("Using the key to encrypt plaintext...");
return crypto.subtle.encrypt({name: "aes-cbc", iv: iv}, key, [plaintext]);
}).then(undefined, function(result) {
debug("Failed, as expected. Note that the spec doesn't appear to clearly define which step should fail."
debug("Failed, as expected. Note that the spec doesn't appear to clearly define which step should fail.");
finishJSTest();
});
......
......@@ -13,12 +13,9 @@ description("Test calling AES-CBC encrypt with a HMAC key.");
jsTestIsAsync = true;
if (!window.subtle)
window.crypto.subtle = window.crypto.webkitSubtle;
var iv = hexToArrayBuffer("000102030405060708090a0b0c0d0e0f");
var plaintext = hexToArrayBuffer("6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc1191a0a52eff69f2445df4f9b17ad2b417be66c3710");
var hmacKey = asciiToArrayBuffer('a');
var iv = hexStringToUint8Array("000102030405060708090a0b0c0d0e0f");
var plaintext = hexStringToUint8Array("6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc1191a0a52eff69f2445df4f9b17ad2b417be66c3710");
var hmacKey = asciiToUint8Array('a');
var extractable = true;
debug("Importing a raw HMAC key from string literal...");
......
......@@ -5,7 +5,7 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE
Importing a JWK key...
Exporting the key as raw data...
PASS byteArrayToHexString(new Uint8Array(exportedData)) is '[8e 73 b0 f7 da 0e 64 52 c8 10 f3 2b 80 90 79 e5 62 f8 ea d2 52 2c 6b 7b]'
PASS bytesToHexString(new Uint8Array(exportedData)) is '8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b'
PASS successfullyParsed is true
TEST COMPLETE
......
......@@ -13,9 +13,6 @@ description("Test exporting an AES key.");
jsTestIsAsync = true;
if (!window.subtle)
window.crypto.subtle = window.crypto.webkitSubtle;
var extractable = true;
var jwkKey = {
......@@ -23,7 +20,7 @@ var jwkKey = {
"k": "jnOw99oOZFLIEPMrgJB55WL46tJSLGt7"
};
var jwkKeyAsArrayBuffer = asciiToArrayBuffer(JSON.stringify(jwkKey));
var jwkKeyAsArrayBuffer = asciiToUint8Array(JSON.stringify(jwkKey));
debug("Importing a JWK key...");
crypto.subtle.importKey("jwk", jwkKeyAsArrayBuffer, "AES-CBC", extractable, []).then(function(result) {
......@@ -33,7 +30,7 @@ crypto.subtle.importKey("jwk", jwkKeyAsArrayBuffer, "AES-CBC", extractable, []).
return crypto.subtle.exportKey("raw", key);
}).then(function(result) {
exportedData = result;
shouldBe("byteArrayToHexString(new Uint8Array(exportedData))", "'[8e 73 b0 f7 da 0e 64 52 c8 10 f3 2b 80 90 79 e5 62 f8 ea d2 52 2c 6b 7b]'");
shouldBe("bytesToHexString(new Uint8Array(exportedData))", "'8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b'");
finishJSTest();
});
......
......@@ -4,7 +4,7 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE
SHA1 of new Uint8Array([]))
= [da 39 a3 ee 5e 6b 4b 0d 32 55 bf ef 95 60 18 90 af d8 07 09]
PASS bytesToHexString(new Uint8Array(digest)) is 'da39a3ee5e6b4b0d3255bfef95601890afd80709'
Passing algorithm name as a string object...
PASS ...succeeded
......
......@@ -13,16 +13,15 @@ description("Test crypto.subtle argument conversion");
jsTestIsAsync = true;
if (!window.subtle)
window.crypto.subtle = window.crypto.webkitSubtle;
Promise.fulfill(null).then(function() {
// This looks like invalid input, but it actually isn't - Uint8Array is a sequence too,
// so it's just an empty sequence, same as passing [].
debug("SHA1 of new Uint8Array([]))");
return crypto.subtle.digest('sha-1', new Uint8Array([]));
}).then(function(result) {
printAcceptedResult(result);
digest = result;
shouldBe("bytesToHexString(new Uint8Array(digest))", "'da39a3ee5e6b4b0d3255bfef95601890afd80709'");
debug("\nPassing algorithm name as a string object...");
return crypto.subtle.digest(new String('sha-1'), []);
}).then(function(result) {
......
......@@ -5,7 +5,7 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE
Importing a JWK key...
Exporting the key as raw data...
PASS byteArrayToHexString(new Uint8Array(exportedData)) is '[6a 18 e4 9f ef f7 f3 b7 e0 9e c8 9b 7f 6d ea b2 f6 a1 8e 49 fe ff 7f 3b 7e 09 ec 89 b7 f6 de ab]'
PASS bytesToHexString(new Uint8Array(exportedData)) is '6a18e49feff7f3b7e09ec89b7f6deab2f6a18e49feff7f3b7e09ec89b7f6deab'
PASS successfullyParsed is true
TEST COMPLETE
......
......@@ -13,9 +13,6 @@ description("Test exporting an AES key.");
jsTestIsAsync = true;
if (!window.subtle)
window.crypto.subtle = window.crypto.webkitSubtle;
var extractable = true;
var jwkKey = {
......@@ -23,7 +20,7 @@ var jwkKey = {
"k": "ahjkn-_387fgnsibf23qsvahjkn-_387fgnsibf23qs"
};
var jwkKeyAsArrayBuffer = asciiToArrayBuffer(JSON.stringify(jwkKey));
var jwkKeyAsArrayBuffer = asciiToUint8Array(JSON.stringify(jwkKey));
debug("Importing a JWK key...");
crypto.subtle.importKey("jwk", jwkKeyAsArrayBuffer, { name: "HMAC", hash: "SHA-512" }, extractable, ["sign", "verify"]).then(function(result) {
......@@ -33,7 +30,7 @@ crypto.subtle.importKey("jwk", jwkKeyAsArrayBuffer, { name: "HMAC", hash: "SHA-5
return crypto.subtle.exportKey("raw", key);
}).then(function(result) {
exportedData = result;
shouldBe("byteArrayToHexString(new Uint8Array(exportedData))", "'[6a 18 e4 9f ef f7 f3 b7 e0 9e c8 9b 7f 6d ea b2 f6 a1 8e 49 fe ff 7f 3b 7e 09 ec 89 b7 f6 de ab]'");
shouldBe("bytesToHexString(new Uint8Array(exportedData))", "'6a18e49feff7f3b7e09ec89b7f6deab2f6a18e49feff7f3b7e09ec89b7f6deab'");
finishJSTest();
});
......
......@@ -13,9 +13,6 @@ description("Test generating a HMAC key.");
jsTestIsAsync = true;
if (!window.subtle)
window.crypto.subtle = window.crypto.webkitSubtle;
var extractable = true;
shouldThrow('crypto.subtle.generateKey("hmac", extractable, ["sign", "verify"])');
......
......@@ -12,7 +12,7 @@ PASS key.algorithm.length is 32
PASS key.usages is ["sign", "verify"]
Using the key to sign message 'foo'...
PASS byteArrayToHexString(new Uint8Array(signature)) is '[e0 37 36 fe 09 88 92 b2 a2 da 77 81 24 31 f7 c0 14 d3 2e 2f d6 9f 3b cf f8 83 ac 92 3a 8f a2 da]'
PASS bytesToHexString(new Uint8Array(signature)) is 'e03736fe098892b2a2da77812431f7c014d32e2fd69f3bcff883ac923a8fa2da'
Verifying the signature...
PASS verificationResult is true
......
......@@ -13,9 +13,6 @@ description("Test importing a JWK key for HMAC.");
jsTestIsAsync = true;
if (!window.subtle)
window.crypto.subtle = window.crypto.webkitSubtle;
var extractable = true;
var hmacKey = {
......@@ -26,7 +23,7 @@ var hmacKey = {
"k": "ahjkn-_387fgnsibf23qsvahjkn-_387fgnsibf23qs"
};
var hmacKeyAsArrayBuffer = asciiToArrayBuffer(JSON.stringify(hmacKey));
var hmacKeyAsArrayBuffer = asciiToUint8Array(JSON.stringify(hmacKey));
debug("Importing a key...\n");
crypto.subtle.importKey("jwk", hmacKeyAsArrayBuffer, null, extractable, ["sign", "verify"]).then(function(result) {
......@@ -39,13 +36,13 @@ crypto.subtle.importKey("jwk", hmacKeyAsArrayBuffer, null, extractable, ["sign",
shouldBe("key.usages", '["sign", "verify"]');
debug("\nUsing the key to sign message 'foo'...");
return crypto.subtle.sign(key.algorithm, key, [asciiToArrayBuffer('foo')]);
return crypto.subtle.sign(key.algorithm, key, [asciiToUint8Array('foo')]);
}).then(function(result) {
signature = result;
shouldBe("byteArrayToHexString(new Uint8Array(signature))", "'[e0 37 36 fe 09 88 92 b2 a2 da 77 81 24 31 f7 c0 14 d3 2e 2f d6 9f 3b cf f8 83 ac 92 3a 8f a2 da]'");
shouldBe("bytesToHexString(new Uint8Array(signature))", "'e03736fe098892b2a2da77812431f7c014d32e2fd69f3bcff883ac923a8fa2da'");
debug("\nVerifying the signature...");
return crypto.subtle.verify(key.algorithm, key, result, [asciiToArrayBuffer('foo')]);
return crypto.subtle.verify(key.algorithm, key, result, [asciiToUint8Array('foo')]);
}).then(function(result) {
verificationResult = result;
shouldBe("verificationResult", "true");
......
......@@ -11,7 +11,7 @@ PASS key.algorithm.length is 0
PASS key.algorithm.hash.name is 'sha-1'
PASS key.usages is ['sign', 'verify']
Using the key to sign 'foo'...
PASS byteArrayToHexString(new Uint8Array(signature)) is '[a3 cc 77 0f c0 33 e2 cb 41 9d 42 b6 4e 00 81 a3 bd 3b e3 0e]'
PASS bytesToHexString(new Uint8Array(signature)) is 'a3cc770fc033e2cb419d42b64e0081a3bd3be30e'
Verifying the signature...
PASS verificationResult is true
PASS successfullyParsed is true
......
......@@ -13,10 +13,7 @@ description("Test HMAC sign and verify functions with an empty key.");
jsTestIsAsync = true;
if (!window.subtle)
window.crypto.subtle = window.crypto.webkitSubtle;
var hmacKey = asciiToArrayBuffer('');
var hmacKey = asciiToUint8Array('');
var extractable = true;
debug("Importing a raw HMAC key from string literal...");
......@@ -30,13 +27,13 @@ crypto.subtle.importKey("raw", hmacKey, {name: 'hmac', hash: {name: 'sha-1'}}, e
shouldBe("key.usages", "['sign', 'verify']");
debug("Using the key to sign 'foo'...");
return crypto.subtle.sign(key.algorithm, key, [asciiToArrayBuffer('foo')]);
return crypto.subtle.sign(key.algorithm, key, [asciiToUint8Array('foo')]);
}).then(function(result) {
signature = result;
shouldBe("byteArrayToHexString(new Uint8Array(signature))", "'[a3 cc 77 0f c0 33 e2 cb 41 9d 42 b6 4e 00 81 a3 bd 3b e3 0e]'");
shouldBe("bytesToHexString(new Uint8Array(signature))", "'a3cc770fc033e2cb419d42b64e0081a3bd3be30e'");
debug("Verifying the signature...");
return crypto.subtle.verify(key.algorithm, key, result, [asciiToArrayBuffer('foo')]);
return crypto.subtle.verify(key.algorithm, key, result, [asciiToUint8Array('foo')]);
}).then(function(result) {
verificationResult = result;
shouldBe("verificationResult", "true");
......
......@@ -11,7 +11,7 @@ PASS key.algorithm.length is 1
PASS key.algorithm.hash.name is 'sha-1'
PASS key.usages is ['sign', 'verify']
Using the key to sign 'foo'...
= [be bb c0 2e 46 b0 f8 11 83 f4 0c 25 dc e2 3e 50 45 d6 55 19]
PASS bytesToHexString(new Uint8Array(signature)) is 'bebbc02e46b0f81183f40c25dce23e5045d65519'
Verifying the signature...
PASS verificationResult is true
PASS successfullyParsed is true
......
......@@ -13,10 +13,7 @@ description("Test HMAC sign and verify functions.");
jsTestIsAsync = true;
if (!window.subtle)
window.crypto.subtle = window.crypto.webkitSubtle;
var hmacKey = asciiToArrayBuffer('a');
var hmacKey = asciiToUint8Array('a');
var extractable = true;
debug("Importing a raw HMAC key from string literal...");
......@@ -30,12 +27,13 @@ crypto.subtle.importKey("raw", hmacKey, {name: 'hmac', hash: {name: 'sha-1'}}, e
shouldBe("key.usages", "['sign', 'verify']");
debug("Using the key to sign 'foo'...");
return crypto.subtle.sign(key.algorithm, key, [asciiToArrayBuffer('foo')]);
return crypto.subtle.sign(key.algorithm, key, [asciiToUint8Array('foo')]);
}).then(function(result) {
printAcceptedResult(result);
signature = result;
shouldBe("bytesToHexString(new Uint8Array(signature))", "'bebbc02e46b0f81183f40c25dce23e5045d65519'");
debug("Verifying the signature...");
return crypto.subtle.verify(key.algorithm, key, result, [asciiToArrayBuffer('foo')]);
return crypto.subtle.verify(key.algorithm, key, result, [asciiToUint8Array('foo')]);
}).then(function(result) {
verificationResult = result;
shouldBe("verificationResult", "true");
......
......@@ -3,27 +3,27 @@ Test error handling for JWK import.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS crypto.subtle.importKey("jwk", asciiToArrayBuffer(''), null) threw exception TypeError: Invalid JWK serialization.
PASS crypto.subtle.importKey("jwk", asciiToArrayBuffer('{'), null) threw exception TypeError: Invalid JWK serialization.
PASS crypto.subtle.importKey("jwk", asciiToArrayBuffer('null'), null) threw exception TypeError: Invalid JWK serialization.
PASS crypto.subtle.importKey("jwk", asciiToArrayBuffer('undefined'), null) threw exception TypeError: Invalid JWK serialization.
PASS crypto.subtle.importKey("jwk", asciiToArrayBuffer('{}'), null) threw exception TypeError: Neither key nor function argument has crypto algorithm specified.
PASS crypto.subtle.importKey("jwk", asciiToArrayBuffer('{}'), "aes-cbc") threw exception TypeError: Required JWK "kty" member is missing.
PASS crypto.subtle.importKey("jwk", asciiToArrayBuffer('{ "kty": "foobar", "alg": "HS256", "use": "sig", "k": "ahjkn23387fgnsibf23qsvahjkn37387fgnsibf23qs" }'), null) threw exception TypeError: Unsupported JWK key type foobar.
PASS crypto.subtle.importKey("jwk", asciiToArrayBuffer('{ "kty": "oct", "alg": "foobar", "use": "sig", "k": "ahjkn23387fgnsibf23qsvahjkn37387fgnsibf23qs" }'), null) threw exception TypeError: Unsupported JWK algorithm foobar.
PASS crypto.subtle.importKey("jwk", asciiToArrayBuffer('{ "kty": "oct", "alg": "HS256", "use": "sig", "extractable": false, "k": "ahjkn23387fgnsibf23qsvahjkn37387fgnsibf23qs" }'), "aes-cbc") threw exception TypeError: Algorithm specified in key is not compatible with one passed to importKey as argument.
PASS crypto.subtle.importKey("jwk", asciiToArrayBuffer('{ "kty": "oct", "alg": "HS256", "use": "sig", "extractable": false, "k": "ahjkn23387fgnsibf23qsvahjkn37387fgnsibf23qs" }'), { name: "hmac", hash: "sha-1" }) threw exception TypeError: Algorithm specified in key is not compatible with one passed to importKey as argument.
PASS crypto.subtle.importKey("jwk", asciiToArrayBuffer('{ "kty": "oct", "alg": "HS256" }'), null) threw exception TypeError: Secret key data is not present is JWK.
PASS crypto.subtle.importKey("jwk", asciiToArrayBuffer('{ "kty": "oct", "alg": "A128CBC" }'), null) threw exception TypeError: Secret key data is not present is JWK.
PASS crypto.subtle.importKey("jwk", asciiToArrayBuffer('{ "kty": "oct", "alg": "HS256", "use": "sig", "extractable": false, "k": "1234" }'), null) threw exception TypeError: Key size is not valid for HS256.
PASS crypto.subtle.importKey("jwk", asciiToArrayBuffer('{ "kty": "oct", "alg": "A128CBC", "use": "sig", "extractable": false, "k": "1234" }'), null) threw exception TypeError: Key size is not valid for A128CBC.
PASS crypto.subtle.importKey("jwk", asciiToArrayBuffer('{ "kty": "oct", "alg": "A128CBC", "use": "sig", "extractable": false, "k": "ahjkn23387fgnsibf23qsvahjkn37387fgnsibf23qs" }'), null) threw exception TypeError: Key size is not valid for A128CBC.
PASS crypto.subtle.importKey("jwk", asciiToArrayBuffer('{ "kty": "oct", "alg": "HS256", "use": "sig", "extractable": false, "k": "ahjkn23387f+nsibf23qsvahjkn37387fgnsibf23qs" }'), null) threw exception TypeError: Cannot decode base64url key data in JWK.
PASS crypto.subtle.importKey("jwk", asciiToArrayBuffer('{ "kty": 1, "alg": "HS256", "use": "sig", "extractable": false, "k": "ahjkn23387fgnsibf23qsvahjkn37387fgnsibf23qs" }'), null) threw exception TypeError: Expected a string value for "kty" JSON key.
PASS crypto.subtle.importKey("jwk", asciiToArrayBuffer('{ "kty": "oct", "alg": 1, "use": "sig", "extractable": false, "k": "ahjkn23387fgnsibf23qsvahjkn37387fgnsibf23qs" }'), null) threw exception TypeError: Expected a string value for "alg" JSON key.
PASS crypto.subtle.importKey("jwk", asciiToArrayBuffer('{ "kty": "oct", "alg": "HS256", "use": 1, "extractable": false, "k": "ahjkn23387fgnsibf23qsvahjkn37387fgnsibf23qs" }'), null) threw exception TypeError: Expected a string value for "use" JSON key.
PASS crypto.subtle.importKey("jwk", asciiToArrayBuffer('{ "kty": "oct", "alg": "HS256", "use": "sig", "extractable": "false", "k": "ahjkn23387fgnsibf23qsvahjkn37387fgnsibf23qs" }'), null) threw exception TypeError: Expected a boolean value for "extractable" JSON key.
PASS crypto.subtle.importKey("jwk", asciiToArrayBuffer('{ "kty": "oct", "alg": "HS256", "use": "sig", "extractable": false, "k": 1 }'), null) threw exception TypeError: Expected a string value for "k" JSON key.
PASS crypto.subtle.importKey("jwk", asciiToUint8Array(''), null) threw exception TypeError: Invalid JWK serialization.
PASS crypto.subtle.importKey("jwk", asciiToUint8Array('{'), null) threw exception TypeError: Invalid JWK serialization.
PASS crypto.subtle.importKey("jwk", asciiToUint8Array('null'), null) threw exception TypeError: Invalid JWK serialization.
PASS crypto.subtle.importKey("jwk", asciiToUint8Array('undefined'), null) threw exception TypeError: Invalid JWK serialization.
PASS crypto.subtle.importKey("jwk", asciiToUint8Array('{}'), null) threw exception TypeError: Neither key nor function argument has crypto algorithm specified.
PASS crypto.subtle.importKey("jwk", asciiToUint8Array('{}'), "aes-cbc") threw exception TypeError: Required JWK "kty" member is missing.
PASS crypto.subtle.importKey("jwk", asciiToUint8Array('{ "kty": "foobar", "alg": "HS256", "use": "sig", "k": "ahjkn23387fgnsibf23qsvahjkn37387fgnsibf23qs" }'), null) threw exception TypeError: Unsupported JWK key type foobar.
PASS crypto.subtle.importKey("jwk", asciiToUint8Array('{ "kty": "oct", "alg": "foobar", "use": "sig", "k": "ahjkn23387fgnsibf23qsvahjkn37387fgnsibf23qs" }'), null) threw exception TypeError: Unsupported JWK algorithm foobar.
PASS crypto.subtle.importKey("jwk", asciiToUint8Array('{ "kty": "oct", "alg": "HS256", "use": "sig", "extractable": false, "k": "ahjkn23387fgnsibf23qsvahjkn37387fgnsibf23qs" }'), "aes-cbc") threw exception TypeError: Algorithm specified in key is not compatible with one passed to importKey as argument.
PASS crypto.subtle.importKey("jwk", asciiToUint8Array('{ "kty": "oct", "alg": "HS256", "use": "sig", "extractable": false, "k": "ahjkn23387fgnsibf23qsvahjkn37387fgnsibf23qs" }'), { name: "hmac", hash: "sha-1" }) threw exception TypeError: Algorithm specified in key is not compatible with one passed to importKey as argument.
PASS crypto.subtle.importKey("jwk", asciiToUint8Array('{ "kty": "oct", "alg": "HS256" }'), null) threw exception TypeError: Secret key data is not present is JWK.
PASS crypto.subtle.importKey("jwk", asciiToUint8Array('{ "kty": "oct", "alg": "A128CBC" }'), null) threw exception TypeError: Secret key data is not present is JWK.
PASS crypto.subtle.importKey("jwk", asciiToUint8Array('{ "kty": "oct", "alg": "HS256", "use": "sig", "extractable": false, "k": "1234" }'), null) threw exception TypeError: Key size is not valid for HS256.
PASS crypto.subtle.importKey("jwk", asciiToUint8Array('{ "kty": "oct", "alg": "A128CBC", "use": "sig", "extractable": false, "k": "1234" }'), null) threw exception TypeError: Key size is not valid for A128CBC.
PASS crypto.subtle.importKey("jwk", asciiToUint8Array('{ "kty": "oct", "alg": "A128CBC", "use": "sig", "extractable": false, "k": "ahjkn23387fgnsibf23qsvahjkn37387fgnsibf23qs" }'), null) threw exception TypeError: Key size is not valid for A128CBC.
PASS crypto.subtle.importKey("jwk", asciiToUint8Array('{ "kty": "oct", "alg": "HS256", "use": "sig", "extractable": false, "k": "ahjkn23387f+nsibf23qsvahjkn37387fgnsibf23qs" }'), null) threw exception TypeError: Cannot decode base64url key data in JWK.
PASS crypto.subtle.importKey("jwk", asciiToUint8Array('{ "kty": 1, "alg": "HS256", "use": "sig", "extractable": false, "k": "ahjkn23387fgnsibf23qsvahjkn37387fgnsibf23qs" }'), null) threw exception TypeError: Expected a string value for "kty" JSON key.
PASS crypto.subtle.importKey("jwk", asciiToUint8Array('{ "kty": "oct", "alg": 1, "use": "sig", "extractable": false, "k": "ahjkn23387fgnsibf23qsvahjkn37387fgnsibf23qs" }'), null) threw exception TypeError: Expected a string value for "alg" JSON key.
PASS crypto.subtle.importKey("jwk", asciiToUint8Array('{ "kty": "oct", "alg": "HS256", "use": 1, "extractable": false, "k": "ahjkn23387fgnsibf23qsvahjkn37387fgnsibf23qs" }'), null) threw exception TypeError: Expected a string value for "use" JSON key.
PASS crypto.subtle.importKey("jwk", asciiToUint8Array('{ "kty": "oct", "alg": "HS256", "use": "sig", "extractable": "false", "k": "ahjkn23387fgnsibf23qsvahjkn37387fgnsibf23qs" }'), null) threw exception TypeError: Expected a boolean value for "extractable" JSON key.
PASS crypto.subtle.importKey("jwk", asciiToUint8Array('{ "kty": "oct", "alg": "HS256", "use": "sig", "extractable": false, "k": 1 }'), null) threw exception TypeError: Expected a string value for "k" JSON key.
PASS successfullyParsed is true
TEST COMPLETE
......
......@@ -11,44 +11,39 @@
<script>
description("Test error handling for JWK import.");
//jsTestIsAsync = true;
if (!window.subtle)
window.crypto.subtle = window.crypto.webkitSubtle;
shouldThrow('crypto.subtle.importKey("jwk", asciiToArrayBuffer(\'\'), null)')
shouldThrow('crypto.subtle.importKey("jwk", asciiToArrayBuffer(\'{\'), null)')
shouldThrow('crypto.subtle.importKey("jwk", asciiToArrayBuffer(\'null\'), null)')
shouldThrow('crypto.subtle.importKey("jwk", asciiToArrayBuffer(\'undefined\'), null)')
shouldThrow('crypto.subtle.importKey("jwk", asciiToArrayBuffer(\'{}\'), null)')
shouldThrow('crypto.subtle.importKey("jwk", asciiToArrayBuffer(\'{}\'), "aes-cbc")')
shouldThrow('crypto.subtle.importKey("jwk", asciiToUint8Array(\'\'), null)')
shouldThrow('crypto.subtle.importKey("jwk", asciiToUint8Array(\'{\'), null)')
shouldThrow('crypto.subtle.importKey("jwk", asciiToUint8Array(\'null\'), null)')
shouldThrow('crypto.subtle.importKey("jwk", asciiToUint8Array(\'undefined\'), null)')
shouldThrow('crypto.subtle.importKey("jwk", asciiToUint8Array(\'{}\'), null)')
shouldThrow('crypto.subtle.importKey("jwk", asciiToUint8Array(\'{}\'), "aes-cbc")')
// Unknown/invalid JWK values.
shouldThrow('crypto.subtle.importKey("jwk", asciiToArrayBuffer(\'{ "kty": "foobar", "alg": "HS256", "use": "sig", "k": "ahjkn23387fgnsibf23qsvahjkn37387fgnsibf23qs" }\'), null)')
shouldThrow('crypto.subtle.importKey("jwk", asciiToArrayBuffer(\'{ "kty": "oct", "alg": "foobar", "use": "sig", "k": "ahjkn23387fgnsibf23qsvahjkn37387fgnsibf23qs" }\'), null)')
shouldThrow('crypto.subtle.importKey("jwk", asciiToUint8Array(\'{ "kty": "foobar", "alg": "HS256", "use": "sig", "k": "ahjkn23387fgnsibf23qsvahjkn37387fgnsibf23qs" }\'), null)')
shouldThrow('crypto.subtle.importKey("jwk", asciiToUint8Array(\'{ "kty": "oct", "alg": "foobar", "use": "sig", "k": "ahjkn23387fgnsibf23qsvahjkn37387fgnsibf23qs" }\'), null)')
// Algorithm mismatch.
shouldThrow('crypto.subtle.importKey("jwk", asciiToArrayBuffer(\'{ "kty": "oct", "alg": "HS256", "use": "sig", "extractable": false, "k": "ahjkn23387fgnsibf23qsvahjkn37387fgnsibf23qs" }\'), "aes-cbc")')
shouldThrow('crypto.subtle.importKey("jwk", asciiToArrayBuffer(\'{ "kty": "oct", "alg": "HS256", "use": "sig", "extractable": false, "k": "ahjkn23387fgnsibf23qsvahjkn37387fgnsibf23qs" }\'), { name: "hmac", hash: "sha-1" })')
shouldThrow('crypto.subtle.importKey("jwk", asciiToUint8Array(\'{ "kty": "oct", "alg": "HS256", "use": "sig", "extractable": false, "k": "ahjkn23387fgnsibf23qsvahjkn37387fgnsibf23qs" }\'), "aes-cbc")')
shouldThrow('crypto.subtle.importKey("jwk", asciiToUint8Array(\'{ "kty": "oct", "alg": "HS256", "use": "sig", "extractable": false, "k": "ahjkn23387fgnsibf23qsvahjkn37387fgnsibf23qs" }\'), { name: "hmac", hash: "sha-1" })')
// No key data.
shouldThrow('crypto.subtle.importKey("jwk", asciiToArrayBuffer(\'{ "kty": "oct", "alg": "HS256" }\'), null)')
shouldThrow('crypto.subtle.importKey("jwk", asciiToArrayBuffer(\'{ "kty": "oct", "alg": "A128CBC" }\'), null)')
shouldThrow('crypto.subtle.importKey("jwk", asciiToUint8Array(\'{ "kty": "oct", "alg": "HS256" }\'), null)')
shouldThrow('crypto.subtle.importKey("jwk", asciiToUint8Array(\'{ "kty": "oct", "alg": "A128CBC" }\'), null)')
// Key data length is incorrect, not allowed in JWK.
shouldThrow('crypto.subtle.importKey("jwk", asciiToArrayBuffer(\'{ "kty": "oct", "alg": "HS256", "use": "sig", "extractable": false, "k": "1234" }\'), null)')
shouldThrow('crypto.subtle.importKey("jwk", asciiToArrayBuffer(\'{ "kty": "oct", "alg": "A128CBC", "use": "sig", "extractable": false, "k": "1234" }\'), null)')
shouldThrow('crypto.subtle.importKey("jwk", asciiToArrayBuffer(\'{ "kty": "oct", "alg": "A128CBC", "use": "sig", "extractable": false, "k": "ahjkn23387fgnsibf23qsvahjkn37387fgnsibf23qs" }\'), null)')
shouldThrow('crypto.subtle.importKey("jwk", asciiToUint8Array(\'{ "kty": "oct", "alg": "HS256", "use": "sig", "extractable": false, "k": "1234" }\'), null)')
shouldThrow('crypto.subtle.importKey("jwk", asciiToUint8Array(\'{ "kty": "oct", "alg": "A128CBC", "use": "sig", "extractable": false, "k": "1234" }\'), null)')