⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 249001 in webkit


Ignore:
Timestamp:
Aug 22, 2019, 4:05:12 AM (7 years ago)
Author:
youenn@apple.com
Message:

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.

Source/WebKit:

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:

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:

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.
Location:
trunk
Files:
3 added
34 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r248996 r249001  
     12019-08-22  Youenn Fablet  <youenn@apple.com>
     2
     3        Add a WebsiteDataStore delegate to handle AuthenticationChallenge that do not come from pages
     4        https://bugs.webkit.org/show_bug.cgi?id=196870
     5
     6        Reviewed by Alex Christensen.
     7
     8        Add tests to validate that the delegate decision is respected for beacons and service worker loads.
     9
     10        * http/wpt/beacon/cors/crossorigin-arraybufferview-no-preflight-expected.txt:
     11        * http/wpt/beacon/cors/crossorigin-arraybufferview-no-preflight.html:
     12        * http/wpt/beacon/resources/beacon-preflight.py:
     13        (main):
     14        * http/wpt/service-workers/resources/lengthy-pass.py:
     15        (main):
     16        * http/wpt/service-workers/server-trust-evaluation.https-expected.txt: Added.
     17        * http/wpt/service-workers/server-trust-evaluation.https.html: Added.
     18        * http/wpt/service-workers/server-trust-worker.js: Added.
     19
    1202019-08-21  Ryosuke Niwa  <rniwa@webkit.org>
    221
  • trunk/LayoutTests/http/wpt/beacon/cors/crossorigin-arraybufferview-no-preflight-expected.txt

    r220817 r249001  
    11
     2PASS Beacon load should not be sent if server is not trusted.
    23PASS Should send beacon with no CORS preflight
    34
  • trunk/LayoutTests/http/wpt/beacon/cors/crossorigin-arraybufferview-no-preflight.html

    r220817 r249001  
    2727}
    2828
    29 function testCORSPreflightSuccess(what) {
    30   var testBase = get_host_info().HTTP_REMOTE_ORIGIN + RESOURCES_DIR;
    31   var id = self.token();
    32   var testUrl = testBase + "beacon-preflight.py?allowCors=1&cmd=put&id=" + id;
     29function testCORSPreflight(what) {
     30  var testBase = get_host_info().HTTPS_REMOTE_ORIGIN + RESOURCES_DIR;
    3331
    34   promise_test(function(test) {
     32  promise_test(async function(test) {
     33    var id = "ca33c073-1cf0-41e5-bbd4-55969fb1a6c7";
     34    var testUrl = testBase + "beacon-preflight.py?allowCors=1&cmd=put&id=" + id;
     35    if (window.testRunner) {
     36      window.testRunner.setAllowsAnySSLCertificate(false);
     37      window.testRunner.terminateNetworkProcess();
     38      await fetch("").then(() => { }, () => { });
     39    }
     40
     41    assert_true(navigator.sendBeacon(testUrl, what), "sendBeacon succeeded");
     42    const result = await pollResult(test, id);
     43    assert_equals(result['preflight'], 0, "Did not receive CORS preflight")
     44    assert_equals(result['beacon'], 0, "Did not receive beacon")
     45  }, "Beacon load should not be sent if server is not trusted.");
     46
     47  promise_test(async function(test) {
     48    var id = self.token();
     49    var testUrl = testBase + "beacon-preflight.py?allowCors=1&cmd=put&id=" + id;
     50    if (window.testRunner) {
     51      window.testRunner.setAllowsAnySSLCertificate(true);
     52      window.testRunner.terminateNetworkProcess();
     53      await fetch("").then(() => { }, () => { });
     54    }
     55
    3556    assert_true(navigator.sendBeacon(testUrl, what), "SendBeacon Succeeded");
    3657    return pollResult(test, id) .then(result => {
     
    5273}
    5374
    54 testCORSPreflightSuccess(stringToArrayBufferView("123"));
     75testCORSPreflight(stringToArrayBufferView("123"));
    5576    </script>
    5677  </body>
  • trunk/LayoutTests/http/wpt/beacon/resources/beacon-preflight.py

    r244700 r249001  
    4545      request.server.stash.put(test_id, stashed_data)
    4646    return [("Content-Type", "text/plain")], ""
    47  
     47
    4848  if command == "get":
    49     if stashed_data is not None:
    50       return [("Content-Type", "text/plain")], json.dumps(stashed_data)
    51     return [("Content-Type", "text/plain")], ""
     49    return [("Content-Type", "text/plain")], json.dumps(stashed_data)
    5250
    5351  response.set_error(400, "Bad Command")
  • trunk/LayoutTests/http/wpt/service-workers/resources/lengthy-pass.py

    r227581 r249001  
    44    delay = 0.05
    55    response.headers.set("Content-type", "text/javascript")
     6    response.headers.append("Access-Control-Allow-Origin", "*")
    67    response.write_status_headers()
    78    time.sleep(delay);
  • trunk/Source/WebKit/ChangeLog

    r248999 r249001  
     12019-08-22  Youenn Fablet  <youenn@apple.com>
     2
     3        Add a WebsiteDataStore delegate to handle AuthenticationChallenge that do not come from pages
     4        https://bugs.webkit.org/show_bug.cgi?id=196870
     5
     6        Reviewed by Alex Christensen.
     7
     8        Make NetworkProcess provide the session ID for any authentication challenge.
     9        In case there is no associated page for the authentication challenge or this is related to a service worker,
     10        ask the website data store to take a decision.
     11        Add website data store delegate to allow applications to make the decision.
     12        Restrict using the delegate to server trust evaluation only.
     13
     14        Make ping loads reuse the same mechanism.
     15
     16        Covered by service worker tests and updated beacon test.
     17
     18        * NetworkProcess/NetworkCORSPreflightChecker.cpp:
     19        (WebKit::NetworkCORSPreflightChecker::didReceiveChallenge):
     20        * NetworkProcess/NetworkDataTask.cpp:
     21        (WebKit::NetworkDataTask::sessionID const):
     22        * NetworkProcess/NetworkDataTask.h:
     23        * NetworkProcess/NetworkLoad.cpp:
     24        (WebKit::NetworkLoad::didReceiveChallenge):
     25        * NetworkProcess/NetworkLoadChecker.h:
     26        (WebKit::NetworkLoadChecker::networkProcess):
     27        * NetworkProcess/PingLoad.cpp:
     28        (WebKit::PingLoad::didReceiveChallenge):
     29        * Shared/Authentication/AuthenticationManager.cpp:
     30        (WebKit::AuthenticationManager::didReceiveAuthenticationChallenge):
     31        * Shared/Authentication/AuthenticationManager.h:
     32        * Shared/Authentication/cocoa/AuthenticationChallengeDispositionCocoa.h: Copied from Tools/WebKitTestRunner/cocoa/TestWebsiteDataStoreDelegate.h.
     33        * Shared/Authentication/cocoa/AuthenticationChallengeDispositionCocoa.mm: Copied from Source/WebKit/Shared/Authentication/cocoa/ClientCertificateAuthenticationXPCConstants.h.
     34        (WebKit::toAuthenticationChallengeDisposition):
     35        * SourcesCocoa.txt:
     36        * UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
     37        (WebsiteDataStoreClient::WebsiteDataStoreClient):
     38        * UIProcess/API/Cocoa/_WKWebsiteDataStoreDelegate.h:
     39        * UIProcess/Cocoa/NavigationState.mm:
     40        (WebKit::NavigationState::NavigationClient::didReceiveAuthenticationChallenge):
     41        * UIProcess/Network/NetworkProcessProxy.cpp:
     42        (WebKit::NetworkProcessProxy::didReceiveAuthenticationChallenge):
     43        * UIProcess/Network/NetworkProcessProxy.h:
     44        * UIProcess/Network/NetworkProcessProxy.messages.in:
     45        * UIProcess/ServiceWorkerProcessProxy.cpp:
     46        * UIProcess/ServiceWorkerProcessProxy.h:
     47        * UIProcess/WebPageProxy.cpp:
     48        * UIProcess/WebProcessPool.cpp:
     49        (WebKit::WebProcessPool::isServiceWorkerPageID const):
     50        * UIProcess/WebProcessPool.h:
     51        * UIProcess/WebsiteData/WebsiteDataStoreClient.h:
     52        (WebKit::WebsiteDataStoreClient::didReceiveAuthenticationChallenge):
     53        * WebKit.xcodeproj/project.pbxproj:
     54
    1552019-08-22  Claudio Saavedra  <csaavedra@igalia.com>
    256
  • trunk/Source/WebKit/NetworkProcess/NetworkCORSPreflightChecker.cpp

    r248677 r249001  
    102102    }
    103103
    104     m_networkProcess->authenticationManager().didReceiveAuthenticationChallenge(m_parameters.pageID, m_parameters.frameID, challenge, WTFMove(completionHandler));
     104    m_networkProcess->authenticationManager().didReceiveAuthenticationChallenge(m_parameters.sessionID, m_parameters.pageID, m_parameters.frameID, challenge, WTFMove(completionHandler));
    105105}
    106106
  • trunk/Source/WebKit/NetworkProcess/NetworkDataTask.cpp

    r247831 r249001  
    151151}
    152152
     153PAL::SessionID NetworkDataTask::sessionID() const
     154{
     155    return m_session->sessionID();
     156}
     157
    153158} // namespace WebKit
  • trunk/Source/WebKit/NetworkProcess/NetworkDataTask.h

    r248874 r249001  
    3535#include <WebCore/StoredCredentialsPolicy.h>
    3636#include <WebCore/Timer.h>
     37#include <pal/SessionID.h>
    3738#include <wtf/CompletionHandler.h>
    3839#include <wtf/ThreadSafeRefCounted.h>
     
    131132    virtual String description() const;
    132133
     134    PAL::SessionID sessionID() const;
     135
    133136protected:
    134137    NetworkDataTask(NetworkSession&, NetworkDataTaskClient&, const WebCore::ResourceRequest&, WebCore::StoredCredentialsPolicy, bool shouldClearReferrerOnHTTPSToHTTPRedirect, bool dataTaskIsForMainFrameNavigation);
  • trunk/Source/WebKit/NetworkProcess/NetworkLoad.cpp

    r248846 r249001  
    202202        m_networkProcess->authenticationManager().didReceiveAuthenticationChallenge(*pendingDownload, challenge, WTFMove(completionHandler));
    203203    else
    204         m_networkProcess->authenticationManager().didReceiveAuthenticationChallenge(m_parameters.webPageID, m_parameters.webFrameID, challenge, WTFMove(completionHandler));
     204        m_networkProcess->authenticationManager().didReceiveAuthenticationChallenge(m_task->sessionID(), m_parameters.webPageID, m_parameters.webFrameID, challenge, WTFMove(completionHandler));
    205205}
    206206
  • trunk/Source/WebKit/NetworkProcess/NetworkLoadChecker.h

    r248713 r249001  
    8585#endif
    8686
     87    NetworkProcess& networkProcess() { return m_networkProcess; }
     88
    8789    const URL& url() const { return m_url; }
    8890    WebCore::StoredCredentialsPolicy storedCredentialsPolicy() const { return m_storedCredentialsPolicy; }
  • trunk/Source/WebKit/NetworkProcess/PingLoad.cpp

    r245979 r249001  
    149149    RELEASE_LOG_IF_ALLOWED("didReceiveChallenge");
    150150    if (challenge.protectionSpace().authenticationScheme() == ProtectionSpaceAuthenticationSchemeServerTrustEvaluationRequested) {
    151         completionHandler(AuthenticationChallengeDisposition::PerformDefaultHandling, { });
     151        m_networkLoadChecker->networkProcess().authenticationManager().didReceiveAuthenticationChallenge(m_parameters.sessionID, m_parameters.webPageID, m_parameters.webFrameID, challenge, WTFMove(completionHandler));
    152152        return;
    153153    }
  • trunk/Source/WebKit/Shared/Authentication/AuthenticationManager.cpp

    r248713 r249001  
    109109}
    110110
    111 void AuthenticationManager::didReceiveAuthenticationChallenge(PageIdentifier pageID, FrameIdentifier frameID, const AuthenticationChallenge& authenticationChallenge, ChallengeCompletionHandler&& completionHandler)
     111void AuthenticationManager::didReceiveAuthenticationChallenge(PAL::SessionID sessionID, PageIdentifier pageID, FrameIdentifier frameID, const AuthenticationChallenge& authenticationChallenge, ChallengeCompletionHandler&& completionHandler)
    112112{
    113113    ASSERT(pageID);
     
    120120        return;
    121121   
    122     m_process.send(Messages::NetworkProcessProxy::DidReceiveAuthenticationChallenge(pageID, frameID, authenticationChallenge, challengeID));
     122    m_process.send(Messages::NetworkProcessProxy::DidReceiveAuthenticationChallenge(sessionID, pageID, frameID, authenticationChallenge, challengeID));
    123123}
    124124
  • trunk/Source/WebKit/Shared/Authentication/AuthenticationManager.h

    r248762 r249001  
    6464    static const char* supplementName();
    6565
    66     void didReceiveAuthenticationChallenge(WebCore::PageIdentifier, WebCore::FrameIdentifier, const WebCore::AuthenticationChallenge&, ChallengeCompletionHandler&&);
     66    void didReceiveAuthenticationChallenge(PAL::SessionID, WebCore::PageIdentifier, WebCore::FrameIdentifier, const WebCore::AuthenticationChallenge&, ChallengeCompletionHandler&&);
    6767    void didReceiveAuthenticationChallenge(IPC::MessageSender& download, const WebCore::AuthenticationChallenge&, ChallengeCompletionHandler&&);
    6868
  • trunk/Source/WebKit/Shared/Authentication/cocoa/AuthenticationChallengeDispositionCocoa.h

    r249000 r249001  
    1 /*
     1  /*
    22 * Copyright (C) 2019 Apple Inc. All rights reserved.
    33 *
     
    2626#pragma once
    2727
    28 #include <WebKit/_WKWebsiteDataStoreDelegate.h>
     28#import "AuthenticationChallengeDisposition.h"
     29#import <Foundation/NSURLSession.h>
    2930
    30 @interface TestWebsiteDataStoreDelegate: NSObject <_WKWebsiteDataStoreDelegate> {
    31 @private
    32     BOOL _shouldAllowRaisingQuota;
    33 }
    34 - (instancetype)init;
    35 - (void)setAllowRaisingQuota:(BOOL)shouldAllowRaisingQuota;
    36 @end
     31namespace WebKit {
     32
     33AuthenticationChallengeDisposition toAuthenticationChallengeDisposition(NSURLSessionAuthChallengeDisposition);
     34
     35} // namespace WebKit
  • trunk/Source/WebKit/Shared/Authentication/cocoa/AuthenticationChallengeDispositionCocoa.mm

    r249000 r249001  
    11/*
    2  * Copyright (C) 2019 Apple Inc. All rights reserved.
     2 * Copyright (C) 2018-2019 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2424 */
    2525
    26 #pragma once
    27 
    28 #include <wtf/CompletionHandler.h>
    29 
    30 namespace WebCore {
    31 struct SecurityOriginData;
    32 }
     26#include "config.h"
     27#include "AuthenticationChallengeDispositionCocoa.h"
    3328
    3429namespace WebKit {
    3530
    36 class WebsiteDataStoreClient {
    37     WTF_MAKE_FAST_ALLOCATED;
    38 public:
    39     virtual ~WebsiteDataStoreClient() { }
    40 
    41     virtual void requestStorageSpace(const WebCore::SecurityOriginData& topOrigin, const WebCore::SecurityOriginData& frameOrigin, uint64_t quota, uint64_t currentSize, uint64_t spaceRequired, CompletionHandler<void(Optional<uint64_t>)>&& completionHandler)
    42     {
    43         completionHandler({ });
     31AuthenticationChallengeDisposition toAuthenticationChallengeDisposition(NSURLSessionAuthChallengeDisposition disposition)
     32{
     33    switch (disposition) {
     34    case NSURLSessionAuthChallengeUseCredential:
     35        return AuthenticationChallengeDisposition::UseCredential;
     36    case NSURLSessionAuthChallengePerformDefaultHandling:
     37        return AuthenticationChallengeDisposition::PerformDefaultHandling;
     38    case NSURLSessionAuthChallengeCancelAuthenticationChallenge:
     39        return AuthenticationChallengeDisposition::Cancel;
     40    case NSURLSessionAuthChallengeRejectProtectionSpace:
     41        return AuthenticationChallengeDisposition::RejectProtectionSpaceAndContinue;
    4442    }
    45 };
     43    [NSException raise:NSInvalidArgumentException format:@"Invalid NSURLSessionAuthChallengeDisposition (%ld)", (long)disposition];
     44}
    4645
    4746} // namespace WebKit
  • trunk/Source/WebKit/SourcesCocoa.txt

    r248033 r249001  
    134134Shared/cg/ShareableBitmapCG.cpp
    135135
     136Shared/Authentication/cocoa/AuthenticationChallengeDispositionCocoa.mm
    136137Shared/Authentication/cocoa/AuthenticationManagerCocoa.mm
    137138Shared/Authentication/cocoa/ClientCertificateAuthenticationXPCConstants.cpp
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm

    r248144 r249001  
    2828
    2929#import "APIString.h"
     30#import "AuthenticationChallengeDispositionCocoa.h"
    3031#import "CompletionHandlerCallChecker.h"
    3132#import "WKHTTPCookieStoreInternal.h"
    3233#import "WKNSArray.h"
     34#import "WKNSURLAuthenticationChallenge.h"
    3335#import "WKWebViewInternal.h"
    3436#import "WKWebsiteDataRecordInternal.h"
     
    3941#import "_WKWebsiteDataStoreConfiguration.h"
    4042#import "_WKWebsiteDataStoreDelegate.h"
     43#import <WebCore/Credential.h>
    4144#import <WebKit/ServiceWorkerProcessProxy.h>
    4245#import <wtf/BlockPtr.h>
     
    4952        : m_delegate(delegate)
    5053        , m_hasRequestStorageSpaceSelector([m_delegate.get() respondsToSelector:@selector(requestStorageSpace: frameOrigin: quota: currentSize: spaceRequired: decisionHandler:)])
     54        , m_hasAuthenticationChallengeSelector([m_delegate.get() respondsToSelector:@selector(didReceiveAuthenticationChallenge: completionHandler:)])
    5155    {
    5256    }
     
    7478    }
    7579
     80    void didReceiveAuthenticationChallenge(Ref<WebKit::AuthenticationChallengeProxy>&& challenge) final
     81    {
     82        if (!m_hasAuthenticationChallengeSelector || !m_delegate) {
     83            challenge->listener().completeChallenge(WebKit::AuthenticationChallengeDisposition::PerformDefaultHandling);
     84            return;
     85        }
     86
     87        auto nsURLChallenge = wrapper(challenge);
     88        auto checker = WebKit::CompletionHandlerCallChecker::create(m_delegate.getAutoreleased(), @selector(didReceiveAuthenticationChallenge: completionHandler:));
     89        auto completionHandler = makeBlockPtr([challenge = WTFMove(challenge), checker = WTFMove(checker)](NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential) mutable {
     90            if (checker->completionHandlerHasBeenCalled())
     91                return;
     92            checker->didCallCompletionHandler();
     93            challenge->listener().completeChallenge(WebKit::toAuthenticationChallengeDisposition(disposition), WebCore::Credential(credential));
     94        });
     95
     96        [m_delegate.getAutoreleased() didReceiveAuthenticationChallenge:nsURLChallenge completionHandler:completionHandler.get()];
     97    }
     98
    7699    WeakObjCPtr<id <_WKWebsiteDataStoreDelegate> > m_delegate;
    77100    bool m_hasRequestStorageSpaceSelector { false };
     101    bool m_hasAuthenticationChallengeSelector { false };
    78102};
    79103
  • trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebsiteDataStoreDelegate.h

    r243376 r249001  
    3535- (void)requestStorageSpace:(NSURL *)mainFrameURL frameOrigin:(NSURL *)frameURL quota:(NSUInteger)quota currentSize:(NSUInteger)currentSize spaceRequired:(NSUInteger)spaceRequired decisionHandler:(void (^)(unsigned long long quota))decisionHandler;
    3636
     37- (void)didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential))completionHandler;
     38
    3739@end
  • trunk/Source/WebKit/UIProcess/Cocoa/NavigationState.mm

    r247026 r249001  
    3636#import "APIWebsiteDataStore.h"
    3737#import "AuthenticationChallengeDisposition.h"
     38#import "AuthenticationChallengeDispositionCocoa.h"
    3839#import "AuthenticationDecisionListener.h"
    3940#import "CompletionHandlerCallChecker.h"
     
    960961}
    961962
    962 static AuthenticationChallengeDisposition toAuthenticationChallengeDisposition(NSURLSessionAuthChallengeDisposition disposition)
    963 {
    964     switch (disposition) {
    965     case NSURLSessionAuthChallengeUseCredential:
    966         return AuthenticationChallengeDisposition::UseCredential;
    967     case NSURLSessionAuthChallengePerformDefaultHandling:
    968         return AuthenticationChallengeDisposition::PerformDefaultHandling;
    969     case NSURLSessionAuthChallengeCancelAuthenticationChallenge:
    970         return AuthenticationChallengeDisposition::Cancel;
    971     case NSURLSessionAuthChallengeRejectProtectionSpace:
    972         return AuthenticationChallengeDisposition::RejectProtectionSpaceAndContinue;
    973     }
    974     [NSException raise:NSInvalidArgumentException format:@"Invalid NSURLSessionAuthChallengeDisposition (%ld)", (long)disposition];
    975 }
    976    
    977963void NavigationState::NavigationClient::didReceiveAuthenticationChallenge(WebPageProxy&, AuthenticationChallengeProxy& authenticationChallenge)
    978964{
     
    989975            return;
    990976        checker->didCallCompletionHandler();
    991         challenge->listener().completeChallenge(toAuthenticationChallengeDisposition(disposition), Credential(credential));
     977        challenge->listener().completeChallenge(WebKit::toAuthenticationChallengeDisposition(disposition), Credential(credential));
    992978    }).get()];
    993979}
  • trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp

    r248854 r249001  
    3838#include "NetworkProcessMessages.h"
    3939#include "SandboxExtension.h"
     40#if HAVE(SEC_KEY_PROXY)
     41#include "SecKeyProxyStore.h"
     42#endif
    4043#include "ShouldGrandfatherStatistics.h"
    4144#include "StorageAccessStatus.h"
     
    313316}
    314317
    315 void NetworkProcessProxy::didReceiveAuthenticationChallenge(PageIdentifier pageID, FrameIdentifier frameID, WebCore::AuthenticationChallenge&& coreChallenge, uint64_t challengeID)
    316 {
    317 #if ENABLE(SERVICE_WORKER)
    318     if (auto* serviceWorkerProcessProxy = m_processPool.serviceWorkerProcessProxyFromPageID(pageID)) {
    319         auto authenticationChallenge = AuthenticationChallengeProxy::create(WTFMove(coreChallenge), challengeID, makeRef(*connection()), nullptr);
    320         serviceWorkerProcessProxy->didReceiveAuthenticationChallenge(pageID, frameID, WTFMove(authenticationChallenge));
    321         return;
    322     }
    323 #endif
    324 
    325     WebPageProxy* page = WebProcessProxy::webPage(pageID);
    326     MESSAGE_CHECK(page);
    327 
    328     auto authenticationChallenge = AuthenticationChallengeProxy::create(WTFMove(coreChallenge), challengeID, makeRef(*connection()), page->secKeyProxyStore(coreChallenge));
     318void NetworkProcessProxy::didReceiveAuthenticationChallenge(PAL::SessionID sessionID, PageIdentifier pageID, FrameIdentifier frameID, WebCore::AuthenticationChallenge&& coreChallenge, uint64_t challengeID)
     319{
     320#if HAVE(SEC_KEY_PROXY)
     321    WeakPtr<SecKeyProxyStore> secKeyProxyStore;
     322    if (coreChallenge.protectionSpace().authenticationScheme() == ProtectionSpaceAuthenticationSchemeClientCertificateRequested) {
     323        if (auto* store = websiteDataStoreFromSessionID(sessionID)) {
     324            auto newSecKeyProxyStore = SecKeyProxyStore::create();
     325            secKeyProxyStore = makeWeakPtr(newSecKeyProxyStore.get());
     326            store->addSecKeyProxyStore(WTFMove(newSecKeyProxyStore));
     327        }
     328    }
     329    auto authenticationChallenge = AuthenticationChallengeProxy::create(WTFMove(coreChallenge), challengeID, makeRef(*connection()), WTFMove(secKeyProxyStore));
     330#else
     331    auto authenticationChallenge = AuthenticationChallengeProxy::create(WTFMove(coreChallenge), challengeID, makeRef(*connection()), nullptr);
     332#endif
     333
     334    WebPageProxy* page = nullptr;
     335    if (pageID && !m_processPool.isServiceWorkerPageID(pageID))
     336        page = WebProcessProxy::webPage(pageID);
     337
     338    if (!page) {
     339        auto* store = websiteDataStoreFromSessionID(sessionID);
     340        if (!store || coreChallenge.protectionSpace().authenticationScheme() != ProtectionSpaceAuthenticationSchemeServerTrustEvaluationRequested) {
     341            authenticationChallenge->listener().completeChallenge(AuthenticationChallengeDisposition::PerformDefaultHandling);
     342            return;
     343        }
     344        store->client().didReceiveAuthenticationChallenge(WTFMove(authenticationChallenge));
     345        return;
     346    }
     347
    329348    page->didReceiveAuthenticationChallengeProxy(frameID, WTFMove(authenticationChallenge));
    330349}
  • trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h

    r248762 r249001  
    214214    void didReceiveNetworkProcessProxyMessage(IPC::Connection&, IPC::Decoder&);
    215215    void didCreateNetworkConnectionToWebProcess(const IPC::Attachment&);
    216     void didReceiveAuthenticationChallenge(WebCore::PageIdentifier, WebCore::FrameIdentifier, WebCore::AuthenticationChallenge&&, uint64_t challengeID);
     216    void didReceiveAuthenticationChallenge(PAL::SessionID, WebCore::PageIdentifier, WebCore::FrameIdentifier, WebCore::AuthenticationChallenge&&, uint64_t challengeID);
    217217    void didFetchWebsiteData(uint64_t callbackID, const WebsiteData&);
    218218    void didDeleteWebsiteData(uint64_t callbackID);
  • trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.messages.in

    r248713 r249001  
    2424    DidCreateNetworkConnectionToWebProcess(IPC::Attachment connectionIdentifier)
    2525
    26     DidReceiveAuthenticationChallenge(WebCore::PageIdentifier pageID, WebCore::FrameIdentifier frameID, WebCore::AuthenticationChallenge challenge, uint64_t challengeID)
     26    DidReceiveAuthenticationChallenge(PAL::SessionID sessionID, WebCore::PageIdentifier pageID, WebCore::FrameIdentifier frameID, WebCore::AuthenticationChallenge challenge, uint64_t challengeID)
    2727
    2828    DidFetchWebsiteData(uint64_t callbackID, struct WebKit::WebsiteData websiteData)
  • trunk/Source/WebKit/UIProcess/ServiceWorkerProcessProxy.cpp

    r248713 r249001  
    9191}
    9292
    93 void ServiceWorkerProcessProxy::didReceiveAuthenticationChallenge(PageIdentifier pageID, FrameIdentifier frameID, Ref<AuthenticationChallengeProxy>&& challenge)
    94 {
    95     UNUSED_PARAM(pageID);
    96     UNUSED_PARAM(frameID);
    97 
    98     // FIXME: Expose an API to delegate the actual decision to the application layer.
    99     auto& protectionSpace = challenge->core().protectionSpace();
    100     if (protectionSpace.authenticationScheme() == WebCore::ProtectionSpaceAuthenticationSchemeServerTrustEvaluationRequested && processPool().allowsAnySSLCertificateForServiceWorker()) {
    101         auto credential = WebCore::Credential("accept server trust"_s, emptyString(), WebCore::CredentialPersistenceNone);
    102         challenge->listener().completeChallenge(AuthenticationChallengeDisposition::UseCredential, credential);
    103         return;
    104     }
    105     notImplemented();
    106     challenge->listener().completeChallenge(AuthenticationChallengeDisposition::PerformDefaultHandling);
    107 }
    108 
    10993} // namespace WebKit
    11094
  • trunk/Source/WebKit/UIProcess/ServiceWorkerProcessProxy.h

    r248713 r249001  
    4242    static bool hasRegisteredServiceWorkers(const String& serviceWorkerDirectory);
    4343
    44     void didReceiveAuthenticationChallenge(WebCore::PageIdentifier, WebCore::FrameIdentifier, Ref<AuthenticationChallengeProxy>&&);
    45 
    4644    void start(const WebPreferencesStore&, Optional<PAL::SessionID> initialSessionID);
    4745    void setUserAgent(const String&);
  • trunk/Source/WebKit/UIProcess/WebPageProxy.cpp

    r248849 r249001  
    73347334#endif
    73357335
    7336 WeakPtr<SecKeyProxyStore> WebPageProxy::secKeyProxyStore(const WebCore::AuthenticationChallenge& challenge)
    7337 {
    7338 #if HAVE(SEC_KEY_PROXY)
    7339     if (challenge.protectionSpace().authenticationScheme() == ProtectionSpaceAuthenticationSchemeClientCertificateRequested) {
    7340         auto secKeyProxyStore = SecKeyProxyStore::create();
    7341         auto weakPointer = makeWeakPtr(secKeyProxyStore.get());
    7342         m_websiteDataStore->addSecKeyProxyStore(WTFMove(secKeyProxyStore));
    7343         return weakPointer;
    7344     }
    7345 #endif
    7346     return nullptr;
    7347 }
    7348    
    73497336void WebPageProxy::didReceiveAuthenticationChallengeProxy(FrameIdentifier, Ref<AuthenticationChallengeProxy>&& authenticationChallenge)
    73507337{
  • trunk/Source/WebKit/UIProcess/WebProcessPool.cpp

    r248856 r249001  
    22322232}
    22332233
     2234bool WebProcessPool::isServiceWorkerPageID(PageIdentifier pageID) const
     2235{
    22342236#if ENABLE(SERVICE_WORKER)
    2235 ServiceWorkerProcessProxy* WebProcessPool::serviceWorkerProcessProxyFromPageID(PageIdentifier pageID) const
    2236 {
    22372237    // FIXME: This is inefficient.
    22382238    for (auto* serviceWorkerProcess : m_serviceWorkerProcesses.values()) {
    22392239        if (serviceWorkerProcess->pageID() == pageID)
    2240             return serviceWorkerProcess;
    2241     }
    2242     return nullptr;
    2243 }
    2244 #endif
     2240            return true;
     2241    }
     2242#endif
     2243    return false;
     2244}
    22452245
    22462246void WebProcessPool::addProcessToOriginCacheSet(WebProcessProxy& process, const URL& url)
  • trunk/Source/WebKit/UIProcess/WebProcessPool.h

    r248856 r249001  
    380380    void getNetworkProcessConnection(WebProcessProxy&, Messages::WebProcessProxy::GetNetworkProcessConnection::DelayedReply&&);
    381381
     382    bool isServiceWorkerPageID(WebCore::PageIdentifier) const;
    382383#if ENABLE(SERVICE_WORKER)
    383384    void establishWorkerContextConnectionToNetworkProcess(NetworkProcessProxy&, WebCore::RegistrableDomain&&, Optional<PAL::SessionID>);
    384     ServiceWorkerProcessProxy* serviceWorkerProcessProxyFromPageID(WebCore::PageIdentifier) const;
    385385    const HashMap<WebCore::RegistrableDomain, ServiceWorkerProcessProxy*>& serviceWorkerProxies() const { return m_serviceWorkerProcesses; }
    386386    void setAllowsAnySSLCertificateForServiceWorker(bool allows) { m_allowsAnySSLCertificateForServiceWorker = allows; }
  • trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStoreClient.h

    r248762 r249001  
    2626#pragma once
    2727
     28#include "AuthenticationChallengeDisposition.h"
     29#include "AuthenticationChallengeProxy.h"
     30#include "AuthenticationDecisionListener.h"
    2831#include <wtf/CompletionHandler.h>
    2932
     
    4346        completionHandler({ });
    4447    }
     48
     49    virtual void didReceiveAuthenticationChallenge(Ref<AuthenticationChallengeProxy>&& challenge)
     50    {
     51        challenge->listener().completeChallenge(AuthenticationChallengeDisposition::PerformDefaultHandling);
     52    }
    4553};
    4654
  • trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj

    r248901 r249001  
    31483148                41897ED61F415D860016FA42 /* CacheStorageEngine.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = CacheStorageEngine.cpp; sourceTree = "<group>"; };
    31493149                419ACF9B1F981D26009F1A83 /* WebServiceWorkerFetchTaskClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebServiceWorkerFetchTaskClient.h; sourceTree = "<group>"; };
     3150                41A5F7B9226ECF7C00671764 /* AuthenticationChallengeDispositionCocoa.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AuthenticationChallengeDispositionCocoa.h; sourceTree = "<group>"; };
     3151                41A5F7BA226ECF7C00671764 /* AuthenticationChallengeDispositionCocoa.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = AuthenticationChallengeDispositionCocoa.mm; sourceTree = "<group>"; };
    31503152                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>"; };
    31513153                41B28B081F83AD3E00FB52AC /* RTCPacketOptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RTCPacketOptions.h; sourceTree = "<group>"; };
     
    70117013                        isa = PBXGroup;
    70127014                        children = (
     7015                                41A5F7B9226ECF7C00671764 /* AuthenticationChallengeDispositionCocoa.h */,
     7016                                41A5F7BA226ECF7C00671764 /* AuthenticationChallengeDispositionCocoa.mm */,
    70137017                                57B4B45D20B504AB00D4AD79 /* AuthenticationManagerCocoa.mm */,
    70147018                                44A481C621F2D27B00F2F919 /* ClientCertificateAuthenticationXPCConstants.cpp */,
  • trunk/Tools/ChangeLog

    r248995 r249001  
     12019-08-22  Youenn Fablet  <youenn@apple.com>
     2
     3        Add a WebsiteDataStore delegate to handle AuthenticationChallenge that do not come from pages
     4        https://bugs.webkit.org/show_bug.cgi?id=196870
     5
     6        Reviewed by Alex Christensen.
     7
     8        Implement the new delegate by respecting the value set by testRunner.setAllowsAnySSLCertificate
     9        Accept any server certificate by default.
     10
     11        * WebKitTestRunner/TestController.cpp:
     12        * WebKitTestRunner/cocoa/TestControllerCocoa.mm:
     13        (WTR::TestController::cocoaResetStateToConsistentValues):
     14        (WTR::TestController::setAllowsAnySSLCertificate):
     15        * WebKitTestRunner/cocoa/TestWebsiteDataStoreDelegate.h:
     16        * WebKitTestRunner/cocoa/TestWebsiteDataStoreDelegate.mm:
     17        (-[TestWebsiteDataStoreDelegate didReceiveAuthenticationChallenge:completionHandler:]):
     18        (-[TestWebsiteDataStoreDelegate setAllowAnySSLCertificate:]):
     19
    1202019-08-21  Jonathan Bedard  <jbedard@apple.com>
    221
  • trunk/Tools/WebKitTestRunner/TestController.cpp

    r248960 r249001  
    10331033    m_openPanelFileURLsMediaIcon = nullptr;
    10341034#endif
    1035    
     1035
     1036    setAllowsAnySSLCertificate(true);
     1037
    10361038    statisticsResetToConsistentState();
    10371039   
     
    11931195}
    11941196
     1197#if !PLATFORM(COCOA)
    11951198void TestController::setAllowsAnySSLCertificate(bool allows)
    11961199{
     1200    m_allowsAnySSLCertificate = allows;
    11971201    WKContextSetAllowsAnySSLCertificateForWebSocketTesting(platformContext(), allows);
    11981202}
     1203#endif
    11991204
    12001205static std::string testPath(WKURLRef url)
     
    23402345        m_serverTrustEvaluationCallbackCallsCount++;
    23412346
    2342         WKRetainPtr<WKCredentialRef> credential = adoptWK(WKCredentialCreate(toWK("accept server trust").get(), toWK("").get(), kWKCredentialPersistenceNone));
    2343         WKAuthenticationDecisionListenerUseCredential(decisionListener, credential.get());
     2347        if (m_allowsAnySSLCertificate) {
     2348            WKRetainPtr<WKCredentialRef> credential = adoptWK(WKCredentialCreate(toWK("accept server trust").get(), toWK("").get(), kWKCredentialPersistenceNone));
     2349            WKAuthenticationDecisionListenerUseCredential(decisionListener, credential.get());
     2350            return;
     2351        }
     2352        WKAuthenticationDecisionListenerRejectProtectionSpaceAndContinue(decisionListener);
    23442353        return;
    23452354    }
  • trunk/Tools/WebKitTestRunner/TestController.h

    r248856 r249001  
    592592    uint64_t m_serverTrustEvaluationCallbackCallsCount { 0 };
    593593    bool m_shouldDismissJavaScriptAlertsAsynchronously { false };
     594    bool m_allowsAnySSLCertificate { true };
    594595};
    595596
  • trunk/Tools/WebKitTestRunner/cocoa/TestControllerCocoa.mm

    r248846 r249001  
    3636#import <Security/SecItem.h>
    3737#import <WebKit/WKContextConfigurationRef.h>
     38#import <WebKit/WKContextPrivate.h>
    3839#import <WebKit/WKCookieManager.h>
    3940#import <WebKit/WKPreferencesRefPrivate.h>
     
    398399}
    399400
     401void TestController::setAllowsAnySSLCertificate(bool allows)
     402{
     403    m_allowsAnySSLCertificate = allows;
     404    WKContextSetAllowsAnySSLCertificateForWebSocketTesting(platformContext(), allows);
     405    [globalWebsiteDataStoreDelegateClient setAllowAnySSLCertificate: allows];
     406}
     407
    400408bool TestController::canDoServerTrustEvaluationInNetworkProcess() const
    401409{
  • trunk/Tools/WebKitTestRunner/cocoa/TestWebsiteDataStoreDelegate.h

    r242339 r249001  
    3131@private
    3232    BOOL _shouldAllowRaisingQuota;
     33    BOOL _shouldAllowAnySSLCertificate;
    3334}
    3435- (instancetype)init;
    3536- (void)setAllowRaisingQuota:(BOOL)shouldAllowRaisingQuota;
     37- (void)setAllowAnySSLCertificate:(BOOL)shouldAllowAnySSLCertificate;
    3638@end
  • trunk/Tools/WebKitTestRunner/cocoa/TestWebsiteDataStoreDelegate.mm

    r242727 r249001  
    4343    _shouldAllowRaisingQuota = shouldAllowRaisingQuota;
    4444}
     45
     46- (void)didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential * _Nullable credential))completionHandler
     47{
     48    NSString *method = challenge.protectionSpace.authenticationMethod;
     49    if ([method isEqualToString:NSURLAuthenticationMethodServerTrust]) {
     50        if (_shouldAllowAnySSLCertificate)
     51            completionHandler(NSURLSessionAuthChallengeUseCredential, [NSURLCredential credentialForTrust: challenge.protectionSpace.serverTrust]);
     52        else
     53            completionHandler(NSURLSessionAuthChallengeCancelAuthenticationChallenge, nil);
     54        return;
     55    }
     56    completionHandler(NSURLSessionAuthChallengePerformDefaultHandling, nil);
     57}
     58
     59- (void)setAllowAnySSLCertificate:(BOOL)shouldAllowAnySSLCertificate
     60{
     61    _shouldAllowAnySSLCertificate = shouldAllowAnySSLCertificate;
     62}
     63
    4564@end
Note: See TracChangeset for help on using the changeset viewer.