Update SubtleCrypto::sign to match the latest spec
authorjiewen_tan@apple.com <jiewen_tan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 29 Nov 2016 22:52:03 +0000 (22:52 +0000)
committerjiewen_tan@apple.com <jiewen_tan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 29 Nov 2016 22:52:03 +0000 (22:52 +0000)
https://bugs.webkit.org/show_bug.cgi?id=164740
<rdar://problem/29257864>

Reviewed by Brent Fulgham.

LayoutTests/imported/w3c:

* WebCryptoAPI/idlharness-expected.txt:

Source/WebCore:

This patch does following few things:
1. It updates the SubtleCrypto::sign method to match the latest spec:
   https://www.w3.org/TR/WebCryptoAPI/#SubtleCrypto-method-sign.
   It also refers to the latest Editor's Draft to a certain degree:
   https://w3c.github.io/webcrypto/Overview.html#SubtleCrypto-method-sign.
2. It implements sign operations of the following algorithms: HMAC, and
   RSASSA-PKCS1-V1_5.
3. It also replaces promise.copyRef() with WTFMove(promise) for all the
   capture lists of exception callbacks in promise functions.

Tests: crypto/subtle/hmac-import-key-sign-sha1.html
       crypto/subtle/hmac-import-key-sign-sha224.html
       crypto/subtle/hmac-import-key-sign-sha256.html
       crypto/subtle/hmac-import-key-sign-sha384.html
       crypto/subtle/hmac-import-key-sign-sha512.html
       crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha1.html
       crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha224.html
       crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha256.html
       crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha384.html
       crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha512.html
       crypto/subtle/sign-malformed-parameters.html
       crypto/workers/subtle/hmac-import-key-sign.html
       crypto/workers/subtle/rsassa-pkcs1-v1_5-import-key-sign.html

* bindings/js/JSSubtleCryptoCustom.cpp:
(WebCore::normalizeCryptoAlgorithmParameters):
(WebCore::jsSubtleCryptoFunctionDecryptPromise):
Fix a minor bug.
(WebCore::jsSubtleCryptoFunctionEncryptPromise):
(WebCore::jsSubtleCryptoFunctionDecryptPromise):
(WebCore::jsSubtleCryptoFunctionSignPromise):
(WebCore::jsSubtleCryptoFunctionGenerateKeyPromise):
(WebCore::jsSubtleCryptoFunctionImportKeyPromise):
(WebCore::jsSubtleCryptoFunctionExportKeyPromise):
(WebCore::JSSubtleCrypto::sign):
* crypto/CryptoAlgorithm.cpp:
(WebCore::CryptoAlgorithm::sign):
* crypto/CryptoAlgorithm.h:
* crypto/SubtleCrypto.idl:
* crypto/algorithms/CryptoAlgorithmHMAC.cpp:
(WebCore::CryptoAlgorithmHMAC::sign):
* crypto/algorithms/CryptoAlgorithmHMAC.h:
* crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp:
(WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::sign):
* crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.h:
* crypto/gcrypt/CryptoAlgorithmHMACGCrypt.cpp:
(WebCore::CryptoAlgorithmHMAC::platformSign):
* crypto/gnutls/CryptoAlgorithmHMACGnuTLS.cpp:
(WebCore::CryptoAlgorithmHMAC::platformSign):
* crypto/gnutls/CryptoAlgorithmRSASSA_PKCS1_v1_5GnuTLS.cpp:
(WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::platformSign):
* crypto/mac/CryptoAlgorithmHMACMac.cpp:
(WebCore::commonCryptoHMACAlgorithm):
(WebCore::calculateSignature):
Remove a null guardance since the depending bug is resolved.
(WebCore::CryptoAlgorithmHMAC::platformSign):
(WebCore::CryptoAlgorithmHMAC::platformVerify):
* crypto/mac/CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp:
(WebCore::signRSASSA_PKCS1_v1_5):
(WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::platformSign):

LayoutTests:

* crypto/subtle/hmac-import-key-sign-sha1-expected.txt: Added.
* crypto/subtle/hmac-import-key-sign-sha1.html: Added.
* crypto/subtle/hmac-import-key-sign-sha224-expected.txt: Added.
* crypto/subtle/hmac-import-key-sign-sha224.html: Added.
* crypto/subtle/hmac-import-key-sign-sha256-expected.txt: Added.
* crypto/subtle/hmac-import-key-sign-sha256.html: Added.
* crypto/subtle/hmac-import-key-sign-sha384-expected.txt: Added.
* crypto/subtle/hmac-import-key-sign-sha384.html: Added.
* crypto/subtle/hmac-import-key-sign-sha512-expected.txt: Added.
* crypto/subtle/hmac-import-key-sign-sha512.html: Added.
* crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha1-expected.txt: Added.
* crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha1.html: Added.
* crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha224-expected.txt: Added.
* crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha224.html: Added.
* crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha256-expected.txt: Added.
* crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha256.html: Added.
* crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha384-expected.txt: Added.
* crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha384.html: Added.
* crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha512-expected.txt: Added.
* crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha512.html: Added.
* crypto/subtle/sign-malformed-parameters-expected.txt: Added.
* crypto/subtle/sign-malformed-parameters.html: Added.
* crypto/workers/subtle/hmac-import-key-sign-expected.txt: Added.
* crypto/workers/subtle/hmac-import-key-sign.html: Added.
* crypto/workers/subtle/resources/hmac-import-key-sign.js: Added.
* crypto/workers/subtle/resources/rsassa-pkcs1-v1_5-import-key-sign.js: Added.
* crypto/workers/subtle/rsassa-pkcs1-v1_5-import-key-sign-expected.txt: Added.
* crypto/workers/subtle/rsassa-pkcs1-v1_5-import-key-sign.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@209092 268f45cc-cd09-0410-ab3c-d52691b4dbfc

45 files changed:
LayoutTests/ChangeLog
LayoutTests/crypto/subtle/hmac-import-key-sign-sha1-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/hmac-import-key-sign-sha1.html [new file with mode: 0644]
LayoutTests/crypto/subtle/hmac-import-key-sign-sha224-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/hmac-import-key-sign-sha224.html [new file with mode: 0644]
LayoutTests/crypto/subtle/hmac-import-key-sign-sha256-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/hmac-import-key-sign-sha256.html [new file with mode: 0644]
LayoutTests/crypto/subtle/hmac-import-key-sign-sha384-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/hmac-import-key-sign-sha384.html [new file with mode: 0644]
LayoutTests/crypto/subtle/hmac-import-key-sign-sha512-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/hmac-import-key-sign-sha512.html [new file with mode: 0644]
LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha1-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha1.html [new file with mode: 0644]
LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha224-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha224.html [new file with mode: 0644]
LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha256-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha256.html [new file with mode: 0644]
LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha384-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha384.html [new file with mode: 0644]
LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha512-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha512.html [new file with mode: 0644]
LayoutTests/crypto/subtle/sign-malformed-parameters-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/sign-malformed-parameters.html [new file with mode: 0644]
LayoutTests/crypto/workers/subtle/hmac-import-key-sign-expected.txt [new file with mode: 0644]
LayoutTests/crypto/workers/subtle/hmac-import-key-sign.html [new file with mode: 0644]
LayoutTests/crypto/workers/subtle/resources/hmac-import-key-sign.js [new file with mode: 0644]
LayoutTests/crypto/workers/subtle/resources/rsassa-pkcs1-v1_5-import-key-sign.js [new file with mode: 0644]
LayoutTests/crypto/workers/subtle/rsassa-pkcs1-v1_5-import-key-sign-expected.txt [new file with mode: 0644]
LayoutTests/crypto/workers/subtle/rsassa-pkcs1-v1_5-import-key-sign.html [new file with mode: 0644]
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/WebCryptoAPI/idlharness-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSSubtleCryptoCustom.cpp
Source/WebCore/crypto/CryptoAlgorithm.cpp
Source/WebCore/crypto/CryptoAlgorithm.h
Source/WebCore/crypto/SubtleCrypto.idl
Source/WebCore/crypto/algorithms/CryptoAlgorithmHMAC.cpp
Source/WebCore/crypto/algorithms/CryptoAlgorithmHMAC.h
Source/WebCore/crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp
Source/WebCore/crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.h
Source/WebCore/crypto/gcrypt/CryptoAlgorithmHMACGCrypt.cpp
Source/WebCore/crypto/gnutls/CryptoAlgorithmHMACGnuTLS.cpp
Source/WebCore/crypto/gnutls/CryptoAlgorithmRSASSA_PKCS1_v1_5GnuTLS.cpp
Source/WebCore/crypto/mac/CryptoAlgorithmHMACMac.cpp
Source/WebCore/crypto/mac/CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp

index a46f9f3..fdbb496 100644 (file)
@@ -1,3 +1,40 @@
+2016-11-22  Jiewen Tan  <jiewen_tan@apple.com>
+
+        Update SubtleCrypto::sign to match the latest spec
+        https://bugs.webkit.org/show_bug.cgi?id=164740
+        <rdar://problem/29257864>
+
+        Reviewed by Brent Fulgham.
+
+        * crypto/subtle/hmac-import-key-sign-sha1-expected.txt: Added.
+        * crypto/subtle/hmac-import-key-sign-sha1.html: Added.
+        * crypto/subtle/hmac-import-key-sign-sha224-expected.txt: Added.
+        * crypto/subtle/hmac-import-key-sign-sha224.html: Added.
+        * crypto/subtle/hmac-import-key-sign-sha256-expected.txt: Added.
+        * crypto/subtle/hmac-import-key-sign-sha256.html: Added.
+        * crypto/subtle/hmac-import-key-sign-sha384-expected.txt: Added.
+        * crypto/subtle/hmac-import-key-sign-sha384.html: Added.
+        * crypto/subtle/hmac-import-key-sign-sha512-expected.txt: Added.
+        * crypto/subtle/hmac-import-key-sign-sha512.html: Added.
+        * crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha1-expected.txt: Added.
+        * crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha1.html: Added.
+        * crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha224-expected.txt: Added.
+        * crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha224.html: Added.
+        * crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha256-expected.txt: Added.
+        * crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha256.html: Added.
+        * crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha384-expected.txt: Added.
+        * crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha384.html: Added.
+        * crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha512-expected.txt: Added.
+        * crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha512.html: Added.
+        * crypto/subtle/sign-malformed-parameters-expected.txt: Added.
+        * crypto/subtle/sign-malformed-parameters.html: Added.
+        * crypto/workers/subtle/hmac-import-key-sign-expected.txt: Added.
+        * crypto/workers/subtle/hmac-import-key-sign.html: Added.
+        * crypto/workers/subtle/resources/hmac-import-key-sign.js: Added.
+        * crypto/workers/subtle/resources/rsassa-pkcs1-v1_5-import-key-sign.js: Added.
+        * crypto/workers/subtle/rsassa-pkcs1-v1_5-import-key-sign-expected.txt: Added.
+        * crypto/workers/subtle/rsassa-pkcs1-v1_5-import-key-sign.html: Added.
+
 2016-11-29  Chris Dumez  <cdumez@apple.com>
 
         Can't download move.simple.com direct deposit transition PDF: Non user-triggered activations of anchors that have a download attribute are ignored
