Title: [249096] trunk
Revision
249096
Author
[email protected]
Date
2019-08-26 08:00:05 -0700 (Mon, 26 Aug 2019)

Log Message

Add a WebsiteDataStore delegate to handle AuthenticationChallenge that do not come from pages
https://bugs.webkit.org/show_bug.cgi?id=196870
LayoutTests/imported/w3c:

<rdar://problem/54593556>

Reviewed by Alex Christensen.

* web-platform-tests/service-workers/service-worker/websocket-in-service-worker.https-expected.txt:

Source/WebKit:

Reviewed by Alex Christensen.

Make NetworkProcess provide the session ID for any authentication challenge.
In case there is no associated page for the authentication challenge or this is related to a service worker,
ask the website data store to take a decision.
Add website data store delegate to allow applications to make the decision.
Restrict using the delegate to server trust evaluation only.

Make ping loads reuse the same mechanism.

Covered by service worker tests and updated beacon test.

* NetworkProcess/NetworkCORSPreflightChecker.cpp:
(WebKit::NetworkCORSPreflightChecker::didReceiveChallenge):
* NetworkProcess/NetworkDataTask.cpp:
(WebKit::NetworkDataTask::sessionID const):
* NetworkProcess/NetworkDataTask.h:
* NetworkProcess/NetworkLoad.cpp:
(WebKit::NetworkLoad::didReceiveChallenge):
* NetworkProcess/NetworkLoadChecker.h:
(WebKit::NetworkLoadChecker::networkProcess):
* NetworkProcess/PingLoad.cpp:
(WebKit::PingLoad::didReceiveChallenge):
* Shared/Authentication/AuthenticationManager.cpp:
(WebKit::AuthenticationManager::didReceiveAuthenticationChallenge):
* Shared/Authentication/AuthenticationManager.h:
* Shared/Authentication/cocoa/AuthenticationChallengeDispositionCocoa.h: Copied from Tools/WebKitTestRunner/cocoa/TestWebsiteDataStoreDelegate.h.
* Shared/Authentication/cocoa/AuthenticationChallengeDispositionCocoa.mm: Copied from Source/WebKit/Shared/Authentication/cocoa/ClientCertificateAuthenticationXPCConstants.h.
(WebKit::toAuthenticationChallengeDisposition):
* SourcesCocoa.txt:
* UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
(WebsiteDataStoreClient::WebsiteDataStoreClient):
* UIProcess/API/Cocoa/_WKWebsiteDataStoreDelegate.h:
* UIProcess/Cocoa/NavigationState.mm:
(WebKit::NavigationState::NavigationClient::didReceiveAuthenticationChallenge):
* UIProcess/Network/NetworkProcessProxy.cpp:
(WebKit::NetworkProcessProxy::didReceiveAuthenticationChallenge):
* UIProcess/Network/NetworkProcessProxy.h:
* UIProcess/Network/NetworkProcessProxy.messages.in:
* UIProcess/ServiceWorkerProcessProxy.cpp:
* UIProcess/ServiceWorkerProcessProxy.h:
* UIProcess/WebPageProxy.cpp:
* UIProcess/WebProcessPool.cpp:
(WebKit::WebProcessPool::isServiceWorkerPageID const):
* UIProcess/WebProcessPool.h:
* UIProcess/WebsiteData/WebsiteDataStoreClient.h:
(WebKit::WebsiteDataStoreClient::didReceiveAuthenticationChallenge):
* WebKit.xcodeproj/project.pbxproj:

Tools:

Reviewed by Alex Christensen.

Implement the new delegate by respecting the value set by testRunner.setAllowsAnySSLCertificate
Accept any server certificate by default.

* WebKitTestRunner/TestController.cpp:
* WebKitTestRunner/cocoa/TestControllerCocoa.mm:
(WTR::TestController::cocoaResetStateToConsistentValues):
(WTR::TestController::setAllowsAnySSLCertificate):
* WebKitTestRunner/cocoa/TestWebsiteDataStoreDelegate.h:
* WebKitTestRunner/cocoa/TestWebsiteDataStoreDelegate.mm:
(-[TestWebsiteDataStoreDelegate didReceiveAuthenticationChallenge:completionHandler:]):
(-[TestWebsiteDataStoreDelegate setAllowAnySSLCertificate:]):

LayoutTests:

Reviewed by Alex Christensen.

Add tests to validate that the delegate decision is respected for beacons and service worker loads.

* http/wpt/beacon/cors/crossorigin-arraybufferview-no-preflight-expected.txt:
* http/wpt/beacon/cors/crossorigin-arraybufferview-no-preflight.html:
* http/wpt/beacon/resources/beacon-preflight.py:
(main):
* http/wpt/service-workers/resources/lengthy-pass.py:
(main):
* http/wpt/service-workers/server-trust-evaluation.https-expected.txt: Added.
* http/wpt/service-workers/server-trust-evaluation.https.html: Added.
* http/wpt/service-workers/server-trust-worker.js: Added.
* http/tests/ssl/certificate-validation.html: Remove unneeded setting call
since we deny server trust requests if SSL certificates are not all allowed.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (249095 => 249096)


--- trunk/LayoutTests/ChangeLog	2019-08-26 14:36:47 UTC (rev 249095)
+++ trunk/LayoutTests/ChangeLog	2019-08-26 15:00:05 UTC (rev 249096)
@@ -1,3 +1,24 @@
+2019-08-26  Youenn Fablet  <[email protected]>
+
+        Add a WebsiteDataStore delegate to handle AuthenticationChallenge that do not come from pages
+        https://bugs.webkit.org/show_bug.cgi?id=196870
+
+        Reviewed by Alex Christensen.
+
+        Add tests to validate that the delegate decision is respected for beacons and service worker loads.
+
+        * http/wpt/beacon/cors/crossorigin-arraybufferview-no-preflight-expected.txt:
+        * http/wpt/beacon/cors/crossorigin-arraybufferview-no-preflight.html:
+        * http/wpt/beacon/resources/beacon-preflight.py:
+        (main):
+        * http/wpt/service-workers/resources/lengthy-pass.py:
+        (main):
+        * http/wpt/service-workers/server-trust-evaluation.https-expected.txt: Added.
+        * http/wpt/service-workers/server-trust-evaluation.https.html: Added.
+        * http/wpt/service-workers/server-trust-worker.js: Added.
+        * http/tests/ssl/certificate-validation.html: Remove unneeded setting call
+        since we deny server trust requests if SSL certificates are not all allowed.
+
 2019-08-24  Simon Fraser  <[email protected]>
 
         Page crashes under CGPathAddUnevenCornersRoundedRect

Modified: trunk/LayoutTests/http/tests/ssl/certificate-validation.html (249095 => 249096)


--- trunk/LayoutTests/http/tests/ssl/certificate-validation.html	2019-08-26 14:36:47 UTC (rev 249095)
+++ trunk/LayoutTests/http/tests/ssl/certificate-validation.html	2019-08-26 15:00:05 UTC (rev 249096)
@@ -24,7 +24,6 @@
     if (!window.testRunner.canDoServerTrustEvaluationInNetworkProcess)
         return;
 
-    window.testRunner.setAllowsAnySSLCertificate(false);
     // This should trigger network process server trust evaluation.
     window.testRunner.setCanHandleHTTPSServerTrustEvaluation(false);
 

Modified: trunk/LayoutTests/http/wpt/beacon/cors/crossorigin-arraybufferview-no-preflight-expected.txt (249095 => 249096)


--- trunk/LayoutTests/http/wpt/beacon/cors/crossorigin-arraybufferview-no-preflight-expected.txt	2019-08-26 14:36:47 UTC (rev 249095)
+++ trunk/LayoutTests/http/wpt/beacon/cors/crossorigin-arraybufferview-no-preflight-expected.txt	2019-08-26 15:00:05 UTC (rev 249096)
@@ -1,3 +1,4 @@
 
