Diff
Modified: trunk/LayoutTests/ChangeLog (208917 => 208918)
--- trunk/LayoutTests/ChangeLog 2016-11-19 04:25:38 UTC (rev 208917)
+++ trunk/LayoutTests/ChangeLog 2016-11-19 04:38:59 UTC (rev 208918)
@@ -1,3 +1,43 @@
+2016-11-18 Jiewen Tan <[email protected]>
+
+ Update SubtleCrypto::decrypt to match the latest spec
+ https://bugs.webkit.org/show_bug.cgi?id=164739
+ <rdar://problem/29257848>
+
+ Reviewed by Brent Fulgham.
+
+ * crypto/subtle/aes-cbc-decrypt-malformed-parameters-expected.txt: Added.
+ * crypto/subtle/aes-cbc-decrypt-malformed-parameters.html: Added.
+ * crypto/subtle/aes-cbc-generate-key-encrypt-decrypt-expected.txt: Added.
+ * crypto/subtle/aes-cbc-generate-key-encrypt-decrypt.html: Added.
+ * crypto/subtle/aes-cbc-import-key-decrypt-expected.txt: Added.
+ * crypto/subtle/aes-cbc-import-key-decrypt.html: Added.
+ * crypto/subtle/decrypt-malformed-parameters-expected.txt: Added.
+ * crypto/subtle/decrypt-malformed-parameters.html: Added.
+ * crypto/subtle/rsa-oaep-decrypt-malformed-parameters-expected.txt: Added.
+ * crypto/subtle/rsa-oaep-decrypt-malformed-parameters.html: Added.
+ * crypto/subtle/rsa-oaep-generate-key-encrypt-decrypt-expected.txt: Added.
+ * crypto/subtle/rsa-oaep-generate-key-encrypt-decrypt-label-expected.txt: Added.
+ * crypto/subtle/rsa-oaep-generate-key-encrypt-decrypt-label.html: Added.
+ * crypto/subtle/rsa-oaep-generate-key-encrypt-decrypt.html: Added.
+ * crypto/subtle/rsa-oaep-import-key-decrypt-expected.txt: Added.
+ * crypto/subtle/rsa-oaep-import-key-decrypt-label-expected.txt: Added.
+ * crypto/subtle/rsa-oaep-import-key-decrypt-label.html: Added.
+ * crypto/subtle/rsa-oaep-import-key-decrypt.html: Added.
+ * crypto/subtle/rsaes-pkcs1-v1_5-generate-key-encrypt-decrypt-expected.txt: Added.
+ * crypto/subtle/rsaes-pkcs1-v1_5-generate-key-encrypt-decrypt.html: Added.
+ * crypto/subtle/rsaes-pkcs1-v1_5-import-key-decrypt-expected.txt: Added.
+ * crypto/subtle/rsaes-pkcs1-v1_5-import-key-decrypt.html: Added.
+ * crypto/workers/subtle/aes-cbc-import-key-decrypt-expected.txt: Added.
+ * crypto/workers/subtle/aes-cbc-import-key-decrypt.html: Added.
+ * crypto/workers/subtle/resources/aes-cbc-import-key-decrypt.js: Added.
+ * crypto/workers/subtle/resources/rsa-oaep-import-key-decrypt.js: Added.
+ * crypto/workers/subtle/resources/rsaes-pkcs1-v1_5-import-key-decrypt.js: Added.
+ * crypto/workers/subtle/rsa-oaep-import-key-decrypt-expected.txt: Added.
+ * crypto/workers/subtle/rsa-oaep-import-key-decrypt.html: Added.
+ * crypto/workers/subtle/rsaes-pkcs1-v1_5-import-key-decrypt-expected.txt: Added.
+ * crypto/workers/subtle/rsaes-pkcs1-v1_5-import-key-decrypt.html: Added.
+
2016-11-18 Chris Dumez <[email protected]>
Unreviewed, rolling out r208837.
Added: trunk/LayoutTests/crypto/subtle/aes-cbc-decrypt-malformed-parameters-expected.txt (0 => 208918)
--- trunk/LayoutTests/crypto/subtle/aes-cbc-decrypt-malformed-parameters-expected.txt (rev 0)
+++ trunk/LayoutTests/crypto/subtle/aes-cbc-decrypt-malformed-parameters-expected.txt 2016-11-19 04:38:59 UTC (rev 208918)
@@ -0,0 +1,12 @@
+Test decrypting using AES-CBC with malformed parameters
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS crypto.subtle.decrypt({name: "aes-cbc", iv: asciiToUint8Array("")}, key, cipherText) rejected promise with OperationError (DOM Exception 34): The operation failed for an operation-specific reason.
+PASS crypto.subtle.decrypt({name: "aes-cbc", iv: asciiToUint8Array("j")}, key, cipherText) rejected promise with OperationError (DOM Exception 34): The operation failed for an operation-specific reason.
+PASS crypto.subtle.decrypt({name: "aes-cbc", iv: asciiToUint8Array("jnOw99oOZFLIEPMrd")}, key, cipherText) rejected promise with OperationError (DOM Exception 34): The operation failed for an operation-specific reason.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/crypto/subtle/aes-cbc-decrypt-malformed-parameters.html (0 => 208918)
--- trunk/LayoutTests/crypto/subtle/aes-cbc-decrypt-malformed-parameters.html (rev 0)
+++ trunk/LayoutTests/crypto/subtle/aes-cbc-decrypt-malformed-parameters.html 2016-11-19 04:38:59 UTC (rev 208918)
@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script src=""
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test decrypting using AES-CBC with malformed parameters");
+
+jsTestIsAsync = true;
+
+var extractable = false;
+var cipherText = hexStringToUint8Array("2ffa4618784dfd414b22c40c6330d022");
+var rawKey = asciiToUint8Array("jnOw99oOZFLIEPMr");
+
+crypto.subtle.importKey("raw", rawKey, "aes-cbc", extractable, ["decrypt"]).then(function(result) {
+ key = result;
+ // Wrong iv length
+ shouldReject('crypto.subtle.decrypt({name: "aes-cbc", iv: asciiToUint8Array("")}, key, cipherText)');
+ shouldReject('crypto.subtle.decrypt({name: "aes-cbc", iv: asciiToUint8Array("j")}, key, cipherText)');
+ shouldReject('crypto.subtle.decrypt({name: "aes-cbc", iv: asciiToUint8Array("jnOw99oOZFLIEPMrd")}, key, cipherText)');
+
+ finishJSTest();
+});
+
+</script>
+
+<script src=""
+</body>
+</html>
Added: trunk/LayoutTests/crypto/subtle/aes-cbc-generate-key-encrypt-decrypt-expected.txt (0 => 208918)
--- trunk/LayoutTests/crypto/subtle/aes-cbc-generate-key-encrypt-decrypt-expected.txt (rev 0)
+++ trunk/LayoutTests/crypto/subtle/aes-cbc-generate-key-encrypt-decrypt-expected.txt 2016-11-19 04:38:59 UTC (rev 208918)
@@ -0,0 +1,13 @@
+Test encrypting&decrypting using AES-CBC algorithm with a generated 256bit key
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Generating a key...
+Encrypting...
+Decrypting...
+PASS bytesToASCIIString(decryptedText) is plainText
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/crypto/subtle/aes-cbc-generate-key-encrypt-decrypt.html (0 => 208918)
--- trunk/LayoutTests/crypto/subtle/aes-cbc-generate-key-encrypt-decrypt.html (rev 0)
+++ trunk/LayoutTests/crypto/subtle/aes-cbc-generate-key-encrypt-decrypt.html 2016-11-19 04:38:59 UTC (rev 208918)
@@ -0,0 +1,40 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script src=""
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test encrypting&decrypting using AES-CBC algorithm with a generated 256bit key");
+
+jsTestIsAsync = true;
+var plainText = "Hello, World!";
+var aesCbcParams = {
+ name: "aes-cbc",
+ iv: asciiToUint8Array("jnOw99oOZFLIEPMr"),
+}
+
+debug("Generating a key...");
+crypto.subtle.generateKey({name: "aes-cbc", length: 256}, true, ["decrypt", "encrypt"]).then(function(result) {
+ key = result;
+ debug("Encrypting...");
+ return crypto.subtle.encrypt(aesCbcParams, key, asciiToUint8Array(plainText));
+}).then(function(cipherText) {
+ debug("Decrypting...");
+ return crypto.subtle.decrypt(aesCbcParams, key, cipherText);
+}).then(function(result) {
+ decryptedText = result;
+
+ shouldBe("bytesToASCIIString(decryptedText)", "plainText");
+
+ finishJSTest();
+});
+</script>
+
+<script src=""
+</body>
+</html>
Added: trunk/LayoutTests/crypto/subtle/aes-cbc-import-key-decrypt-expected.txt (0 => 208918)
--- trunk/LayoutTests/crypto/subtle/aes-cbc-import-key-decrypt-expected.txt (rev 0)
+++ trunk/LayoutTests/crypto/subtle/aes-cbc-import-key-decrypt-expected.txt 2016-11-19 04:38:59 UTC (rev 208918)
@@ -0,0 +1,10 @@
+Test decrypting using AES-CBC with an imported 128bit key
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS bytesToASCIIString(plainText) is expectedPlainText
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/crypto/subtle/aes-cbc-import-key-decrypt.html (0 => 208918)
--- trunk/LayoutTests/crypto/subtle/aes-cbc-import-key-decrypt.html (rev 0)
+++ trunk/LayoutTests/crypto/subtle/aes-cbc-import-key-decrypt.html 2016-11-19 04:38:59 UTC (rev 208918)
@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script src=""
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test decrypting using AES-CBC with an imported 128bit key");
+
+jsTestIsAsync = true;
+
+var extractable = false;
+var cipherText = hexStringToUint8Array("2ffa4618784dfd414b22c40c6330d022");
+var aesCbcParams = {
+ name: "aes-cbc",
+ iv: asciiToUint8Array("jnOw99oOZFLIEPMr"),
+}
+var rawKey = asciiToUint8Array("jnOw99oOZFLIEPMr");
+var expectedPlainText = "Hello, World!";
+
+crypto.subtle.importKey("raw", rawKey, "aes-cbc", extractable, ["decrypt"]).then(function(key) {
+ return crypto.subtle.decrypt(aesCbcParams, key, cipherText);
+}).then(function(result) {
+ plainText = result;
+
+ shouldBe("bytesToASCIIString(plainText)", "expectedPlainText");
+
+ finishJSTest();
+});
+
+</script>
+
+<script src=""
+</body>
+</html>
Added: trunk/LayoutTests/crypto/subtle/decrypt-malformed-parameters-expected.txt (0 => 208918)
--- trunk/LayoutTests/crypto/subtle/decrypt-malformed-parameters-expected.txt (rev 0)
+++ trunk/LayoutTests/crypto/subtle/decrypt-malformed-parameters-expected.txt 2016-11-19 04:38:59 UTC (rev 208918)
@@ -0,0 +1,14 @@
+Test decrypting with malformed parameters
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS crypto.subtle.decrypt() rejected promise with TypeError: Not enough arguments.
+PASS crypto.subtle.decrypt(1) rejected promise with TypeError: Not enough arguments.
+PASS crypto.subtle.decrypt(1, 2) rejected promise with TypeError: Not enough arguments.
+PASS crypto.subtle.decrypt(aesCbcParams, wrongKey, cipherText) rejected promise with InvalidAccessError (DOM Exception 15): CryptoKey doesn't match AlgorithmIdentifier.
+PASS crypto.subtle.decrypt(aesCbcParams, wrongKey, cipherText) rejected promise with InvalidAccessError (DOM Exception 15): CryptoKey doesn't support decryption.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/crypto/subtle/decrypt-malformed-parameters.html (0 => 208918)
--- trunk/LayoutTests/crypto/subtle/decrypt-malformed-parameters.html (rev 0)
+++ trunk/LayoutTests/crypto/subtle/decrypt-malformed-parameters.html 2016-11-19 04:38:59 UTC (rev 208918)
@@ -0,0 +1,45 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script src=""
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test decrypting with malformed parameters");
+
+jsTestIsAsync = true;
+
+var extractable = false;
+var cipherText = hexStringToUint8Array("2ffa4618784dfd414b22c40c6330d022");
+var aesCbcParams = {
+ name: "aes-cbc",
+ iv: asciiToUint8Array("jnOw99oOZFLIEPMr"),
+}
+var rawKey = asciiToUint8Array("jnOw99oOZFLIEPMr");
+
+// Not enough arguments.
+shouldReject('crypto.subtle.decrypt()');
+shouldReject('crypto.subtle.decrypt(1)');
+shouldReject('crypto.subtle.decrypt(1, 2)');
+
+crypto.subtle.importKey("raw", rawKey, "aes-kw", extractable, ["wrapKey", "unwrapKey"]).then(function(result) {
+ wrongKey = result;
+ // Wrong algorithm identifier.
+ shouldReject('crypto.subtle.decrypt(aesCbcParams, wrongKey, cipherText)');
+
+ return crypto.subtle.importKey("raw", rawKey, "aes-cbc", extractable, ["wrapKey", "unwrapKey"]);
+}).then(function(result) {
+ wrongKey = result;
+ // Wrong usage.
+ return shouldReject('crypto.subtle.decrypt(aesCbcParams, wrongKey, cipherText)');
+}).then(finishJSTest);
+
+</script>
+
+<script src=""
+</body>
+</html>
Added: trunk/LayoutTests/crypto/subtle/rsa-oaep-decrypt-malformed-parameters-expected.txt (0 => 208918)
--- trunk/LayoutTests/crypto/subtle/rsa-oaep-decrypt-malformed-parameters-expected.txt (rev 0)
+++ trunk/LayoutTests/crypto/subtle/rsa-oaep-decrypt-malformed-parameters-expected.txt 2016-11-19 04:38:59 UTC (rev 208918)
@@ -0,0 +1,10 @@
+Test decrypting using RSA-OAEP with malformed parameters
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS crypto.subtle.decrypt(rsaOaepParams, key, cipherText) rejected promise with OperationError (DOM Exception 34): The operation failed for an operation-specific reason.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/crypto/subtle/rsa-oaep-decrypt-malformed-parameters.html (0 => 208918)
--- trunk/LayoutTests/crypto/subtle/rsa-oaep-decrypt-malformed-parameters.html (rev 0)
+++ trunk/LayoutTests/crypto/subtle/rsa-oaep-decrypt-malformed-parameters.html 2016-11-19 04:38:59 UTC (rev 208918)
@@ -0,0 +1,50 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script src=""
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test decrypting using RSA-OAEP with malformed parameters");
+
+jsTestIsAsync = true;
+
+var extractable = false;
+var cipherText = hexStringToUint8Array("346dc8f3a158e494004cf82c0843ab1c1e7a612263a1c44d941309175a3d2598997be651f2d3419f89923843ca344414d45989e886aaa79573d96d4f3f777af3b2e9fcd44b51c00a8e4395bf54ac89d88559c712d49853de448e190fad886c45fa0742f2ddf18e5f6155eb7f38348217efd67c14ef141e81f3b1c1804b3bb437ef1b23a25dadb594985c500181208c74cd2068cbfdccc02db7113ed5e72d7a3543a78ec9c2070715e409ab10687762358f786c669e592e467107a13caaaadc3c341facf249baf743a3b93c49f73ea5634052f1a6ee46265e02391dd2cbcd4a523bfee8321470279fff63b87a4a53465b4736fb31ee99e9b0379761f3e630f636");
+var jwkKey = {
+ kty: "RSA",
+ alg: "RSA-OAEP",
+ use: "enc",
+ key_ops: ["decrypt", "unwrapKey"],
+ ext: true,
+ n: "lxHN0N9VRZ0_pl0xv3-NXx70WnjkODSkQ5LjHXTFy3DOQsvkagFzD9HqYQezCmcewLjdK5PLwSesDoMdfL6tusBHcvyit1kvydYFQ3NLbENNkYsiBG5_nW4IQGL6JKbZ5iGdUop98QHKm6YZR1u4zrAtxM6bVEo05VvhjRS0M8yWoZVi-7Vdsc0LqI0Qdq_NoctX5Fu-AqiBN7Uo1HkYGcP2oC82J_J5cjw98BQiP5kDWThq9RK-X6S-EUALx_m4iG6iOYKTA3SQyf1xBqFaXXoEJjcckbOqkegecz5b-YWUh8iZPvhwnt-RZwpIbLJgKwz19ndkn9KvoEEw7YbEow",
+ e: "AQAB",
+ d: "cj5DkDakjM2bKduGWJREO-_zyEtuA1dD9doqKMd7IRuA0CDS7puEAS20-oXRDwfmyMXEdEUDrGGtCxh6fzDPvs_T-JA3GUK4EgHo3xZcrlXDXlKCeil6Fnr0gISZOIh5dkBrcdVL4quBJe4ZZc5mVuAC7Ld13et0TxMJ4iALGrPuqPVUOGSYIcZ9idx5zKKBWhY3tPggEdKpnHBmPfTRO4yZaf0Nw1QXrgSMZY9ejeuaurAh4Q8o4-6-r8O2LUe7ufMh_ccKkXISEh4KdOnT17EM9BQTn9UNS9GoK2ZZU0U3io5DSu_kpasr4uOVWcGlE2wczOv2nkGwG39F3sFF0Q",
+ p: "x5vnco5j-TD6hTOzyN4DhkZ44m05NycxT6SUE2qTurT3-uze_L7TYutLRIRkovRMhTHZAr2pziRlasEs13PEz9Zvx1I_T68srsonrdbak-SFMecM7EjHc5C-J13gXhw9HIW28_Sx9rQ-JkGwEwE9PEdIUfuvdqpgh3SmXwPJrEs",
+ q: "wb9vllg_2n-kNge0bThg_7xu1UwTzipM8vxSUkkV2IipJKIAekkU3aAB8LoPhUI0-17pSGw3ETOO27t163TI9qIPpzLbhTH9aUi7qLGbKlzPlgnqP43Z0LHxc3xKDgit-Ar29QLaX2uoJBX6VVWvhmh7BIPDHNVM5GZjwWORYgk",
+ dp: "C2c8sa6wx2uk5Dcv7inAycr83PKgciYrCwG78-AC0IfGIu-lTYsZSG1ov2FQ3n5WYMWYQC_Vo5EwugiPJz_V3onBmQF53HOFefbSjXvYwNotQcyRUG5X9qIuOtGCH949H4QED6vK_u0NH-JgzLUlamwoFYbrXzwch6CCYKs2ukE",
+ dq: "hbtRloDLclHwUqr2yvzDV0IFbozYjtF706x-VfXEcnXB6ls34TBYirFLJZIH7H9KeseEVkz7pY_k5555QlCV9kbebxYXl9RtiiJ-BW6yH4d4caPeYIfU9MweUQxVQWKUUkWfOHcDrCFvKZlR9Vzzjt7HKtKX9mr0bCKQcIf9baE",
+ qi: "a-7hUTTnclUPKOfSgH8zEKGJ-AvdFEzxvZ5sq46Qf2MbORxVjN4dJamVvM-FoqcwN-9cuUlyr9bSFTwUBW4vXa8Xj9a8JfViuMCqzR-mL1rGIUQ5ARGhNcSsRlyKTqz5BlWlVKmXIx_p-DeVwPWiJJy4k_FqyBxrnxkzomHfrxk",
+};
+var rsaOaepParams = {
+ name: "rsa-oaep",
+ // Wrong label. Correct one is "WebKit.org"
+ label: asciiToUint8Array("apple.com"),
+}
+
+crypto.subtle.importKey("jwk", jwkKey, {name: "RSA-OAEP", hash: "SHA-1"}, extractable, ["decrypt"]).then(function(result) {
+ key = result;
+
+ // Wrong label.
+ shouldReject("crypto.subtle.decrypt(rsaOaepParams, key, cipherText)").then(finishJSTest);
+});
+
+</script>
+
+<script src=""
+</body>
+</html>
Added: trunk/LayoutTests/crypto/subtle/rsa-oaep-generate-key-encrypt-decrypt-expected.txt (0 => 208918)
--- trunk/LayoutTests/crypto/subtle/rsa-oaep-generate-key-encrypt-decrypt-expected.txt (rev 0)
+++ trunk/LayoutTests/crypto/subtle/rsa-oaep-generate-key-encrypt-decrypt-expected.txt 2016-11-19 04:38:59 UTC (rev 208918)
@@ -0,0 +1,13 @@
+Test encrypting&decrypting using RSA-OAEP SHA-512 algorithm with a generated key
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Generating a key...
+Encrypting...
+Decrypting...
+PASS bytesToASCIIString(decryptedText) is plainText
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/crypto/subtle/rsa-oaep-generate-key-encrypt-decrypt-label-expected.txt (0 => 208918)
--- trunk/LayoutTests/crypto/subtle/rsa-oaep-generate-key-encrypt-decrypt-label-expected.txt (rev 0)
+++ trunk/LayoutTests/crypto/subtle/rsa-oaep-generate-key-encrypt-decrypt-label-expected.txt 2016-11-19 04:38:59 UTC (rev 208918)
@@ -0,0 +1,13 @@
+Test encrypting&decrypting using RSA-OAEP SHA-512 algorithm with a generated key and a label
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Generating a key...
+Encrypting...
+Decrypting...
+PASS bytesToASCIIString(decryptedText) is plainText
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/crypto/subtle/rsa-oaep-generate-key-encrypt-decrypt-label.html (0 => 208918)
--- trunk/LayoutTests/crypto/subtle/rsa-oaep-generate-key-encrypt-decrypt-label.html (rev 0)
+++ trunk/LayoutTests/crypto/subtle/rsa-oaep-generate-key-encrypt-decrypt-label.html 2016-11-19 04:38:59 UTC (rev 208918)
@@ -0,0 +1,47 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script src=""
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test encrypting&decrypting using RSA-OAEP SHA-512 algorithm with a generated key and a label");
+
+jsTestIsAsync = true;
+var plainText = "Hello, World!";
+var algorithmKeyGen = {
+ name: "RSA-OAEP",
+ // RsaKeyGenParams
+ modulusLength: 2048,
+ publicExponent: new Uint8Array([0x01, 0x00, 0x01]), // Equivalent to 65537
+ hash: "sha-512"
+};
+var rsaOaepParams = {
+ name: "rsa-oaep",
+ label: asciiToUint8Array("WebKit.org"),
+}
+
+debug("Generating a key...");
+crypto.subtle.generateKey(algorithmKeyGen, true, ["decrypt", "encrypt"]).then(function(result) {
+ keyPair = result;
+ debug("Encrypting...");
+ return crypto.subtle.encrypt(rsaOaepParams, keyPair.publicKey, asciiToUint8Array(plainText));
+}).then(function(cipherText) {
+ debug("Decrypting...");
+ return crypto.subtle.decrypt(rsaOaepParams, keyPair.privateKey, cipherText);
+}).then(function(result) {
+ decryptedText = result;
+
+ shouldBe("bytesToASCIIString(decryptedText)", "plainText");
+
+ finishJSTest();
+});
+</script>
+
+<script src=""
+</body>
+</html>
Added: trunk/LayoutTests/crypto/subtle/rsa-oaep-generate-key-encrypt-decrypt.html (0 => 208918)
--- trunk/LayoutTests/crypto/subtle/rsa-oaep-generate-key-encrypt-decrypt.html (rev 0)
+++ trunk/LayoutTests/crypto/subtle/rsa-oaep-generate-key-encrypt-decrypt.html 2016-11-19 04:38:59 UTC (rev 208918)
@@ -0,0 +1,46 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script src=""
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test encrypting&decrypting using RSA-OAEP SHA-512 algorithm with a generated key");
+
+jsTestIsAsync = true;
+var plainText = "Hello, World!";
+var algorithmKeyGen = {
+ name: "RSA-OAEP",
+ // RsaKeyGenParams
+ modulusLength: 2048,
+ publicExponent: new Uint8Array([0x01, 0x00, 0x01]), // Equivalent to 65537
+ hash: "sha-512"
+};
+var rsaOaepParams = {
+ name: "rsa-oaep"
+}
+
+debug("Generating a key...");
+crypto.subtle.generateKey(algorithmKeyGen, true, ["decrypt", "encrypt"]).then(function(result) {
+ keyPair = result;
+ debug("Encrypting...");
+ return crypto.subtle.encrypt(rsaOaepParams, keyPair.publicKey, asciiToUint8Array(plainText));
+}).then(function(cipherText) {
+ debug("Decrypting...");
+ return crypto.subtle.decrypt(rsaOaepParams, keyPair.privateKey, cipherText);
+}).then(function(result) {
+ decryptedText = result;
+
+ shouldBe("bytesToASCIIString(decryptedText)", "plainText");
+
+ finishJSTest();
+});
+</script>
+
+<script src=""
+</body>
+</html>
Added: trunk/LayoutTests/crypto/subtle/rsa-oaep-import-key-decrypt-expected.txt (0 => 208918)
--- trunk/LayoutTests/crypto/subtle/rsa-oaep-import-key-decrypt-expected.txt (rev 0)
+++ trunk/LayoutTests/crypto/subtle/rsa-oaep-import-key-decrypt-expected.txt 2016-11-19 04:38:59 UTC (rev 208918)
@@ -0,0 +1,10 @@
+Test decrypting using RSA-OAEP SHA-1 with an imported key
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS bytesToASCIIString(plainText) is expectedPlainText
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/crypto/subtle/rsa-oaep-import-key-decrypt-label-expected.txt (0 => 208918)
--- trunk/LayoutTests/crypto/subtle/rsa-oaep-import-key-decrypt-label-expected.txt (rev 0)
+++ trunk/LayoutTests/crypto/subtle/rsa-oaep-import-key-decrypt-label-expected.txt 2016-11-19 04:38:59 UTC (rev 208918)
@@ -0,0 +1,10 @@
+Test decrypting using RSA-OAEP SHA-1 with an imported key and a label
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS bytesToASCIIString(plainText) is expectedPlainText
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/crypto/subtle/rsa-oaep-import-key-decrypt-label.html (0 => 208918)
--- trunk/LayoutTests/crypto/subtle/rsa-oaep-import-key-decrypt-label.html (rev 0)
+++ trunk/LayoutTests/crypto/subtle/rsa-oaep-import-key-decrypt-label.html 2016-11-19 04:38:59 UTC (rev 208918)
@@ -0,0 +1,52 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script src=""
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test decrypting using RSA-OAEP SHA-1 with an imported key and a label");
+
+jsTestIsAsync = true;
+
+var extractable = false;
+var cipherText = hexStringToUint8Array("346dc8f3a158e494004cf82c0843ab1c1e7a612263a1c44d941309175a3d2598997be651f2d3419f89923843ca344414d45989e886aaa79573d96d4f3f777af3b2e9fcd44b51c00a8e4395bf54ac89d88559c712d49853de448e190fad886c45fa0742f2ddf18e5f6155eb7f38348217efd67c14ef141e81f3b1c1804b3bb437ef1b23a25dadb594985c500181208c74cd2068cbfdccc02db7113ed5e72d7a3543a78ec9c2070715e409ab10687762358f786c669e592e467107a13caaaadc3c341facf249baf743a3b93c49f73ea5634052f1a6ee46265e02391dd2cbcd4a523bfee8321470279fff63b87a4a53465b4736fb31ee99e9b0379761f3e630f636");
+var jwkKey = {
+ kty: "RSA",
+ alg: "RSA-OAEP",
+ use: "enc",
+ key_ops: ["decrypt", "unwrapKey"],
+ ext: true,
+ n: "lxHN0N9VRZ0_pl0xv3-NXx70WnjkODSkQ5LjHXTFy3DOQsvkagFzD9HqYQezCmcewLjdK5PLwSesDoMdfL6tusBHcvyit1kvydYFQ3NLbENNkYsiBG5_nW4IQGL6JKbZ5iGdUop98QHKm6YZR1u4zrAtxM6bVEo05VvhjRS0M8yWoZVi-7Vdsc0LqI0Qdq_NoctX5Fu-AqiBN7Uo1HkYGcP2oC82J_J5cjw98BQiP5kDWThq9RK-X6S-EUALx_m4iG6iOYKTA3SQyf1xBqFaXXoEJjcckbOqkegecz5b-YWUh8iZPvhwnt-RZwpIbLJgKwz19ndkn9KvoEEw7YbEow",
+ e: "AQAB",
+ d: "cj5DkDakjM2bKduGWJREO-_zyEtuA1dD9doqKMd7IRuA0CDS7puEAS20-oXRDwfmyMXEdEUDrGGtCxh6fzDPvs_T-JA3GUK4EgHo3xZcrlXDXlKCeil6Fnr0gISZOIh5dkBrcdVL4quBJe4ZZc5mVuAC7Ld13et0TxMJ4iALGrPuqPVUOGSYIcZ9idx5zKKBWhY3tPggEdKpnHBmPfTRO4yZaf0Nw1QXrgSMZY9ejeuaurAh4Q8o4-6-r8O2LUe7ufMh_ccKkXISEh4KdOnT17EM9BQTn9UNS9GoK2ZZU0U3io5DSu_kpasr4uOVWcGlE2wczOv2nkGwG39F3sFF0Q",
+ p: "x5vnco5j-TD6hTOzyN4DhkZ44m05NycxT6SUE2qTurT3-uze_L7TYutLRIRkovRMhTHZAr2pziRlasEs13PEz9Zvx1I_T68srsonrdbak-SFMecM7EjHc5C-J13gXhw9HIW28_Sx9rQ-JkGwEwE9PEdIUfuvdqpgh3SmXwPJrEs",
+ q: "wb9vllg_2n-kNge0bThg_7xu1UwTzipM8vxSUkkV2IipJKIAekkU3aAB8LoPhUI0-17pSGw3ETOO27t163TI9qIPpzLbhTH9aUi7qLGbKlzPlgnqP43Z0LHxc3xKDgit-Ar29QLaX2uoJBX6VVWvhmh7BIPDHNVM5GZjwWORYgk",
+ dp: "C2c8sa6wx2uk5Dcv7inAycr83PKgciYrCwG78-AC0IfGIu-lTYsZSG1ov2FQ3n5WYMWYQC_Vo5EwugiPJz_V3onBmQF53HOFefbSjXvYwNotQcyRUG5X9qIuOtGCH949H4QED6vK_u0NH-JgzLUlamwoFYbrXzwch6CCYKs2ukE",
+ dq: "hbtRloDLclHwUqr2yvzDV0IFbozYjtF706x-VfXEcnXB6ls34TBYirFLJZIH7H9KeseEVkz7pY_k5555QlCV9kbebxYXl9RtiiJ-BW6yH4d4caPeYIfU9MweUQxVQWKUUkWfOHcDrCFvKZlR9Vzzjt7HKtKX9mr0bCKQcIf9baE",
+ qi: "a-7hUTTnclUPKOfSgH8zEKGJ-AvdFEzxvZ5sq46Qf2MbORxVjN4dJamVvM-FoqcwN-9cuUlyr9bSFTwUBW4vXa8Xj9a8JfViuMCqzR-mL1rGIUQ5ARGhNcSsRlyKTqz5BlWlVKmXIx_p-DeVwPWiJJy4k_FqyBxrnxkzomHfrxk",
+};
+var rsaOaepParams = {
+ name: "rsa-oaep",
+ label: asciiToUint8Array("WebKit.org"),
+}
+var expectedPlainText = "Hello, World!";
+
+crypto.subtle.importKey("jwk", jwkKey, {name: "RSA-OAEP", hash: "SHA-1"}, extractable, ["decrypt"]).then(function(key) {
+ return crypto.subtle.decrypt(rsaOaepParams, key, cipherText);
+}).then(function(result) {
+ plainText = result;
+
+ shouldBe("bytesToASCIIString(plainText)", "expectedPlainText");
+
+ finishJSTest();
+});
+</script>
+
+<script src=""
+</body>
+</html>
Added: trunk/LayoutTests/crypto/subtle/rsa-oaep-import-key-decrypt.html (0 => 208918)
--- trunk/LayoutTests/crypto/subtle/rsa-oaep-import-key-decrypt.html (rev 0)
+++ trunk/LayoutTests/crypto/subtle/rsa-oaep-import-key-decrypt.html 2016-11-19 04:38:59 UTC (rev 208918)
@@ -0,0 +1,52 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script src=""
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test decrypting using RSA-OAEP SHA-1 with an imported key");
+
+jsTestIsAsync = true;
+
+var extractable = false;
+var cipherText = hexStringToUint8Array("64ea45b5234b05666dc21ca6f7cd6ecb0be8ce4576c0bbe9686e70c9f3ab67a9f0a4db226554f217ba7259634c7b70eb422633277d83aeb2181a001099bacbca8b5b534a77843fe611f646838999e82e681f1d1724ef0e9f65ac3020128c56ea90a0345d936e8e226b363687c7b57146eecd4ab599760661a278671b5b249051b1f1720d6e78085e321ce82867df81a67b8606e340850b189fcd08d63b1ac8ce9a97300b8c15c3c475c97f1266606b48b67a15c28937d88e0749c83212737732c74a7fdf79188405c6df72b9ee2b753f4f70ae35f2f035c5827e0c87fcceeef1c4e303c0e89ecc76773fb58e6f5a06b792ae7a1b58ee7bf09893c8fd2b93da0d");
+var jwkKey = {
+ kty: "RSA",
+ alg: "RSA-OAEP",
+ use: "enc",
+ key_ops: ["decrypt", "unwrapKey"],
+ ext: true,
+ n: "lxHN0N9VRZ0_pl0xv3-NXx70WnjkODSkQ5LjHXTFy3DOQsvkagFzD9HqYQezCmcewLjdK5PLwSesDoMdfL6tusBHcvyit1kvydYFQ3NLbENNkYsiBG5_nW4IQGL6JKbZ5iGdUop98QHKm6YZR1u4zrAtxM6bVEo05VvhjRS0M8yWoZVi-7Vdsc0LqI0Qdq_NoctX5Fu-AqiBN7Uo1HkYGcP2oC82J_J5cjw98BQiP5kDWThq9RK-X6S-EUALx_m4iG6iOYKTA3SQyf1xBqFaXXoEJjcckbOqkegecz5b-YWUh8iZPvhwnt-RZwpIbLJgKwz19ndkn9KvoEEw7YbEow",
+ e: "AQAB",
+ d: "cj5DkDakjM2bKduGWJREO-_zyEtuA1dD9doqKMd7IRuA0CDS7puEAS20-oXRDwfmyMXEdEUDrGGtCxh6fzDPvs_T-JA3GUK4EgHo3xZcrlXDXlKCeil6Fnr0gISZOIh5dkBrcdVL4quBJe4ZZc5mVuAC7Ld13et0TxMJ4iALGrPuqPVUOGSYIcZ9idx5zKKBWhY3tPggEdKpnHBmPfTRO4yZaf0Nw1QXrgSMZY9ejeuaurAh4Q8o4-6-r8O2LUe7ufMh_ccKkXISEh4KdOnT17EM9BQTn9UNS9GoK2ZZU0U3io5DSu_kpasr4uOVWcGlE2wczOv2nkGwG39F3sFF0Q",
+ p: "x5vnco5j-TD6hTOzyN4DhkZ44m05NycxT6SUE2qTurT3-uze_L7TYutLRIRkovRMhTHZAr2pziRlasEs13PEz9Zvx1I_T68srsonrdbak-SFMecM7EjHc5C-J13gXhw9HIW28_Sx9rQ-JkGwEwE9PEdIUfuvdqpgh3SmXwPJrEs",
+ q: "wb9vllg_2n-kNge0bThg_7xu1UwTzipM8vxSUkkV2IipJKIAekkU3aAB8LoPhUI0-17pSGw3ETOO27t163TI9qIPpzLbhTH9aUi7qLGbKlzPlgnqP43Z0LHxc3xKDgit-Ar29QLaX2uoJBX6VVWvhmh7BIPDHNVM5GZjwWORYgk",
+ dp: "C2c8sa6wx2uk5Dcv7inAycr83PKgciYrCwG78-AC0IfGIu-lTYsZSG1ov2FQ3n5WYMWYQC_Vo5EwugiPJz_V3onBmQF53HOFefbSjXvYwNotQcyRUG5X9qIuOtGCH949H4QED6vK_u0NH-JgzLUlamwoFYbrXzwch6CCYKs2ukE",
+ dq: "hbtRloDLclHwUqr2yvzDV0IFbozYjtF706x-VfXEcnXB6ls34TBYirFLJZIH7H9KeseEVkz7pY_k5555QlCV9kbebxYXl9RtiiJ-BW6yH4d4caPeYIfU9MweUQxVQWKUUkWfOHcDrCFvKZlR9Vzzjt7HKtKX9mr0bCKQcIf9baE",
+ qi: "a-7hUTTnclUPKOfSgH8zEKGJ-AvdFEzxvZ5sq46Qf2MbORxVjN4dJamVvM-FoqcwN-9cuUlyr9bSFTwUBW4vXa8Xj9a8JfViuMCqzR-mL1rGIUQ5ARGhNcSsRlyKTqz5BlWlVKmXIx_p-DeVwPWiJJy4k_FqyBxrnxkzomHfrxk",
+};
+var rsaOaepParams = {
+ name: "rsa-oaep"
+}
+var expectedPlainText = "Hello, World!";
+
+crypto.subtle.importKey("jwk", jwkKey, {name: "RSA-OAEP", hash: "SHA-1"}, extractable, ["decrypt"]).then(function(key) {
+ return crypto.subtle.decrypt(rsaOaepParams, key, cipherText);
+}).then(function(result) {
+ plainText = result;
+
+ shouldBe("bytesToASCIIString(plainText)", "expectedPlainText");
+
+ finishJSTest();
+});
+
+</script>
+
+<script src=""
+</body>
+</html>
Added: trunk/LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-generate-key-encrypt-decrypt-expected.txt (0 => 208918)
--- trunk/LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-generate-key-encrypt-decrypt-expected.txt (rev 0)
+++ trunk/LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-generate-key-encrypt-decrypt-expected.txt 2016-11-19 04:38:59 UTC (rev 208918)
@@ -0,0 +1,13 @@
+Test encrypting&decrypting using RSAES-PKCS1-v1_5 algorithm with a generated key
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Generating a key...
+Encrypting...
+Decrypting...
+PASS bytesToASCIIString(decryptedText) is plainText
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-generate-key-encrypt-decrypt.html (0 => 208918)
--- trunk/LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-generate-key-encrypt-decrypt.html (rev 0)
+++ trunk/LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-generate-key-encrypt-decrypt.html 2016-11-19 04:38:59 UTC (rev 208918)
@@ -0,0 +1,42 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script src=""
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test encrypting&decrypting using RSAES-PKCS1-v1_5 algorithm with a generated key");
+
+jsTestIsAsync = true;
+var plainText = "Hello, World!";
+var algorithmKeyGen = {
+ name: "RSAES-PKCS1-v1_5",
+ // RsaKeyGenParams
+ modulusLength: 2048,
+ publicExponent: new Uint8Array([0x01, 0x00, 0x01]), // Equivalent to 65537
+};
+
+debug("Generating a key...");
+crypto.subtle.generateKey(algorithmKeyGen, true, ["decrypt", "encrypt"]).then(function(result) {
+ keyPair = result;
+ debug("Encrypting...");
+ return crypto.subtle.encrypt("RSAES-PKCS1-v1_5", keyPair.publicKey, asciiToUint8Array(plainText));
+}).then(function(cipherText) {
+ debug("Decrypting...");
+ return crypto.subtle.decrypt("RSAES-PKCS1-v1_5", keyPair.privateKey, cipherText);
+}).then(function(result) {
+ decryptedText = result;
+
+ shouldBe("bytesToASCIIString(decryptedText)", "plainText");
+
+ finishJSTest();
+});
+</script>
+
+<script src=""
+</body>
+</html>
Added: trunk/LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-import-key-decrypt-expected.txt (0 => 208918)
--- trunk/LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-import-key-decrypt-expected.txt (rev 0)
+++ trunk/LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-import-key-decrypt-expected.txt 2016-11-19 04:38:59 UTC (rev 208918)
@@ -0,0 +1,10 @@
+Test decrypting using RSAES-PKCS1-v1_5 with an imported key
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS bytesToASCIIString(plainText) is expectedPlainText
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-import-key-decrypt.html (0 => 208918)
--- trunk/LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-import-key-decrypt.html (rev 0)
+++ trunk/LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-import-key-decrypt.html 2016-11-19 04:38:59 UTC (rev 208918)
@@ -0,0 +1,48 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script src=""
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test decrypting using RSAES-PKCS1-v1_5 with an imported key");
+
+jsTestIsAsync = true;
+
+var extractable = false;
+var cipherText = hexStringToUint8Array("87ca360442614b6590ea51ba84eb081ecda83c5a19e008ed21a6b93c78a7980348f9eac9a8120a6b67326b58ff6e7a10bec113b01f6bd18a04b82d159eb3532c03d4fca597450333cd4df81456b7b864a276cc3a7551964ccc16de86e2bc7a42981f29a0855fc151692d802f6d0b6fdcc0cc01977c579acde220b60d418a480f0ccdfd370f7e045114be39f03dfd516b51bcba6af20663cb2404e4e8c5b4c239936c672c3c2de4f4f3382cdc68f277fc66ed06a0642584ead53cd676673e8cecf59fe23cbe0a59cd82c8d56187eff6cda9b9e600b9890f42c65ee9a4f16f87c1c0b53cecb6fb59a4de165cc828d6bc5b5bf152e6c3060b54fd4e11b037668e4d");
+var jwkKey = {
+ kty: "RSA",
+ alg: "RSA1_5",
+ use: "enc",
+ key_ops: ["decrypt", "unwrapKey"],
+ ext: true,
+ n: "lxHN0N9VRZ0_pl0xv3-NXx70WnjkODSkQ5LjHXTFy3DOQsvkagFzD9HqYQezCmcewLjdK5PLwSesDoMdfL6tusBHcvyit1kvydYFQ3NLbENNkYsiBG5_nW4IQGL6JKbZ5iGdUop98QHKm6YZR1u4zrAtxM6bVEo05VvhjRS0M8yWoZVi-7Vdsc0LqI0Qdq_NoctX5Fu-AqiBN7Uo1HkYGcP2oC82J_J5cjw98BQiP5kDWThq9RK-X6S-EUALx_m4iG6iOYKTA3SQyf1xBqFaXXoEJjcckbOqkegecz5b-YWUh8iZPvhwnt-RZwpIbLJgKwz19ndkn9KvoEEw7YbEow",
+ e: "AQAB",
+ d: "cj5DkDakjM2bKduGWJREO-_zyEtuA1dD9doqKMd7IRuA0CDS7puEAS20-oXRDwfmyMXEdEUDrGGtCxh6fzDPvs_T-JA3GUK4EgHo3xZcrlXDXlKCeil6Fnr0gISZOIh5dkBrcdVL4quBJe4ZZc5mVuAC7Ld13et0TxMJ4iALGrPuqPVUOGSYIcZ9idx5zKKBWhY3tPggEdKpnHBmPfTRO4yZaf0Nw1QXrgSMZY9ejeuaurAh4Q8o4-6-r8O2LUe7ufMh_ccKkXISEh4KdOnT17EM9BQTn9UNS9GoK2ZZU0U3io5DSu_kpasr4uOVWcGlE2wczOv2nkGwG39F3sFF0Q",
+ p: "x5vnco5j-TD6hTOzyN4DhkZ44m05NycxT6SUE2qTurT3-uze_L7TYutLRIRkovRMhTHZAr2pziRlasEs13PEz9Zvx1I_T68srsonrdbak-SFMecM7EjHc5C-J13gXhw9HIW28_Sx9rQ-JkGwEwE9PEdIUfuvdqpgh3SmXwPJrEs",
+ q: "wb9vllg_2n-kNge0bThg_7xu1UwTzipM8vxSUkkV2IipJKIAekkU3aAB8LoPhUI0-17pSGw3ETOO27t163TI9qIPpzLbhTH9aUi7qLGbKlzPlgnqP43Z0LHxc3xKDgit-Ar29QLaX2uoJBX6VVWvhmh7BIPDHNVM5GZjwWORYgk",
+ dp: "C2c8sa6wx2uk5Dcv7inAycr83PKgciYrCwG78-AC0IfGIu-lTYsZSG1ov2FQ3n5WYMWYQC_Vo5EwugiPJz_V3onBmQF53HOFefbSjXvYwNotQcyRUG5X9qIuOtGCH949H4QED6vK_u0NH-JgzLUlamwoFYbrXzwch6CCYKs2ukE",
+ dq: "hbtRloDLclHwUqr2yvzDV0IFbozYjtF706x-VfXEcnXB6ls34TBYirFLJZIH7H9KeseEVkz7pY_k5555QlCV9kbebxYXl9RtiiJ-BW6yH4d4caPeYIfU9MweUQxVQWKUUkWfOHcDrCFvKZlR9Vzzjt7HKtKX9mr0bCKQcIf9baE",
+ qi: "a-7hUTTnclUPKOfSgH8zEKGJ-AvdFEzxvZ5sq46Qf2MbORxVjN4dJamVvM-FoqcwN-9cuUlyr9bSFTwUBW4vXa8Xj9a8JfViuMCqzR-mL1rGIUQ5ARGhNcSsRlyKTqz5BlWlVKmXIx_p-DeVwPWiJJy4k_FqyBxrnxkzomHfrxk",
+};
+var expectedPlainText = "Hello, World!";
+
+crypto.subtle.importKey("jwk", jwkKey, "RSAES-PKCS1-v1_5", extractable, ["decrypt"]).then(function(key) {
+ return crypto.subtle.decrypt("RSAES-PKCS1-v1_5", key, cipherText);
+}).then(function(result) {
+ plainText = result;
+
+ shouldBe("bytesToASCIIString(plainText)", "expectedPlainText");
+
+ finishJSTest();
+});
+</script>
+
+<script src=""
+</body>
+</html>
Added: trunk/LayoutTests/crypto/workers/subtle/aes-cbc-import-key-decrypt-expected.txt (0 => 208918)
--- trunk/LayoutTests/crypto/workers/subtle/aes-cbc-import-key-decrypt-expected.txt (rev 0)
+++ trunk/LayoutTests/crypto/workers/subtle/aes-cbc-import-key-decrypt-expected.txt 2016-11-19 04:38:59 UTC (rev 208918)
@@ -0,0 +1,11 @@
+[Worker] Test decrypting using AES-CBC with an imported 128bit key in workers
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Starting worker: resources/aes-cbc-import-key-decrypt.js
+PASS [Worker] bytesToASCIIString(plainText) is expectedPlainText
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/crypto/workers/subtle/aes-cbc-import-key-decrypt.html (0 => 208918)
--- trunk/LayoutTests/crypto/workers/subtle/aes-cbc-import-key-decrypt.html (rev 0)
+++ trunk/LayoutTests/crypto/workers/subtle/aes-cbc-import-key-decrypt.html 2016-11-19 04:38:59 UTC (rev 208918)
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src=""
+</head>
+<body>
+ <script>
+ worker = startWorker('resources/aes-cbc-import-key-decrypt.js');
+ </script>
+ <script src=""
+</body>
+</html>
Added: trunk/LayoutTests/crypto/workers/subtle/resources/aes-cbc-import-key-decrypt.js (0 => 208918)
--- trunk/LayoutTests/crypto/workers/subtle/resources/aes-cbc-import-key-decrypt.js (rev 0)
+++ trunk/LayoutTests/crypto/workers/subtle/resources/aes-cbc-import-key-decrypt.js 2016-11-19 04:38:59 UTC (rev 208918)
@@ -0,0 +1,25 @@
+importScripts('../../../../resources/js-test-pre.js');
+importScripts('../../../resources/common.js');
+
+description("Test decrypting using AES-CBC with an imported 128bit key in workers");
+
+jsTestIsAsync = true;
+
+var extractable = false;
+var cipherText = hexStringToUint8Array("2ffa4618784dfd414b22c40c6330d022");
+var aesCbcParams = {
+ name: "aes-cbc",
+ iv: asciiToUint8Array("jnOw99oOZFLIEPMr"),
+}
+var rawKey = asciiToUint8Array("jnOw99oOZFLIEPMr");
+var expectedPlainText = "Hello, World!";
+
+crypto.subtle.importKey("raw", rawKey, "aes-cbc", extractable, ["decrypt"]).then(function(key) {
+ return crypto.subtle.decrypt(aesCbcParams, key, cipherText);
+}).then(function(result) {
+ plainText = result;
+
+ shouldBe("bytesToASCIIString(plainText)", "expectedPlainText");
+
+ finishJSTest();
+});
Added: trunk/LayoutTests/crypto/workers/subtle/resources/rsa-oaep-import-key-decrypt.js (0 => 208918)
--- trunk/LayoutTests/crypto/workers/subtle/resources/rsa-oaep-import-key-decrypt.js (rev 0)
+++ trunk/LayoutTests/crypto/workers/subtle/resources/rsa-oaep-import-key-decrypt.js 2016-11-19 04:38:59 UTC (rev 208918)
@@ -0,0 +1,39 @@
+importScripts('../../../../resources/js-test-pre.js');
+importScripts('../../../resources/common.js');
+
+description("Test decrypting using RSA-OAEP SHA-1 with an imported key and a label in workers");
+
+jsTestIsAsync = true;
+
+var extractable = false;
+var cipherText = hexStringToUint8Array("346dc8f3a158e494004cf82c0843ab1c1e7a612263a1c44d941309175a3d2598997be651f2d3419f89923843ca344414d45989e886aaa79573d96d4f3f777af3b2e9fcd44b51c00a8e4395bf54ac89d88559c712d49853de448e190fad886c45fa0742f2ddf18e5f6155eb7f38348217efd67c14ef141e81f3b1c1804b3bb437ef1b23a25dadb594985c500181208c74cd2068cbfdccc02db7113ed5e72d7a3543a78ec9c2070715e409ab10687762358f786c669e592e467107a13caaaadc3c341facf249baf743a3b93c49f73ea5634052f1a6ee46265e02391dd2cbcd4a523bfee8321470279fff63b87a4a53465b4736fb31ee99e9b0379761f3e630f636");
+var jwkKey = {
+ kty: "RSA",
+ alg: "RSA-OAEP",
+ use: "enc",
+ key_ops: ["decrypt", "unwrapKey"],
+ ext: true,
+ n: "lxHN0N9VRZ0_pl0xv3-NXx70WnjkODSkQ5LjHXTFy3DOQsvkagFzD9HqYQezCmcewLjdK5PLwSesDoMdfL6tusBHcvyit1kvydYFQ3NLbENNkYsiBG5_nW4IQGL6JKbZ5iGdUop98QHKm6YZR1u4zrAtxM6bVEo05VvhjRS0M8yWoZVi-7Vdsc0LqI0Qdq_NoctX5Fu-AqiBN7Uo1HkYGcP2oC82J_J5cjw98BQiP5kDWThq9RK-X6S-EUALx_m4iG6iOYKTA3SQyf1xBqFaXXoEJjcckbOqkegecz5b-YWUh8iZPvhwnt-RZwpIbLJgKwz19ndkn9KvoEEw7YbEow",
+ e: "AQAB",
+ d: "cj5DkDakjM2bKduGWJREO-_zyEtuA1dD9doqKMd7IRuA0CDS7puEAS20-oXRDwfmyMXEdEUDrGGtCxh6fzDPvs_T-JA3GUK4EgHo3xZcrlXDXlKCeil6Fnr0gISZOIh5dkBrcdVL4quBJe4ZZc5mVuAC7Ld13et0TxMJ4iALGrPuqPVUOGSYIcZ9idx5zKKBWhY3tPggEdKpnHBmPfTRO4yZaf0Nw1QXrgSMZY9ejeuaurAh4Q8o4-6-r8O2LUe7ufMh_ccKkXISEh4KdOnT17EM9BQTn9UNS9GoK2ZZU0U3io5DSu_kpasr4uOVWcGlE2wczOv2nkGwG39F3sFF0Q",
+ p: "x5vnco5j-TD6hTOzyN4DhkZ44m05NycxT6SUE2qTurT3-uze_L7TYutLRIRkovRMhTHZAr2pziRlasEs13PEz9Zvx1I_T68srsonrdbak-SFMecM7EjHc5C-J13gXhw9HIW28_Sx9rQ-JkGwEwE9PEdIUfuvdqpgh3SmXwPJrEs",
+ q: "wb9vllg_2n-kNge0bThg_7xu1UwTzipM8vxSUkkV2IipJKIAekkU3aAB8LoPhUI0-17pSGw3ETOO27t163TI9qIPpzLbhTH9aUi7qLGbKlzPlgnqP43Z0LHxc3xKDgit-Ar29QLaX2uoJBX6VVWvhmh7BIPDHNVM5GZjwWORYgk",
+ dp: "C2c8sa6wx2uk5Dcv7inAycr83PKgciYrCwG78-AC0IfGIu-lTYsZSG1ov2FQ3n5WYMWYQC_Vo5EwugiPJz_V3onBmQF53HOFefbSjXvYwNotQcyRUG5X9qIuOtGCH949H4QED6vK_u0NH-JgzLUlamwoFYbrXzwch6CCYKs2ukE",
+ dq: "hbtRloDLclHwUqr2yvzDV0IFbozYjtF706x-VfXEcnXB6ls34TBYirFLJZIH7H9KeseEVkz7pY_k5555QlCV9kbebxYXl9RtiiJ-BW6yH4d4caPeYIfU9MweUQxVQWKUUkWfOHcDrCFvKZlR9Vzzjt7HKtKX9mr0bCKQcIf9baE",
+ qi: "a-7hUTTnclUPKOfSgH8zEKGJ-AvdFEzxvZ5sq46Qf2MbORxVjN4dJamVvM-FoqcwN-9cuUlyr9bSFTwUBW4vXa8Xj9a8JfViuMCqzR-mL1rGIUQ5ARGhNcSsRlyKTqz5BlWlVKmXIx_p-DeVwPWiJJy4k_FqyBxrnxkzomHfrxk",
+};
+var rsaOaepParams = {
+ name: "rsa-oaep",
+ label: asciiToUint8Array("WebKit.org"),
+}
+var expectedPlainText = "Hello, World!";
+
+crypto.subtle.importKey("jwk", jwkKey, {name: "RSA-OAEP", hash: "SHA-1"}, extractable, ["decrypt"]).then(function(key) {
+ return crypto.subtle.decrypt(rsaOaepParams, key, cipherText);
+}).then(function(result) {
+ plainText = result;
+
+ shouldBe("bytesToASCIIString(plainText)", "expectedPlainText");
+
+ finishJSTest();
+});
Added: trunk/LayoutTests/crypto/workers/subtle/resources/rsaes-pkcs1-v1_5-import-key-decrypt.js (0 => 208918)
--- trunk/LayoutTests/crypto/workers/subtle/resources/rsaes-pkcs1-v1_5-import-key-decrypt.js (rev 0)
+++ trunk/LayoutTests/crypto/workers/subtle/resources/rsaes-pkcs1-v1_5-import-key-decrypt.js 2016-11-19 04:38:59 UTC (rev 208918)
@@ -0,0 +1,35 @@
+importScripts('../../../../resources/js-test-pre.js');
+importScripts('../../../resources/common.js');
+
+description("Test decrypting using RSAES-PKCS1-v1_5 with an imported key in workers");
+
+jsTestIsAsync = true;
+
+var extractable = false;
+var cipherText = hexStringToUint8Array("87ca360442614b6590ea51ba84eb081ecda83c5a19e008ed21a6b93c78a7980348f9eac9a8120a6b67326b58ff6e7a10bec113b01f6bd18a04b82d159eb3532c03d4fca597450333cd4df81456b7b864a276cc3a7551964ccc16de86e2bc7a42981f29a0855fc151692d802f6d0b6fdcc0cc01977c579acde220b60d418a480f0ccdfd370f7e045114be39f03dfd516b51bcba6af20663cb2404e4e8c5b4c239936c672c3c2de4f4f3382cdc68f277fc66ed06a0642584ead53cd676673e8cecf59fe23cbe0a59cd82c8d56187eff6cda9b9e600b9890f42c65ee9a4f16f87c1c0b53cecb6fb59a4de165cc828d6bc5b5bf152e6c3060b54fd4e11b037668e4d");
+var jwkKey = {
+ kty: "RSA",
+ alg: "RSA1_5",
+ use: "enc",
+ key_ops: ["decrypt", "unwrapKey"],
+ ext: true,
+ n: "lxHN0N9VRZ0_pl0xv3-NXx70WnjkODSkQ5LjHXTFy3DOQsvkagFzD9HqYQezCmcewLjdK5PLwSesDoMdfL6tusBHcvyit1kvydYFQ3NLbENNkYsiBG5_nW4IQGL6JKbZ5iGdUop98QHKm6YZR1u4zrAtxM6bVEo05VvhjRS0M8yWoZVi-7Vdsc0LqI0Qdq_NoctX5Fu-AqiBN7Uo1HkYGcP2oC82J_J5cjw98BQiP5kDWThq9RK-X6S-EUALx_m4iG6iOYKTA3SQyf1xBqFaXXoEJjcckbOqkegecz5b-YWUh8iZPvhwnt-RZwpIbLJgKwz19ndkn9KvoEEw7YbEow",
+ e: "AQAB",
+ d: "cj5DkDakjM2bKduGWJREO-_zyEtuA1dD9doqKMd7IRuA0CDS7puEAS20-oXRDwfmyMXEdEUDrGGtCxh6fzDPvs_T-JA3GUK4EgHo3xZcrlXDXlKCeil6Fnr0gISZOIh5dkBrcdVL4quBJe4ZZc5mVuAC7Ld13et0TxMJ4iALGrPuqPVUOGSYIcZ9idx5zKKBWhY3tPggEdKpnHBmPfTRO4yZaf0Nw1QXrgSMZY9ejeuaurAh4Q8o4-6-r8O2LUe7ufMh_ccKkXISEh4KdOnT17EM9BQTn9UNS9GoK2ZZU0U3io5DSu_kpasr4uOVWcGlE2wczOv2nkGwG39F3sFF0Q",
+ p: "x5vnco5j-TD6hTOzyN4DhkZ44m05NycxT6SUE2qTurT3-uze_L7TYutLRIRkovRMhTHZAr2pziRlasEs13PEz9Zvx1I_T68srsonrdbak-SFMecM7EjHc5C-J13gXhw9HIW28_Sx9rQ-JkGwEwE9PEdIUfuvdqpgh3SmXwPJrEs",
+ q: "wb9vllg_2n-kNge0bThg_7xu1UwTzipM8vxSUkkV2IipJKIAekkU3aAB8LoPhUI0-17pSGw3ETOO27t163TI9qIPpzLbhTH9aUi7qLGbKlzPlgnqP43Z0LHxc3xKDgit-Ar29QLaX2uoJBX6VVWvhmh7BIPDHNVM5GZjwWORYgk",
+ dp: "C2c8sa6wx2uk5Dcv7inAycr83PKgciYrCwG78-AC0IfGIu-lTYsZSG1ov2FQ3n5WYMWYQC_Vo5EwugiPJz_V3onBmQF53HOFefbSjXvYwNotQcyRUG5X9qIuOtGCH949H4QED6vK_u0NH-JgzLUlamwoFYbrXzwch6CCYKs2ukE",
+ dq: "hbtRloDLclHwUqr2yvzDV0IFbozYjtF706x-VfXEcnXB6ls34TBYirFLJZIH7H9KeseEVkz7pY_k5555QlCV9kbebxYXl9RtiiJ-BW6yH4d4caPeYIfU9MweUQxVQWKUUkWfOHcDrCFvKZlR9Vzzjt7HKtKX9mr0bCKQcIf9baE",
+ qi: "a-7hUTTnclUPKOfSgH8zEKGJ-AvdFEzxvZ5sq46Qf2MbORxVjN4dJamVvM-FoqcwN-9cuUlyr9bSFTwUBW4vXa8Xj9a8JfViuMCqzR-mL1rGIUQ5ARGhNcSsRlyKTqz5BlWlVKmXIx_p-DeVwPWiJJy4k_FqyBxrnxkzomHfrxk",
+};
+var expectedPlainText = "Hello, World!";
+
+crypto.subtle.importKey("jwk", jwkKey, "RSAES-PKCS1-v1_5", extractable, ["decrypt"]).then(function(key) {
+ return crypto.subtle.decrypt("RSAES-PKCS1-v1_5", key, cipherText);
+}).then(function(result) {
+ plainText = result;
+
+ shouldBe("bytesToASCIIString(plainText)", "expectedPlainText");
+
+ finishJSTest();
+});
Added: trunk/LayoutTests/crypto/workers/subtle/rsa-oaep-import-key-decrypt-expected.txt (0 => 208918)
--- trunk/LayoutTests/crypto/workers/subtle/rsa-oaep-import-key-decrypt-expected.txt (rev 0)
+++ trunk/LayoutTests/crypto/workers/subtle/rsa-oaep-import-key-decrypt-expected.txt 2016-11-19 04:38:59 UTC (rev 208918)
@@ -0,0 +1,11 @@
+[Worker] Test decrypting using RSA-OAEP SHA-1 with an imported key and a label in workers
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Starting worker: resources/rsa-oaep-import-key-decrypt.js
+PASS [Worker] bytesToASCIIString(plainText) is expectedPlainText
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/crypto/workers/subtle/rsa-oaep-import-key-decrypt.html (0 => 208918)
--- trunk/LayoutTests/crypto/workers/subtle/rsa-oaep-import-key-decrypt.html (rev 0)
+++ trunk/LayoutTests/crypto/workers/subtle/rsa-oaep-import-key-decrypt.html 2016-11-19 04:38:59 UTC (rev 208918)
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src=""
+</head>
+<body>
+ <script>
+ worker = startWorker('resources/rsa-oaep-import-key-decrypt.js');
+ </script>
+ <script src=""
+</body>
+</html>
Added: trunk/LayoutTests/crypto/workers/subtle/rsaes-pkcs1-v1_5-import-key-decrypt-expected.txt (0 => 208918)
--- trunk/LayoutTests/crypto/workers/subtle/rsaes-pkcs1-v1_5-import-key-decrypt-expected.txt (rev 0)
+++ trunk/LayoutTests/crypto/workers/subtle/rsaes-pkcs1-v1_5-import-key-decrypt-expected.txt 2016-11-19 04:38:59 UTC (rev 208918)
@@ -0,0 +1,11 @@
+[Worker] Test decrypting using RSAES-PKCS1-v1_5 with an imported key in workers
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Starting worker: resources/rsaes-pkcs1-v1_5-import-key-decrypt.js
+PASS [Worker] bytesToASCIIString(plainText) is expectedPlainText
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/crypto/workers/subtle/rsaes-pkcs1-v1_5-import-key-decrypt.html (0 => 208918)
--- trunk/LayoutTests/crypto/workers/subtle/rsaes-pkcs1-v1_5-import-key-decrypt.html (rev 0)
+++ trunk/LayoutTests/crypto/workers/subtle/rsaes-pkcs1-v1_5-import-key-decrypt.html 2016-11-19 04:38:59 UTC (rev 208918)
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src=""
+</head>
+<body>
+ <script>
+ worker = startWorker('resources/rsaes-pkcs1-v1_5-import-key-decrypt.js');
+ </script>
+ <script src=""
+</body>
+</html>
Modified: trunk/LayoutTests/imported/w3c/ChangeLog (208917 => 208918)
--- trunk/LayoutTests/imported/w3c/ChangeLog 2016-11-19 04:25:38 UTC (rev 208917)
+++ trunk/LayoutTests/imported/w3c/ChangeLog 2016-11-19 04:38:59 UTC (rev 208918)
@@ -1,3 +1,14 @@
+2016-11-18 Jiewen Tan <[email protected]>
+
+ Update SubtleCrypto::decrypt to match the latest spec
+ https://bugs.webkit.org/show_bug.cgi?id=164739
+ <rdar://problem/29257848>
+
+ Reviewed by Brent Fulgham.
+
+ * WebCryptoAPI/encrypt_decrypt/test_aes_cbc-expected.txt:
+ * WebCryptoAPI/idlharness-expected.txt:
+
2016-11-18 Alex Christensen <[email protected]>
TextDecoder constructor should not accept replacement encodings
Modified: trunk/LayoutTests/imported/w3c/WebCryptoAPI/encrypt_decrypt/test_aes_cbc-expected.txt (208917 => 208918)
--- trunk/LayoutTests/imported/w3c/WebCryptoAPI/encrypt_decrypt/test_aes_cbc-expected.txt 2016-11-19 04:25:38 UTC (rev 208917)
+++ trunk/LayoutTests/imported/w3c/WebCryptoAPI/encrypt_decrypt/test_aes_cbc-expected.txt 2016-11-19 04:38:59 UTC (rev 208918)
@@ -7,12 +7,12 @@
PASS AES-CBC 128-bit key with altered plaintext
PASS AES-CBC 192-bit key with altered plaintext
PASS AES-CBC 256-bit key with altered plaintext
-FAIL AES-CBC 128-bit key decryption subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined)
-FAIL AES-CBC 192-bit key decryption subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined)
-FAIL AES-CBC 256-bit key decryption subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined)
-FAIL AES-CBC 128-bit key decryption with altered ciphertext subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, ciphertext)', 'subtle.decrypt' is undefined)
-FAIL AES-CBC 192-bit key decryption with altered ciphertext subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, ciphertext)', 'subtle.decrypt' is undefined)
-FAIL AES-CBC 256-bit key decryption with altered ciphertext subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, ciphertext)', 'subtle.decrypt' is undefined)
+PASS AES-CBC 128-bit key decryption
+PASS AES-CBC 192-bit key decryption
+PASS AES-CBC 256-bit key decryption
+PASS AES-CBC 128-bit key decryption with altered ciphertext
+PASS AES-CBC 192-bit key decryption with altered ciphertext
+PASS AES-CBC 256-bit key decryption with altered ciphertext
PASS AES-CBC 128-bit key without encrypt usage
PASS AES-CBC 192-bit key without encrypt usage
PASS AES-CBC 256-bit key without encrypt usage
@@ -19,9 +19,9 @@
FAIL AES-CBC 128-bit key with mismatched key and algorithm assert_equals: Mismatch should cause InvalidAccessError instead of The operation is not supported. expected "InvalidAccessError" but got "NotSupportedError"
FAIL AES-CBC 192-bit key with mismatched key and algorithm assert_equals: Mismatch should cause InvalidAccessError instead of The operation is not supported. expected "InvalidAccessError" but got "NotSupportedError"
FAIL AES-CBC 256-bit key with mismatched key and algorithm assert_equals: Mismatch should cause InvalidAccessError instead of The operation is not supported. expected "InvalidAccessError" but got "NotSupportedError"
-FAIL AES-CBC 128-bit key without decrypt usage subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined)
-FAIL AES-CBC 192-bit key without decrypt usage subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined)
-FAIL AES-CBC 256-bit key without decrypt usage subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined)
+PASS AES-CBC 128-bit key without decrypt usage
+PASS AES-CBC 192-bit key without decrypt usage
+PASS AES-CBC 256-bit key without decrypt usage
PASS AES-CBC 128-bit key, 64-bit IV
PASS AES-CBC 128-bit key, 192-bit IV
PASS AES-CBC 192-bit key, 64-bit IV
@@ -28,19 +28,19 @@
PASS AES-CBC 192-bit key, 192-bit IV
PASS AES-CBC 256-bit key, 64-bit IV
PASS AES-CBC 256-bit key, 192-bit IV
-FAIL AES-CBC 128-bit key, 64-bit IV decryption subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined)
-FAIL AES-CBC 128-bit key, 192-bit IV decryption subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined)
-FAIL AES-CBC 192-bit key, 64-bit IV decryption subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined)
-FAIL AES-CBC 192-bit key, 192-bit IV decryption subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined)
-FAIL AES-CBC 256-bit key, 64-bit IV decryption subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined)
-FAIL AES-CBC 256-bit key, 192-bit IV decryption subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined)
-FAIL AES-CBC 128-bit key, zeroPadChar subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined)
-FAIL AES-CBC 128-bit key, bigPadChar subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined)
-FAIL AES-CBC 128-bit key, inconsistentPadChars subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined)
-FAIL AES-CBC 192-bit key, zeroPadChar subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined)
-FAIL AES-CBC 192-bit key, bigPadChar subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined)
-FAIL AES-CBC 192-bit key, inconsistentPadChars subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined)
-FAIL AES-CBC 256-bit key, zeroPadChar subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined)
-FAIL AES-CBC 256-bit key, bigPadChar subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined)
-FAIL AES-CBC 256-bit key, inconsistentPadChars subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined)
+PASS AES-CBC 128-bit key, 64-bit IV decryption
+PASS AES-CBC 128-bit key, 192-bit IV decryption
+PASS AES-CBC 192-bit key, 64-bit IV decryption
+PASS AES-CBC 192-bit key, 192-bit IV decryption
+PASS AES-CBC 256-bit key, 64-bit IV decryption
+PASS AES-CBC 256-bit key, 192-bit IV decryption
+FAIL AES-CBC 128-bit key, zeroPadChar assert_unreached: should have thrown exception for test AES-CBC 128-bit key, zeroPadChar Reached unreachable code
+FAIL AES-CBC 128-bit key, bigPadChar assert_unreached: should have thrown exception for test AES-CBC 128-bit key, bigPadChar Reached unreachable code
+FAIL AES-CBC 128-bit key, inconsistentPadChars assert_unreached: should have thrown exception for test AES-CBC 128-bit key, inconsistentPadChars Reached unreachable code
+FAIL AES-CBC 192-bit key, zeroPadChar assert_unreached: should have thrown exception for test AES-CBC 192-bit key, zeroPadChar Reached unreachable code
+FAIL AES-CBC 192-bit key, bigPadChar assert_unreached: should have thrown exception for test AES-CBC 192-bit key, bigPadChar Reached unreachable code
+FAIL AES-CBC 192-bit key, inconsistentPadChars assert_unreached: should have thrown exception for test AES-CBC 192-bit key, inconsistentPadChars Reached unreachable code
+FAIL AES-CBC 256-bit key, zeroPadChar assert_unreached: should have thrown exception for test AES-CBC 256-bit key, zeroPadChar Reached unreachable code
+FAIL AES-CBC 256-bit key, bigPadChar assert_unreached: should have thrown exception for test AES-CBC 256-bit key, bigPadChar Reached unreachable code
+FAIL AES-CBC 256-bit key, inconsistentPadChars assert_unreached: should have thrown exception for test AES-CBC 256-bit key, inconsistentPadChars Reached unreachable code
Modified: trunk/LayoutTests/imported/w3c/WebCryptoAPI/idlharness-expected.txt (208917 => 208918)
--- trunk/LayoutTests/imported/w3c/WebCryptoAPI/idlharness-expected.txt 2016-11-19 04:25:38 UTC (rev 208917)
+++ trunk/LayoutTests/imported/w3c/WebCryptoAPI/idlharness-expected.txt 2016-11-19 04:38:59 UTC (rev 208918)
@@ -45,8 +45,8 @@
PASS Stringification of crypto.subtle
PASS SubtleCrypto interface: crypto.subtle must inherit property "encrypt" with the proper type (0)
PASS SubtleCrypto interface: calling encrypt(AlgorithmIdentifier,CryptoKey,BufferSource) on crypto.subtle with too few arguments must throw TypeError
-FAIL SubtleCrypto interface: crypto.subtle must inherit property "decrypt" with the proper type (1) assert_inherits: property "decrypt" not found in prototype chain
-FAIL SubtleCrypto interface: calling decrypt(AlgorithmIdentifier,CryptoKey,BufferSource) on crypto.subtle with too few arguments must throw TypeError assert_inherits: property "decrypt" not found in prototype chain
+PASS SubtleCrypto interface: crypto.subtle must inherit property "decrypt" with the proper type (1)
+PASS SubtleCrypto interface: calling decrypt(AlgorithmIdentifier,CryptoKey,BufferSource) on crypto.subtle with too few arguments must throw TypeError
FAIL SubtleCrypto interface: crypto.subtle must inherit property "sign" with the proper type (2) assert_inherits: property "sign" not found in prototype chain
FAIL SubtleCrypto interface: calling sign(AlgorithmIdentifier,CryptoKey,BufferSource) on crypto.subtle with too few arguments must throw TypeError assert_inherits: property "sign" not found in prototype chain
FAIL SubtleCrypto interface: crypto.subtle must inherit property "verify" with the proper type (3) assert_inherits: property "verify" not found in prototype chain
Modified: trunk/Source/WebCore/ChangeLog (208917 => 208918)
--- trunk/Source/WebCore/ChangeLog 2016-11-19 04:25:38 UTC (rev 208917)
+++ trunk/Source/WebCore/ChangeLog 2016-11-19 04:38:59 UTC (rev 208918)
@@ -1,3 +1,70 @@
+2016-11-18 Jiewen Tan <[email protected]>
+
+ Update SubtleCrypto::decrypt to match the latest spec
+ https://bugs.webkit.org/show_bug.cgi?id=164739
+ <rdar://problem/29257848>
+
+ Reviewed by Brent Fulgham.
+
+ This patch does following few things:
+ 1. It updates the SubtleCrypto::decrypt method to match the latest spec:
+ https://www.w3.org/TR/WebCryptoAPI/#SubtleCrypto-method-decrypt.
+ It also refers to the latest Editor's Draft to a certain degree:
+ https://w3c.github.io/webcrypto/Overview.html#SubtleCrypto-method-decrypt.
+ 2. It implements decrypt operations of the following algorithms: AES-CBC,
+ RSAES-PKCS1-V1_5, and RSA-OAEP.
+
+ Tests: crypto/subtle/aes-cbc-decrypt-malformed-parameters.html
+ crypto/subtle/aes-cbc-generate-key-encrypt-decrypt.html
+ crypto/subtle/aes-cbc-import-key-decrypt.html
+ crypto/subtle/decrypt-malformed-parameters.html
+ crypto/subtle/rsa-oaep-decrypt-malformed-parameters.html
+ crypto/subtle/rsa-oaep-generate-key-encrypt-decrypt-label.html
+ crypto/subtle/rsa-oaep-generate-key-encrypt-decrypt.html
+ crypto/subtle/rsa-oaep-import-key-decrypt-label.html
+ crypto/subtle/rsa-oaep-import-key-decrypt.html
+ crypto/subtle/rsaes-pkcs1-v1_5-generate-key-encrypt-decrypt.html
+ crypto/subtle/rsaes-pkcs1-v1_5-import-key-decrypt.html
+ crypto/workers/subtle/aes-cbc-import-key-decrypt.html
+ crypto/workers/subtle/rsa-oaep-import-key-decrypt.html
+ crypto/workers/subtle/rsaes-pkcs1-v1_5-import-key-decrypt.html
+
+ * bindings/js/JSSubtleCryptoCustom.cpp:
+ (WebCore::normalizeCryptoAlgorithmParameters):
+ (WebCore::toCryptoKey):
+ (WebCore::toVector):
+ (WebCore::jsSubtleCryptoFunctionEncryptPromise):
+ (WebCore::jsSubtleCryptoFunctionDecryptPromise):
+ (WebCore::jsSubtleCryptoFunctionExportKeyPromise):
+ (WebCore::JSSubtleCrypto::decrypt):
+ * crypto/CryptoAlgorithm.cpp:
+ (WebCore::CryptoAlgorithm::decrypt):
+ * crypto/CryptoAlgorithm.h:
+ * crypto/SubtleCrypto.idl:
+ * crypto/algorithms/CryptoAlgorithmAES_CBC.cpp:
+ (WebCore::CryptoAlgorithmAES_CBC::decrypt):
+ * crypto/algorithms/CryptoAlgorithmAES_CBC.h:
+ * crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp:
+ (WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::decrypt):
+ * crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.h:
+ * crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp:
+ (WebCore::CryptoAlgorithmRSA_OAEP::decrypt):
+ * crypto/algorithms/CryptoAlgorithmRSA_OAEP.h:
+ * crypto/gnutls/CryptoAlgorithmAES_CBCGnuTLS.cpp:
+ (WebCore::CryptoAlgorithmAES_CBC::platformDecrypt):
+ * crypto/gnutls/CryptoAlgorithmRSAES_PKCS1_v1_5GnuTLS.cpp:
+ (WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::platformDecrypt):
+ * crypto/gnutls/CryptoAlgorithmRSA_OAEPGnuTLS.cpp:
+ (WebCore::CryptoAlgorithmRSA_OAEP::platformDecrypt):
+ * crypto/mac/CryptoAlgorithmAES_CBCMac.cpp:
+ (WebCore::CryptoAlgorithmAES_CBC::platformDecrypt):
+ * crypto/mac/CryptoAlgorithmRSAES_PKCS1_v1_5Mac.cpp:
+ (WebCore::decryptRSAES_PKCS1_v1_5):
+ (WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::platformDecrypt):
+ * crypto/mac/CryptoAlgorithmRSA_OAEPMac.cpp:
+ (WebCore::decryptRSA_OAEP):
+ (WebCore::CryptoAlgorithmRSA_OAEP::platformDecrypt):
+
2016-11-18 Chris Dumez <[email protected]>
Unreviewed, rolling out r208837.
Modified: trunk/Source/WebCore/bindings/js/JSSubtleCryptoCustom.cpp (208917 => 208918)
--- trunk/Source/WebCore/bindings/js/JSSubtleCryptoCustom.cpp 2016-11-19 04:25:38 UTC (rev 208917)
+++ trunk/Source/WebCore/bindings/js/JSSubtleCryptoCustom.cpp 2016-11-19 04:38:59 UTC (rev 208918)
@@ -53,6 +53,7 @@
enum class Operations {
Encrypt,
+ Decrypt,
Digest,
GenerateKey,
ImportKey,
@@ -94,6 +95,7 @@
std::unique_ptr<CryptoAlgorithmParameters> result;
switch (operation) {
case Operations::Encrypt:
+ case Operations::Decrypt:
switch (*identifier) {
case CryptoAlgorithmIdentifier::RSAES_PKCS1_v1_5:
result = std::make_unique<CryptoAlgorithmParameters>(params);
@@ -388,6 +390,32 @@
return result;
}
+static RefPtr<CryptoKey> toCryptoKey(ExecState& state, JSValue value)
+{
+ VM& vm = state.vm();
+ auto scope = DECLARE_THROW_SCOPE(vm);
+
+ RefPtr<CryptoKey> result = JSCryptoKey::toWrapped(value);
+ if (!result) {
+ throwTypeError(&state, scope, ASCIILiteral("Invalid CryptoKey"));
+ return nullptr;
+ }
+ return result;
+}
+
+static Vector<uint8_t> toVector(ExecState& state, JSValue value)
+{
+ VM& vm = state.vm();
+ auto scope = DECLARE_THROW_SCOPE(vm);
+
+ BufferSource data = "" value);
+ RETURN_IF_EXCEPTION(scope, { });
+ Vector<uint8_t> dataVector;
+ dataVector.append(data.data(), data.length());
+
+ return dataVector;
+}
+
static void jsSubtleCryptoFunctionEncryptPromise(ExecState& state, Ref<DeferredPromise>&& promise)
{
VM& vm = state.vm();
@@ -401,16 +429,11 @@
auto params = normalizeCryptoAlgorithmParameters(state, state.uncheckedArgument(0), Operations::Encrypt);
RETURN_IF_EXCEPTION(scope, void());
- RefPtr<CryptoKey> key = JSCryptoKey::toWrapped(state.uncheckedArgument(1));
- if (!key) {
- promise->reject(TypeError, ASCIILiteral("Invalid CryptoKey"));
- return;
- }
+ auto key = toCryptoKey(state, state.uncheckedArgument(1));
+ RETURN_IF_EXCEPTION(scope, void());
- BufferSource data = "" state.uncheckedArgument(2));
+ auto data = "" state.uncheckedArgument(2));
RETURN_IF_EXCEPTION(scope, void());
- Vector<uint8_t> dataVector;
- dataVector.append(data.data(), data.length());
if (params->identifier != key->algorithmIdentifier()) {
promise->reject(INVALID_ACCESS_ERR, ASCIILiteral("CryptoKey doesn't match AlgorithmIdentifier"));
@@ -435,9 +458,54 @@
JSSubtleCrypto* subtle = jsDynamicDowncast<JSSubtleCrypto*>(state.thisValue());
ASSERT(subtle);
- algorithm->encrypt(WTFMove(params), key.releaseNonNull(), WTFMove(dataVector), WTFMove(callback), WTFMove(exceptionCallback), *scriptExecutionContextFromExecState(&state), subtle->wrapped().workQueue());
+ algorithm->encrypt(WTFMove(params), key.releaseNonNull(), WTFMove(data), WTFMove(callback), WTFMove(exceptionCallback), *scriptExecutionContextFromExecState(&state), subtle->wrapped().workQueue());
}
+static void jsSubtleCryptoFunctionDecryptPromise(ExecState& state, Ref<DeferredPromise>&& promise)
+{
+ VM& vm = state.vm();
+ auto scope = DECLARE_THROW_SCOPE(vm);
+
+ if (UNLIKELY(state.argumentCount() < 3)) {
+ promise->reject<JSValue>(createNotEnoughArgumentsError(&state));
+ return;
+ }
+
+ auto params = normalizeCryptoAlgorithmParameters(state, state.uncheckedArgument(0), Operations::Decrypt);
+ RETURN_IF_EXCEPTION(scope, void());
+
+ auto key = toCryptoKey(state, state.uncheckedArgument(1));
+ RETURN_IF_EXCEPTION(scope, void());
+
+ auto data = "" state.uncheckedArgument(2));
+ RETURN_IF_EXCEPTION(scope, void());
+
+ if (params->identifier != key->algorithmIdentifier()) {
+ promise->reject(INVALID_ACCESS_ERR, ASCIILiteral("CryptoKey doesn't match AlgorithmIdentifier"));
+ return;
+ }
+
+ if (!key->allows(CryptoKeyUsageDecrypt)) {
+ promise->reject(INVALID_ACCESS_ERR, ASCIILiteral("CryptoKey doesn't support decryption"));
+ return;
+ }
+
+ auto algorithm = createAlgorithm(state, key->algorithmIdentifier());
+ RETURN_IF_EXCEPTION(scope, void());
+
+ auto callback = [capturedPromise = promise.copyRef()](const Vector<uint8_t>& cipherText) mutable {
+ fulfillPromiseWithArrayBuffer(WTFMove(capturedPromise), cipherText.data(), cipherText.size());
+ return;
+ };
+ auto exceptionCallback = [capturedPromise = promise.copyRef()](ExceptionCode ec) mutable {
+ rejectWithException(WTFMove(capturedPromise), ec);
+ };
+
+ JSSubtleCrypto* subtle = jsDynamicDowncast<JSSubtleCrypto*>(state.thisValue());
+ ASSERT(subtle);
+ algorithm->decrypt(WTFMove(params), key.releaseNonNull(), WTFMove(data), WTFMove(callback), WTFMove(exceptionCallback), *scriptExecutionContextFromExecState(&state), subtle->wrapped().workQueue());
+}
+
static void jsSubtleCryptoFunctionGenerateKeyPromise(ExecState& state, Ref<DeferredPromise>&& promise)
{
VM& vm = state.vm();
@@ -545,11 +613,8 @@
auto format = convertEnumeration<SubtleCrypto::KeyFormat>(state, state.uncheckedArgument(0));
RETURN_IF_EXCEPTION(scope, void());
- RefPtr<CryptoKey> key = JSCryptoKey::toWrapped(state.uncheckedArgument(1));
- if (!key) {
- promise->reject(TypeError, ASCIILiteral("Invalid CryptoKey"));
- return;
- }
+ auto key = toCryptoKey(state, state.uncheckedArgument(1));
+ RETURN_IF_EXCEPTION(scope, void());
switch (key->algorithmIdentifier()) {
case CryptoAlgorithmIdentifier::RSAES_PKCS1_v1_5:
@@ -607,6 +672,11 @@
return callPromiseFunction<jsSubtleCryptoFunctionEncryptPromise, PromiseExecutionScope::WindowOrWorker>(state);
}
+JSValue JSSubtleCrypto::decrypt(ExecState& state)
+{
+ return callPromiseFunction<jsSubtleCryptoFunctionDecryptPromise, PromiseExecutionScope::WindowOrWorker>(state);
+}
+
JSValue JSSubtleCrypto::generateKey(ExecState& state)
{
return callPromiseFunction<jsSubtleCryptoFunctionGenerateKeyPromise, PromiseExecutionScope::WindowOrWorker>(state);
Modified: trunk/Source/WebCore/crypto/CryptoAlgorithm.cpp (208917 => 208918)
--- trunk/Source/WebCore/crypto/CryptoAlgorithm.cpp 2016-11-19 04:25:38 UTC (rev 208917)
+++ trunk/Source/WebCore/crypto/CryptoAlgorithm.cpp 2016-11-19 04:38:59 UTC (rev 208918)
@@ -37,6 +37,11 @@
exceptionCallback(NOT_SUPPORTED_ERR);
}
+void CryptoAlgorithm::decrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&& exceptionCallback, ScriptExecutionContext&, WorkQueue&)
+{
+ exceptionCallback(NOT_SUPPORTED_ERR);
+}
+
void CryptoAlgorithm::generateKey(const std::unique_ptr<CryptoAlgorithmParameters>&&, bool, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&& exceptionCallback, ScriptExecutionContext&)
{
exceptionCallback(NOT_SUPPORTED_ERR);
Modified: trunk/Source/WebCore/crypto/CryptoAlgorithm.h (208917 => 208918)
--- trunk/Source/WebCore/crypto/CryptoAlgorithm.h 2016-11-19 04:25:38 UTC (rev 208917)
+++ trunk/Source/WebCore/crypto/CryptoAlgorithm.h 2016-11-19 04:38:59 UTC (rev 208918)
@@ -65,6 +65,7 @@
using KeyDataCallback = WTF::Function<void(SubtleCrypto::KeyFormat, KeyData&&)>;
virtual void encrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
+ virtual void decrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
virtual void generateKey(const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&&, ScriptExecutionContext&);
virtual void importKey(SubtleCrypto::KeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&);
virtual void exportKey(SubtleCrypto::KeyFormat, Ref<CryptoKey>&&, KeyDataCallback&&, ExceptionCallback&&);
Modified: trunk/Source/WebCore/crypto/SubtleCrypto.idl (208917 => 208918)
--- trunk/Source/WebCore/crypto/SubtleCrypto.idl 2016-11-19 04:25:38 UTC (rev 208917)
+++ trunk/Source/WebCore/crypto/SubtleCrypto.idl 2016-11-19 04:38:59 UTC (rev 208918)
@@ -32,6 +32,7 @@
NoInterfaceObject,
] interface SubtleCrypto {
[Custom] Promise<any> encrypt(AlgorithmIdentifier algorithm, CryptoKey key, BufferSource data);
+ [Custom] Promise<any> decrypt(AlgorithmIdentifier algorithm, CryptoKey key, BufferSource data);
// FIXME: Should this return a Promise<(CryptoKey or CryptoKeyPair)>?
[Custom] Promise<any> generateKey(AlgorithmIdentifier algorithm, boolean extractable, sequence<CryptoKeyUsage> keyUsages);
[Custom] Promise<CryptoKey> importKey(KeyFormat format, (BufferSource or JsonWebKey) keyData, AlgorithmIdentifier algorithm, boolen extractable, sequence<CryptoKeyUsage> keyUsages);
Modified: trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_CBC.cpp (208917 => 208918)
--- trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_CBC.cpp 2016-11-19 04:25:38 UTC (rev 208917)
+++ trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_CBC.cpp 2016-11-19 04:38:59 UTC (rev 208918)
@@ -77,6 +77,17 @@
platformEncrypt(WTFMove(parameters), WTFMove(key), WTFMove(plainText), WTFMove(callback), WTFMove(exceptionCallback), context, workQueue);
}
+void CryptoAlgorithmAES_CBC::decrypt(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& cipherText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+{
+ ASSERT(parameters);
+ auto& aesParameters = downcast<CryptoAlgorithmAesCbcParams>(*parameters);
+ if (aesParameters.ivVector().size() != IVSIZE) {
+ exceptionCallback(OperationError);
+ return;
+ }
+ platformDecrypt(WTFMove(parameters), WTFMove(key), WTFMove(cipherText), WTFMove(callback), WTFMove(exceptionCallback), context, workQueue);
+}
+
void CryptoAlgorithmAES_CBC::generateKey(const std::unique_ptr<CryptoAlgorithmParameters>&& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyOrKeyPairCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext&)
{
ASSERT(parameters);
Modified: trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_CBC.h (208917 => 208918)
--- trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_CBC.h 2016-11-19 04:25:38 UTC (rev 208917)
+++ trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_CBC.h 2016-11-19 04:38:59 UTC (rev 208918)
@@ -45,6 +45,7 @@
CryptoAlgorithmIdentifier identifier() const final;
void encrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
+ void decrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
void generateKey(const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&&, ScriptExecutionContext&) final;
void importKey(SubtleCrypto::KeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final;
void exportKey(SubtleCrypto::KeyFormat, Ref<CryptoKey>&&, KeyDataCallback&&, ExceptionCallback&&) final;
@@ -56,6 +57,7 @@
bool keyAlgorithmMatches(const CryptoAlgorithmAesCbcParamsDeprecated& algorithmParameters, const CryptoKey&) const;
void platformEncrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
+ void platformDecrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
ExceptionOr<void> platformEncrypt(const CryptoAlgorithmAesCbcParamsDeprecated&, const CryptoKeyAES&, const CryptoOperationData&, VectorCallback&&, VoidCallback&& failureCallback);
ExceptionOr<void> platformDecrypt(const CryptoAlgorithmAesCbcParamsDeprecated&, const CryptoKeyAES&, const CryptoOperationData&, VectorCallback&&, VoidCallback&& failureCallback);
};
Modified: trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp (208917 => 208918)
--- trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp 2016-11-19 04:25:38 UTC (rev 208917)
+++ trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp 2016-11-19 04:38:59 UTC (rev 208918)
@@ -68,6 +68,15 @@
platformEncrypt(WTFMove(key), WTFMove(plainText), WTFMove(callback), WTFMove(exceptionCallback), context, workQueue);
}
+void CryptoAlgorithmRSAES_PKCS1_v1_5::decrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&& key, Vector<uint8_t>&& cipherText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+{
+ if (key->type() != CryptoKeyType::Private) {
+ exceptionCallback(INVALID_ACCESS_ERR);
+ return;
+ }
+ platformDecrypt(WTFMove(key), WTFMove(cipherText), WTFMove(callback), WTFMove(exceptionCallback), context, workQueue);
+}
+
void CryptoAlgorithmRSAES_PKCS1_v1_5::generateKey(const std::unique_ptr<CryptoAlgorithmParameters>&& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyOrKeyPairCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context)
{
ASSERT(parameters);
Modified: trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.h (208917 => 208918)
--- trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.h 2016-11-19 04:25:38 UTC (rev 208917)
+++ trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.h 2016-11-19 04:38:59 UTC (rev 208918)
@@ -45,6 +45,7 @@
CryptoAlgorithmIdentifier identifier() const final;
void encrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
+ void decrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
void generateKey(const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&&, ScriptExecutionContext&) final;
void importKey(SubtleCrypto::KeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final;
void exportKey(SubtleCrypto::KeyFormat, Ref<CryptoKey>&&, KeyDataCallback&&, ExceptionCallback&&) final;
@@ -56,6 +57,7 @@
bool keyAlgorithmMatches(const CryptoKey&) const;
void platformEncrypt(Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
+ void platformDecrypt(Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
ExceptionOr<void> platformEncrypt(const CryptoKeyRSA&, const CryptoOperationData&, VectorCallback&&, VoidCallback&& failureCallback);
ExceptionOr<void> platformDecrypt(const CryptoKeyRSA&, const CryptoOperationData&, VectorCallback&&, VoidCallback&& failureCallback);
};
Modified: trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp (208917 => 208918)
--- trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp 2016-11-19 04:25:38 UTC (rev 208917)
+++ trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp 2016-11-19 04:38:59 UTC (rev 208918)
@@ -78,6 +78,15 @@
platformEncrypt(WTFMove(parameters), WTFMove(key), WTFMove(plainText), WTFMove(callback), WTFMove(exceptionCallback), context, workQueue);
}
+void CryptoAlgorithmRSA_OAEP::decrypt(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& cipherText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+{
+ ASSERT(parameters);
+ if (key->type() != CryptoKeyType::Private) {
+ exceptionCallback(INVALID_ACCESS_ERR);
+ return;
+ }
+ platformDecrypt(WTFMove(parameters), WTFMove(key), WTFMove(cipherText), WTFMove(callback), WTFMove(exceptionCallback), context, workQueue);
+}
void CryptoAlgorithmRSA_OAEP::generateKey(const std::unique_ptr<CryptoAlgorithmParameters>&& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyOrKeyPairCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context)
{
Modified: trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSA_OAEP.h (208917 => 208918)
--- trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSA_OAEP.h 2016-11-19 04:25:38 UTC (rev 208917)
+++ trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSA_OAEP.h 2016-11-19 04:38:59 UTC (rev 208918)
@@ -45,6 +45,7 @@
CryptoAlgorithmIdentifier identifier() const final;
void encrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
+ void decrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
void generateKey(const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&&, ScriptExecutionContext&) final;
void importKey(SubtleCrypto::KeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final;
void exportKey(SubtleCrypto::KeyFormat, Ref<CryptoKey>&&, KeyDataCallback&&, ExceptionCallback&&) final;
@@ -56,6 +57,7 @@
bool keyAlgorithmMatches(const CryptoAlgorithmRsaOaepParamsDeprecated& algorithmParameters, const CryptoKey&) const;
void platformEncrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
+ void platformDecrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
ExceptionOr<void> platformEncrypt(const CryptoAlgorithmRsaOaepParamsDeprecated&, const CryptoKeyRSA&, const CryptoOperationData&, VectorCallback&&, VoidCallback&& failureCallback);
ExceptionOr<void> platformDecrypt(const CryptoAlgorithmRsaOaepParamsDeprecated&, const CryptoKeyRSA&, const CryptoOperationData&, VectorCallback&&, VoidCallback&& failureCallback);
};
Modified: trunk/Source/WebCore/crypto/gnutls/CryptoAlgorithmAES_CBCGnuTLS.cpp (208917 => 208918)
--- trunk/Source/WebCore/crypto/gnutls/CryptoAlgorithmAES_CBCGnuTLS.cpp 2016-11-19 04:25:38 UTC (rev 208917)
+++ trunk/Source/WebCore/crypto/gnutls/CryptoAlgorithmAES_CBCGnuTLS.cpp 2016-11-19 04:38:59 UTC (rev 208918)
@@ -38,6 +38,11 @@
notImplemented();
}
+void CryptoAlgorithmAES_CBC::platformDecrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&)
+{
+ notImplemented();
+}
+
ExceptionOr<void> CryptoAlgorithmAES_CBC::platformEncrypt(const CryptoAlgorithmAesCbcParamsDeprecated&, const CryptoKeyAES&, const CryptoOperationData&, VectorCallback&&, VoidCallback&&)
{
notImplemented();
Modified: trunk/Source/WebCore/crypto/gnutls/CryptoAlgorithmRSAES_PKCS1_v1_5GnuTLS.cpp (208917 => 208918)
--- trunk/Source/WebCore/crypto/gnutls/CryptoAlgorithmRSAES_PKCS1_v1_5GnuTLS.cpp 2016-11-19 04:25:38 UTC (rev 208917)
+++ trunk/Source/WebCore/crypto/gnutls/CryptoAlgorithmRSAES_PKCS1_v1_5GnuTLS.cpp 2016-11-19 04:38:59 UTC (rev 208918)
@@ -39,6 +39,11 @@
notImplemented();
}
+void CryptoAlgorithmRSAES_PKCS1_v1_5::platformDecrypt(Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&)
+{
+ notImplemented();
+}
+
ExceptionOr<void> CryptoAlgorithmRSAES_PKCS1_v1_5::platformEncrypt(const CryptoKeyRSA&, const CryptoOperationData&, VectorCallback&&, VoidCallback&&)
{
notImplemented();
Modified: trunk/Source/WebCore/crypto/gnutls/CryptoAlgorithmRSA_OAEPGnuTLS.cpp (208917 => 208918)
--- trunk/Source/WebCore/crypto/gnutls/CryptoAlgorithmRSA_OAEPGnuTLS.cpp 2016-11-19 04:25:38 UTC (rev 208917)
+++ trunk/Source/WebCore/crypto/gnutls/CryptoAlgorithmRSA_OAEPGnuTLS.cpp 2016-11-19 04:38:59 UTC (rev 208918)
@@ -38,6 +38,11 @@
notImplemented();
}
+void CryptoAlgorithmRSA_OAEP::platformDecrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&)
+{
+ notImplemented();
+}
+
ExceptionOr<void> CryptoAlgorithmRSA_OAEP::platformEncrypt(const CryptoAlgorithmRsaOaepParamsDeprecated&, const CryptoKeyRSA&, const CryptoOperationData&, VectorCallback&&, VoidCallback&&)
{
notImplemented();
Modified: trunk/Source/WebCore/crypto/mac/CryptoAlgorithmAES_CBCMac.cpp (208917 => 208918)
--- trunk/Source/WebCore/crypto/mac/CryptoAlgorithmAES_CBCMac.cpp 2016-11-19 04:25:38 UTC (rev 208917)
+++ trunk/Source/WebCore/crypto/mac/CryptoAlgorithmAES_CBCMac.cpp 2016-11-19 04:38:59 UTC (rev 208918)
@@ -95,6 +95,28 @@
});
}
+void CryptoAlgorithmAES_CBC::platformDecrypt(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& cipherText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+{
+ context.ref();
+ workQueue.dispatch([parameters = WTFMove(parameters), key = WTFMove(key), cipherText = WTFMove(cipherText), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable {
+ auto& aesParameters = downcast<CryptoAlgorithmAesCbcParams>(*parameters);
+ auto& aesKey = downcast<CryptoKeyAES>(key.get());
+ assert(aesParameters.ivVector().size() == kCCBlockSizeAES128);
+ auto result = transformAES_CBC(kCCDecrypt, aesParameters.ivVector().data(), aesKey.key(), cipherText.data(), cipherText.size());
+ if (result.hasException()) {
+ context.postTask([exceptionCallback = WTFMove(exceptionCallback), ec = result.releaseException().code()](ScriptExecutionContext& context) {
+ exceptionCallback(ec);
+ context.deref();
+ });
+ return;
+ }
+ context.postTask([callback = WTFMove(callback), result = result.releaseReturnValue()](ScriptExecutionContext& context) {
+ callback(result);
+ context.deref();
+ });
+ });
+}
+
ExceptionOr<void> CryptoAlgorithmAES_CBC::platformEncrypt(const CryptoAlgorithmAesCbcParamsDeprecated& parameters, const CryptoKeyAES& key, const CryptoOperationData& data, VectorCallback&& callback, VoidCallback&& failureCallback)
{
ASSERT(sizeof(parameters.iv) == kCCBlockSizeAES128);
Modified: trunk/Source/WebCore/crypto/mac/CryptoAlgorithmRSAES_PKCS1_v1_5Mac.cpp (208917 => 208918)
--- trunk/Source/WebCore/crypto/mac/CryptoAlgorithmRSAES_PKCS1_v1_5Mac.cpp 2016-11-19 04:25:38 UTC (rev 208917)
+++ trunk/Source/WebCore/crypto/mac/CryptoAlgorithmRSAES_PKCS1_v1_5Mac.cpp 2016-11-19 04:38:59 UTC (rev 208918)
@@ -47,6 +47,19 @@
return WTFMove(cipherText);
}
+// FIXME: We should change data to Vector<uint8_t> type once WebKitSubtleCrypto is deprecated.
+// https://bugs.webkit.org/show_bug.cgi?id=164939
+static ExceptionOr<Vector<uint8_t>> decryptRSAES_PKCS1_v1_5(const PlatformRSAKey key, size_t keyLength, const uint8_t* data, size_t dataLength)
+{
+ Vector<uint8_t> plainText(keyLength / 8); // Per Step 1 of https://tools.ietf.org/html/rfc3447#section-7.2.1
+ size_t plainTextLength = plainText.size();
+ if (CCRSACryptorDecrypt(key, ccPKCS1Padding, data, dataLength, plainText.data(), &plainTextLength, 0, 0, kCCDigestNone))
+ return Exception { OperationError };
+
+ plainText.resize(plainTextLength);
+ return WTFMove(plainText);
+}
+
void CryptoAlgorithmRSAES_PKCS1_v1_5::platformEncrypt(Ref<CryptoKey>&& key, Vector<uint8_t>&& plainText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
{
context.ref();
@@ -67,6 +80,26 @@
});
}
+void CryptoAlgorithmRSAES_PKCS1_v1_5::platformDecrypt(Ref<CryptoKey>&& key, Vector<uint8_t>&& cipherText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+{
+ context.ref();
+ workQueue.dispatch([key = WTFMove(key), cipherText = WTFMove(cipherText), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable {
+ auto& rsaKey = downcast<CryptoKeyRSA>(key.get());
+ auto result = decryptRSAES_PKCS1_v1_5(rsaKey.platformKey(), rsaKey.keySizeInBits(), cipherText.data(), cipherText.size());
+ if (result.hasException()) {
+ context.postTask([exceptionCallback = WTFMove(exceptionCallback), ec = result.releaseException().code()](ScriptExecutionContext& context) {
+ exceptionCallback(ec);
+ context.deref();
+ });
+ return;
+ }
+ context.postTask([callback = WTFMove(callback), result = result.releaseReturnValue()](ScriptExecutionContext& context) {
+ callback(result);
+ context.deref();
+ });
+ });
+}
+
ExceptionOr<void> CryptoAlgorithmRSAES_PKCS1_v1_5::platformEncrypt(const CryptoKeyRSA& key, const CryptoOperationData& data, VectorCallback&& callback, VoidCallback&& failureCallback)
{
auto result = encryptRSAES_PKCS1_v1_5(key.platformKey(), key.keySizeInBits(), data.first, data.second);
@@ -78,19 +111,14 @@
return { };
}
-// FIXME: We should get rid of the magic number 1024. It only makes sense when key length < 8192 bits
ExceptionOr<void> CryptoAlgorithmRSAES_PKCS1_v1_5::platformDecrypt(const CryptoKeyRSA& key, const CryptoOperationData& data, VectorCallback&& callback, VoidCallback&& failureCallback)
{
- Vector<uint8_t> plainText(1024);
- size_t plainTextLength = plainText.size();
- CCCryptorStatus status = CCRSACryptorDecrypt(key.platformKey(), ccPKCS1Padding, data.first, data.second, plainText.data(), &plainTextLength, 0, 0, kCCDigestNone);
- if (status) {
+ auto result = decryptRSAES_PKCS1_v1_5(key.platformKey(), key.keySizeInBits(), data.first, data.second);
+ if (result.hasException()) {
failureCallback();
return { };
}
-
- plainText.resize(plainTextLength);
- callback(plainText);
+ callback(result.releaseReturnValue());
return { };
}
Modified: trunk/Source/WebCore/crypto/mac/CryptoAlgorithmRSA_OAEPMac.cpp (208917 => 208918)
--- trunk/Source/WebCore/crypto/mac/CryptoAlgorithmRSA_OAEPMac.cpp 2016-11-19 04:25:38 UTC (rev 208917)
+++ trunk/Source/WebCore/crypto/mac/CryptoAlgorithmRSA_OAEPMac.cpp 2016-11-19 04:38:59 UTC (rev 208918)
@@ -53,6 +53,23 @@
return WTFMove(cipherText);
}
+// FIXME: We should change data to Vector<uint8_t> type once WebKitSubtleCrypto is deprecated.
+// https://bugs.webkit.org/show_bug.cgi?id=164939
+static ExceptionOr<Vector<uint8_t>> decryptRSA_OAEP(CryptoAlgorithmIdentifier hash, const Vector<uint8_t>& label, const PlatformRSAKey key, size_t keyLength, const uint8_t* data, size_t dataLength)
+{
+ CCDigestAlgorithm digestAlgorithm;
+ if (!getCommonCryptoDigestAlgorithm(hash, digestAlgorithm))
+ return Exception { OperationError };
+
+ Vector<uint8_t> plainText(keyLength / 8); // Per Step 1.b of https://tools.ietf.org/html/rfc3447#section-7.1.1
+ size_t plainTextLength = plainText.size();
+ if (CCRSACryptorDecrypt(key, ccOAEPPadding, data, dataLength, plainText.data(), &plainTextLength, label.data(), label.size(), digestAlgorithm))
+ return Exception { OperationError };
+
+ plainText.resize(plainTextLength);
+ return WTFMove(plainText);
+}
+
void CryptoAlgorithmRSA_OAEP::platformEncrypt(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& plainText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
{
context.ref();
@@ -74,6 +91,27 @@
});
}
+void CryptoAlgorithmRSA_OAEP::platformDecrypt(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& cipherText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+{
+ context.ref();
+ workQueue.dispatch([parameters = WTFMove(parameters), key = WTFMove(key), cipherText = WTFMove(cipherText), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable {
+ auto& rsaParameters = downcast<CryptoAlgorithmRsaOaepParams>(*parameters);
+ auto& rsaKey = downcast<CryptoKeyRSA>(key.get());
+ auto result = decryptRSA_OAEP(rsaKey.hashAlgorithmIdentifier(), rsaParameters.labelVector(), rsaKey.platformKey(), rsaKey.keySizeInBits(), cipherText.data(), cipherText.size());
+ if (result.hasException()) {
+ context.postTask([exceptionCallback = WTFMove(exceptionCallback), ec = result.releaseException().code()](ScriptExecutionContext& context) {
+ exceptionCallback(ec);
+ context.deref();
+ });
+ return;
+ }
+ context.postTask([callback = WTFMove(callback), result = result.releaseReturnValue()](ScriptExecutionContext& context) {
+ callback(result);
+ context.deref();
+ });
+ });
+}
+
ExceptionOr<void> CryptoAlgorithmRSA_OAEP::platformEncrypt(const CryptoAlgorithmRsaOaepParamsDeprecated& parameters, const CryptoKeyRSA& key, const CryptoOperationData& data, VectorCallback&& callback, VoidCallback&& failureCallback)
{
ASSERT(parameters.hasLabel || parameters.label.isEmpty());
@@ -86,23 +124,15 @@
return { };
}
-// FIXME: We should get rid of the magic number 1024. It only makes sense when key length < 8192 bits
ExceptionOr<void> CryptoAlgorithmRSA_OAEP::platformDecrypt(const CryptoAlgorithmRsaOaepParamsDeprecated& parameters, const CryptoKeyRSA& key, const CryptoOperationData& data, VectorCallback&& callback, VoidCallback&& failureCallback)
{
- CCDigestAlgorithm digestAlgorithm;
- if (!getCommonCryptoDigestAlgorithm(parameters.hash, digestAlgorithm))
- return Exception { NOT_SUPPORTED_ERR };
-
- Vector<uint8_t> plainText(1024);
- size_t plainTextLength = plainText.size();
- CCCryptorStatus status = CCRSACryptorDecrypt(key.platformKey(), ccOAEPPadding, data.first, data.second, plainText.data(), &plainTextLength, parameters.label.data(), parameters.label.size(), digestAlgorithm);
- if (status) {
+ ASSERT(parameters.hasLabel || parameters.label.isEmpty());
+ auto result = decryptRSA_OAEP(parameters.hash, parameters.label, key.platformKey(), key.keySizeInBits(), data.first, data.second);
+ if (result.hasException()) {
failureCallback();
return { };
}
-
- plainText.resize(plainTextLength);
- callback(plainText);
+ callback(result.releaseReturnValue());
return { };
}