Title: [230192] trunk/Tools
Revision
230192
Author
[email protected]
Date
2018-04-02 16:12:12 -0700 (Mon, 02 Apr 2018)

Log Message

Add infrastructure to relax SSL for allowed hosts in DumpRenderTree and WebKitTestRunner
https://bugs.webkit.org/show_bug.cgi?id=184239

Reviewed by Alexey Proskuryakov.

Adds a new optional command line option --allow-any-certificate-for-allowed-hosts (defaults to disabled)
to allow the allowed hosts to accept any HTTPS certificate. You can specify an allowed host
by using the existing command line option --allowed-host.

Currently both DumpRenderTree and WebKitTestRunner relax SSL certificate validation
for 127.0.0.1 and localhost so that we can run HTTPS tests from these hosts using
a self-signed certificate. They do not relax these restrictions for any allowed host,
specified using the optional command line option --allowed-host. For testing purposes
it is useful to be able to run a local HTTPS server with a self-signed certificate and
mimic a non-localhost hostname (by adding an alias(es) for 127.0.0.1 to /etc/hosts).
We should support relaxing SSL restrictions for such testing purposes.

For example, to allow host example.test to present any HTTPS certificate when running
tests you would invoke:

    run-webkit-tests --allowed-host example.test --additional-drt-flag '--allow-any-certificate-for-allowed-hosts'

* DumpRenderTree/mac/DumpRenderTree.mm:
(initializeGlobalsFromCommandLineOptions): Parse the command line option --allow-any-certificate-for-allowed-hosts.
(dumpRenderTree): Allow any HTTPS certificate from each allowed host.
* WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:
(WTR::InjectedBundle::didReceiveMessageToPage): Clear out the existing list of allowed hosts
before appending entries to it to avoid growing the list of allowed hosts without bound. Call
platformAllowAnyHTTPSCertificateForAllowedHosts() to apply SSL relaxation for each allowed host.
* WebKitTestRunner/Options.cpp:
(WTR::handleOptionAllowAnyHTTPSCertificateForAllowedHosts): Added.
(WTR::handleOptionAllowedHost): Update code as needed now that Options::allowedHosts is a std::set.
(WTR::OptionsHandler::OptionsHandler):
* WebKitTestRunner/Options.h: Change the data type of allowedHosts from a std::vector to a std::set
so that we can make use of the convenience functon std::set::find() in TestController::canAuthenticateAgainstProtectionSpace().
* WebKitTestRunner/TestController.cpp:
(WTR::TestController::initialize):
(WTR::TestController::canAuthenticateAgainstProtectionSpace): Allow any HTTPS certificate from each allowed host.
* WebKitTestRunner/TestController.h:

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (230191 => 230192)


--- trunk/Tools/ChangeLog	2018-04-02 23:09:13 UTC (rev 230191)
+++ trunk/Tools/ChangeLog	2018-04-02 23:12:12 UTC (rev 230192)
@@ -1,3 +1,45 @@
+2018-04-02  Daniel Bates  <[email protected]>
+
+        Add infrastructure to relax SSL for allowed hosts in DumpRenderTree and WebKitTestRunner
+        https://bugs.webkit.org/show_bug.cgi?id=184239
+
+        Reviewed by Alexey Proskuryakov.
+
+        Adds a new optional command line option --allow-any-certificate-for-allowed-hosts (defaults to disabled)
+        to allow the allowed hosts to accept any HTTPS certificate. You can specify an allowed host
+        by using the existing command line option --allowed-host.
+
+        Currently both DumpRenderTree and WebKitTestRunner relax SSL certificate validation
+        for 127.0.0.1 and localhost so that we can run HTTPS tests from these hosts using
+        a self-signed certificate. They do not relax these restrictions for any allowed host,
+        specified using the optional command line option --allowed-host. For testing purposes
+        it is useful to be able to run a local HTTPS server with a self-signed certificate and
+        mimic a non-localhost hostname (by adding an alias(es) for 127.0.0.1 to /etc/hosts).
+        We should support relaxing SSL restrictions for such testing purposes.
+
+        For example, to allow host example.test to present any HTTPS certificate when running
+        tests you would invoke:
+
+            run-webkit-tests --allowed-host example.test --additional-drt-flag '--allow-any-certificate-for-allowed-hosts'
+
+        * DumpRenderTree/mac/DumpRenderTree.mm:
+        (initializeGlobalsFromCommandLineOptions): Parse the command line option --allow-any-certificate-for-allowed-hosts.
+        (dumpRenderTree): Allow any HTTPS certificate from each allowed host.
+        * WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:
+        (WTR::InjectedBundle::didReceiveMessageToPage): Clear out the existing list of allowed hosts
+        before appending entries to it to avoid growing the list of allowed hosts without bound. Call
+        platformAllowAnyHTTPSCertificateForAllowedHosts() to apply SSL relaxation for each allowed host.
+        * WebKitTestRunner/Options.cpp:
+        (WTR::handleOptionAllowAnyHTTPSCertificateForAllowedHosts): Added.
+        (WTR::handleOptionAllowedHost): Update code as needed now that Options::allowedHosts is a std::set.
+        (WTR::OptionsHandler::OptionsHandler):
+        * WebKitTestRunner/Options.h: Change the data type of allowedHosts from a std::vector to a std::set
+        so that we can make use of the convenience functon std::set::find() in TestController::canAuthenticateAgainstProtectionSpace().
+        * WebKitTestRunner/TestController.cpp:
+        (WTR::TestController::initialize):
+        (WTR::TestController::canAuthenticateAgainstProtectionSpace): Allow any HTTPS certificate from each allowed host.
+        * WebKitTestRunner/TestController.h:
+
 2018-04-02  Ryan Haddad  <[email protected]>
 
         Unreviewed, rolling out r230174.