+PASS Beacon load should not be sent if server is not trusted. 
 PASS Should send beacon with no CORS preflight 
 

Modified: trunk/LayoutTests/http/wpt/beacon/cors/crossorigin-arraybufferview-no-preflight.html (249095 => 249096)


--- trunk/LayoutTests/http/wpt/beacon/cors/crossorigin-arraybufferview-no-preflight.html	2019-08-26 14:36:47 UTC (rev 249095)
+++ trunk/LayoutTests/http/wpt/beacon/cors/crossorigin-arraybufferview-no-preflight.html	2019-08-26 15:00:05 UTC (rev 249096)
@@ -26,12 +26,33 @@
   });
 }
 
-function testCORSPreflightSuccess(what) {
-  var testBase = get_host_info().HTTP_REMOTE_ORIGIN + RESOURCES_DIR;
-  var id = self.token();
-  var testUrl = testBase + "beacon-preflight.py?allowCors=1&cmd=put&id=" + id;
+function testCORSPreflight(what) {
+  var testBase = get_host_info().HTTPS_REMOTE_ORIGIN + RESOURCES_DIR;
 
-  promise_test(function(test) {
+  promise_test(async function(test) {
+    var id = "ca33c073-1cf0-41e5-bbd4-55969fb1a6c7";
+    var testUrl = testBase + "beacon-preflight.py?allowCors=1&cmd=put&id=" + id;
+    if (window.testRunner) {
+      window.testRunner.setAllowsAnySSLCertificate(false);
+      window.testRunner.terminateNetworkProcess();
+      await fetch("").then(() => { }, () => { });
+    }
+
+    assert_true(navigator.sendBeacon(testUrl, what), "sendBeacon succeeded");
+    const result = await pollResult(test, id);
+    assert_equals(result['preflight'], 0, "Did not receive CORS preflight")
+    assert_equals(result['beacon'], 0, "Did not receive beacon")
+  }, "Beacon load should not be sent if server is not trusted.");
+
+  promise_test(async function(test) {
+    var id = self.token();
+    var testUrl = testBase + "beacon-preflight.py?allowCors=1&cmd=put&id=" + id;
+    if (window.testRunner) {
+      window.testRunner.setAllowsAnySSLCertificate(true);
+      window.testRunner.terminateNetworkProcess();
+      await fetch("").then(() => { }, () => { });
+    }
+
     assert_true(navigator.sendBeacon(testUrl, what), "SendBeacon Succeeded");
     return pollResult(test, id) .then(result => {
       assert_equals(result['preflight'], 0, "Did not receive CORS preflight")
@@ -51,7 +72,7 @@
   return view;
 }
 
-testCORSPreflightSuccess(stringToArrayBufferView("123"));
+testCORSPreflight(stringToArrayBufferView("123"));
     </script>
   </body>
 </html>

Modified: trunk/LayoutTests/http/wpt/beacon/resources/beacon-preflight.py (249095 => 249096)


--- trunk/LayoutTests/http/wpt/beacon/resources/beacon-preflight.py	2019-08-26 14:36:47 UTC (rev 249095)
+++ trunk/LayoutTests/http/wpt/beacon/resources/beacon-preflight.py	2019-08-26 15:00:05 UTC (rev 249096)
@@ -44,11 +44,9 @@
       stashed_data['beacon_origin'] = request.headers.get("Origin", "")
       request.server.stash.put(test_id, stashed_data)
     return [("Content-Type", "text/plain")], ""
-  
+
   if command == "get":
-    if stashed_data is not None:
-      return [("Content-Type", "text/plain")], json.dumps(stashed_data)
-    return [("Content-Type", "text/plain")], ""
+    return [("Content-Type", "text/plain")], json.dumps(stashed_data)
 
   response.set_error(400, "Bad Command")
   return [("Content-Type", "text/plain")], "ERROR: Bad Command!"

Modified: trunk/LayoutTests/http/wpt/service-workers/resources/lengthy-pass.py (249095 => 249096)


--- trunk/LayoutTests/http/wpt/service-workers/resources/lengthy-pass.py	2019-08-26 14:36:47 UTC (rev 249095)
+++ trunk/LayoutTests/http/wpt/service-workers/resources/lengthy-pass.py	2019-08-26 15:00:05 UTC (rev 249096)
@@ -3,6 +3,7 @@
 def main(request, response):
     delay = 0.05
     response.headers.set("Content-type", "text/_javascript_")
+    response.headers.append("Access-Control-Allow-Origin", "*")
     response.write_status_headers()
     time.sleep(delay);
     response.writer.write_content("document")

Added: trunk/LayoutTests/http/wpt/service-workers/server-trust-evaluation.https-expected.txt (0 => 249096)


--- trunk/LayoutTests/http/wpt/service-workers/server-trust-evaluation.https-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/wpt/service-workers/server-trust-evaluation.https-expected.txt	2019-08-26 15:00:05 UTC (rev 249096)
@@ -0,0 +1,5 @@
+
+PASS Setup worker 
+PASS Service worker load should fail 
+PASS Service worker load should succeed 
+

Added: trunk/LayoutTests/http/wpt/service-workers/server-trust-evaluation.https.html (0 => 249096)


--- trunk/LayoutTests/http/wpt/service-workers/server-trust-evaluation.https.html	                        (rev 0)
+++ trunk/LayoutTests/http/wpt/service-workers/server-trust-evaluation.https.html	2019-08-26 15:00:05 UTC (rev 249096)
@@ -0,0 +1,53 @@
+<html>
+<head>
+<title>Service Worker triggering server trust evaluation</title>
+<script src=""
+<script src=""
+<script src=""
+</head>
+<body>
+<script>
+var registration;
+var iframe;
+promise_test(async (test) => {
+    if (window.testRunner) {
+        window.testRunner.terminateNetworkProcess();
+        await fetch("").then(() => { }, () => { });
+    }
+
+    registration = await navigator.serviceWorker.getRegistration("resources/");
+    if (registration)
+        await registration.unregister();
+    registration = await navigator.serviceWorker.register("server-trust-worker.js", { scope : "resources/" });
+    activeWorker = registration.active;
+    if (activeWorker)
+        return;
+    activeWorker = registration.installing;
+    await new Promise(resolve => {
+        activeWorker.addEventListener('statechange', () => {
+            if (activeWorker.state === "activated")
+                resolve();
+        });
+    });
+}, "Setup worker");
+
+promise_test(async (test) => {
+    if (window.testRunner)
+        window.testRunner.setAllowsAnySSLCertificate(false);
+
+    iframe = await with_iframe("resources/iframe1.html");
+    assert_true(iframe.contentWindow.document.body.innerHTML.trim().indexOf("Load failed: ") !== -1);
+    iframe.remove();
+}, "Service worker load should fail");
+
+promise_test(async (test) => {
+    if (window.testRunner)
+        window.testRunner.setAllowsAnySSLCertificate(true);
+
+    iframe = await with_iframe("resources/iframe2.html");
+    assert_true(iframe.contentWindow.document.body.innerHTML.trim().indexOf("PASS") !== -1);
+    iframe.remove();
+}, "Service worker load should succeed");
+</script>
+</body>
+</html>

Added: trunk/LayoutTests/http/wpt/service-workers/server-trust-worker.js (0 => 249096)


--- trunk/LayoutTests/http/wpt/service-workers/server-trust-worker.js	                        (rev 0)
+++ trunk/LayoutTests/http/wpt/service-workers/server-trust-worker.js	2019-08-26 15:00:05 UTC (rev 249096)
@@ -0,0 +1,5 @@
+var remoteUrl = 'https://127.0.0.1:9443/WebKit/service-workers/resources/lengthy-pass.py?';
+var counter = 0;
+self.addEventListener('fetch', (event) => {
+    event.respondWith(fetch(remoteUrl + counter++).then(response => new Response("PASS")).catch(e => new Response("Load failed: " + e)));
+});

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (249095 => 249096)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2019-08-26 14:36:47 UTC (rev 249095)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2019-08-26 15:00:05 UTC (rev 249096)
@@ -1,3 +1,13 @@
+2019-08-26  Youenn Fablet  <[email protected]>
+
+        Add a WebsiteDataStore delegate to handle AuthenticationChallenge that do not come from pages
+        https://bugs.webkit.org/show_bug.cgi?id=196870
+        <rdar://problem/54593556>
+
+        Reviewed by Alex Christensen.
+
+        * web-platform-tests/service-workers/service-worker/websocket-in-service-worker.https-expected.txt:
+
 2019-08-22  Ryosuke Niwa  <[email protected]>
 
         Implement StaticRange constructor

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/websocket-in-service-worker.https-expected.txt (249095 => 249096)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/websocket-in-service-worker.https-expected.txt	2019-08-26 14:36:47 UTC (rev 249095)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/websocket-in-service-worker.https-expected.txt	2019-08-26 15:00:05 UTC (rev 249096)
@@ -1,3 +1,3 @@
 
-FAIL Verify WebSockets can be created in a Service Worker assert_equals: expected "PASS" but got "FAIL: Got an error event"
+PASS Verify WebSockets can be created in a Service Worker 
 

Modified: trunk/Source/WebKit/ChangeLog (249095 => 249096)


--- trunk/Source/WebKit/ChangeLog	2019-08-26 14:36:47 UTC (rev 249095)
+++ trunk/Source/WebKit/ChangeLog	2019-08-26 15:00:05 UTC (rev 249096)
@@ -1,3 +1,57 @@
+2019-08-26  Youenn Fablet  <[email protected]>
+
+        Add a WebsiteDataStore delegate to handle AuthenticationChallenge that do not come from pages
+        https://bugs.webkit.org/show_bug.cgi?id=196870
+
+        Reviewed by Alex Christensen.
+
+        Make NetworkProcess provide the session ID for any authentication challenge.
+        In case there is no associated page for the authentication challenge or this is related to a service worker,
+        ask the website data store to take a decision.
+        Add website data store delegate to allow applications to make the decision.
+        Restrict using the delegate to server trust evaluation only.
+
+        Make ping loads reuse the same mechanism.
+
+        Covered by service worker tests and updated beacon test.
+
+        * NetworkProcess/NetworkCORSPreflightChecker.cpp:
+        (WebKit::NetworkCORSPreflightChecker::didReceiveChallenge):
+        * NetworkProcess/NetworkDataTask.cpp:
+        (WebKit::NetworkDataTask::sessionID const):
+        * NetworkProcess/NetworkDataTask.h:
+        * NetworkProcess/NetworkLoad.cpp:
+        (WebKit::NetworkLoad::didReceiveChallenge):
+        * NetworkProcess/NetworkLoadChecker.h:
+        (WebKit::NetworkLoadChecker::networkProcess):
+        * NetworkProcess/PingLoad.cpp:
+        (WebKit::PingLoad::didReceiveChallenge):
+        * Shared/Authentication/AuthenticationManager.cpp:
+        (WebKit::AuthenticationManager::didReceiveAuthenticationChallenge):
+        * Shared/Authentication/AuthenticationManager.h:
+        * Shared/Authentication/cocoa/AuthenticationChallengeDispositionCocoa.h: Copied from Tools/WebKitTestRunner/cocoa/TestWebsiteDataStoreDelegate.h.
+        * Shared/Authentication/cocoa/AuthenticationChallengeDispositionCocoa.mm: Copied from Source/WebKit/Shared/Authentication/cocoa/ClientCertificateAuthenticationXPCConstants.h.
+        (WebKit::toAuthenticationChallengeDisposition):
+        * SourcesCocoa.txt:
+        * UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
+        (WebsiteDataStoreClient::WebsiteDataStoreClient):
+        * UIProcess/API/Cocoa/_WKWebsiteDataStoreDelegate.h:
+        * UIProcess/Cocoa/NavigationState.mm:
+        (WebKit::NavigationState::NavigationClient::didReceiveAuthenticationChallenge):
+        * UIProcess/Network/NetworkProcessProxy.cpp:
+        (WebKit::NetworkProcessProxy::didReceiveAuthenticationChallenge):
+        * UIProcess/Network/NetworkProcessProxy.h:
+        * UIProcess/Network/NetworkProcessProxy.messages.in:
+        * UIProcess/ServiceWorkerProcessProxy.cpp:
+        * UIProcess/ServiceWorkerProcessProxy.h:
+        * UIProcess/WebPageProxy.cpp:
+        * UIProcess/WebProcessPool.cpp:
+        (WebKit::WebProcessPool::isServiceWorkerPageID const):
+        * UIProcess/WebProcessPool.h:
+        * UIProcess/WebsiteData/WebsiteDataStoreClient.h:
+        (WebKit::WebsiteDataStoreClient::didReceiveAuthenticationChallenge):
+        * WebKit.xcodeproj/project.pbxproj:
+
 2019-08-25  Simon Fraser  <[email protected]>
 
         [iOS WK2] Make a strongly-typed TransactionID to replace uint64_t transactionIDs

Modified: trunk/Source/WebKit/NetworkProcess/NetworkCORSPreflightChecker.cpp (249095 => 249096)


--- trunk/Source/WebKit/NetworkProcess/NetworkCORSPreflightChecker.cpp	2019-08-26 14:36:47 UTC (rev 249095)
+++ trunk/Source/WebKit/NetworkProcess/NetworkCORSPreflightChecker.cpp	2019-08-26 15:00:05 UTC (rev 249096)
@@ -101,7 +101,7 @@
         return;
     }
 
-    m_networkProcess->authenticationManager().didReceiveAuthenticationChallenge(m_parameters.pageID, m_parameters.frameID, challenge, WTFMove(completionHandler));
+    m_networkProcess->authenticationManager().didReceiveAuthenticationChallenge(m_parameters.sessionID, m_parameters.pageID, m_parameters.frameID, challenge, WTFMove(completionHandler));
 }
 
 void NetworkCORSPreflightChecker::didReceiveResponse(WebCore::ResourceResponse&& response, ResponseCompletionHandler&& completionHandler)

Modified: trunk/Source/WebKit/NetworkProcess/NetworkDataTask.cpp (249095 => 249096)


--- trunk/Source/WebKit/NetworkProcess/NetworkDataTask.cpp	2019-08-26 14:36:47 UTC (rev 249095)
+++ trunk/Source/WebKit/NetworkProcess/NetworkDataTask.cpp	2019-08-26 15:00:05 UTC (rev 249096)
@@ -150,4 +150,9 @@
     return emptyString();
 }
 
+PAL::SessionID NetworkDataTask::sessionID() const
+{
+    return m_session->sessionID();
+}
+
 } // namespace WebKit

Modified: trunk/Source/WebKit/NetworkProcess/NetworkDataTask.h (249095 => 249096)


--- trunk/Source/WebKit/NetworkProcess/NetworkDataTask.h	2019-08-26 14:36:47 UTC (rev 249095)
+++ trunk/Source/WebKit/NetworkProcess/NetworkDataTask.h	2019-08-26 15:00:05 UTC (rev 249096)
@@ -34,6 +34,7 @@
 #include <WebCore/ResourceRequest.h>
 #include <WebCore/StoredCredentialsPolicy.h>
 #include <WebCore/Timer.h>
+#include <pal/SessionID.h>
 #include <wtf/CompletionHandler.h>
 #include <wtf/ThreadSafeRefCounted.h>
 #include <wtf/text/WTFString.h>
@@ -130,6 +131,8 @@
 
     virtual String description() const;
 
+    PAL::SessionID sessionID() const;
+
 protected:
     NetworkDataTask(NetworkSession&, NetworkDataTaskClient&, const WebCore::ResourceRequest&, WebCore::StoredCredentialsPolicy, bool shouldClearReferrerOnHTTPSToHTTPRedirect, bool dataTaskIsForMainFrameNavigation);
 

Modified: trunk/Source/WebKit/NetworkProcess/NetworkLoad.cpp (249095 => 249096)


--- trunk/Source/WebKit/NetworkProcess/NetworkLoad.cpp	2019-08-26 14:36:47 UTC (rev 249095)
+++ trunk/Source/WebKit/NetworkProcess/NetworkLoad.cpp	2019-08-26 15:00:05 UTC (rev 249096)
@@ -201,7 +201,7 @@
     if (auto* pendingDownload = m_task->pendingDownload())
         m_networkProcess->authenticationManager().didReceiveAuthenticationChallenge(*pendingDownload, challenge, WTFMove(completionHandler));
     else
-        m_networkProcess->authenticationManager().didReceiveAuthenticationChallenge(m_parameters.webPageID, m_parameters.webFrameID, challenge, WTFMove(completionHandler));
+        m_networkProcess->authenticationManager().didReceiveAuthenticationChallenge(m_task->sessionID(), m_parameters.webPageID, m_parameters.webFrameID, challenge, WTFMove(completionHandler));
 }
 
 void NetworkLoad::didReceiveResponse(ResourceResponse&& response, ResponseCompletionHandler&& completionHandler)

Modified: trunk/Source/WebKit/NetworkProcess/NetworkLoadChecker.h (249095 => 249096)


--- trunk/Source/WebKit/NetworkProcess/NetworkLoadChecker.h	2019-08-26 14:36:47 UTC (rev 249095)
+++ trunk/Source/WebKit/NetworkProcess/NetworkLoadChecker.h	2019-08-26 15:00:05 UTC (rev 249096)
@@ -84,6 +84,8 @@
     }
 #endif
 
+    NetworkProcess& networkProcess() { return m_networkProcess; }
+
     const URL& url() const { return m_url; }
     WebCore::StoredCredentialsPolicy storedCredentialsPolicy() const { return m_storedCredentialsPolicy; }
 

Modified: trunk/Source/WebKit/NetworkProcess/PingLoad.cpp (249095 => 249096)


--- trunk/Source/WebKit/NetworkProcess/PingLoad.cpp	2019-08-26 14:36:47 UTC (rev 249095)
+++ trunk/Source/WebKit/NetworkProcess/PingLoad.cpp	2019-08-26 15:00:05 UTC (rev 249096)
@@ -148,7 +148,7 @@
 {
     RELEASE_LOG_IF_ALLOWED("didReceiveChallenge");
     if (challenge.protectionSpace().authenticationScheme() == ProtectionSpaceAuthenticationSchemeServerTrustEvaluationRequested) {
-        completionHandler(AuthenticationChallengeDisposition::PerformDefaultHandling, { });
+        m_networkLoadChecker->networkProcess().authenticationManager().didReceiveAuthenticationChallenge(m_parameters.sessionID, m_parameters.webPageID, m_parameters.webFrameID, challenge, WTFMove(completionHandler));
         return;
     }
     auto weakThis = makeWeakPtr(*this);

Modified: trunk/Source/WebKit/Shared/Authentication/AuthenticationManager.cpp (249095 => 249096)


--- trunk/Source/WebKit/Shared/Authentication/AuthenticationManager.cpp	2019-08-26 14:36:47 UTC (rev 249095)
+++ trunk/Source/WebKit/Shared/Authentication/AuthenticationManager.cpp	2019-08-26 15:00:05 UTC (rev 249096)
@@ -108,7 +108,7 @@
     return challengesToCoalesce;
 }
 
-void AuthenticationManager::didReceiveAuthenticationChallenge(PageIdentifier pageID, FrameIdentifier frameID, const AuthenticationChallenge& authenticationChallenge, ChallengeCompletionHandler&& completionHandler)
+void AuthenticationManager::didReceiveAuthenticationChallenge(PAL::SessionID sessionID, PageIdentifier pageID, FrameIdentifier frameID, const AuthenticationChallenge& authenticationChallenge, ChallengeCompletionHandler&& completionHandler)
 {
     ASSERT(pageID);
     ASSERT(frameID);
@@ -119,7 +119,7 @@
     if (shouldCoalesceChallenge(pageID, challengeID, authenticationChallenge))
         return;
     
-    m_process.send(Messages::NetworkProcessProxy::DidReceiveAuthenticationChallenge(pageID, frameID, authenticationChallenge, challengeID));
+    m_process.send(Messages::NetworkProcessProxy::DidReceiveAuthenticationChallenge(sessionID, pageID, frameID, authenticationChallenge, challengeID));
 }
 
 void AuthenticationManager::didReceiveAuthenticationChallenge(IPC::MessageSender& download, const WebCore::AuthenticationChallenge& authenticationChallenge, ChallengeCompletionHandler&& completionHandler)

Modified: trunk/Source/WebKit/Shared/Authentication/AuthenticationManager.h (249095 => 249096)


--- trunk/Source/WebKit/Shared/Authentication/AuthenticationManager.h	2019-08-26 14:36:47 UTC (rev 249095)
+++ trunk/Source/WebKit/Shared/Authentication/AuthenticationManager.h	2019-08-26 15:00:05 UTC (rev 249096)
@@ -63,7 +63,7 @@
 
     static const char* supplementName();
 
-    void didReceiveAuthenticationChallenge(WebCore::PageIdentifier, WebCore::FrameIdentifier, const WebCore::AuthenticationChallenge&, ChallengeCompletionHandler&&);
+    void didReceiveAuthenticationChallenge(PAL::SessionID, WebCore::PageIdentifier, WebCore::FrameIdentifier, const WebCore::AuthenticationChallenge&, ChallengeCompletionHandler&&);
     void didReceiveAuthenticationChallenge(IPC::MessageSender& download, const WebCore::AuthenticationChallenge&, ChallengeCompletionHandler&&);
 
     void completeAuthenticationChallenge(uint64_t challengeID, AuthenticationChallengeDisposition, WebCore::Credential&&);

Copied: trunk/Source/WebKit/Shared/Authentication/cocoa/AuthenticationChallengeDispositionCocoa.h (from rev 249095, trunk/Tools/WebKitTestRunner/cocoa/TestWebsiteDataStoreDelegate.h) (0 => 249096)


--- trunk/Source/WebKit/Shared/Authentication/cocoa/AuthenticationChallengeDispositionCocoa.h	                        (rev 0)
+++ trunk/Source/WebKit/Shared/Authentication/cocoa/AuthenticationChallengeDispositionCocoa.h	2019-08-26 15:00:05 UTC (rev 249096)
@@ -0,0 +1,35 @@
+  /*
+ * Copyright (C) 2019 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.
+ */
+
+#pragma once
+
+#import "AuthenticationChallengeDisposition.h"
+#import <Foundation/NSURLSession.h>
+
+namespace WebKit {
+
+AuthenticationChallengeDisposition toAuthenticationChallengeDisposition(NSURLSessionAuthChallengeDisposition);
+
+} // namespace WebKit

Copied: trunk/Source/WebKit/Shared/Authentication/cocoa/AuthenticationChallengeDispositionCocoa.mm (from rev 249095, trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStoreClient.h) (0 => 249096)


--- trunk/Source/WebKit/Shared/Authentication/cocoa/AuthenticationChallengeDispositionCocoa.mm	                        (rev 0)
+++ trunk/Source/WebKit/Shared/Authentication/cocoa/AuthenticationChallengeDispositionCocoa.mm	2019-08-26 15:00:05 UTC (rev 249096)
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2018-2019 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.
+ */
+
+#include "config.h"
+#include "AuthenticationChallengeDispositionCocoa.h"
+
+namespace WebKit {
+
+AuthenticationChallengeDisposition toAuthenticationChallengeDisposition(NSURLSessionAuthChallengeDisposition disposition)
+{
+    switch (disposition) {
+    case NSURLSessionAuthChallengeUseCredential:
+        return AuthenticationChallengeDisposition::UseCredential;
+    case NSURLSessionAuthChallengePerformDefaultHandling:
+        return AuthenticationChallengeDisposition::PerformDefaultHandling;
+    case NSURLSessionAuthChallengeCancelAuthenticationChallenge:
+        return AuthenticationChallengeDisposition::Cancel;
+    case NSURLSessionAuthChallengeRejectProtectionSpace:
+        return AuthenticationChallengeDisposition::RejectProtectionSpaceAndContinue;
+    }
+    [NSException raise:NSInvalidArgumentException format:@"Invalid NSURLSessionAuthChallengeDisposition (%ld)", (long)disposition];
+}
+
+} // namespace WebKit

Modified: trunk/Source/WebKit/SourcesCocoa.txt (249095 => 249096)


--- trunk/Source/WebKit/SourcesCocoa.txt	2019-08-26 14:36:47 UTC (rev 249095)
+++ trunk/Source/WebKit/SourcesCocoa.txt	2019-08-26 15:00:05 UTC (rev 249096)
@@ -133,6 +133,7 @@
 
 Shared/cg/ShareableBitmapCG.cpp
 
+Shared/Authentication/cocoa/AuthenticationChallengeDispositionCocoa.mm
 Shared/Authentication/cocoa/AuthenticationManagerCocoa.mm
 Shared/Authentication/cocoa/ClientCertificateAuthenticationXPCConstants.cpp
 

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm (249095 => 249096)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm	2019-08-26 14:36:47 UTC (rev 249095)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm	2019-08-26 15:00:05 UTC (rev 249096)
@@ -27,9 +27,11 @@
 #import "WKWebsiteDataStoreInternal.h"
 
 #import "APIString.h"
+#import "AuthenticationChallengeDispositionCocoa.h"
 #import "CompletionHandlerCallChecker.h"
 #import "WKHTTPCookieStoreInternal.h"
 #import "WKNSArray.h"
+#import "WKNSURLAuthenticationChallenge.h"
 #import "WKWebViewInternal.h"
 #import "WKWebsiteDataRecordInternal.h"
 #import "WebPageProxy.h"
@@ -38,6 +40,7 @@
 #import "WebsiteDataFetchOption.h"
 #import "_WKWebsiteDataStoreConfiguration.h"
 #import "_WKWebsiteDataStoreDelegate.h"
+#import <WebCore/Credential.h>
 #import <WebKit/ServiceWorkerProcessProxy.h>
 #import <wtf/BlockPtr.h>
 #import <wtf/URL.h>
@@ -48,6 +51,7 @@
     explicit WebsiteDataStoreClient(id <_WKWebsiteDataStoreDelegate> delegate)
         : m_delegate(delegate)
         , m_hasRequestStorageSpaceSelector([m_delegate.get() respondsToSelector:@selector(requestStorageSpace: frameOrigin: quota: currentSize: spaceRequired: decisionHandler:)])
+        , m_hasAuthenticationChallengeSelector([m_delegate.get() respondsToSelector:@selector(didReceiveAuthenticationChallenge: completionHandler:)])
     {
     }
 
@@ -73,8 +77,28 @@
         [m_delegate.getAutoreleased() requestStorageSpace:mainFrameURL frameOrigin:frameURL quota:quota currentSize:currentSize spaceRequired:spaceRequired decisionHandler:decisionHandler.get()];
     }
 
