SubtleCrypto::deriveBits always return NOT_SUPPORTED_ERR for now
authorjiewen_tan@apple.com <jiewen_tan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 1 Dec 2016 19:42:30 +0000 (19:42 +0000)
committerjiewen_tan@apple.com <jiewen_tan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 1 Dec 2016 19:42:30 +0000 (19:42 +0000)
https://bugs.webkit.org/show_bug.cgi?id=164745
<rdar://problem/29258118>

Reviewed by Darin Adler.

LayoutTests/imported/w3c:

* WebCryptoAPI/idlharness-expected.txt:

Source/WebCore:

Since we don't support any cryptography algorithms that has deriveBits operations,
SubtleCrypto::deriveBits will always return NOT_SUPPORTED_ERR for now.

Test: crypto/subtle/deriveBits-malformed-parameters.html

* bindings/js/JSSubtleCryptoCustom.cpp:
(WebCore::normalizeCryptoAlgorithmParameters):
(WebCore::jsSubtleCryptoFunctionDeriveBitsPromise):
(WebCore::JSSubtleCrypto::deriveBits):
* crypto/SubtleCrypto.idl:

LayoutTests:

* crypto/subtle/deriveBits-malformed-parameters-expected.txt: Added.
* crypto/subtle/deriveBits-malformed-parameters.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/crypto/subtle/deriveBits-malformed-parameters-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/deriveBits-malformed-parameters.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/SubtleCrypto.idl

index d166e3b..bc1c88b 100644 (file)
@@ -1,3 +1,14 @@
+2016-12-01  Jiewen Tan  <jiewen_tan@apple.com>
+
+        SubtleCrypto::deriveBits always return NOT_SUPPORTED_ERR for now
+        https://bugs.webkit.org/show_bug.cgi?id=164745
+        <rdar://problem/29258118>
+
+        Reviewed by Darin Adler.
+
+        * crypto/subtle/deriveBits-malformed-parameters-expected.txt: Added.
+        * crypto/subtle/deriveBits-malformed-parameters.html: Added.
+
 2016-12-01  Ryan Haddad  <ryanhaddad@apple.com>
 
         Marking media/modern-media-controls/tracks-panel/tracks-panel-select-track-with-keyboard.html as failing on mac-wk1.
diff --git a/LayoutTests/crypto/subtle/deriveBits-malformed-parameters-expected.txt b/LayoutTests/crypto/subtle/deriveBits-malformed-parameters-expected.txt
new file mode 100644 (file)
index 0000000..6f13784
--- /dev/null
@@ -0,0 +1,13 @@
+Test deriveBits operation with malformed parameters
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS crypto.subtle.deriveBits() rejected promise  with TypeError: Not enough arguments.
+PASS crypto.subtle.deriveBits(1) rejected promise  with TypeError: Not enough arguments.
+PASS crypto.subtle.deriveBits(1, 2) rejected promise  with TypeError: Not enough arguments.
+PASS crypto.subtle.deriveBits("ECDH", 2, 3) rejected promise  with NotSupportedError (DOM Exception 9): The operation is not supported..
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/subtle/deriveBits-malformed-parameters.html b/LayoutTests/crypto/subtle/deriveBits-malformed-parameters.html
new file mode 100644 (file)
index 0000000..10150d9
--- /dev/null
@@ -0,0 +1,24 @@
+<!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 deriveBits operation with malformed parameters");
+
+// Not enough arguments.
+shouldReject('crypto.subtle.deriveBits()');
+shouldReject('crypto.subtle.deriveBits(1)');
+shouldReject('crypto.subtle.deriveBits(1, 2)');
+// Not support.
+shouldReject('crypto.subtle.deriveBits("ECDH", 2, 3)');
+</script>
+
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
index e529fe8..63ae854 100644 (file)
@@ -1,3 +1,13 @@
+2016-12-01  Jiewen Tan  <jiewen_tan@apple.com>
+
+        SubtleCrypto::deriveBits always return NOT_SUPPORTED_ERR for now
+        https://bugs.webkit.org/show_bug.cgi?id=164745
+        <rdar://problem/29258118>
+
+        Reviewed by Darin Adler.
+
+        * WebCryptoAPI/idlharness-expected.txt:
+
 2016-11-30  Sam Weinig  <sam@webkit.org>
 
         [WebIDL] Remove custom bindings for File and Blob constructors
index 0ad6c68..bec119f 100644 (file)
@@ -57,8 +57,8 @@ PASS SubtleCrypto interface: crypto.subtle must inherit property "generateKey" w
 PASS SubtleCrypto interface: calling generateKey(AlgorithmIdentifier,boolean,[object Object]) on crypto.subtle with too few arguments must throw TypeError 
 PASS SubtleCrypto interface: crypto.subtle must inherit property "deriveKey" with the proper type (6) 
 PASS SubtleCrypto interface: calling deriveKey(AlgorithmIdentifier,CryptoKey,AlgorithmIdentifier,boolean,[object Object]) on crypto.subtle with too few arguments must throw TypeError 
