REGRESSION (Safari 10 combined with WK changes): Unable to store WebCrypto keys in...
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 30 Sep 2016 22:38:58 +0000 (22:38 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 30 Sep 2016 22:38:58 +0000 (22:38 +0000)
<rdar://problem/28334440> and https://bugs.webkit.org/show_bug.cgi?id=162554

Reviewed by Alexey Proskuryakov.

Safari 10 has a WKPageNavigation client but does not implement the "copyWebCryptoMasterKey" callback.

WebKit just fails in this case, instead of falling back to "getDefaultWebCryptoMasterKey".
It should fall back.

Additionally there's a WKContextClient callback to get the crypto key, also, but it is completely unused.
So it should be pulled.

* UIProcess/API/APILoaderClient.h:
(API::LoaderClient::webCryptoMasterKey): Deleted.
* UIProcess/API/C/WKContext.h:

* UIProcess/API/C/WKPage.cpp:
(WKPageSetPageLoaderClient):
(WKPageSetPageNavigationClient): If the client doesn't implement this method, fallback to getDefaultWebCryptoMasterKey.

* UIProcess/Cocoa/NavigationState.mm:
(WebKit::NavigationState::NavigationClient::webCryptoMasterKey): If the client doesn't implement this method,
  fallback to getDefaultWebCryptoMasterKey.

* UIProcess/WebContextClient.cpp:
(WebKit::WebContextClient::copyWebCryptoMasterKey): Deleted.
* UIProcess/WebContextClient.h:

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::wrapCryptoKey): Only ask the NavigationClient before falling back. Don't ask the loader client.
(WebKit::WebPageProxy::unwrapCryptoKey): Ditto.

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

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/APILoaderClient.h
Source/WebKit2/UIProcess/API/C/WKContext.h
Source/WebKit2/UIProcess/API/C/WKPage.cpp
Source/WebKit2/UIProcess/Cocoa/NavigationState.mm
Source/WebKit2/UIProcess/WebContextClient.cpp
Source/WebKit2/UIProcess/WebContextClient.h
Source/WebKit2/UIProcess/WebPageProxy.cpp

index 771aa72..cbbc3eb 100644 (file)
@@ -1,3 +1,38 @@
+2016-09-30  Brady Eidson  <beidson@apple.com>
+
+        REGRESSION (Safari 10 combined with WK changes): Unable to store WebCrypto keys in IndexedDB database.
+        <rdar://problem/28334440> and https://bugs.webkit.org/show_bug.cgi?id=162554
+
+        Reviewed by Alexey Proskuryakov.
+
+        Safari 10 has a WKPageNavigation client but does not implement the "copyWebCryptoMasterKey" callback.
+
+        WebKit just fails in this case, instead of falling back to "getDefaultWebCryptoMasterKey".
+        It should fall back.
+
+        Additionally there's a WKContextClient callback to get the crypto key, also, but it is completely unused.
+        So it should be pulled.
+
+        * UIProcess/API/APILoaderClient.h:
+        (API::LoaderClient::webCryptoMasterKey): Deleted.
+        * UIProcess/API/C/WKContext.h:
+
+        * UIProcess/API/C/WKPage.cpp:
+        (WKPageSetPageLoaderClient):
+        (WKPageSetPageNavigationClient): If the client doesn't implement this method, fallback to getDefaultWebCryptoMasterKey.
+
+        * UIProcess/Cocoa/NavigationState.mm:
+        (WebKit::NavigationState::NavigationClient::webCryptoMasterKey): If the client doesn't implement this method,
+          fallback to getDefaultWebCryptoMasterKey.
+
+        * UIProcess/WebContextClient.cpp:
+        (WebKit::WebContextClient::copyWebCryptoMasterKey): Deleted.
+        * UIProcess/WebContextClient.h:
+
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::wrapCryptoKey): Only ask the NavigationClient before falling back. Don't ask the loader client.
+        (WebKit::WebPageProxy::unwrapCryptoKey): Ditto.
+
 2016-09-30  Said Abou-Hallawa  <sabouhallawa@apple.com>
 
         The dragged image should be the current frame only of the animated image