+    void didReceiveAuthenticationChallenge(Ref<WebKit::AuthenticationChallengeProxy>&& challenge) final
+    {
+        if (!m_hasAuthenticationChallengeSelector || !m_delegate) {
+            challenge->listener().completeChallenge(WebKit::AuthenticationChallengeDisposition::PerformDefaultHandling);
+            return;
+        }
+
+        auto nsURLChallenge = wrapper(challenge);
+        auto checker = WebKit::CompletionHandlerCallChecker::create(m_delegate.getAutoreleased(), @selector(didReceiveAuthenticationChallenge: completionHandler:));
+        auto completionHandler = makeBlockPtr([challenge = WTFMove(challenge), checker = WTFMove(checker)](NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential) mutable {
+            if (checker->completionHandlerHasBeenCalled())
+                return;
+            checker->didCallCompletionHandler();
+            challenge->listener().completeChallenge(WebKit::toAuthenticationChallengeDisposition(disposition), WebCore::Credential(credential));
+        });
+
+        [m_delegate.getAutoreleased() didReceiveAuthenticationChallenge:nsURLChallenge completionHandler:completionHandler.get()];
+    }
+
     WeakObjCPtr<id <_WKWebsiteDataStoreDelegate> > m_delegate;
     bool m_hasRequestStorageSpaceSelector { false };