-FAIL SubtleCrypto interface: crypto.subtle must inherit property "deriveBits" with the proper type (7) assert_inherits: property "deriveBits" not found in prototype chain
-FAIL SubtleCrypto interface: calling deriveBits(AlgorithmIdentifier,CryptoKey,unsigned long) on crypto.subtle with too few arguments must throw TypeError assert_inherits: property "deriveBits" not found in prototype chain
+PASS SubtleCrypto interface: crypto.subtle must inherit property "deriveBits" with the proper type (7) 
+PASS SubtleCrypto interface: calling deriveBits(AlgorithmIdentifier,CryptoKey,unsigned long) on crypto.subtle with too few arguments must throw TypeError 
 PASS SubtleCrypto interface: crypto.subtle must inherit property "importKey" with the proper type (8) 
 PASS SubtleCrypto interface: calling importKey(KeyFormat,[object Object],[object Object],AlgorithmIdentifier,boolean,[object Object]) on crypto.subtle with too few arguments must throw TypeError 
 PASS SubtleCrypto interface: crypto.subtle must inherit property "exportKey" with the proper type (9) 
index 72e6136..03a9223 100644 (file)
@@ -1,3 +1,22 @@
+2016-12-01  Jiewen Tan  <jiewen_tan@apple.com>
+
+        SubtleCrypto::deriveBits always return NOT_SUPPORTED_ERR for now
+        https://bugs.webkit.org/show_bug.cgi?id=164745
+        <rdar://problem/29258118>
+
+        Reviewed by Darin Adler.
+
+        Since we don't support any cryptography algorithms that has deriveBits operations,
+        SubtleCrypto::deriveBits will always return NOT_SUPPORTED_ERR for now.
+
+        Test: crypto/subtle/deriveBits-malformed-parameters.html
+
+        * bindings/js/JSSubtleCryptoCustom.cpp:
+        (WebCore::normalizeCryptoAlgorithmParameters):
+        (WebCore::jsSubtleCryptoFunctionDeriveBitsPromise):
+        (WebCore::JSSubtleCrypto::deriveBits):
+        * crypto/SubtleCrypto.idl:
+
 2016-12-01  Eric Carlson  <eric.carlson@apple.com>
 
         [MediaStream][Mac] Video presets sometimes don't work
index b2dd323..beedd47 100644 (file)
@@ -59,6 +59,7 @@ enum class Operations {
     Verify,
     Digest,
     DeriveKey,
+    DeriveBits,
     GenerateKey,
     ImportKey,
     WrapKey,
@@ -149,6 +150,7 @@ static std::unique_ptr<CryptoAlgorithmParameters> normalizeCryptoAlgorithmParame
             }
             break;
         case Operations::DeriveKey:
+        case Operations::DeriveBits:
             setDOMException(&state, NOT_SUPPORTED_ERR);
             return nullptr;
         case Operations::GenerateKey:
@@ -698,6 +700,23 @@ static void jsSubtleCryptoFunctionDeriveKeyPromise(ExecState& state, Ref<Deferre
     ASSERT_NOT_REACHED();
 }
 
+static void jsSubtleCryptoFunctionDeriveBitsPromise(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::DeriveBits);
+    RETURN_IF_EXCEPTION(scope, void());
+
+    // We should always return a NOT_SUPPORTED_ERR since we currently don't support any algorithms that has deriveBits operation.
+    ASSERT_NOT_REACHED();
+}
+
 static void jsSubtleCryptoFunctionGenerateKeyPromise(ExecState& state, Ref<DeferredPromise>&& promise)
 {
     VM& vm = state.vm();
@@ -973,6 +992,11 @@ JSValue JSSubtleCrypto::deriveKey(ExecState& state)
     return callPromiseFunction<jsSubtleCryptoFunctionDeriveKeyPromise, PromiseExecutionScope::WindowOrWorker>(state);
 }
 
+JSValue JSSubtleCrypto::deriveBits(ExecState& state)
+{
+    return callPromiseFunction<jsSubtleCryptoFunctionDeriveBitsPromise, PromiseExecutionScope::WindowOrWorker>(state);
+}
+
 JSValue JSSubtleCrypto::generateKey(ExecState& state)
 {
     return callPromiseFunction<jsSubtleCryptoFunctionGenerateKeyPromise, PromiseExecutionScope::WindowOrWorker>(state);
index 1b79f34..f6f17ef 100644 (file)
@@ -37,6 +37,7 @@ enum KeyFormat { "raw", "spki", "pkcs8", "jwk" };
     [Custom] Promise<any> verify(AlgorithmIdentifier algorithm, CryptoKey key, BufferSource signature, BufferSource data);
     [Custom] Promise<any> digest(AlgorithmIdentifier algorithm, BufferSource data);
     [Custom] Promise<any> deriveKey(AlgorithmIdentifier algorithm, CryptoKey baseKey, AlgorithmIdentifier derivedKeyType, boolean extractable, sequence<KeyUsage> keyUsages);
+    [Custom] Promise<ArrayBuffer> deriveBits(AlgorithmIdentifier algorithm, CryptoKey baseKey, unsigned long length);
     // 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);