Diff
Modified: trunk/Tools/ChangeLog (216156 => 216157)
--- trunk/Tools/ChangeLog 2017-05-03 23:50:18 UTC (rev 216156)
+++ trunk/Tools/ChangeLog 2017-05-03 23:50:38 UTC (rev 216157)
@@ -1,3 +1,21 @@
+2017-04-26 Jiewen Tan <[email protected]>
+
+ [WebCrypto] Add an api test for testing wrapping/unwrapping serialized crypto keys
+ https://bugs.webkit.org/show_bug.cgi?id=171350
+ <rdar://problem/28600836>
+
+ Patched by Brady Eidson.
+
+ Reviewed by Brent Fulgham.
+
+ * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+ * TestWebKitAPI/Tests/WebKit2/NavigationClientDefaultCrypto.cpp: Added.
+ (TestWebKitAPI::runJavaScriptAlert):
+ (TestWebKitAPI::decidePolicyForNavigationAction):
+ (TestWebKitAPI::decidePolicyForNavigationResponse):
+ (TestWebKitAPI::TEST):
+ * TestWebKitAPI/Tests/WebKit2/navigation-client-default-crypto.html: Added.
+
2017-05-03 Simon Fraser <[email protected]>
Have WKWebView call _updateVisibleContentRects for the current transaction if possible, rather than always delaying
Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (216156 => 216157)
--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2017-05-03 23:50:18 UTC (rev 216156)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2017-05-03 23:50:38 UTC (rev 216157)
@@ -188,6 +188,8 @@
5714ECBD1CA8C22A00051AC8 /* DownloadRequestOriginalURL2.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 5714ECBC1CA8C21800051AC8 /* DownloadRequestOriginalURL2.html */; };
5769C50B1D9B0002000847FB /* SerializedCryptoKeyWrap.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5769C50A1D9B0001000847FB /* SerializedCryptoKeyWrap.mm */; };
57901FB11CAF142D00ED64F9 /* LoadInvalidURLRequest.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 57901FB01CAF141C00ED64F9 /* LoadInvalidURLRequest.html */; };
+ 5797FE311EB15A6800B2F4A0 /* NavigationClientDefaultCrypto.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5797FE2F1EB15A5F00B2F4A0 /* NavigationClientDefaultCrypto.cpp */; };
+ 5797FE331EB15AB100B2F4A0 /* navigation-client-default-crypto.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 5797FE321EB15A8900B2F4A0 /* navigation-client-default-crypto.html */; };
57F56A5C1C7F8CC100F31D7E /* IsNavigationActionTrusted.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 57F56A5B1C7F8A4000F31D7E /* IsNavigationActionTrusted.html */; };
5C0BF88D1DD5964D00B00328 /* MemoryPressureHandler.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5C0BF88C1DD5957400B00328 /* MemoryPressureHandler.mm */; };
5C0BF8911DD599A900B00328 /* WebViewCanPasteZeroPng.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5C0BF88F1DD5999B00B00328 /* WebViewCanPasteZeroPng.mm */; };
@@ -684,6 +686,7 @@
dstSubfolderSpec = 7;
files = (
55226A2F1EBA44B900C36AD0 /* large-red-square-image.html in Copy Resources */,
+ 5797FE331EB15AB100B2F4A0 /* navigation-client-default-crypto.html in Copy Resources */,
074994421EA5034B000DA44E /* getUserMedia.html in Copy Resources */,
C9BF06EF1E9C132500595E3E /* autoplay-muted-with-controls.html in Copy Resources */,
F4DEF6ED1E9B4DB60048EF61 /* image-in-link-and-input.html in Copy Resources */,
@@ -1142,6 +1145,8 @@
57901FAC1CAF12C200ED64F9 /* LoadInvalidURLRequest.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = LoadInvalidURLRequest.mm; sourceTree = "<group>"; };
57901FAE1CAF137100ED64F9 /* LoadInvalidURLRequest.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = LoadInvalidURLRequest.mm; sourceTree = "<group>"; };
57901FB01CAF141C00ED64F9 /* LoadInvalidURLRequest.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = LoadInvalidURLRequest.html; sourceTree = "<group>"; };
+ 5797FE2F1EB15A5F00B2F4A0 /* NavigationClientDefaultCrypto.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NavigationClientDefaultCrypto.cpp; sourceTree = "<group>"; };
+ 5797FE321EB15A8900B2F4A0 /* navigation-client-default-crypto.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "navigation-client-default-crypto.html"; sourceTree = "<group>"; };
5798E2AF1CAF5C2800C5CBA0 /* ProvisionalURLNotChange.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ProvisionalURLNotChange.mm; sourceTree = "<group>"; };
57F10D921C7E7B3800ECDF30 /* IsNavigationActionTrusted.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = IsNavigationActionTrusted.mm; sourceTree = "<group>"; };
57F56A5B1C7F8A4000F31D7E /* IsNavigationActionTrusted.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = IsNavigationActionTrusted.html; sourceTree = "<group>"; };
@@ -2084,6 +2089,7 @@
51CB4AD71B3A079C00C1B1C6 /* ModalAlertsSPI.cpp */,
33BE5AF4137B5A6C00705813 /* MouseMoveAfterCrash.cpp */,
33BE5AF8137B5AAE00705813 /* MouseMoveAfterCrash_Bundle.cpp */,
+ 5797FE2F1EB15A5F00B2F4A0 /* NavigationClientDefaultCrypto.cpp */,
93F1DB3014DA20760024C362 /* NewFirstVisuallyNonEmptyLayout.cpp */,
93F1DB3314DA20870024C362 /* NewFirstVisuallyNonEmptyLayout_Bundle.cpp */,
93F1DB5414DB1B730024C362 /* NewFirstVisuallyNonEmptyLayoutFails.cpp */,
@@ -2256,6 +2262,7 @@
93AF4ECF1506F123007FD57E /* lots-of-images.html */,
2DD7D3AE178227AC0026E1E3 /* lots-of-text-vertical-lr.html */,
930AD401150698B30067970F /* lots-of-text.html */,
+ 5797FE321EB15A8900B2F4A0 /* navigation-client-default-crypto.html */,
AD57AC1D1DA7463800FF1BDE /* many-iframes.html */,
51CD1C711B38D48400142CA5 /* modal-alerts-in-new-about-blank-window.html */,
7A1458FB1AD5C03500E06772 /* mouse-button-listener.html */,
@@ -3086,6 +3093,7 @@
9BD4239A1E04BD9800200395 /* AttributedSubstringForProposedRangeWithImage.mm in Sources */,
2E7765CD16C4D80A00BA2BB1 /* mainIOS.mm in Sources */,
2E7765CF16C4D81100BA2BB1 /* mainMac.mm in Sources */,
+ 5797FE311EB15A6800B2F4A0 /* NavigationClientDefaultCrypto.cpp in Sources */,
7AD3FE8E1D76131200B169A4 /* TransformationMatrix.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2/NavigationClientDefaultCrypto.cpp (0 => 216157)
--- trunk/Tools/TestWebKitAPI/Tests/WebKit2/NavigationClientDefaultCrypto.cpp (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2/NavigationClientDefaultCrypto.cpp 2017-05-03 23:50:38 UTC (rev 216157)
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import <WebKit/WKFoundation.h>
+
+#if WK_HAVE_C_SPI
+
+#import "PlatformUtilities.h"
+#import "PlatformWebView.h"
+#import "Test.h"
+#import <wtf/RetainPtr.h>
+
+namespace TestWebKitAPI {
+
+static bool receivedAlert;
+static RetainPtr<WKStringRef> lastAlert;
+
+static void runJavaScriptAlert(WKPageRef page, WKStringRef alertText, WKFrameRef frame, WKSecurityOriginRef, const void* clientInfo)
+{
+ lastAlert = alertText;
+ receivedAlert = true;
+}
+
+static void decidePolicyForNavigationAction(WKPageRef, WKNavigationActionRef, WKFramePolicyListenerRef listener, WKTypeRef, const void*)
+{
+ WKFramePolicyListenerUse(listener);
+}
+
+static void decidePolicyForNavigationResponse(WKPageRef, WKNavigationResponseRef, WKFramePolicyListenerRef listener, WKTypeRef, const void*)
+{
+ WKFramePolicyListenerUse(listener);
+}
+
+TEST(WebKit2, NavigationClientDefaultCrypto)
+{
+ auto context = adoptWK(WKContextCreate());
+ PlatformWebView webView(context.get());
+
+ // The navigationClient quite explicitly does *not* have a copyWebCryptoMasterKey callback,
+ // which allows this test to make sure that WebKit2 instead creates a default crypto master key.
+ WKPageNavigationClientV0 navigationClient;
+ memset(&navigationClient, 0, sizeof(navigationClient));
+ navigationClient.base.version = 0;
+ navigationClient.decidePolicyForNavigationAction = decidePolicyForNavigationAction;
+ navigationClient.decidePolicyForNavigationResponse = decidePolicyForNavigationResponse;
+
+ WKPageSetPageNavigationClient(webView.page(), &navigationClient.base);
+
+ WKPageUIClientV5 uiClient;
+ memset(&uiClient, 0, sizeof(uiClient));
+ uiClient.base.version = 5;
+ uiClient.runJavaScriptAlert = runJavaScriptAlert;
+
+ WKPageSetPageUIClient(webView.page(), &uiClient.base);
+
+ WKRetainPtr<WKURLRef> url = "" "html"));
+ WKPageLoadURL(webView.page(), url.get());
+
+ Util::run(&receivedAlert);
+ EXPECT_TRUE(WKStringIsEqualToUTF8CString(lastAlert.get(), "successfully stored key"));
+
+ receivedAlert = false;
+ Util::run(&receivedAlert);
+ EXPECT_TRUE(WKStringIsEqualToUTF8CString(lastAlert.get(), "retrieved valid key"));
+}
+
+} // namespace TestWebKitAPI
+
+#endif // WK_HAVE_C_SPI
Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2/navigation-client-default-crypto.html (0 => 216157)
--- trunk/Tools/TestWebKitAPI/Tests/WebKit2/navigation-client-default-crypto.html (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2/navigation-client-default-crypto.html 2017-05-03 23:50:38 UTC (rev 216157)
@@ -0,0 +1,97 @@
+<script>
+
+var privateKeyJSON = {
+ kty: "RSA",
+ alg: "RS256",
+ n: "rcCUCv7Oc1HVam1DIhCzqknThWawOp8QLk8Ziy2p10ByjQFCajoFiyuAWl-R1WXZaf4xitLRracT9agpzIzc-MbLSHIGgWQGO21lGiImy5ftZ-D8bHAqRz2y15pzD4c4CEou7XSSLDoRnR0QG5MsDhD6s2gV9mwHkrtkCxtMWdBi-77as8wGmlNRldcOSgZDLK8UnCSgA1OguZ989bFyc8tOOEIb0xUSfPSz3LPSCnyYz68aDjmKVeNH-ig857O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kkI_QlJnFSFr-YjGRdfNHqWBkxlSMZL770R9mIATndGkH7z5x-r9KwBZFC4FCG2hg_zE",
+ qi: "YCX_pLwbMBA1ThVH0WcwmnytqNcrMCEwTm7ByA2eU6nWbQrULvf7m9_kzfLUcjsnpAVlBQG5JMXMy0Sq4ptwbywsa5-G8KAOOOR2L3v4hC-Eys9ftgFM_3i0o40eeQH4b3haPbntrIeMg8IzlOuVYKf9-2QuKDoWeRdd7NsdxTk"
+};
+
+function asciiToUint8Array(str)
+{
+ var chars = [];
+ for (var i = 0; i < str.length; ++i)
+ chars.push(str.charCodeAt(i));
+ return new Uint8Array(chars);
+}
+
+function bytesToHexString(bytes)
+{
+ if (!bytes)
+ return null;
+
+ bytes = new Uint8Array(bytes);
+ var hexBytes = [];
+
+ for (var i = 0; i < bytes.length; ++i) {
+ var byteString = bytes[i].toString(16);
+ if (byteString.length < 2)
+ byteString = "0" + byteString;
+ hexBytes.push(byteString);
+ }
+
+ return hexBytes.join("");
+}
+
+crypto.subtle.importKey("jwk", privateKeyJSON, { name: 'RSASSA-PKCS1-v1_5', hash: "sha-256" }, true, ["sign"]).then(function(key) {
+ var openRequest = indexedDB.open("crypto_subtle");
+ openRequest._onupgradeneeded_ = function(event) {
+ var objectStore = event.target.result.createObjectStore("rsa-indexeddb");
+ }
+ openRequest._onerror_ = function(event) {
+ alert("Could not open database: " + event.target.error.name);
+ }
+ openRequest._onsuccess_ = function(event) {
+ db = event.target.result;
+ storeKey();
+ }
+
+ function storeKey() {
+ var objectStore = db.transaction("rsa-indexeddb", "readwrite").objectStore("rsa-indexeddb");
+ var req = objectStore.put(key, "mykey");
+ req._onerror_ = function(event) {
+ alert('failed to store key');
+ }
+ req._onsuccess_ = function(event) {
+ alert('successfully stored key');
+ readKey();
+ }
+ }
+
+ function readKey() {
+ var objectStore = db.transaction("rsa-indexeddb").objectStore("rsa-indexeddb");
+ var req = objectStore.get("mykey");
+ req._onerror_ = function(event) {
+ alert('failed to read key');
+ }
+ req._onsuccess_ = function(event) {
+ window.retrievedKey = event.target.result;
+ if (retrievedKey.type != 'private')
+ return alert("retrievedKey.type != 'private': " + retrievedKey.type);
+ if (retrievedKey.extractable != true)
+ return alert("retrievedKey.extractable != true: " + retrievedKey.extractable);
+ if (retrievedKey.algorithm.name != 'RSASSA-PKCS1-v1_5')
+ return alert("retrievedKey.algorithm.name != 'RSASSA-PKCS1-v1_5': " + retrievedKey.algorithm.name);
+ if (retrievedKey.algorithm.modulusLength != 2048)
+ return alert("retrievedKey.algorithm.modulusLength != 2048: " + retrievedKey.algorithm.modulusLength);
+ if (bytesToHexString(retrievedKey.algorithm.publicExponent) != '010001')
+ return alert("bytesToHexString(retrievedKey.algorithm.publicExponent) != '010001': " + bytesToHexString(retrievedKey.algorithm.publicExponent));
+ if (retrievedKey.algorithm.hash.name != 'SHA-256')
+ return alert("retrievedKey.algorithm.hash.name != 'SHA-256': " + retrievedKey.algorithm.hash.name);
+ if (retrievedKey.usages.length != 1)
+ return alert("retrievedKey.usages.length != 1: " + retrievedKey.usages.length);
+ if (retrievedKey.usages[0] != 'sign')
+ return alert("retrievedKey.usages[0] != 'sign': " + retrievedKey.usages[0]);
+
+ alert('retrieved valid key');
+ }
+ }
+});
+
+</script>