+    bool m_hasAuthenticationChallengeSelector { false };
 };
 
 @implementation WKWebsiteDataStore

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebsiteDataStoreDelegate.h (249095 => 249096)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebsiteDataStoreDelegate.h	2019-08-26 14:36:47 UTC (rev 249095)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebsiteDataStoreDelegate.h	2019-08-26 15:00:05 UTC (rev 249096)
@@ -34,4 +34,6 @@
 
 - (void)requestStorageSpace:(NSURL *)mainFrameURL frameOrigin:(NSURL *)frameURL quota:(NSUInteger)quota currentSize:(NSUInteger)currentSize spaceRequired:(NSUInteger)spaceRequired decisionHandler:(void (^)(unsigned long long quota))decisionHandler;
 
+- (void)didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential))completionHandler;
+
 @end

Modified: trunk/Source/WebKit/UIProcess/Cocoa/NavigationState.mm (249095 => 249096)


--- trunk/Source/WebKit/UIProcess/Cocoa/NavigationState.mm	2019-08-26 14:36:47 UTC (rev 249095)
+++ trunk/Source/WebKit/UIProcess/Cocoa/NavigationState.mm	2019-08-26 15:00:05 UTC (rev 249096)
@@ -35,6 +35,7 @@
 #import "APIURL.h"
 #import "APIWebsiteDataStore.h"
 #import "AuthenticationChallengeDisposition.h"