diff --git a/LayoutTests/crypto/subtle/hmac-import-key-sign-sha1-expected.txt b/LayoutTests/crypto/subtle/hmac-import-key-sign-sha1-expected.txt
new file mode 100644 (file)
index 0000000..d7ef599
--- /dev/null
@@ -0,0 +1,10 @@
+Test signing with HMAC SHA-1 using an imported key
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS bytesToHexString(signature) is expectedSignature
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/subtle/hmac-import-key-sign-sha1.html b/LayoutTests/crypto/subtle/hmac-import-key-sign-sha1.html
new file mode 100644 (file)
index 0000000..8bc09f1
--- /dev/null
@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+<script src="../resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test signing with HMAC SHA-1 using an imported key");
+
+jsTestIsAsync = true;
+
+var extractable = false;
+var text = asciiToUint8Array("Hello, World!");
+var hmacImportParams = {
+    name: "hmac",
+    hash: "sha-1",
+}
+var rawKey = asciiToUint8Array("jnOw99oOZFLIEPMr");
+var expectedSignature = "6e8e66ff128606f52b8c589196ef5e0f7ca04816";
+
+crypto.subtle.importKey("raw", rawKey, hmacImportParams, extractable, ["sign", "verify"]).then(function(key) {
+    return crypto.subtle.sign("hmac", key, text);
+}).then(function(result) {
+    signature = result;
+
+    shouldBe("bytesToHexString(signature)", "expectedSignature");
+
+    finishJSTest();
+});
+
+</script>
+
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/crypto/subtle/hmac-import-key-sign-sha224-expected.txt b/LayoutTests/crypto/subtle/hmac-import-key-sign-sha224-expected.txt
new file mode 100644 (file)
index 0000000..4349393
--- /dev/null
@@ -0,0 +1,10 @@
+Test signing with HMAC SHA-224 using an imported key
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS bytesToHexString(signature) is expectedSignature
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/subtle/hmac-import-key-sign-sha224.html b/LayoutTests/crypto/subtle/hmac-import-key-sign-sha224.html
new file mode 100644 (file)
index 0000000..bcf8046
--- /dev/null
@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+<script src="../resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test signing with HMAC SHA-224 using an imported key");
+
+jsTestIsAsync = true;
+
+var extractable = false;
+var text = asciiToUint8Array("Hello, World!");
+var hmacImportParams = {
+    name: "hmac",
+    hash: "sha-224",
+}
+var rawKey = asciiToUint8Array("jnOw99oOZFLIEPMr");
+var expectedSignature = "70b638e082fabc3bf391a1935c4b6a74168401214f4fb5c31e0cebf4";
+
+crypto.subtle.importKey("raw", rawKey, hmacImportParams, extractable, ["sign", "verify"]).then(function(key) {
+    return crypto.subtle.sign("hmac", key, text);
+}).then(function(result) {
+    signature = result;
+
+    shouldBe("bytesToHexString(signature)", "expectedSignature");
+
+    finishJSTest();
+});
+
+</script>
+
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/crypto/subtle/hmac-import-key-sign-sha256-expected.txt b/LayoutTests/crypto/subtle/hmac-import-key-sign-sha256-expected.txt
new file mode 100644 (file)
index 0000000..cbe989c
--- /dev/null
@@ -0,0 +1,10 @@
+Test signing with HMAC SHA-256 using an imported key
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS bytesToHexString(signature) is expectedSignature
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/subtle/hmac-import-key-sign-sha256.html b/LayoutTests/crypto/subtle/hmac-import-key-sign-sha256.html
new file mode 100644 (file)
index 0000000..7b87c1e
--- /dev/null
@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+<script src="../resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test signing with HMAC SHA-256 using an imported key");
+
+jsTestIsAsync = true;
+
+var extractable = false;
+var text = asciiToUint8Array("Hello, World!");
+var hmacImportParams = {
+    name: "hmac",
+    hash: "sha-256",
+}
+var rawKey = asciiToUint8Array("jnOw99oOZFLIEPMr");
+var expectedSignature = "d6b92f34723a8de7ba53dceea8c821f5d21757ddb478c27d564b356c38f583db";
+
+crypto.subtle.importKey("raw", rawKey, hmacImportParams, extractable, ["sign", "verify"]).then(function(key) {
+    return crypto.subtle.sign("hmac", key, text);
+}).then(function(result) {
+    signature = result;
+
+    shouldBe("bytesToHexString(signature)", "expectedSignature");
+
+    finishJSTest();
+});
+
+</script>
+
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/crypto/subtle/hmac-import-key-sign-sha384-expected.txt b/LayoutTests/crypto/subtle/hmac-import-key-sign-sha384-expected.txt
new file mode 100644 (file)
index 0000000..8b327b4
--- /dev/null
@@ -0,0 +1,10 @@
+Test signing with HMAC SHA-384 using an imported key
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS bytesToHexString(signature) is expectedSignature
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/subtle/hmac-import-key-sign-sha384.html b/LayoutTests/crypto/subtle/hmac-import-key-sign-sha384.html
new file mode 100644 (file)
index 0000000..dd087a1
--- /dev/null
@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+<script src="../resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test signing with HMAC SHA-384 using an imported key");
+
+jsTestIsAsync = true;
+
+var extractable = false;
+var text = asciiToUint8Array("Hello, World!");
+var hmacImportParams = {
+    name: "hmac",
+    hash: "sha-384",
+}
+var rawKey = asciiToUint8Array("jnOw99oOZFLIEPMr");
+var expectedSignature = "5cfc6cba3135c99cb426d5d59bd33c5e212aac082f5ba57a1f70def2b3e987e3f3078be80f142221b6a8e23768dd994f";
+
+crypto.subtle.importKey("raw", rawKey, hmacImportParams, extractable, ["sign", "verify"]).then(function(key) {
+    return crypto.subtle.sign("hmac", key, text);
+}).then(function(result) {
+    signature = result;
+
+    shouldBe("bytesToHexString(signature)", "expectedSignature");
+
+    finishJSTest();
+});
+
+</script>
+
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/crypto/subtle/hmac-import-key-sign-sha512-expected.txt b/LayoutTests/crypto/subtle/hmac-import-key-sign-sha512-expected.txt
new file mode 100644 (file)
index 0000000..946d00d
--- /dev/null
@@ -0,0 +1,10 @@
+Test signing with HMAC SHA-512 using an imported key
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS bytesToHexString(signature) is expectedSignature
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/subtle/hmac-import-key-sign-sha512.html b/LayoutTests/crypto/subtle/hmac-import-key-sign-sha512.html
new file mode 100644 (file)
index 0000000..e7e92b9
--- /dev/null
@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+<script src="../resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test signing with HMAC SHA-512 using an imported key");
+
+jsTestIsAsync = true;
+
+var extractable = false;
+var text = asciiToUint8Array("Hello, World!");
+var hmacImportParams = {
+    name: "hmac",
+    hash: "sha-512",
+}
+var rawKey = asciiToUint8Array("jnOw99oOZFLIEPMr");
+var expectedSignature = "74b22e7422bd3d8562294040b8e9ff08849cf694d3f7729e02a111647b290058af5e1ca8321e5d0f512b5a55a287b39762fae85bef73611d0bddd0b3ddf252ec";
+
+crypto.subtle.importKey("raw", rawKey, hmacImportParams, extractable, ["sign", "verify"]).then(function(key) {
+    return crypto.subtle.sign("hmac", key, text);
+}).then(function(result) {
+    signature = result;
+
+    shouldBe("bytesToHexString(signature)", "expectedSignature");
+
+    finishJSTest();
+});
+
+</script>
+
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha1-expected.txt b/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha1-expected.txt
new file mode 100644 (file)
index 0000000..e3d5b4a
--- /dev/null
@@ -0,0 +1,10 @@
+Test signing with RSASSA-PKCS1-v1_5 SHA-1 using an imported key
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS bytesToHexString(signature) is expectedSignature
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha1.html b/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha1.html
new file mode 100644 (file)
index 0000000..a63c47d
--- /dev/null
@@ -0,0 +1,53 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+<script src="../resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test signing with RSASSA-PKCS1-v1_5 SHA-1 using an imported key");
+
+jsTestIsAsync = true;
+
+var extractable = false;
+var text = asciiToUint8Array("Hello, World!");
+var rsaImportParams = {
+    name: "RSASSA-PKCS1-v1_5",
+    hash: "SHA-1",
+}
+var jwkKey = {
+    kty: "RSA",
+    alg: "RS1",
+    use: "sig",
+    key_ops: ["sign"],
+    ext: true,
+    n: "rcCUCv7Oc1HVam1DIhCzqknThWawOp8QLk8Ziy2p10ByjQFCajoFiyuAWl-R1WXZaf4xitLRracT9agpzIzc-MbLSHIGgWQGO21lGiImy5ftZ-D8bHAqRz2y15pzD4c4CEou7XSSLDoRnR0QG5MsDhD6s2gV9mwHkrtkCxtMWdBi-77as8wGmlNRldcOSgZDLK8UnCSgA1OguZ989bFyc8tOOEIb0xUSfPSz3LPSCnyYz68aDjmKVeNH-ig857OScyWbGyEy3Biw64qun3juUlNWsJ3zngkOdteYWytx5Qr4XKNs6R-Myyq72KUp02mJDZiiyiglxML_i3-_CeecCw",
+    e: "AQAB",
+    d: "eNLS37aCz7RXSNPD_DtLBJ6j5T8cSxdzRBCjPaI6WcGqJp16lq3UTwuoDLAqlA9oGYm238dsIWpuucP_lQtbWe-7SpxoI6_vmYGf7YVUHv1-DF9qiOmSrMmdxMnVOzYXY8RaT6thPjn_J5cfLV2xI_LwsrMtmpdSyNlgX0zTUhwtuahgAKMEChYjH2EnjHdHw6sY2-wApdcQI7ULE0oo5RzbQZpmuhcN9hiBc0L3hhF0qo50mbl02_65_GQ7DpVkXBxNgRBLzlPabmzzG2oAhfefLgYmSC1opaCkXE6vRWQNWNL45RZNZFYM3uoJghOMqGeocM0BpjdChHrPOlFvSQ",
+    p: "4miTuAjKMeH5uJ5KB397QUwhbkYEgSbcA2mifmSkvE2018gb55qkBHK1eVryf1_m43LNlc6O_ak6gfzdZIZvS5NCGjPl0q09plUpu8qFOSspBwA67qGH76lFlZLn_d4yglS7wfLru4_5Ys8qLLs-DqVLviwposOnyyWqwM5AXp0",
+    q: "xHYrzkivtmnz_sGchnWGc0q-pDOkKicptRpv2pMFIIXxnFX5aMeEXIZjVujXtwUy1UlFIN2GZJSvy5KJ79mu_XyNnFHMzedH-A3ee3u8h1UUrZF-vUu1_e4U_x67NN1dedzUSKynN7pFl3OkuShMBWGV-cwzOPdcVAfVuZlxUMc",
+    dp: "fBzDzYDUBmBQGop7Hn0dvf_T27V6RqpctWo074CQZcFbP2atFVtKSj3viWT3xid2VHzcgiDHdfpM3nEVlEO1wwIonGCSvdjGEOZiiFVOjrZAOVxA8guOjyyFvqbXke06VwPIIVvfKeSU2zuhbP__1tt6F_fxow4Kb2xonGT0GGk",
+    dq: "jmE2DiIPdhwDgLXAQpIaBqQ81bO3XfVT_LRULAwwwwlPuQV148H04zlh9TJ6Y2GZHYokV1U0eOBpJxfkb7dLYtpJpuiBjRf4yIUEoGlkkI_QlJnFSFr-YjGRdfNHqWBkxlSMZL770R9mIATndGkH7z5x-r9KwBZFC4FCG2hg_zE",
+    qi: "YCX_pLwbMBA1ThVH0WcwmnytqNcrMCEwTm7ByA2eU6nWbQrULvf7m9_kzfLUcjsnpAVlBQG5JMXMy0Sq4ptwbywsa5-G8KAOOOR2L3v4hC-Eys9ftgFM_3i0o40eeQH4b3haPbntrIeMg8IzlOuVYKf9-2QuKDoWeRdd7NsdxTk",
+};
+var expectedSignature = "08b83a4a58aff1db76529fe97f6dc2b58914a56f08ebc73aebf740680fc524e721c30842759acacab8acdf6e31e7cc83dbe8a48ace80b6a6558a9df892e4c2a9276c154cd605e632c8b857855a064aea68550b660a15044a0917026e494a71e4fee99fa57941268545f338c8601baa9c4f2116f0eb5432cfee5e3ed9978876fed201647921e599101930a99a2b645a9a879bce8c24592729f1f62a3b83fe21475871273cdbbe8efa7be314cabd087fbe1931ddf3fb86cbff5176a27554726b54c43208200725c6ad71d335ee5e09f3bbff7164ddf5bc857a41c5961e6f9581459db0fd0f09ee251d63b7a01bd716f6f72632b5c0f9a2c4dc2257d1e342138c13";
+
+crypto.subtle.importKey("jwk", jwkKey, rsaImportParams, extractable, ["sign"]).then(function(key) {
+    return crypto.subtle.sign("RSASSA-PKCS1-v1_5", key, text);
+}).then(function(result) {
+    signature = result;
+
+    shouldBe("bytesToHexString(signature)", "expectedSignature");
+
+    finishJSTest();
+});
+
+</script>
+
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha224-expected.txt b/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha224-expected.txt
new file mode 100644 (file)
index 0000000..08edcaf
--- /dev/null
@@ -0,0 +1,10 @@
+Test signing with RSASSA-PKCS1-v1_5 SHA-224 using an imported key
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS bytesToHexString(signature) is expectedSignature
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha224.html b/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha224.html
new file mode 100644 (file)
index 0000000..f6b1596
--- /dev/null
@@ -0,0 +1,53 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+<script src="../resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test signing with RSASSA-PKCS1-v1_5 SHA-224 using an imported key");
+
+jsTestIsAsync = true;
+
+var extractable = false;
+var text = asciiToUint8Array("Hello, World!");
+var rsaImportParams = {
+    name: "RSASSA-PKCS1-v1_5",
+    hash: "SHA-224",
+}
+var jwkKey = {
+    kty: "RSA",
+    alg: "RS224",
+    use: "sig",
+    key_ops: ["sign"],
+    ext: true,
+    n: "rcCUCv7Oc1HVam1DIhCzqknThWawOp8QLk8Ziy2p10ByjQFCajoFiyuAWl-R1WXZaf4xitLRracT9agpzIzc-MbLSHIGgWQGO21lGiImy5ftZ-D8bHAqRz2y15pzD4c4CEou7XSSLDoRnR0QG5MsDhD6s2gV9mwHkrtkCxtMWdBi-77as8wGmlNRldcOSgZDLK8UnCSgA1OguZ989bFyc8tOOEIb0xUSfPSz3LPSCnyYz68aDjmKVeNH-ig857OScyWbGyEy3Biw64qun3juUlNWsJ3zngkOdteYWytx5Qr4XKNs6R-Myyq72KUp02mJDZiiyiglxML_i3-_CeecCw",
+    e: "AQAB",
+    d: "eNLS37aCz7RXSNPD_DtLBJ6j5T8cSxdzRBCjPaI6WcGqJp16lq3UTwuoDLAqlA9oGYm238dsIWpuucP_lQtbWe-7SpxoI6_vmYGf7YVUHv1-DF9qiOmSrMmdxMnVOzYXY8RaT6thPjn_J5cfLV2xI_LwsrMtmpdSyNlgX0zTUhwtuahgAKMEChYjH2EnjHdHw6sY2-wApdcQI7ULE0oo5RzbQZpmuhcN9hiBc0L3hhF0qo50mbl02_65_GQ7DpVkXBxNgRBLzlPabmzzG2oAhfefLgYmSC1opaCkXE6vRWQNWNL45RZNZFYM3uoJghOMqGeocM0BpjdChHrPOlFvSQ",
+    p: "4miTuAjKMeH5uJ5KB397QUwhbkYEgSbcA2mifmSkvE2018gb55qkBHK1eVryf1_m43LNlc6O_ak6gfzdZIZvS5NCGjPl0q09plUpu8qFOSspBwA67qGH76lFlZLn_d4yglS7wfLru4_5Ys8qLLs-DqVLviwposOnyyWqwM5AXp0",
+    q: "xHYrzkivtmnz_sGchnWGc0q-pDOkKicptRpv2pMFIIXxnFX5aMeEXIZjVujXtwUy1UlFIN2GZJSvy5KJ79mu_XyNnFHMzedH-A3ee3u8h1UUrZF-vUu1_e4U_x67NN1dedzUSKynN7pFl3OkuShMBWGV-cwzOPdcVAfVuZlxUMc",
+    dp: "fBzDzYDUBmBQGop7Hn0dvf_T27V6RqpctWo074CQZcFbP2atFVtKSj3viWT3xid2VHzcgiDHdfpM3nEVlEO1wwIonGCSvdjGEOZiiFVOjrZAOVxA8guOjyyFvqbXke06VwPIIVvfKeSU2zuhbP__1tt6F_fxow4Kb2xonGT0GGk",
+    dq: "jmE2DiIPdhwDgLXAQpIaBqQ81bO3XfVT_LRULAwwwwlPuQV148H04zlh9TJ6Y2GZHYokV1U0eOBpJxfkb7dLYtpJpuiBjRf4yIUEoGlkkI_QlJnFSFr-YjGRdfNHqWBkxlSMZL770R9mIATndGkH7z5x-r9KwBZFC4FCG2hg_zE",
+    qi: "YCX_pLwbMBA1ThVH0WcwmnytqNcrMCEwTm7ByA2eU6nWbQrULvf7m9_kzfLUcjsnpAVlBQG5JMXMy0Sq4ptwbywsa5-G8KAOOOR2L3v4hC-Eys9ftgFM_3i0o40eeQH4b3haPbntrIeMg8IzlOuVYKf9-2QuKDoWeRdd7NsdxTk",
+};
+var expectedSignature = "3cb10634bbb4022b64e0af31d0c0533837e14c8a9a4d7b9ef8c6816133843ef58603887fb05f7215bf39e803326367d95ea8894dda321b753a62dcc3214c7e85a134bf741c883f1ee0037dde6334d62b8efe54dcb59c8510e4d733b35466ad5a064686616898d73e25138cc6fd572d52df5e80f70d3d803ae9100516b4bde58cafc068c655f0cdbd2249ae61eb1a952d49df493b3c3c4a15ffb900d4f489df797498a0e7333c58cb953c2f3b169290ae7dd51e3c53bdb0bdf4311ae3fd5d7a1c3de038f696c05190db1c60056f664c6421580385b9fe54e1b2f41eef9eb83d18c6d28745d9c0eb2c15b45f5949b78762558488ae09877f4305f8c9068576e6e5";
+
+crypto.subtle.importKey("jwk", jwkKey, rsaImportParams, extractable, ["sign"]).then(function(key) {
+    return crypto.subtle.sign("RSASSA-PKCS1-v1_5", key, text);
+}).then(function(result) {
+    signature = result;
+
+    shouldBe("bytesToHexString(signature)", "expectedSignature");
+
+    finishJSTest();
+});
+
+</script>
+
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha256-expected.txt b/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha256-expected.txt
new file mode 100644 (file)
index 0000000..bf2666b
--- /dev/null
@@ -0,0 +1,10 @@
+Test signing with RSASSA-PKCS1-v1_5 SHA-256 using an imported key
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS bytesToHexString(signature) is expectedSignature
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha256.html b/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha256.html
new file mode 100644 (file)
index 0000000..05955aa
--- /dev/null
@@ -0,0 +1,53 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+<script src="../resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test signing with RSASSA-PKCS1-v1_5 SHA-256 using an imported key");
+
+jsTestIsAsync = true;
+
+var extractable = false;
+var text = asciiToUint8Array("Hello, World!");
+var rsaImportParams = {
+    name: "RSASSA-PKCS1-v1_5",
+    hash: "SHA-256",
+}
+var jwkKey = {
+    kty: "RSA",
+    alg: "RS256",
+    use: "sig",
+    key_ops: ["sign"],
+    ext: true,
+    n: "rcCUCv7Oc1HVam1DIhCzqknThWawOp8QLk8Ziy2p10ByjQFCajoFiyuAWl-R1WXZaf4xitLRracT9agpzIzc-MbLSHIGgWQGO21lGiImy5ftZ-D8bHAqRz2y15pzD4c4CEou7XSSLDoRnR0QG5MsDhD6s2gV9mwHkrtkCxtMWdBi-77as8wGmlNRldcOSgZDLK8UnCSgA1OguZ989bFyc8tOOEIb0xUSfPSz3LPSCnyYz68aDjmKVeNH-ig857OScyWbGyEy3Biw64qun3juUlNWsJ3zngkOdteYWytx5Qr4XKNs6R-Myyq72KUp02mJDZiiyiglxML_i3-_CeecCw",
+    e: "AQAB",
+    d: "eNLS37aCz7RXSNPD_DtLBJ6j5T8cSxdzRBCjPaI6WcGqJp16lq3UTwuoDLAqlA9oGYm238dsIWpuucP_lQtbWe-7SpxoI6_vmYGf7YVUHv1-DF9qiOmSrMmdxMnVOzYXY8RaT6thPjn_J5cfLV2xI_LwsrMtmpdSyNlgX0zTUhwtuahgAKMEChYjH2EnjHdHw6sY2-wApdcQI7ULE0oo5RzbQZpmuhcN9hiBc0L3hhF0qo50mbl02_65_GQ7DpVkXBxNgRBLzlPabmzzG2oAhfefLgYmSC1opaCkXE6vRWQNWNL45RZNZFYM3uoJghOMqGeocM0BpjdChHrPOlFvSQ",
+    p: "4miTuAjKMeH5uJ5KB397QUwhbkYEgSbcA2mifmSkvE2018gb55qkBHK1eVryf1_m43LNlc6O_ak6gfzdZIZvS5NCGjPl0q09plUpu8qFOSspBwA67qGH76lFlZLn_d4yglS7wfLru4_5Ys8qLLs-DqVLviwposOnyyWqwM5AXp0",
+    q: "xHYrzkivtmnz_sGchnWGc0q-pDOkKicptRpv2pMFIIXxnFX5aMeEXIZjVujXtwUy1UlFIN2GZJSvy5KJ79mu_XyNnFHMzedH-A3ee3u8h1UUrZF-vUu1_e4U_x67NN1dedzUSKynN7pFl3OkuShMBWGV-cwzOPdcVAfVuZlxUMc",
+    dp: "fBzDzYDUBmBQGop7Hn0dvf_T27V6RqpctWo074CQZcFbP2atFVtKSj3viWT3xid2VHzcgiDHdfpM3nEVlEO1wwIonGCSvdjGEOZiiFVOjrZAOVxA8guOjyyFvqbXke06VwPIIVvfKeSU2zuhbP__1tt6F_fxow4Kb2xonGT0GGk",
+    dq: "jmE2DiIPdhwDgLXAQpIaBqQ81bO3XfVT_LRULAwwwwlPuQV148H04zlh9TJ6Y2GZHYokV1U0eOBpJxfkb7dLYtpJpuiBjRf4yIUEoGlkkI_QlJnFSFr-YjGRdfNHqWBkxlSMZL770R9mIATndGkH7z5x-r9KwBZFC4FCG2hg_zE",
+    qi: "YCX_pLwbMBA1ThVH0WcwmnytqNcrMCEwTm7ByA2eU6nWbQrULvf7m9_kzfLUcjsnpAVlBQG5JMXMy0Sq4ptwbywsa5-G8KAOOOR2L3v4hC-Eys9ftgFM_3i0o40eeQH4b3haPbntrIeMg8IzlOuVYKf9-2QuKDoWeRdd7NsdxTk",
+};
+var expectedSignature = "6dd6df5884c84e8494794f5104559fd2966b266b7d6f3f9b8080adfb36e7c63d8f9b3b1d26084028735030749e829da0d22e3ba39454c07db7c104a19b9f509f0e4c0908c16cd604b5771bdf06507dec95d6545b896f56684016777675c16d852bb6d6ff98e1dbfc27a11d06fa028d4b8c8d2ac6790406f89283674e3f3d200aa17feb4332cbd6a6dca6b73008f5996297ac572f943037950da37b25420b24c51e76918f3e4aedeb70a0d026c75f6ae20f7fa3185f34914fc0ffd682e514d84fb73c1ce33bd1c19e4ec4b96536004af0a6206d0114196863a11d0ea575e14aedaceac6e08f1d1f9e2fab1f0cd49a0c840a8c94f9c30a2483d770cb8f9867ba6d";
+
+crypto.subtle.importKey("jwk", jwkKey, rsaImportParams, extractable, ["sign"]).then(function(key) {
+    return crypto.subtle.sign("RSASSA-PKCS1-v1_5", key, text);
+}).then(function(result) {
+    signature = result;
+
+    shouldBe("bytesToHexString(signature)", "expectedSignature");
+
+    finishJSTest();
+});
+
+</script>
+
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha384-expected.txt b/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha384-expected.txt
new file mode 100644 (file)
index 0000000..92ad974
--- /dev/null
@@ -0,0 +1,10 @@
+Test signing with RSASSA-PKCS1-v1_5 SHA-384 using an imported key
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS bytesToHexString(signature) is expectedSignature
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha384.html b/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha384.html
new file mode 100644 (file)
index 0000000..3791ea2
--- /dev/null
@@ -0,0 +1,53 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+<script src="../resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test signing with RSASSA-PKCS1-v1_5 SHA-384 using an imported key");
+
+jsTestIsAsync = true;
+
+var extractable = false;
+var text = asciiToUint8Array("Hello, World!");
+var rsaImportParams = {
+    name: "RSASSA-PKCS1-v1_5",
+    hash: "SHA-384",
+}
+var jwkKey = {
+    kty: "RSA",
+    alg: "RS384",
+    use: "sig",
+    key_ops: ["sign"],
+    ext: true,
+    n: "rcCUCv7Oc1HVam1DIhCzqknThWawOp8QLk8Ziy2p10ByjQFCajoFiyuAWl-R1WXZaf4xitLRracT9agpzIzc-MbLSHIGgWQGO21lGiImy5ftZ-D8bHAqRz2y15pzD4c4CEou7XSSLDoRnR0QG5MsDhD6s2gV9mwHkrtkCxtMWdBi-77as8wGmlNRldcOSgZDLK8UnCSgA1OguZ989bFyc8tOOEIb0xUSfPSz3LPSCnyYz68aDjmKVeNH-ig857OScyWbGyEy3Biw64qun3juUlNWsJ3zngkOdteYWytx5Qr4XKNs6R-Myyq72KUp02mJDZiiyiglxML_i3-_CeecCw",
+    e: "AQAB",
+    d: "eNLS37aCz7RXSNPD_DtLBJ6j5T8cSxdzRBCjPaI6WcGqJp16lq3UTwuoDLAqlA9oGYm238dsIWpuucP_lQtbWe-7SpxoI6_vmYGf7YVUHv1-DF9qiOmSrMmdxMnVOzYXY8RaT6thPjn_J5cfLV2xI_LwsrMtmpdSyNlgX0zTUhwtuahgAKMEChYjH2EnjHdHw6sY2-wApdcQI7ULE0oo5RzbQZpmuhcN9hiBc0L3hhF0qo50mbl02_65_GQ7DpVkXBxNgRBLzlPabmzzG2oAhfefLgYmSC1opaCkXE6vRWQNWNL45RZNZFYM3uoJghOMqGeocM0BpjdChHrPOlFvSQ",
+    p: "4miTuAjKMeH5uJ5KB397QUwhbkYEgSbcA2mifmSkvE2018gb55qkBHK1eVryf1_m43LNlc6O_ak6gfzdZIZvS5NCGjPl0q09plUpu8qFOSspBwA67qGH76lFlZLn_d4yglS7wfLru4_5Ys8qLLs-DqVLviwposOnyyWqwM5AXp0",
+    q: "xHYrzkivtmnz_sGchnWGc0q-pDOkKicptRpv2pMFIIXxnFX5aMeEXIZjVujXtwUy1UlFIN2GZJSvy5KJ79mu_XyNnFHMzedH-A3ee3u8h1UUrZF-vUu1_e4U_x67NN1dedzUSKynN7pFl3OkuShMBWGV-cwzOPdcVAfVuZlxUMc",
+    dp: "fBzDzYDUBmBQGop7Hn0dvf_T27V6RqpctWo074CQZcFbP2atFVtKSj3viWT3xid2VHzcgiDHdfpM3nEVlEO1wwIonGCSvdjGEOZiiFVOjrZAOVxA8guOjyyFvqbXke06VwPIIVvfKeSU2zuhbP__1tt6F_fxow4Kb2xonGT0GGk",
+    dq: "jmE2DiIPdhwDgLXAQpIaBqQ81bO3XfVT_LRULAwwwwlPuQV148H04zlh9TJ6Y2GZHYokV1U0eOBpJxfkb7dLYtpJpuiBjRf4yIUEoGlkkI_QlJnFSFr-YjGRdfNHqWBkxlSMZL770R9mIATndGkH7z5x-r9KwBZFC4FCG2hg_zE",
+    qi: "YCX_pLwbMBA1ThVH0WcwmnytqNcrMCEwTm7ByA2eU6nWbQrULvf7m9_kzfLUcjsnpAVlBQG5JMXMy0Sq4ptwbywsa5-G8KAOOOR2L3v4hC-Eys9ftgFM_3i0o40eeQH4b3haPbntrIeMg8IzlOuVYKf9-2QuKDoWeRdd7NsdxTk",
+};
+var expectedSignature = "8517104ae42b39e958e01a78158f90077b7711a60634873c3ae62565900dc1c7a3e75626b30e1281fa396594bbab742a5fc3be39dee3d981b9e4e83248bf69ed3671dee86a8f03c6a9b4465bf7b3dcd1dd04c3446e77aa340f20f9bd203966dd3dec2d4d135ea1c916f218a711ccaa167332f021ed7163ba61ffed6c0c48c4097ff979eea349011febf10398c3abcec9b4540ff0767fa9a29e7b119b8fdb8eb55786d311058dc509ce58da8abf50fe0ab2f1b092a24d3f8ae2f1f533a1ef0b7e191a43bb710acb376f4f5e620ffff602d9865a93e90f5d264309559a6acd4071058abb3ce0935a06df59b6c7c273cb033bc6d6a18b32559a8d4b14da2bfa2b15";
+
+crypto.subtle.importKey("jwk", jwkKey, rsaImportParams, extractable, ["sign"]).then(function(key) {
+    return crypto.subtle.sign("RSASSA-PKCS1-v1_5", key, text);
+}).then(function(result) {
+    signature = result;
+
+    shouldBe("bytesToHexString(signature)", "expectedSignature");
+
+    finishJSTest();
+});
+
+</script>
+
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha512-expected.txt b/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha512-expected.txt
new file mode 100644 (file)
index 0000000..efab6e8
--- /dev/null
@@ -0,0 +1,10 @@
+Test signing with RSASSA-PKCS1-v1_5 SHA-512 using an imported key
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS bytesToHexString(signature) is expectedSignature
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha512.html b/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha512.html
new file mode 100644 (file)
index 0000000..b64540c
--- /dev/null
@@ -0,0 +1,53 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+<script src="../resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test signing with RSASSA-PKCS1-v1_5 SHA-512 using an imported key");
+
+jsTestIsAsync = true;
+
+var extractable = false;
+var text = asciiToUint8Array("Hello, World!");
+var rsaImportParams = {
+    name: "RSASSA-PKCS1-v1_5",
+    hash: "SHA-512",
+}
+var jwkKey = {
+    kty: "RSA",
+    alg: "RS512",
+    use: "sig",
+    key_ops: ["sign"],
+    ext: true,
+    n: "rcCUCv7Oc1HVam1DIhCzqknThWawOp8QLk8Ziy2p10ByjQFCajoFiyuAWl-R1WXZaf4xitLRracT9agpzIzc-MbLSHIGgWQGO21lGiImy5ftZ-D8bHAqRz2y15pzD4c4CEou7XSSLDoRnR0QG5MsDhD6s2gV9mwHkrtkCxtMWdBi-77as8wGmlNRldcOSgZDLK8UnCSgA1OguZ989bFyc8tOOEIb0xUSfPSz3LPSCnyYz68aDjmKVeNH-ig857OScyWbGyEy3Biw64qun3juUlNWsJ3zngkOdteYWytx5Qr4XKNs6R-Myyq72KUp02mJDZiiyiglxML_i3-_CeecCw",
+    e: "AQAB",
+    d: "eNLS37aCz7RXSNPD_DtLBJ6j5T8cSxdzRBCjPaI6WcGqJp16lq3UTwuoDLAqlA9oGYm238dsIWpuucP_lQtbWe-7SpxoI6_vmYGf7YVUHv1-DF9qiOmSrMmdxMnVOzYXY8RaT6thPjn_J5cfLV2xI_LwsrMtmpdSyNlgX0zTUhwtuahgAKMEChYjH2EnjHdHw6sY2-wApdcQI7ULE0oo5RzbQZpmuhcN9hiBc0L3hhF0qo50mbl02_65_GQ7DpVkXBxNgRBLzlPabmzzG2oAhfefLgYmSC1opaCkXE6vRWQNWNL45RZNZFYM3uoJghOMqGeocM0BpjdChHrPOlFvSQ",
+    p: "4miTuAjKMeH5uJ5KB397QUwhbkYEgSbcA2mifmSkvE2018gb55qkBHK1eVryf1_m43LNlc6O_ak6gfzdZIZvS5NCGjPl0q09plUpu8qFOSspBwA67qGH76lFlZLn_d4yglS7wfLru4_5Ys8qLLs-DqVLviwposOnyyWqwM5AXp0",
+    q: "xHYrzkivtmnz_sGchnWGc0q-pDOkKicptRpv2pMFIIXxnFX5aMeEXIZjVujXtwUy1UlFIN2GZJSvy5KJ79mu_XyNnFHMzedH-A3ee3u8h1UUrZF-vUu1_e4U_x67NN1dedzUSKynN7pFl3OkuShMBWGV-cwzOPdcVAfVuZlxUMc",
+    dp: "fBzDzYDUBmBQGop7Hn0dvf_T27V6RqpctWo074CQZcFbP2atFVtKSj3viWT3xid2VHzcgiDHdfpM3nEVlEO1wwIonGCSvdjGEOZiiFVOjrZAOVxA8guOjyyFvqbXke06VwPIIVvfKeSU2zuhbP__1tt6F_fxow4Kb2xonGT0GGk",
+    dq: "jmE2DiIPdhwDgLXAQpIaBqQ81bO3XfVT_LRULAwwwwlPuQV148H04zlh9TJ6Y2GZHYokV1U0eOBpJxfkb7dLYtpJpuiBjRf4yIUEoGlkkI_QlJnFSFr-YjGRdfNHqWBkxlSMZL770R9mIATndGkH7z5x-r9KwBZFC4FCG2hg_zE",
+    qi: "YCX_pLwbMBA1ThVH0WcwmnytqNcrMCEwTm7ByA2eU6nWbQrULvf7m9_kzfLUcjsnpAVlBQG5JMXMy0Sq4ptwbywsa5-G8KAOOOR2L3v4hC-Eys9ftgFM_3i0o40eeQH4b3haPbntrIeMg8IzlOuVYKf9-2QuKDoWeRdd7NsdxTk",
+};
+var expectedSignature = "04dfcced9635d2208ea05c73ce76745678db57b7575a7ffa9770615a9ef9c68455bb49e9c70a99d053eb91c9dd2ecf09dba2a1334325318a2e75b78f4c4eb63c0d05a2a9418d6aefc5cb97ffbfb8cd06b39f8adaa545ea6b95e09934b0e2ef8e05734dcb1f1a72877f891637a99cd80b2f8a5ad419aebe18fa354bff95141b207f986e60ae16f192011b7f9c97137820a7af77be59d771ad35f51a895a2c5e0aafc96ba8f1f2dfcfbe5257b7b603d37e25670996c6c05f3db940c973f561bac8582659701fad4b4c84faa56af2dfeab450c40714f46bdd1bc6e24a3efc10bf3767ad452a79fb7de5fff282b2302e3f3f98bfdbb4037780e793343358b51cead1";
+
+crypto.subtle.importKey("jwk", jwkKey, rsaImportParams, extractable, ["sign"]).then(function(key) {
+    return crypto.subtle.sign("RSASSA-PKCS1-v1_5", key, text);
+}).then(function(result) {
+    signature = result;
+
+    shouldBe("bytesToHexString(signature)", "expectedSignature");
+
+    finishJSTest();
+});
+
+</script>
+
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/crypto/subtle/sign-malformed-parameters-expected.txt b/LayoutTests/crypto/subtle/sign-malformed-parameters-expected.txt
new file mode 100644 (file)
index 0000000..8668e9e
--- /dev/null
@@ -0,0 +1,14 @@
+Test signing with malformed parameters
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS crypto.subtle.sign() rejected promise  with TypeError: Not enough arguments.
+PASS crypto.subtle.sign(1) rejected promise  with TypeError: Not enough arguments.
+PASS crypto.subtle.sign(1, 2) rejected promise  with TypeError: Not enough arguments.
+PASS crypto.subtle.sign("rsassa-pkcs1-v1_5", wrongKey, text) rejected promise  with InvalidAccessError (DOM Exception 15): CryptoKey doesn't match AlgorithmIdentifier.
+PASS crypto.subtle.sign("hmac", wrongKey, text) rejected promise  with InvalidAccessError (DOM Exception 15): CryptoKey doesn't support signing.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/subtle/sign-malformed-parameters.html b/LayoutTests/crypto/subtle/sign-malformed-parameters.html
new file mode 100644 (file)
index 0000000..a95dee5
--- /dev/null
@@ -0,0 +1,45 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+<script src="../resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test signing with malformed parameters");
+
+jsTestIsAsync = true;
+
+var extractable = false;
+var text = asciiToUint8Array("Hello, World!");
+var hmacImportParams = {
+    name: "hmac",
+    hash: "sha-1",
+}
+var rawKey = asciiToUint8Array("jnOw99oOZFLIEPMr");
+
+// Not enough arguments.
+shouldReject('crypto.subtle.sign()');
+shouldReject('crypto.subtle.sign(1)');
+shouldReject('crypto.subtle.sign(1, 2)');
+
+crypto.subtle.importKey("raw", rawKey, hmacImportParams, extractable, ["sign", "verify"]).then(function(result) {
+    wrongKey = result;
+    // Wrong algorithm identifier.
+    shouldReject('crypto.subtle.sign("rsassa-pkcs1-v1_5", wrongKey, text)');
+
+    return crypto.subtle.importKey("raw", rawKey, hmacImportParams, extractable, ["verify"]);
+}).then(function(result) {
+    wrongKey = result;
+    // Wrong usage.
+    return shouldReject('crypto.subtle.sign("hmac", wrongKey, text)');
+}).then(finishJSTest);
+
+</script>
+
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/crypto/workers/subtle/hmac-import-key-sign-expected.txt b/LayoutTests/crypto/workers/subtle/hmac-import-key-sign-expected.txt
new file mode 100644 (file)
index 0000000..ac9d8d0
--- /dev/null
@@ -0,0 +1,11 @@
+[Worker] Test signing with HMAC SHA-1 using an imported key in workers
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Starting worker: resources/hmac-import-key-sign.js
+PASS [Worker] bytesToHexString(signature) is expectedSignature
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/workers/subtle/hmac-import-key-sign.html b/LayoutTests/crypto/workers/subtle/hmac-import-key-sign.html
new file mode 100644 (file)
index 0000000..28f6c61
--- /dev/null
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script src="../../../resources/js-test-pre.js"></script>
+</head>
+<body>
+    <script>
+        worker = startWorker('resources/hmac-import-key-sign.js');
+    </script>
+    <script src="../../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/crypto/workers/subtle/resources/hmac-import-key-sign.js b/LayoutTests/crypto/workers/subtle/resources/hmac-import-key-sign.js
new file mode 100644 (file)
index 0000000..2000fbe
--- /dev/null
@@ -0,0 +1,25 @@
+importScripts('../../../../resources/js-test-pre.js');
+importScripts('../../../resources/common.js');
+
+description("Test signing with HMAC SHA-1 using an imported key in workers");
+
+jsTestIsAsync = true;
+
+var extractable = false;
+var text = asciiToUint8Array("Hello, World!");
+var hmacImportParams = {
+    name: "hmac",
+    hash: "sha-1",
+}
+var rawKey = asciiToUint8Array("jnOw99oOZFLIEPMr");
+var expectedSignature = "6e8e66ff128606f52b8c589196ef5e0f7ca04816";
+
+crypto.subtle.importKey("raw", rawKey, hmacImportParams, extractable, ["sign", "verify"]).then(function(key) {
+    return crypto.subtle.sign("hmac", key, text);
+}).then(function(result) {
+    signature = result;
+
+    shouldBe("bytesToHexString(signature)", "expectedSignature");
+
+    finishJSTest();
+});
diff --git a/LayoutTests/crypto/workers/subtle/resources/rsassa-pkcs1-v1_5-import-key-sign.js b/LayoutTests/crypto/workers/subtle/resources/rsassa-pkcs1-v1_5-import-key-sign.js
new file mode 100644 (file)
index 0000000..4182bd6
--- /dev/null
@@ -0,0 +1,39 @@
+importScripts('../../../../resources/js-test-pre.js');
+importScripts('../../../resources/common.js');
+
+description("Test signing with RSASSA-PKCS1-v1_5 SHA-1 using an imported key in workers");
+
+jsTestIsAsync = true;
+
+var extractable = false;
+var text = asciiToUint8Array("Hello, World!");
+var rsaImportParams = {
+    name: "RSASSA-PKCS1-v1_5",
+    hash: "SHA-1",
+}
+var jwkKey = {
+    kty: "RSA",
+    alg: "RS1",
+    use: "sig",
+    key_ops: ["sign"],
+    ext: true,
+    n: "rcCUCv7Oc1HVam1DIhCzqknThWawOp8QLk8Ziy2p10ByjQFCajoFiyuAWl-R1WXZaf4xitLRracT9agpzIzc-MbLSHIGgWQGO21lGiImy5ftZ-D8bHAqRz2y15pzD4c4CEou7XSSLDoRnR0QG5MsDhD6s2gV9mwHkrtkCxtMWdBi-77as8wGmlNRldcOSgZDLK8UnCSgA1OguZ989bFyc8tOOEIb0xUSfPSz3LPSCnyYz68aDjmKVeNH-ig857OScyWbGyEy3Biw64qun3juUlNWsJ3zngkOdteYWytx5Qr4XKNs6R-Myyq72KUp02mJDZiiyiglxML_i3-_CeecCw",
+    e: "AQAB",
+    d: "eNLS37aCz7RXSNPD_DtLBJ6j5T8cSxdzRBCjPaI6WcGqJp16lq3UTwuoDLAqlA9oGYm238dsIWpuucP_lQtbWe-7SpxoI6_vmYGf7YVUHv1-DF9qiOmSrMmdxMnVOzYXY8RaT6thPjn_J5cfLV2xI_LwsrMtmpdSyNlgX0zTUhwtuahgAKMEChYjH2EnjHdHw6sY2-wApdcQI7ULE0oo5RzbQZpmuhcN9hiBc0L3hhF0qo50mbl02_65_GQ7DpVkXBxNgRBLzlPabmzzG2oAhfefLgYmSC1opaCkXE6vRWQNWNL45RZNZFYM3uoJghOMqGeocM0BpjdChHrPOlFvSQ",
+    p: "4miTuAjKMeH5uJ5KB397QUwhbkYEgSbcA2mifmSkvE2018gb55qkBHK1eVryf1_m43LNlc6O_ak6gfzdZIZvS5NCGjPl0q09plUpu8qFOSspBwA67qGH76lFlZLn_d4yglS7wfLru4_5Ys8qLLs-DqVLviwposOnyyWqwM5AXp0",
+    q: "xHYrzkivtmnz_sGchnWGc0q-pDOkKicptRpv2pMFIIXxnFX5aMeEXIZjVujXtwUy1UlFIN2GZJSvy5KJ79mu_XyNnFHMzedH-A3ee3u8h1UUrZF-vUu1_e4U_x67NN1dedzUSKynN7pFl3OkuShMBWGV-cwzOPdcVAfVuZlxUMc",
+    dp: "fBzDzYDUBmBQGop7Hn0dvf_T27V6RqpctWo074CQZcFbP2atFVtKSj3viWT3xid2VHzcgiDHdfpM3nEVlEO1wwIonGCSvdjGEOZiiFVOjrZAOVxA8guOjyyFvqbXke06VwPIIVvfKeSU2zuhbP__1tt6F_fxow4Kb2xonGT0GGk",
+    dq: "jmE2DiIPdhwDgLXAQpIaBqQ81bO3XfVT_LRULAwwwwlPuQV148H04zlh9TJ6Y2GZHYokV1U0eOBpJxfkb7dLYtpJpuiBjRf4yIUEoGlkkI_QlJnFSFr-YjGRdfNHqWBkxlSMZL770R9mIATndGkH7z5x-r9KwBZFC4FCG2hg_zE",
+    qi: "YCX_pLwbMBA1ThVH0WcwmnytqNcrMCEwTm7ByA2eU6nWbQrULvf7m9_kzfLUcjsnpAVlBQG5JMXMy0Sq4ptwbywsa5-G8KAOOOR2L3v4hC-Eys9ftgFM_3i0o40eeQH4b3haPbntrIeMg8IzlOuVYKf9-2QuKDoWeRdd7NsdxTk",
+};
+var expectedSignature = "08b83a4a58aff1db76529fe97f6dc2b58914a56f08ebc73aebf740680fc524e721c30842759acacab8acdf6e31e7cc83dbe8a48ace80b6a6558a9df892e4c2a9276c154cd605e632c8b857855a064aea68550b660a15044a0917026e494a71e4fee99fa57941268545f338c8601baa9c4f2116f0eb5432cfee5e3ed9978876fed201647921e599101930a99a2b645a9a879bce8c24592729f1f62a3b83fe21475871273cdbbe8efa7be314cabd087fbe1931ddf3fb86cbff5176a27554726b54c43208200725c6ad71d335ee5e09f3bbff7164ddf5bc857a41c5961e6f9581459db0fd0f09ee251d63b7a01bd716f6f72632b5c0f9a2c4dc2257d1e342138c13";
+
+crypto.subtle.importKey("jwk", jwkKey, rsaImportParams, extractable, ["sign"]).then(function(key) {
+    return crypto.subtle.sign("RSASSA-PKCS1-v1_5", key, text);
+}).then(function(result) {
+    signature = result;
+
+    shouldBe("bytesToHexString(signature)", "expectedSignature");
+
+    finishJSTest();
+});
\ No newline at end of file
diff --git a/LayoutTests/crypto/workers/subtle/rsassa-pkcs1-v1_5-import-key-sign-expected.txt b/LayoutTests/crypto/workers/subtle/rsassa-pkcs1-v1_5-import-key-sign-expected.txt
new file mode 100644 (file)
index 0000000..6d41c48
--- /dev/null
@@ -0,0 +1,11 @@
+[Worker] Test signing with RSASSA-PKCS1-v1_5 SHA-1 using an imported key in workers
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Starting worker: resources/rsassa-pkcs1-v1_5-import-key-sign.js
+PASS [Worker] bytesToHexString(signature) is expectedSignature
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/workers/subtle/rsassa-pkcs1-v1_5-import-key-sign.html b/LayoutTests/crypto/workers/subtle/rsassa-pkcs1-v1_5-import-key-sign.html
new file mode 100644 (file)
index 0000000..657c35f
--- /dev/null
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script src="../../../resources/js-test-pre.js"></script>
+</head>
+<body>
+    <script>
+        worker = startWorker('resources/rsassa-pkcs1-v1_5-import-key-sign.js');
+    </script>
+    <script src="../../../resources/js-test-post.js"></script>
+</body>
+</html>
index 8b7e4be..b24d75a 100644 (file)
@@ -1,3 +1,13 @@
+2016-11-22  Jiewen Tan  <jiewen_tan@apple.com>
+
+        Update SubtleCrypto::sign to match the latest spec
+        https://bugs.webkit.org/show_bug.cgi?id=164740
+        <rdar://problem/29257864>
+
+        Reviewed by Brent Fulgham.
+
+        * WebCryptoAPI/idlharness-expected.txt:
+
 2016-11-18  Jiewen Tan  <jiewen_tan@apple.com>
 
         Update SubtleCrypto::decrypt to match the latest spec