Modified: trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm (230191 => 230192)


--- trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm	2018-04-02 23:09:13 UTC (rev 230191)
+++ trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm	2018-04-02 23:12:12 UTC (rev 230192)
@@ -218,6 +218,7 @@
 static int forceComplexText;
 static int useAcceleratedDrawing;
 static int gcBetweenTests;
+static int allowAnyHTTPSCertificateForAllowedHosts;
 static int showWebView;
 static int printTestCount;
 static BOOL printSeparators;
@@ -1107,6 +1108,7 @@
         {"gc-between-tests", no_argument, &gcBetweenTests, YES},
         {"no-timeout", no_argument, &useTimeoutWatchdog, NO},
         {"allowed-host", required_argument, nullptr, 'a'},
+        {"allow-any-certificate-for-allowed-hosts", no_argument, &allowAnyHTTPSCertificateForAllowedHosts, YES},
         {"show-webview", no_argument, &showWebView, YES},
         {"print-test-count", no_argument, &printTestCount, YES},
         {nullptr, 0, nullptr, 0}
@@ -1246,6 +1248,10 @@
 
     [NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:@"localhost"];
     [NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:@"127.0.0.1"];
+    if (allowAnyHTTPSCertificateForAllowedHosts) {
+        for (auto& host : allowedHosts)
+            [NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[NSString stringWithUTF8String:host.c_str()]];
+    }
 
     if (threaded)
         startJavaScriptThreads();

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp (230191 => 230192)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp	2018-04-02 23:09:13 UTC (rev 230191)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp	2018-04-02 23:12:12 UTC (rev 230192)
@@ -180,6 +180,8 @@
         WKRetainPtr<WKStringRef> allowedHostsKey(AdoptWK, WKStringCreateWithUTF8CString("AllowedHosts"));
         WKTypeRef allowedHostsValue = WKDictionaryGetItemForKey(messageBodyDictionary, allowedHostsKey.get());
         if (allowedHostsValue && WKGetTypeID(allowedHostsValue) == WKArrayGetTypeID()) {
+            m_allowedHosts.clear();
+
             WKArrayRef allowedHostsArray = static_cast<WKArrayRef>(allowedHostsValue);
             for (size_t i = 0, size = WKArrayGetSize(allowedHostsArray); i < size; ++i) {
                 WKTypeRef item = WKArrayGetItemAtIndex(allowedHostsArray, i);

Modified: trunk/Tools/WebKitTestRunner/Options.cpp (230191 => 230192)


--- trunk/Tools/WebKitTestRunner/Options.cpp	2018-04-02 23:09:13 UTC (rev 230191)
+++ trunk/Tools/WebKitTestRunner/Options.cpp	2018-04-02 23:12:12 UTC (rev 230192)
@@ -93,9 +93,15 @@
     return true;
 }
 
+static bool handleOptionAllowAnyHTTPSCertificateForAllowedHosts(Options& options, const char*, const char*)
+{
+    options.allowAnyHTTPSCertificateForAllowedHosts = true;
+    return true;
+}
+
 static bool handleOptionAllowedHost(Options& options, const char*, const char* host)
 {
-    options.allowedHosts.push_back(host);
+    options.allowedHosts.insert(host);
     return true;
 }
 
@@ -120,6 +126,7 @@
     optionList.append(Option("--accelerated-drawing", "Use accelerated drawing.", handleOptionAcceleratedDrawing));
     optionList.append(Option("--remote-layer-tree", "Use remote layer tree.", handleOptionRemoteLayerTree));
     optionList.append(Option("--allowed-host", "Allows access to the specified host from tests.", handleOptionAllowedHost, true));
+    optionList.append(Option("--allow-any-certificate-for-allowed-hosts", "Allows any HTTPS certificate for an allowed host.", handleOptionAllowAnyHTTPSCertificateForAllowedHosts));
     optionList.append(Option("--show-webview", "Show the WebView during test runs (for debugging)", handleOptionShowWebView));
     optionList.append(Option("--show-touches", "Show the touches during test runs (for debugging)", handleOptionShowTouches));
 

Modified: trunk/Tools/WebKitTestRunner/Options.h (230191 => 230192)


--- trunk/Tools/WebKitTestRunner/Options.h	2018-04-02 23:09:13 UTC (rev 230191)
+++ trunk/Tools/WebKitTestRunner/Options.h	2018-04-02 23:12:12 UTC (rev 230192)
@@ -28,6 +28,7 @@
 #pragma once
 
 #include <functional>
+#include <set>
 #include <stdio.h>
 #include <string>
 #include <vector>
@@ -47,8 +48,9 @@
     bool shouldUseRemoteLayerTree { false };
     bool shouldShowWebView { false };
     bool shouldShowTouches { false };
+    bool allowAnyHTTPSCertificateForAllowedHosts { false };
     std::vector<std::string> paths;
-    std::vector<std::string> allowedHosts;
+    std::set<std::string> allowedHosts;
 };
 
 class Option {

Modified: trunk/Tools/WebKitTestRunner/TestController.cpp (230191 => 230192)


--- trunk/Tools/WebKitTestRunner/TestController.cpp	2018-04-02 23:09:13 UTC (rev 230191)
+++ trunk/Tools/WebKitTestRunner/TestController.cpp	2018-04-02 23:12:12 UTC (rev 230192)
@@ -374,6 +374,7 @@
     m_allowedHosts = options.allowedHosts;
     m_shouldShowWebView = options.shouldShowWebView;
     m_shouldShowTouches = options.shouldShowTouches;
+    m_allowAnyHTTPSCertificateForAllowedHosts = options.allowAnyHTTPSCertificateForAllowedHosts;
 
     if (options.printSupportedFeatures) {
         // FIXME: On Windows, DumpRenderTree uses this to expose whether it supports 3d
@@ -1752,7 +1753,7 @@
     
     if (authenticationScheme == kWKProtectionSpaceAuthenticationSchemeServerTrustEvaluationRequested) {
         std::string host = toSTD(adoptWK(WKProtectionSpaceCopyHost(protectionSpace)).get());
-        return host == "localhost" || host == "127.0.0.1";
+        return host == "localhost" || host == "127.0.0.1" || (m_allowAnyHTTPSCertificateForAllowedHosts && m_allowedHosts.find(host) != m_allowedHosts.end());
     }
     
     return authenticationScheme <= kWKProtectionSpaceAuthenticationSchemeHTTPDigest;

Modified: trunk/Tools/WebKitTestRunner/TestController.h (230191 => 230192)


--- trunk/Tools/WebKitTestRunner/TestController.h	2018-04-02 23:09:13 UTC (rev 230191)
+++ trunk/Tools/WebKitTestRunner/TestController.h	2018-04-02 23:12:12 UTC (rev 230192)
@@ -30,6 +30,7 @@
 #include "WebNotificationProvider.h"
 #include "WorkQueueManager.h"
 #include <WebKit/WKRetainPtr.h>
+#include <set>
 #include <string>
 #include <vector>
 #include <wtf/HashMap.h>
@@ -359,7 +360,7 @@
     bool m_gcBetweenTests { false };
     bool m_shouldDumpPixelsForAllTests { false };
     std::vector<std::string> m_paths;
-    std::vector<std::string> m_allowedHosts;
+    std::set<std::string> m_allowedHosts;
     WKRetainPtr<WKStringRef> m_injectedBundlePath;
     WKRetainPtr<WKStringRef> m_testPluginDirectory;
 
@@ -420,6 +421,8 @@
     bool m_shouldShowWebView { false };
     
     bool m_shouldShowTouches { false };
+
+    bool m_allowAnyHTTPSCertificateForAllowedHosts { false };
     
     bool m_shouldDecideNavigationPolicyAfterDelay { false };
     bool m_shouldDecideResponsePolicyAfterDelay { false };
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to