+#import "AuthenticationChallengeDispositionCocoa.h"
 #import "AuthenticationDecisionListener.h"
 #import "CompletionHandlerCallChecker.h"
 #import "Logging.h"
@@ -959,21 +960,6 @@
         || m_navigationState.m_navigationDelegateMethods.webViewDecidePolicyForNavigationActionWithPreferencesUserInfoDecisionHandler;
 }
 
-static AuthenticationChallengeDisposition toAuthenticationChallengeDisposition(NSURLSessionAuthChallengeDisposition disposition)
-{
-    switch (disposition) {
-    case NSURLSessionAuthChallengeUseCredential:
-        return AuthenticationChallengeDisposition::UseCredential;
-    case NSURLSessionAuthChallengePerformDefaultHandling:
-        return AuthenticationChallengeDisposition::PerformDefaultHandling;
-    case NSURLSessionAuthChallengeCancelAuthenticationChallenge:
-        return AuthenticationChallengeDisposition::Cancel;
-    case NSURLSessionAuthChallengeRejectProtectionSpace:
-        return AuthenticationChallengeDisposition::RejectProtectionSpaceAndContinue;
-    }
-    [NSException raise:NSInvalidArgumentException format:@"Invalid NSURLSessionAuthChallengeDisposition (%ld)", (long)disposition];
-}
-    
 void NavigationState::NavigationClient::didReceiveAuthenticationChallenge(WebPageProxy&, AuthenticationChallengeProxy& authenticationChallenge)
 {
     if (!m_navigationState.m_navigationDelegateMethods.webViewDidReceiveAuthenticationChallengeCompletionHandler)
@@ -988,7 +974,7 @@
         if (checker->completionHandlerHasBeenCalled())
             return;
         checker->didCallCompletionHandler();
-        challenge->listener().completeChallenge(toAuthenticationChallengeDisposition(disposition), Credential(credential));
+        challenge->listener().completeChallenge(WebKit::toAuthenticationChallengeDisposition(disposition), Credential(credential));
     }).get()];
 }
 