index 5d7bd57..ebdcd16 100644 (file)
@@ -47,8 +47,8 @@ PASS SubtleCrypto interface: crypto.subtle must inherit property "encrypt" with
 PASS SubtleCrypto interface: calling encrypt(AlgorithmIdentifier,CryptoKey,BufferSource) on crypto.subtle with too few arguments must throw TypeError 
 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
+PASS SubtleCrypto interface: crypto.subtle must inherit property "sign" with the proper type (2) 
+PASS SubtleCrypto interface: calling sign(AlgorithmIdentifier,CryptoKey,BufferSource) on crypto.subtle with too few arguments must throw TypeError 
 FAIL SubtleCrypto interface: crypto.subtle must inherit property "verify" with the proper type (3) assert_inherits: property "verify" not found in prototype chain
 FAIL SubtleCrypto interface: calling verify(AlgorithmIdentifier,CryptoKey,BufferSource,BufferSource) on crypto.subtle with too few arguments must throw TypeError assert_inherits: property "verify" not found in prototype chain
 FAIL SubtleCrypto interface: crypto.subtle must inherit property "digest" with the proper type (4) assert_inherits: property "digest" not found in prototype chain
index 7fcda54..b5b9232 100644 (file)
@@ -1,3 +1,72 @@
+2016-11-22  Jiewen Tan  <jiewen_tan@apple.com>
+
+        Update SubtleCrypto::sign to match the latest spec
+        https://bugs.webkit.org/show_bug.cgi?id=164740
+        <rdar://problem/29257864>
+
+        Reviewed by Brent Fulgham.
+
+        This patch does following few things:
+        1. It updates the SubtleCrypto::sign method to match the latest spec:
+           https://www.w3.org/TR/WebCryptoAPI/#SubtleCrypto-method-sign.
+           It also refers to the latest Editor's Draft to a certain degree:
+           https://w3c.github.io/webcrypto/Overview.html#SubtleCrypto-method-sign.
+        2. It implements sign operations of the following algorithms: HMAC, and
+           RSASSA-PKCS1-V1_5.
+        3. It also replaces promise.copyRef() with WTFMove(promise) for all the
+           capture lists of exception callbacks in promise functions.
+
+        Tests: crypto/subtle/hmac-import-key-sign-sha1.html
+               crypto/subtle/hmac-import-key-sign-sha224.html
+               crypto/subtle/hmac-import-key-sign-sha256.html
+               crypto/subtle/hmac-import-key-sign-sha384.html
+               crypto/subtle/hmac-import-key-sign-sha512.html
+               crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha1.html
+               crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha224.html
+               crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha256.html
+               crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha384.html
+               crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha512.html
+               crypto/subtle/sign-malformed-parameters.html
+               crypto/workers/subtle/hmac-import-key-sign.html
+               crypto/workers/subtle/rsassa-pkcs1-v1_5-import-key-sign.html
+
+        * bindings/js/JSSubtleCryptoCustom.cpp:
+        (WebCore::normalizeCryptoAlgorithmParameters):
+        (WebCore::jsSubtleCryptoFunctionDecryptPromise):
+        Fix a minor bug.
+        (WebCore::jsSubtleCryptoFunctionEncryptPromise):
+        (WebCore::jsSubtleCryptoFunctionDecryptPromise):
+        (WebCore::jsSubtleCryptoFunctionSignPromise):
+        (WebCore::jsSubtleCryptoFunctionGenerateKeyPromise):
+        (WebCore::jsSubtleCryptoFunctionImportKeyPromise):
+        (WebCore::jsSubtleCryptoFunctionExportKeyPromise):
+        (WebCore::JSSubtleCrypto::sign):
+        * crypto/CryptoAlgorithm.cpp:
+        (WebCore::CryptoAlgorithm::sign):
+        * crypto/CryptoAlgorithm.h:
+        * crypto/SubtleCrypto.idl:
+        * crypto/algorithms/CryptoAlgorithmHMAC.cpp:
+        (WebCore::CryptoAlgorithmHMAC::sign):
+        * crypto/algorithms/CryptoAlgorithmHMAC.h:
+        * crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp:
+        (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::sign):
+        * crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.h:
+        * crypto/gcrypt/CryptoAlgorithmHMACGCrypt.cpp:
+        (WebCore::CryptoAlgorithmHMAC::platformSign):
+        * crypto/gnutls/CryptoAlgorithmHMACGnuTLS.cpp:
+        (WebCore::CryptoAlgorithmHMAC::platformSign):
+        * crypto/gnutls/CryptoAlgorithmRSASSA_PKCS1_v1_5GnuTLS.cpp:
+        (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::platformSign):
+        * crypto/mac/CryptoAlgorithmHMACMac.cpp:
+        (WebCore::commonCryptoHMACAlgorithm):
+        (WebCore::calculateSignature):
+        Remove a null guardance since the depending bug is resolved.
+        (WebCore::CryptoAlgorithmHMAC::platformSign):
+        (WebCore::CryptoAlgorithmHMAC::platformVerify):
+        * crypto/mac/CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp:
+        (WebCore::signRSASSA_PKCS1_v1_5):
+        (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::platformSign):
+
 2016-11-29  Chris Dumez  <cdumez@apple.com>
 
         Can't download move.simple.com direct deposit transition PDF: Non user-triggered activations of anchors that have a download attribute are ignored