index c1e8271..f9b6e46 100644 (file)
@@ -93,8 +93,6 @@ public:
     virtual bool shouldKeepCurrentBackForwardListItemInList(WebKit::WebPageProxy&, WebKit::WebBackForwardListItem*) { return true; }
     virtual void willGoToBackForwardListItem(WebKit::WebPageProxy&, WebKit::WebBackForwardListItem*, API::Object*) { }
 
-    virtual RefPtr<Data> webCryptoMasterKey(WebKit::WebPageProxy&) { return nullptr; }
-
     virtual void didNavigateWithNavigationData(WebKit::WebPageProxy&, const WebKit::WebNavigationDataStore&, WebKit::WebFrameProxy&) { }
     virtual void didPerformClientRedirect(WebKit::WebPageProxy&, const WTF::String&, const WTF::String&, WebKit::WebFrameProxy&) { }
     virtual void didPerformServerRedirect(WebKit::WebPageProxy&, const WTF::String&, const WTF::String&, WebKit::WebFrameProxy&) { }
index 4c4f458..107b9f3 100644 (file)
@@ -75,7 +75,7 @@ typedef struct WKContextClientV1 {
     WKContextPlugInInformationBecameAvailableCallback                   plugInInformationBecameAvailable;
 
     // Version 1.
-    WKContextCopyWebCryptoMasterKeyCallback                             copyWebCryptoMasterKey;
+    void                                                                (*copyWebCryptoMasterKey_unavailable)(void);
 } WKContextClientV1;
 
 typedef struct WKContextClientV2 {
@@ -87,7 +87,7 @@ typedef struct WKContextClientV2 {
     WKContextPlugInInformationBecameAvailableCallback                   plugInInformationBecameAvailable;
 
     // Version 1.
-    WKContextCopyWebCryptoMasterKeyCallback                             copyWebCryptoMasterKey;
+    void                                                                (*copyWebCryptoMasterKey_unavailable)(void);
 
     // Version 2.
     WKContextDatabaseProcessDidCrashCallback                            databaseProcessDidCrash;
index 60d05f2..152c308 100644 (file)
@@ -72,6 +72,7 @@
 #include "WebProtectionSpace.h"
 #include <WebCore/Page.h>
 #include <WebCore/SecurityOriginData.h>
+#include <WebCore/SerializedCryptoKeyWrap.h>
 #include <WebCore/WindowFeatures.h>
 
 #ifdef __BLOCKS__
@@ -1215,11 +1216,6 @@ void WKPageSetPageLoaderClient(WKPageRef pageRef, const WKPageLoaderClientBase*
                 m_client.willGoToBackForwardListItem(toAPI(&page), toAPI(item), toAPI(userData), m_client.base.clientInfo);
         }
 
-        RefPtr<API::Data> webCryptoMasterKey(WebPageProxy& page) override
-        {
-            return page.process().processPool().client().copyWebCryptoMasterKey(&page.process().processPool());
-        }
-
         void navigationGestureDidBegin(WebPageProxy& page) override
         {
             if (m_client.navigationGestureDidBegin)
@@ -2327,9 +2323,14 @@ void WKPageSetPageNavigationClient(WKPageRef pageRef, const WKPageNavigationClie
 
         RefPtr<API::Data> webCryptoMasterKey(WebPageProxy& page) override
         {
-            if (!m_client.copyWebCryptoMasterKey)
+            if (m_client.copyWebCryptoMasterKey)
+                return adoptRef(toImpl(m_client.copyWebCryptoMasterKey(toAPI(&page), m_client.base.clientInfo)));
+
+            Vector<uint8_t> masterKey;
+            if (!getDefaultWebCryptoMasterKey(masterKey))
                 return nullptr;
-            return adoptRef(toImpl(m_client.copyWebCryptoMasterKey(toAPI(&page), m_client.base.clientInfo)));
+
+            return API::Data::create(masterKey.data(), masterKey.size());
         }
 
         void didBeginNavigationGesture(WebPageProxy& page) override
index 180777f..4529922 100644 (file)
@@ -64,6 +64,7 @@
 #import "_WKSameDocumentNavigationTypeInternal.h"
 #import <WebCore/Credential.h>
 #import <WebCore/SecurityOriginData.h>
+#import <WebCore/SerializedCryptoKeyWrap.h>
 #import <WebCore/URL.h>
 #import <wtf/NeverDestroyed.h>
 
@@ -719,8 +720,13 @@ void NavigationState::NavigationClient::processDidBecomeUnresponsive(WebKit::Web
 
 RefPtr<API::Data> NavigationState::NavigationClient::webCryptoMasterKey(WebKit::WebPageProxy&)
 {
-    if (!m_navigationState.m_navigationDelegateMethods.webCryptoMasterKeyForWebView)
-        return nullptr;
+    if (!m_navigationState.m_navigationDelegateMethods.webCryptoMasterKeyForWebView) {
+        Vector<uint8_t> masterKey;
+        if (!getDefaultWebCryptoMasterKey(masterKey))
+            return nullptr;
+
+        return API::Data::create(masterKey.data(), masterKey.size());
+    }
 
     auto navigationDelegate = m_navigationState.m_navigationDelegate.get();
     if (!navigationDelegate)
index 72a1abf..64dbdef 100644 (file)
@@ -26,7 +26,6 @@
 #include "config.h"
 #include "WebContextClient.h"
 
-#include "APIArray.h"
 #include "WebProcessPool.h"
 
 namespace WebKit {
@@ -55,12 +54,4 @@ void WebContextClient::databaseProcessDidCrash(WebProcessPool* processPool)
     m_client.databaseProcessDidCrash(toAPI(processPool), m_client.base.clientInfo);
 }
 
-PassRefPtr<API::Data> WebContextClient::copyWebCryptoMasterKey(WebProcessPool* processPool)
-{
-    if (!m_client.copyWebCryptoMasterKey)
-        return nullptr;
-
-    return adoptRef(toImpl(m_client.copyWebCryptoMasterKey(toAPI(processPool), m_client.base.clientInfo)));
-}
-
 } // namespace WebKit
index 7f7521e..b25c4d3 100644 (file)
@@ -31,8 +31,6 @@
 #include "WKContext.h"
 
 namespace API {
-class Array;
-
 template<> struct ClientTraits<WKContextClientBase> {
     typedef std::tuple<WKContextClientV0, WKContextClientV1, WKContextClientV2> Versions;
 };
@@ -48,7 +46,6 @@ public:
     void plugInAutoStartOriginHashesChanged(WebProcessPool*);
     void networkProcessDidCrash(WebProcessPool*);
     void databaseProcessDidCrash(WebProcessPool*);
-    PassRefPtr<API::Data> copyWebCryptoMasterKey(WebProcessPool*);
 };
 
 } // namespace WebKit
index 02ffd18..3ff5b7c 100644 (file)
@@ -6145,9 +6145,7 @@ void WebPageProxy::wrapCryptoKey(const Vector<uint8_t>& key, bool& succeeded, Ve
     if (m_navigationClient) {
         if (RefPtr<API::Data> keyData = m_navigationClient->webCryptoMasterKey(*this))
             masterKey = keyData->dataReference().vector();
-    } else if (RefPtr<API::Data> keyData = m_loaderClient->webCryptoMasterKey(*this))
-        masterKey = keyData->dataReference().vector();
-    else if (!getDefaultWebCryptoMasterKey(masterKey)) {
+    } else if (!getDefaultWebCryptoMasterKey(masterKey)) {
         succeeded = false;
         return;
     }
@@ -6164,9 +6162,7 @@ void WebPageProxy::unwrapCryptoKey(const Vector<uint8_t>& wrappedKey, bool& succ
     if (m_navigationClient) {
         if (RefPtr<API::Data> keyData = m_navigationClient->webCryptoMasterKey(*this))
             masterKey = keyData->dataReference().vector();
-    } else if (RefPtr<API::Data> keyData = m_loaderClient->webCryptoMasterKey(*this))
-        masterKey = keyData->dataReference().vector();
-    else if (!getDefaultWebCryptoMasterKey(masterKey)) {
+    } else if (!getDefaultWebCryptoMasterKey(masterKey)) {
         succeeded = false;
         return;
     }