Modified: trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp (249095 => 249096)


--- trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp	2019-08-26 14:36:47 UTC (rev 249095)
+++ trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp	2019-08-26 15:00:05 UTC (rev 249096)
@@ -37,6 +37,9 @@
 #include "NetworkProcessCreationParameters.h"
 #include "NetworkProcessMessages.h"
 #include "SandboxExtension.h"
+#if HAVE(SEC_KEY_PROXY)
+#include "SecKeyProxyStore.h"
+#endif
 #include "ShouldGrandfatherStatistics.h"
 #include "StorageAccessStatus.h"
 #include "WebCompiledContentRuleList.h"
@@ -312,20 +315,36 @@
 #endif
 }
 
-void NetworkProcessProxy::didReceiveAuthenticationChallenge(PageIdentifier pageID, FrameIdentifier frameID, WebCore::AuthenticationChallenge&& coreChallenge, uint64_t challengeID)
+void NetworkProcessProxy::didReceiveAuthenticationChallenge(PAL::SessionID sessionID, PageIdentifier pageID, FrameIdentifier frameID, WebCore::AuthenticationChallenge&& coreChallenge, uint64_t challengeID)
 {
-#if ENABLE(SERVICE_WORKER)
-    if (auto* serviceWorkerProcessProxy = m_processPool.serviceWorkerProcessProxyFromPageID(pageID)) {
-        auto authenticationChallenge = AuthenticationChallengeProxy::create(WTFMove(coreChallenge), challengeID, makeRef(*connection()), nullptr);
-        serviceWorkerProcessProxy->didReceiveAuthenticationChallenge(pageID, frameID, WTFMove(authenticationChallenge));
-        return;
+#if HAVE(SEC_KEY_PROXY)
+    WeakPtr<SecKeyProxyStore> secKeyProxyStore;
+    if (coreChallenge.protectionSpace().authenticationScheme() == ProtectionSpaceAuthenticationSchemeClientCertificateRequested) {
+        if (auto* store = websiteDataStoreFromSessionID(sessionID)) {
+            auto newSecKeyProxyStore = SecKeyProxyStore::create();
+            secKeyProxyStore = makeWeakPtr(newSecKeyProxyStore.get());
+            store->addSecKeyProxyStore(WTFMove(newSecKeyProxyStore));
+        }
     }
+    auto authenticationChallenge = AuthenticationChallengeProxy::create(WTFMove(coreChallenge), challengeID, makeRef(*connection()), WTFMove(secKeyProxyStore));
+#else
+    auto authenticationChallenge = AuthenticationChallengeProxy::create(WTFMove(coreChallenge), challengeID, makeRef(*connection()), nullptr);
 #endif
 
-    WebPageProxy* page = WebProcessProxy::webPage(pageID);
-    MESSAGE_CHECK(page);
+    WebPageProxy* page = nullptr;
+    if (pageID && !m_processPool.isServiceWorkerPageID(pageID))
+        page = WebProcessProxy::webPage(pageID);
 
-    auto authenticationChallenge = AuthenticationChallengeProxy::create(WTFMove(coreChallenge), challengeID, makeRef(*connection()), page->secKeyProxyStore(coreChallenge));
+    if (!page) {
+        auto* store = websiteDataStoreFromSessionID(sessionID);
+        if (!store || coreChallenge.protectionSpace().authenticationScheme() != ProtectionSpaceAuthenticationSchemeServerTrustEvaluationRequested) {
+            authenticationChallenge->listener().completeChallenge(AuthenticationChallengeDisposition::PerformDefaultHandling);
+            return;
+        }
+        store->client().didReceiveAuthenticationChallenge(WTFMove(authenticationChallenge));
+        return;
+    }
+
     page->didReceiveAuthenticationChallengeProxy(frameID, WTFMove(authenticationChallenge));
 }
 

Modified: trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h (249095 => 249096)


--- trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h	2019-08-26 14:36:47 UTC (rev 249095)
+++ trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h	2019-08-26 15:00:05 UTC (rev 249096)
@@ -213,7 +213,7 @@
     // Message handlers
     void didReceiveNetworkProcessProxyMessage(IPC::Connection&, IPC::Decoder&);
     void didCreateNetworkConnectionToWebProcess(const IPC::Attachment&);
-    void didReceiveAuthenticationChallenge(WebCore::PageIdentifier, WebCore::FrameIdentifier, WebCore::AuthenticationChallenge&&, uint64_t challengeID);
+    void didReceiveAuthenticationChallenge(PAL::SessionID, WebCore::PageIdentifier, WebCore::FrameIdentifier, WebCore::AuthenticationChallenge&&, uint64_t challengeID);
     void didFetchWebsiteData(uint64_t callbackID, const WebsiteData&);
     void didDeleteWebsiteData(uint64_t callbackID);
     void didDeleteWebsiteDataForOrigins(uint64_t callbackID);

Modified: trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.messages.in (249095 => 249096)


--- trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.messages.in	2019-08-26 14:36:47 UTC (rev 249095)
+++ trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.messages.in	2019-08-26 15:00:05 UTC (rev 249096)
@@ -23,7 +23,7 @@
 messages -> NetworkProcessProxy LegacyReceiver {
     DidCreateNetworkConnectionToWebProcess(IPC::Attachment connectionIdentifier)
 
-    DidReceiveAuthenticationChallenge(WebCore::PageIdentifier pageID, WebCore::FrameIdentifier frameID, WebCore::AuthenticationChallenge challenge, uint64_t challengeID)
+    DidReceiveAuthenticationChallenge(PAL::SessionID sessionID, WebCore::PageIdentifier pageID, WebCore::FrameIdentifier frameID, WebCore::AuthenticationChallenge challenge, uint64_t challengeID)
 
     DidFetchWebsiteData(uint64_t callbackID, struct WebKit::WebsiteData websiteData)
     DidDeleteWebsiteData(uint64_t callbackID)

Modified: trunk/Source/WebKit/UIProcess/ServiceWorkerProcessProxy.cpp (249095 => 249096)


--- trunk/Source/WebKit/UIProcess/ServiceWorkerProcessProxy.cpp	2019-08-26 14:36:47 UTC (rev 249095)
+++ trunk/Source/WebKit/UIProcess/ServiceWorkerProcessProxy.cpp	2019-08-26 15:00:05 UTC (rev 249096)
@@ -90,22 +90,6 @@
     send(Messages::WebSWContextManagerConnection::UpdatePreferencesStore { store }, 0);
 }
 
-void ServiceWorkerProcessProxy::didReceiveAuthenticationChallenge(PageIdentifier pageID, FrameIdentifier frameID, Ref<AuthenticationChallengeProxy>&& challenge)
-{
-    UNUSED_PARAM(pageID);
-    UNUSED_PARAM(frameID);
-
-    // FIXME: Expose an API to delegate the actual decision to the application layer.
-    auto& protectionSpace = challenge->core().protectionSpace();
-    if (protectionSpace.authenticationScheme() == WebCore::ProtectionSpaceAuthenticationSchemeServerTrustEvaluationRequested && processPool().allowsAnySSLCertificateForServiceWorker()) {
-        auto credential = WebCore::Credential("accept server trust"_s, emptyString(), WebCore::CredentialPersistenceNone);
-        challenge->listener().completeChallenge(AuthenticationChallengeDisposition::UseCredential, credential);
-        return;
-    }
-    notImplemented();
-    challenge->listener().completeChallenge(AuthenticationChallengeDisposition::PerformDefaultHandling);
-}
-
 } // namespace WebKit
 
 #endif // ENABLE(SERVICE_WORKER)

Modified: trunk/Source/WebKit/UIProcess/ServiceWorkerProcessProxy.h (249095 => 249096)