index 2f97074..e4dffe0 100644 (file)
@@ -54,6 +54,7 @@ namespace WebCore {
 enum class Operations {
     Encrypt,
     Decrypt,
+    Sign,
     Digest,
     GenerateKey,
     ImportKey,
@@ -117,6 +118,17 @@ static std::unique_ptr<CryptoAlgorithmParameters> normalizeCryptoAlgorithmParame
                 return nullptr;
             }
             break;
+        case Operations::Sign:
+            switch (*identifier) {
+            case CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5:
+            case CryptoAlgorithmIdentifier::HMAC:
+                result = std::make_unique<CryptoAlgorithmParameters>(params);
+                break;
+            default:
+                setDOMException(&state, NOT_SUPPORTED_ERR);
+                return nullptr;
+            }
+            break;
         case Operations::Digest:
             switch (*identifier) {
             case CryptoAlgorithmIdentifier::SHA_1:
@@ -452,7 +464,7 @@ static void jsSubtleCryptoFunctionEncryptPromise(ExecState& state, Ref<DeferredP
         fulfillPromiseWithArrayBuffer(WTFMove(capturedPromise), cipherText.data(), cipherText.size());
         return;
     };
-    auto exceptionCallback = [capturedPromise = promise.copyRef()](ExceptionCode ec) mutable {
+    auto exceptionCallback = [capturedPromise = WTFMove(promise)](ExceptionCode ec) mutable {
         rejectWithException(WTFMove(capturedPromise), ec);
     };
 
@@ -493,11 +505,11 @@ static void jsSubtleCryptoFunctionDecryptPromise(ExecState& state, Ref<DeferredP
     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());
+    auto callback = [capturedPromise = promise.copyRef()](const Vector<uint8_t>& plainText) mutable {
+        fulfillPromiseWithArrayBuffer(WTFMove(capturedPromise), plainText.data(), plainText.size());
         return;
     };
-    auto exceptionCallback = [capturedPromise = promise.copyRef()](ExceptionCode ec) mutable {
+    auto exceptionCallback = [capturedPromise = WTFMove(promise)](ExceptionCode ec) mutable {
         rejectWithException(WTFMove(capturedPromise), ec);
     };
 
@@ -506,6 +518,51 @@ static void jsSubtleCryptoFunctionDecryptPromise(ExecState& state, Ref<DeferredP
     algorithm->decrypt(WTFMove(params), key.releaseNonNull(), WTFMove(data), WTFMove(callback), WTFMove(exceptionCallback), *scriptExecutionContextFromExecState(&state), subtle->wrapped().workQueue());
 }
 
+static void jsSubtleCryptoFunctionSignPromise(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::Sign);
+    RETURN_IF_EXCEPTION(scope, void());
+
+    auto key = toCryptoKey(state, state.uncheckedArgument(1));
+    RETURN_IF_EXCEPTION(scope, void());
+
+    auto data = toVector(state, 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(CryptoKeyUsageSign)) {
+        promise->reject(INVALID_ACCESS_ERR, ASCIILiteral("CryptoKey doesn't support signing"));
+        return;
+    }
+
+    auto algorithm = createAlgorithm(state, key->algorithmIdentifier());
+    RETURN_IF_EXCEPTION(scope, void());
+
+    auto callback = [capturedPromise = promise.copyRef()](const Vector<uint8_t>& signature) mutable {
+        fulfillPromiseWithArrayBuffer(WTFMove(capturedPromise), signature.data(), signature.size());
+        return;
+    };
+    auto exceptionCallback = [capturedPromise = WTFMove(promise)](ExceptionCode ec) mutable {
+        rejectWithException(WTFMove(capturedPromise), ec);
+    };
+
+    JSSubtleCrypto* subtle = jsDynamicDowncast<JSSubtleCrypto*>(state.thisValue());
+    ASSERT(subtle);
+    algorithm->sign(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,7 +602,7 @@ static void jsSubtleCryptoFunctionGenerateKeyPromise(ExecState& state, Ref<Defer
             capturedPromise->resolve(keyPair);
         }
     };
-    auto exceptionCallback = [capturedPromise =  promise.copyRef()](ExceptionCode ec) mutable {
+    auto exceptionCallback = [capturedPromise = WTFMove(promise)](ExceptionCode ec) mutable {
         rejectWithException(WTFMove(capturedPromise), ec);
     };
 
@@ -590,7 +647,7 @@ static void jsSubtleCryptoFunctionImportKeyPromise(ExecState& state, Ref<Deferre
         }
         capturedPromise->resolve(key);
     };
-    auto exceptionCallback = [capturedPromise =  promise.copyRef()](ExceptionCode ec) mutable {
+    auto exceptionCallback = [capturedPromise = WTFMove(promise)](ExceptionCode ec) mutable {
         rejectWithException(WTFMove(capturedPromise), ec);
     };
 
@@ -657,7 +714,7 @@ static void jsSubtleCryptoFunctionExportKeyPromise(ExecState& state, Ref<Deferre
         }
         ASSERT_NOT_REACHED();
     };
-    auto exceptionCallback = [capturedPromise =  promise.copyRef()](ExceptionCode ec) mutable {
+    auto exceptionCallback = [capturedPromise = WTFMove(promise)](ExceptionCode ec) mutable {
         rejectWithException(WTFMove(capturedPromise), ec);
     };
 
@@ -677,6 +734,11 @@ JSValue JSSubtleCrypto::decrypt(ExecState& state)
     return callPromiseFunction<jsSubtleCryptoFunctionDecryptPromise, PromiseExecutionScope::WindowOrWorker>(state);
 }
 
+JSValue JSSubtleCrypto::sign(ExecState& state)
+{
+    return callPromiseFunction<jsSubtleCryptoFunctionSignPromise, PromiseExecutionScope::WindowOrWorker>(state);
+}
+
 JSValue JSSubtleCrypto::generateKey(ExecState& state)
 {
     return callPromiseFunction<jsSubtleCryptoFunctionGenerateKeyPromise, PromiseExecutionScope::WindowOrWorker>(state);
index 7111ea5..4fe7b95 100644 (file)
@@ -42,6 +42,11 @@ void CryptoAlgorithm::decrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<
     exceptionCallback(NOT_SUPPORTED_ERR);
 }
 
+void CryptoAlgorithm::sign(Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&& exceptionCallback, ScriptExecutionContext&, WorkQueue&)
+{
+    exceptionCallback(NOT_SUPPORTED_ERR);
+}
+
 void CryptoAlgorithm::generateKey(const CryptoAlgorithmParameters&, bool, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&& exceptionCallback, ScriptExecutionContext&)
 {
     exceptionCallback(NOT_SUPPORTED_ERR);
index 41287d0..11984b0 100644 (file)
@@ -66,6 +66,7 @@ public:
 
     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 sign(Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
     virtual void generateKey(const 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&&);
index ed1a644..019f115 100644 (file)
@@ -33,6 +33,7 @@ enum KeyFormat { "raw", "spki", "pkcs8", "jwk" };
 ] interface SubtleCrypto {
     [Custom] Promise<any> encrypt(AlgorithmIdentifier algorithm, CryptoKey key, BufferSource data);
     [Custom] Promise<any> decrypt(AlgorithmIdentifier algorithm, CryptoKey key, BufferSource data);
+    [Custom] Promise<any> sign(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);
index fb97445..5713284 100644 (file)
@@ -69,6 +69,11 @@ bool CryptoAlgorithmHMAC::keyAlgorithmMatches(const CryptoAlgorithmHmacParamsDep
     return true;
 }
 
+void CryptoAlgorithmHMAC::sign(Ref<CryptoKey>&& key, Vector<uint8_t>&& data, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+{
+    platformSign(WTFMove(key), WTFMove(data), WTFMove(callback), WTFMove(exceptionCallback), context, workQueue);
+}
+
 void CryptoAlgorithmHMAC::generateKey(const CryptoAlgorithmParameters& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyOrKeyPairCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext&)
 {
     const auto& hmacParameters = downcast<CryptoAlgorithmHmacKeyParams>(parameters);
index 04fbab4..a88fa79 100644 (file)
@@ -44,6 +44,7 @@ private:
     CryptoAlgorithmHMAC() = default;
     CryptoAlgorithmIdentifier identifier() const final;
 
+    void sign(Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
     void generateKey(const 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;
@@ -55,6 +56,7 @@ private:
     ExceptionOr<void> importKey(const CryptoAlgorithmParametersDeprecated&, const CryptoKeyData&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, VoidCallback&& failureCallback) final;
 
     bool keyAlgorithmMatches(const CryptoAlgorithmHmacParamsDeprecated& algorithmParameters, const CryptoKey&) const;
+    void platformSign(Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
     ExceptionOr<void> platformSign(const CryptoAlgorithmHmacParamsDeprecated&, const CryptoKeyHMAC&, const CryptoOperationData&, VectorCallback&&, VoidCallback&& failureCallback);
     ExceptionOr<void> platformVerify(const CryptoAlgorithmHmacParamsDeprecated&, const CryptoKeyHMAC&, const CryptoOperationData& signature, const CryptoOperationData&, BoolCallback&&, VoidCallback&& failureCallback);
 };
index c5f00b5..d30e9e8 100644 (file)
@@ -68,6 +68,15 @@ bool CryptoAlgorithmRSASSA_PKCS1_v1_5::keyAlgorithmMatches(const CryptoAlgorithm
     return true;
 }
 
+void CryptoAlgorithmRSASSA_PKCS1_v1_5::sign(Ref<CryptoKey>&& key, Vector<uint8_t>&& data, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+{
+    if (key->type() != CryptoKeyType::Private) {
+        exceptionCallback(INVALID_ACCESS_ERR);
+        return;
+    }
+    platformSign(WTFMove(key), WTFMove(data), WTFMove(callback), WTFMove(exceptionCallback), context, workQueue);
+}
+
 void CryptoAlgorithmRSASSA_PKCS1_v1_5::generateKey(const CryptoAlgorithmParameters& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyOrKeyPairCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context)
 {
     const auto& rsaParameters = downcast<CryptoAlgorithmRsaHashedKeyGenParams>(parameters);
index 1f34398..17f0308 100644 (file)
@@ -44,6 +44,7 @@ private:
     CryptoAlgorithmRSASSA_PKCS1_v1_5() = default;
     CryptoAlgorithmIdentifier identifier() const final;
 
+    void sign(Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
     void generateKey(const 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;
@@ -54,6 +55,7 @@ private:
     ExceptionOr<void> importKey(const CryptoAlgorithmParametersDeprecated&, const CryptoKeyData&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, VoidCallback&& failureCallback) final;
 
     bool keyAlgorithmMatches(const CryptoAlgorithmRsaSsaParamsDeprecated& algorithmParameters, const CryptoKey&) const;
+    void platformSign(Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
     ExceptionOr<void> platformSign(const CryptoAlgorithmRsaSsaParamsDeprecated&, const CryptoKeyRSA&, const CryptoOperationData&, VectorCallback&&, VoidCallback&& failureCallback);
     ExceptionOr<void> platformVerify(const CryptoAlgorithmRsaSsaParamsDeprecated&, const CryptoKeyRSA&, const CryptoOperationData& signature, const CryptoOperationData&, BoolCallback&&, VoidCallback&& failureCallback);
 };
index 66aaf34..9c755b7 100644 (file)
@@ -32,6 +32,7 @@
 #include "CryptoAlgorithmHmacParamsDeprecated.h"
 #include "CryptoKeyHMAC.h"
 #include "ExceptionCode.h"
+#include "NotImplemented.h"
 #include <gcrypt.h>
 #include <wtf/CryptographicUtilities.h>
 
@@ -96,6 +97,11 @@ cleanup:
     return WTFMove(signature);
 }
 
+void CryptoAlgorithmHMAC::platformSign(Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&)
+{
+    notImplemented();
+}
+
 ExceptionOr<void> CryptoAlgorithmHMAC::platformSign(const CryptoAlgorithmHmacParamsDeprecated& parameters, const CryptoKeyHMAC& key, const CryptoOperationData& data, VectorCallback&& callback, VoidCallback&& failureCallback)
 {
     int algorithm = getGCryptDigestAlgorithm(parameters.hash);
index 3a6c0ef..174b802 100644 (file)
@@ -31,6 +31,7 @@
 #include "CryptoAlgorithmHmacParamsDeprecated.h"
 #include "CryptoKeyHMAC.h"
 #include "ExceptionCode.h"
+#include "NotImplemented.h"
 #include <gnutls/gnutls.h>
 #include <gnutls/crypto.h>
 #include <wtf/CryptographicUtilities.h>
@@ -68,6 +69,11 @@ static Vector<uint8_t> calculateSignature(gnutls_mac_algorithm_t algorithm, cons
     return result;
 }
 
+void CryptoAlgorithmHMAC::platformSign(Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&)
+{
+    notImplemented();
+}
+
 ExceptionOr<void> CryptoAlgorithmHMAC::platformSign(const CryptoAlgorithmHmacParamsDeprecated& parameters, const CryptoKeyHMAC& key, const CryptoOperationData& data, VectorCallback&& callback, VoidCallback&&)
 {
     gnutls_mac_algorithm_t algorithm = getGnutlsDigestAlgorithm(parameters.hash);
index 374cb94..fce6aaa 100644 (file)
 
 namespace WebCore {
 
+void CryptoAlgorithmRSASSA_PKCS1_v1_5::platformSign(Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&)
+{
+    notImplemented();
+}
+
 ExceptionOr<void> CryptoAlgorithmRSASSA_PKCS1_v1_5::platformSign(const CryptoAlgorithmRsaSsaParamsDeprecated&, const CryptoKeyRSA&, const CryptoOperationData&, VectorCallback&&, VoidCallback&&)
 {
     notImplemented();
index fb4c1b3..f11546d 100644 (file)
@@ -31,6 +31,7 @@
 #include "CryptoAlgorithmHmacParamsDeprecated.h"
 #include "CryptoKeyHMAC.h"
 #include "ExceptionCode.h"
+#include "ScriptExecutionContext.h"
 #include <CommonCrypto/CommonHMAC.h>
 #include <wtf/CryptographicUtilities.h>
 
@@ -54,7 +55,9 @@ static std::optional<CCHmacAlgorithm> commonCryptoHMACAlgorithm(CryptoAlgorithmI
     }
 }
 
-static Vector<uint8_t> calculateSignature(CCHmacAlgorithm algorithm, const Vector<uint8_t>& key, const CryptoOperationData& data)
+// FIXME: We should change data to Vector<uint8_t> type once WebKitSubtleCrypto is deprecated.
+// https://bugs.webkit.org/show_bug.cgi?id=164939
+static Vector<uint8_t> calculateSignature(CCHmacAlgorithm algorithm, const Vector<uint8_t>& key, const uint8_t* data, size_t dataLength)
 {
     size_t digestLength;
     switch (algorithm) {
@@ -79,17 +82,40 @@ static Vector<uint8_t> calculateSignature(CCHmacAlgorithm algorithm, const Vecto
     }
 
     Vector<uint8_t> result(digestLength);
-    const void* keyData = key.data() ? key.data() : reinterpret_cast<const uint8_t*>(""); // <rdar://problem/15467425> HMAC crashes when key pointer is null.
-    CCHmac(algorithm, keyData, key.size(), data.first, data.second, result.data());
+    CCHmac(algorithm, key.data(), key.size(), data, dataLength, result.data());
     return result;
 }
 
+void CryptoAlgorithmHMAC::platformSign(Ref<CryptoKey>&& key, Vector<uint8_t>&& data, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+{
+    context.ref();
+    workQueue.dispatch([key = WTFMove(key), data = WTFMove(data), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable {
+        auto& hmacKey = downcast<CryptoKeyHMAC>(key.get());
+        auto algorithm = commonCryptoHMACAlgorithm(hmacKey.hashAlgorithmIdentifier());
+        if (!algorithm) {
+            // We should only dereference callbacks after being back to the Document/Worker threads.
+            context.postTask([exceptionCallback = WTFMove(exceptionCallback), callback = WTFMove(callback)](ScriptExecutionContext& context) {
+                exceptionCallback(OperationError);
+                context.deref();
+            });
+            return;
+        }
+        auto result = calculateSignature(*algorithm, hmacKey.key(), data.data(), data.size());
+        // We should only dereference callbacks after being back to the Document/Worker threads.
+        context.postTask([callback = WTFMove(callback), result = WTFMove(result), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
+            callback(result);
+            context.deref();
+        });
+    });
+
+}
+
 ExceptionOr<void> CryptoAlgorithmHMAC::platformSign(const CryptoAlgorithmHmacParamsDeprecated& parameters, const CryptoKeyHMAC& key, const CryptoOperationData& data, VectorCallback&& callback, VoidCallback&&)
 {
     auto algorithm = commonCryptoHMACAlgorithm(parameters.hash);
     if (!algorithm)
         return Exception { NOT_SUPPORTED_ERR };
-    callback(calculateSignature(*algorithm, key.key(), data));
+    callback(calculateSignature(*algorithm, key.key(), data.first, data.second));
     return { };
 }
 
@@ -99,7 +125,7 @@ ExceptionOr<void> CryptoAlgorithmHMAC::platformVerify(const CryptoAlgorithmHmacP
     if (!algorithm)
         return Exception { NOT_SUPPORTED_ERR };
 
-    auto signature = calculateSignature(*algorithm, key.key(), data);
+    auto signature = calculateSignature(*algorithm, key.key(), data.first, data.second);
 
     // Using a constant time comparison to prevent timing attacks.
     bool result = signature.size() == expectedSignature.second && !constantTimeMemcmp(signature.data(), expectedSignature.first, signature.size());
index 2e95c84..c85e371 100644 (file)
@@ -33,6 +33,7 @@
 #include "CryptoDigest.h"
 #include "CryptoKeyRSA.h"
 #include "ExceptionCode.h"
+#include "ScriptExecutionContext.h"
 
 namespace WebCore {
 
@@ -54,35 +55,63 @@ inline std::optional<CryptoDigest::Algorithm> cryptoDigestAlgorithm(CryptoAlgori
     }
 }
 
-ExceptionOr<void> CryptoAlgorithmRSASSA_PKCS1_v1_5::platformSign(const CryptoAlgorithmRsaSsaParamsDeprecated& parameters, const CryptoKeyRSA& key, const CryptoOperationData& data, VectorCallback&& callback, VoidCallback&& failureCallback)
+// 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>> signRSASSA_PKCS1_v1_5(CryptoAlgorithmIdentifier hash, const PlatformRSAKey key, size_t keyLength, const uint8_t* data, size_t dataLength)
 {
     CCDigestAlgorithm digestAlgorithm;
-    if (!getCommonCryptoDigestAlgorithm(parameters.hash, digestAlgorithm))
-        return Exception { NOT_SUPPORTED_ERR };
+    if (!getCommonCryptoDigestAlgorithm(hash, digestAlgorithm))
+        return Exception { OperationError };
 
-    auto cryptoDigestAlgorithm = WebCore::cryptoDigestAlgorithm(parameters.hash);
+    auto cryptoDigestAlgorithm = WebCore::cryptoDigestAlgorithm(hash);
     if (!cryptoDigestAlgorithm)
-        return Exception { NOT_SUPPORTED_ERR };
-
+        return Exception { OperationError };
     auto digest = CryptoDigest::create(*cryptoDigestAlgorithm);
     if (!digest)
-        return Exception { NOT_SUPPORTED_ERR };
-
-    digest->addBytes(data.first, data.second);
-
+        return Exception { OperationError };
+    digest->addBytes(data, dataLength);
     auto digestData = digest->computeHash();
 
-    Vector<uint8_t> signature(512);
+    Vector<uint8_t> signature(keyLength / 8); // Per https://tools.ietf.org/html/rfc3447#section-8.2.1
     size_t signatureSize = signature.size();
 
-    CCCryptorStatus status = CCRSACryptorSign(key.platformKey(), ccPKCS1Padding, digestData.data(), digestData.size(), digestAlgorithm, 0, signature.data(), &signatureSize);
-    if (status) {
+    CCCryptorStatus status = CCRSACryptorSign(key, ccPKCS1Padding, digestData.data(), digestData.size(), digestAlgorithm, 0, signature.data(), &signatureSize);
+    if (status)
+        return Exception { OperationError };
+
+    return WTFMove(signature);
+}
+
+void CryptoAlgorithmRSASSA_PKCS1_v1_5::platformSign(Ref<CryptoKey>&& key, Vector<uint8_t>&& data, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+{
+    context.ref();
+    workQueue.dispatch([key = WTFMove(key), data = WTFMove(data), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable {
+        auto& rsaKey = downcast<CryptoKeyRSA>(key.get());
+        auto result = signRSASSA_PKCS1_v1_5(rsaKey.hashAlgorithmIdentifier(), rsaKey.platformKey(), rsaKey.keySizeInBits(), data.data(), data.size());
+        if (result.hasException()) {
+            // We should only dereference callbacks after being back to the Document/Worker threads.
+            context.postTask([exceptionCallback = WTFMove(exceptionCallback), ec = result.releaseException().code(), callback = WTFMove(callback)](ScriptExecutionContext& context) {
+                exceptionCallback(ec);
+                context.deref();
+            });
+            return;
+        }
+        // We should only dereference callbacks after being back to the Document/Worker threads.
+        context.postTask([callback = WTFMove(callback), result = result.releaseReturnValue(), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
+            callback(result);
+            context.deref();
+        });
+    });
+}
+
+ExceptionOr<void> CryptoAlgorithmRSASSA_PKCS1_v1_5::platformSign(const CryptoAlgorithmRsaSsaParamsDeprecated& parameters, const CryptoKeyRSA& key, const CryptoOperationData& data, VectorCallback&& callback, VoidCallback&& failureCallback)
+{
+    auto result = signRSASSA_PKCS1_v1_5(parameters.hash, key.platformKey(), key.keySizeInBits(), data.first, data.second);
+    if (result.hasException()) {
         failureCallback();
         return { };
     }
-
-    signature.resize(signatureSize);
-    callback(signature);
+    callback(result.releaseReturnValue());
     return { };
 }