--- trunk/Source/WebKit/UIProcess/ServiceWorkerProcessProxy.h	2019-08-26 14:36:47 UTC (rev 249095)
+++ trunk/Source/WebKit/UIProcess/ServiceWorkerProcessProxy.h	2019-08-26 15:00:05 UTC (rev 249096)
@@ -41,8 +41,6 @@
 
     static bool hasRegisteredServiceWorkers(const String& serviceWorkerDirectory);
 
-    void didReceiveAuthenticationChallenge(WebCore::PageIdentifier, WebCore::FrameIdentifier, Ref<AuthenticationChallengeProxy>&&);
-
     void start(const WebPreferencesStore&, Optional<PAL::SessionID> initialSessionID);
     void setUserAgent(const String&);
     void updatePreferencesStore(const WebPreferencesStore&);

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (249095 => 249096)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2019-08-26 14:36:47 UTC (rev 249095)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2019-08-26 15:00:05 UTC (rev 249096)
@@ -7333,19 +7333,6 @@
 
 #endif
 
-WeakPtr<SecKeyProxyStore> WebPageProxy::secKeyProxyStore(const WebCore::AuthenticationChallenge& challenge)
-{
-#if HAVE(SEC_KEY_PROXY)
-    if (challenge.protectionSpace().authenticationScheme() == ProtectionSpaceAuthenticationSchemeClientCertificateRequested) {
-        auto secKeyProxyStore = SecKeyProxyStore::create();
-        auto weakPointer = makeWeakPtr(secKeyProxyStore.get());
-        m_websiteDataStore->addSecKeyProxyStore(WTFMove(secKeyProxyStore));
-        return weakPointer;
-    }
-#endif
-    return nullptr;
-}
-    
 void WebPageProxy::didReceiveAuthenticationChallengeProxy(FrameIdentifier, Ref<AuthenticationChallengeProxy>&& authenticationChallenge)
 {
     m_navigationClient->didReceiveAuthenticationChallenge(*this, authenticationChallenge.get());

Modified: trunk/Source/WebKit/UIProcess/WebProcessPool.cpp (249095 => 249096)


--- trunk/Source/WebKit/UIProcess/WebProcessPool.cpp	2019-08-26 14:36:47 UTC (rev 249095)
+++ trunk/Source/WebKit/UIProcess/WebProcessPool.cpp	2019-08-26 15:00:05 UTC (rev 249096)
@@ -2231,17 +2231,17 @@
 #endif
 }
 
+bool WebProcessPool::isServiceWorkerPageID(PageIdentifier pageID) const
+{
 #if ENABLE(SERVICE_WORKER)
-ServiceWorkerProcessProxy* WebProcessPool::serviceWorkerProcessProxyFromPageID(PageIdentifier pageID) const
-{
     // FIXME: This is inefficient.
     for (auto* serviceWorkerProcess : m_serviceWorkerProcesses.values()) {
         if (serviceWorkerProcess->pageID() == pageID)
-            return serviceWorkerProcess;
+            return true;
     }
-    return nullptr;
+#endif
+    return false;
 }
-#endif
 
 void WebProcessPool::addProcessToOriginCacheSet(WebProcessProxy& process, const URL& url)
 {

Modified: trunk/Source/WebKit/UIProcess/WebProcessPool.h (249095 => 249096)


--- trunk/Source/WebKit/UIProcess/WebProcessPool.h	2019-08-26 14:36:47 UTC (rev 249095)
+++ trunk/Source/WebKit/UIProcess/WebProcessPool.h	2019-08-26 15:00:05 UTC (rev 249096)
@@ -379,9 +379,9 @@
 
     void getNetworkProcessConnection(WebProcessProxy&, Messages::WebProcessProxy::GetNetworkProcessConnection::DelayedReply&&);
 
+    bool isServiceWorkerPageID(WebCore::PageIdentifier) const;
 #if ENABLE(SERVICE_WORKER)
     void establishWorkerContextConnectionToNetworkProcess(NetworkProcessProxy&, WebCore::RegistrableDomain&&, Optional<PAL::SessionID>);
-    ServiceWorkerProcessProxy* serviceWorkerProcessProxyFromPageID(WebCore::PageIdentifier) const;
     const HashMap<WebCore::RegistrableDomain, ServiceWorkerProcessProxy*>& serviceWorkerProxies() const { return m_serviceWorkerProcesses; }
     void setAllowsAnySSLCertificateForServiceWorker(bool allows) { m_allowsAnySSLCertificateForServiceWorker = allows; }
     bool allowsAnySSLCertificateForServiceWorker() const { return m_allowsAnySSLCertificateForServiceWorker; }

Modified: trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStoreClient.h (249095 => 249096)


--- trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStoreClient.h	2019-08-26 14:36:47 UTC (rev 249095)
+++ trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStoreClient.h	2019-08-26 15:00:05 UTC (rev 249096)
@@ -25,6 +25,9 @@
 
 #pragma once
 
+#include "AuthenticationChallengeDisposition.h"
+#include "AuthenticationChallengeProxy.h"
+#include "AuthenticationDecisionListener.h"
 #include <wtf/CompletionHandler.h>
 
 namespace WebCore {
@@ -42,6 +45,11 @@
     {
         completionHandler({ });
     }
+
+    virtual void didReceiveAuthenticationChallenge(Ref<AuthenticationChallengeProxy>&& challenge)
+    {
+        challenge->listener().completeChallenge(AuthenticationChallengeDisposition::PerformDefaultHandling);
+    }
 };
 
 } // namespace WebKit

Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (249095 => 249096)


--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2019-08-26 14:36:47 UTC (rev 249095)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2019-08-26 15:00:05 UTC (rev 249096)
@@ -3157,6 +3157,8 @@
 		41897ED51F415D850016FA42 /* CacheStorageEngineConnection.messages.in */ = {isa = PBXFileReference; lastKnownFileType = text; path = CacheStorageEngineConnection.messages.in; sourceTree = "<group>"; };
 		41897ED61F415D860016FA42 /* CacheStorageEngine.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = CacheStorageEngine.cpp; sourceTree = "<group>"; };
 		419ACF9B1F981D26009F1A83 /* WebServiceWorkerFetchTaskClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebServiceWorkerFetchTaskClient.h; sourceTree = "<group>"; };
+		41A5F7B9226ECF7C00671764 /* AuthenticationChallengeDispositionCocoa.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AuthenticationChallengeDispositionCocoa.h; sourceTree = "<group>"; };
+		41A5F7BA226ECF7C00671764 /* AuthenticationChallengeDispositionCocoa.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = AuthenticationChallengeDispositionCocoa.mm; sourceTree = "<group>"; };
 		41AC86811E042E5300303074 /* WebRTCResolver.messages.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; lineEnding = 0; name = WebRTCResolver.messages.in; path = Network/webrtc/WebRTCResolver.messages.in; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = "<none>"; };
 		41B28B081F83AD3E00FB52AC /* RTCPacketOptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RTCPacketOptions.h; sourceTree = "<group>"; };
 		41B28B091F83AD3E00FB52AC /* RTCPacketOptions.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RTCPacketOptions.cpp; sourceTree = "<group>"; };
@@ -7043,6 +7045,8 @@
 		57B4B45C20B5048B00D4AD79 /* cocoa */ = {
 			isa = PBXGroup;
 			children = (
+				41A5F7B9226ECF7C00671764 /* AuthenticationChallengeDispositionCocoa.h */,
+				41A5F7BA226ECF7C00671764 /* AuthenticationChallengeDispositionCocoa.mm */,
 				57B4B45D20B504AB00D4AD79 /* AuthenticationManagerCocoa.mm */,
 				44A481C621F2D27B00F2F919 /* ClientCertificateAuthenticationXPCConstants.cpp */,
 				57B4B45E20B504AB00D4AD79 /* ClientCertificateAuthenticationXPCConstants.h */,

Modified: trunk/Tools/ChangeLog (249095 => 249096)


--- trunk/Tools/ChangeLog	2019-08-26 14:36:47 UTC (rev 249095)
+++ trunk/Tools/ChangeLog	2019-08-26 15:00:05 UTC (rev 249096)
@@ -1,3 +1,22 @@
+2019-08-26  Youenn Fablet  <[email protected]>
+
+        Add a WebsiteDataStore delegate to handle AuthenticationChallenge that do not come from pages
+        https://bugs.webkit.org/show_bug.cgi?id=196870
+
+        Reviewed by Alex Christensen.
+
+        Implement the new delegate by respecting the value set by testRunner.setAllowsAnySSLCertificate
+        Accept any server certificate by default.
+
+        * WebKitTestRunner/TestController.cpp:
+        * WebKitTestRunner/cocoa/TestControllerCocoa.mm:
+        (WTR::TestController::cocoaResetStateToConsistentValues):
+        (WTR::TestController::setAllowsAnySSLCertificate):
+        * WebKitTestRunner/cocoa/TestWebsiteDataStoreDelegate.h:
+        * WebKitTestRunner/cocoa/TestWebsiteDataStoreDelegate.mm:
+        (-[TestWebsiteDataStoreDelegate didReceiveAuthenticationChallenge:completionHandler:]):
+        (-[TestWebsiteDataStoreDelegate setAllowAnySSLCertificate:]):
+
 2019-08-23  Aakash Jain  <[email protected]>
 
         Increase log level for watchlist result

Modified: trunk/Tools/WebKitTestRunner/TestController.cpp (249095 => 249096)


--- trunk/Tools/WebKitTestRunner/TestController.cpp	2019-08-26 14:36:47 UTC (rev 249095)
+++ trunk/Tools/WebKitTestRunner/TestController.cpp	2019-08-26 15:00:05 UTC (rev 249096)
@@ -1032,7 +1032,9 @@
 #if PLATFORM(IOS_FAMILY)
     m_openPanelFileURLsMediaIcon = nullptr;
 #endif
-    
+
+    setAllowsAnySSLCertificate(true);
+
     statisticsResetToConsistentState();
     
     clearAdClickAttribution();
@@ -1181,10 +1183,13 @@
 #endif
 }
 
+#if !PLATFORM(COCOA)
 void TestController::setAllowsAnySSLCertificate(bool allows)
 {
+    m_allowsAnySSLCertificate = allows;
     WKContextSetAllowsAnySSLCertificateForWebSocketTesting(platformContext(), allows);
 }
+#endif
 
 static std::string testPath(WKURLRef url)
 {
@@ -2328,8 +2333,12 @@
 
         m_serverTrustEvaluationCallbackCallsCount++;
 
-        WKRetainPtr<WKCredentialRef> credential = adoptWK(WKCredentialCreate(toWK("accept server trust").get(), toWK("").get(), kWKCredentialPersistenceNone));
-        WKAuthenticationDecisionListenerUseCredential(decisionListener, credential.get());
+        if (m_allowsAnySSLCertificate) {
+            WKRetainPtr<WKCredentialRef> credential = adoptWK(WKCredentialCreate(toWK("accept server trust").get(), toWK("").get(), kWKCredentialPersistenceNone));
+            WKAuthenticationDecisionListenerUseCredential(decisionListener, credential.get());
+            return;
+        }
+        WKAuthenticationDecisionListenerRejectProtectionSpaceAndContinue(decisionListener);
         return;
     }
 

Modified: trunk/Tools/WebKitTestRunner/TestController.h (249095 => 249096)


--- trunk/Tools/WebKitTestRunner/TestController.h	2019-08-26 14:36:47 UTC (rev 249095)
+++ trunk/Tools/WebKitTestRunner/TestController.h	2019-08-26 15:00:05 UTC (rev 249096)
@@ -591,6 +591,7 @@
 
     uint64_t m_serverTrustEvaluationCallbackCallsCount { 0 };
     bool m_shouldDismissJavaScriptAlertsAsynchronously { false };
+    bool m_allowsAnySSLCertificate { true };
 };
 
 struct TestCommand {

Modified: trunk/Tools/WebKitTestRunner/cocoa/TestControllerCocoa.mm (249095 => 249096)


--- trunk/Tools/WebKitTestRunner/cocoa/TestControllerCocoa.mm	2019-08-26 14:36:47 UTC (rev 249095)
+++ trunk/Tools/WebKitTestRunner/cocoa/TestControllerCocoa.mm	2019-08-26 15:00:05 UTC (rev 249096)
@@ -35,6 +35,7 @@
 #import <Foundation/Foundation.h>
 #import <Security/SecItem.h>
 #import <WebKit/WKContextConfigurationRef.h>
+#import <WebKit/WKContextPrivate.h>
 #import <WebKit/WKCookieManager.h>
 #import <WebKit/WKPreferencesRefPrivate.h>
 #import <WebKit/WKProcessPoolPrivate.h>
@@ -397,6 +398,13 @@
     [globalWebsiteDataStoreDelegateClient setAllowRaisingQuota: value];
 }
 
+void TestController::setAllowsAnySSLCertificate(bool allows)
+{
+    m_allowsAnySSLCertificate = allows;
+    WKContextSetAllowsAnySSLCertificateForWebSocketTesting(platformContext(), allows);
+    [globalWebsiteDataStoreDelegateClient setAllowAnySSLCertificate: allows];
+}
+
 bool TestController::canDoServerTrustEvaluationInNetworkProcess() const
 {
 #if HAVE(CFNETWORK_NSURLSESSION_STRICTRUSTEVALUATE)

Modified: trunk/Tools/WebKitTestRunner/cocoa/TestWebsiteDataStoreDelegate.h (249095 => 249096)


--- trunk/Tools/WebKitTestRunner/cocoa/TestWebsiteDataStoreDelegate.h	2019-08-26 14:36:47 UTC (rev 249095)
+++ trunk/Tools/WebKitTestRunner/cocoa/TestWebsiteDataStoreDelegate.h	2019-08-26 15:00:05 UTC (rev 249096)
@@ -30,7 +30,9 @@
 @interface TestWebsiteDataStoreDelegate: NSObject <_WKWebsiteDataStoreDelegate> {
 @private
     BOOL _shouldAllowRaisingQuota;
+    BOOL _shouldAllowAnySSLCertificate;
 }
 - (instancetype)init;
 - (void)setAllowRaisingQuota:(BOOL)shouldAllowRaisingQuota;
+- (void)setAllowAnySSLCertificate:(BOOL)shouldAllowAnySSLCertificate;
 @end

Modified: trunk/Tools/WebKitTestRunner/cocoa/TestWebsiteDataStoreDelegate.mm (249095 => 249096)


--- trunk/Tools/WebKitTestRunner/cocoa/TestWebsiteDataStoreDelegate.mm	2019-08-26 14:36:47 UTC (rev 249095)
+++ trunk/Tools/WebKitTestRunner/cocoa/TestWebsiteDataStoreDelegate.mm	2019-08-26 15:00:05 UTC (rev 249096)
@@ -42,4 +42,23 @@
 {
     _shouldAllowRaisingQuota = shouldAllowRaisingQuota;
 }
+
+- (void)didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential * _Nullable credential))completionHandler
+{
+    NSString *method = challenge.protectionSpace.authenticationMethod;
+    if ([method isEqualToString:NSURLAuthenticationMethodServerTrust]) {
+        if (_shouldAllowAnySSLCertificate)
+            completionHandler(NSURLSessionAuthChallengeUseCredential, [NSURLCredential credentialForTrust: challenge.protectionSpace.serverTrust]);
+        else
+            completionHandler(NSURLSessionAuthChallengeCancelAuthenticationChallenge, nil);
+        return;
+    }
+    completionHandler(NSURLSessionAuthChallengePerformDefaultHandling, nil);
+}
+
+- (void)setAllowAnySSLCertificate:(BOOL)shouldAllowAnySSLCertificate
+{
+    _shouldAllowAnySSLCertificate = shouldAllowAnySSLCertificate;
+}
+
 @end
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to