Title: [222147] trunk/Source/WebCore
Revision
222147
Author
[email protected]
Date
2017-09-18 08:41:15 -0700 (Mon, 18 Sep 2017)

Log Message

[Curl] Create classes dedicated to handle SSL related tasks
and separate verifier and certificate management.
https://bugs.webkit.org/show_bug.cgi?id=176910

Patch by Basuke Suzuki <[email protected]> on 2017-09-18
Reviewed by Alex Christensen.

* platform/Curl.cmake:
* platform/network/curl/CurlContext.cpp:
(WebCore::CurlContext::CurlContext):
(WebCore::CurlHandle::setCACertPath):
(WebCore::certificatePath): Deleted.
(WebCore::CurlHandle::enableCAInfoIfExists): Deleted.
(WebCore::CurlHandle::setSslErrors): Deleted.
(WebCore::CurlHandle::getSslErrors): Deleted.
* platform/network/curl/CurlContext.h:
(WebCore::CurlContext::sslHandle):
(WebCore::CurlContext::getCertificatePath const): Deleted.
(WebCore::CurlContext::shouldIgnoreSSLErrors const): Deleted.
* platform/network/curl/CurlDownload.cpp:
(WebCore::CurlDownload::setupRequest):
* platform/network/curl/CurlSSLHandle.cpp: Added.
(WebCore::CurlSSLHandle::CurlSSLHandle):
(WebCore::CurlSSLHandle::getCACertPathEnv):
(WebCore::CurlSSLHandle::setHostAllowsAnyHTTPSCertificate):
(WebCore::CurlSSLHandle::isAllowedHTTPSCertificateHost):
(WebCore::CurlSSLHandle::canIgnoredHTTPSCertificate):
(WebCore::CurlSSLHandle::setClientCertificateInfo):
(WebCore::CurlSSLHandle::getSSLClientCertificate):
* platform/network/curl/CurlSSLHandle.h: Renamed from Source/WebCore/platform/network/curl/SSLHandle.h.
(WebCore::CurlSSLHandle::shouldIgnoreSSLErrors const):
(WebCore::CurlSSLHandle::getCACertPath const):
* platform/network/curl/CurlSSLVerifier.cpp: Renamed from Source/WebCore/platform/network/curl/SSLHandle.cpp.
(WebCore::CurlSSLVerifier::setSslCtx):
(WebCore::CurlSSLVerifier::certVerifyCallback):
(WebCore::CurlSSLVerifier::getPemDataFromCtx):
(WebCore::CurlSSLVerifier::convertToSSLCertificateFlags):
* platform/network/curl/CurlSSLVerifier.h: Added.
(WebCore::CurlSSLVerifier::setCurlHandle):
(WebCore::CurlSSLVerifier::setHostName):
(WebCore::CurlSSLVerifier::sslErrors):
* platform/network/curl/ResourceHandleCurl.cpp:
(WebCore::ResourceHandle::setHostAllowsAnyHTTPSCertificate):
(WebCore::ResourceHandle::setClientCertificateInfo):
* platform/network/curl/ResourceHandleCurlDelegate.cpp:
(WebCore::ResourceHandleCurlDelegate::ResourceHandleCurlDelegate):
(WebCore::ResourceHandleCurlDelegate::setupRequest):
(WebCore::ResourceHandleCurlDelegate::notifyFail):
(WebCore::ResourceHandleCurlDelegate::willSetupSslCtx):
(WebCore::ResourceHandleCurlDelegate::willSetupSslCtxCallback):
* platform/network/curl/ResourceHandleCurlDelegate.h:

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (222146 => 222147)


--- trunk/Source/WebCore/ChangeLog	2017-09-18 15:29:38 UTC (rev 222146)
+++ trunk/Source/WebCore/ChangeLog	2017-09-18 15:41:15 UTC (rev 222147)
@@ -1,3 +1,56 @@
+2017-09-18  Basuke Suzuki  <[email protected]>
+
+        [Curl] Create classes dedicated to handle SSL related tasks
+        and separate verifier and certificate management.
+        https://bugs.webkit.org/show_bug.cgi?id=176910
+
+        Reviewed by Alex Christensen.
+
+        * platform/Curl.cmake:
+        * platform/network/curl/CurlContext.cpp:
+        (WebCore::CurlContext::CurlContext):
+        (WebCore::CurlHandle::setCACertPath):
+        (WebCore::certificatePath): Deleted.
+        (WebCore::CurlHandle::enableCAInfoIfExists): Deleted.
+        (WebCore::CurlHandle::setSslErrors): Deleted.
+        (WebCore::CurlHandle::getSslErrors): Deleted.
+        * platform/network/curl/CurlContext.h:
+        (WebCore::CurlContext::sslHandle):
+        (WebCore::CurlContext::getCertificatePath const): Deleted.
+        (WebCore::CurlContext::shouldIgnoreSSLErrors const): Deleted.
+        * platform/network/curl/CurlDownload.cpp:
+        (WebCore::CurlDownload::setupRequest):
+        * platform/network/curl/CurlSSLHandle.cpp: Added.
+        (WebCore::CurlSSLHandle::CurlSSLHandle):
+        (WebCore::CurlSSLHandle::getCACertPathEnv):
+        (WebCore::CurlSSLHandle::setHostAllowsAnyHTTPSCertificate):
+        (WebCore::CurlSSLHandle::isAllowedHTTPSCertificateHost):
+        (WebCore::CurlSSLHandle::canIgnoredHTTPSCertificate):
+        (WebCore::CurlSSLHandle::setClientCertificateInfo):
+        (WebCore::CurlSSLHandle::getSSLClientCertificate):
+        * platform/network/curl/CurlSSLHandle.h: Renamed from Source/WebCore/platform/network/curl/SSLHandle.h.
+        (WebCore::CurlSSLHandle::shouldIgnoreSSLErrors const):
+        (WebCore::CurlSSLHandle::getCACertPath const):
+        * platform/network/curl/CurlSSLVerifier.cpp: Renamed from Source/WebCore/platform/network/curl/SSLHandle.cpp.
+        (WebCore::CurlSSLVerifier::setSslCtx):
+        (WebCore::CurlSSLVerifier::certVerifyCallback):
+        (WebCore::CurlSSLVerifier::getPemDataFromCtx):
+        (WebCore::CurlSSLVerifier::convertToSSLCertificateFlags):
+        * platform/network/curl/CurlSSLVerifier.h: Added.
+        (WebCore::CurlSSLVerifier::setCurlHandle):
+        (WebCore::CurlSSLVerifier::setHostName):
+        (WebCore::CurlSSLVerifier::sslErrors):
+        * platform/network/curl/ResourceHandleCurl.cpp:
+        (WebCore::ResourceHandle::setHostAllowsAnyHTTPSCertificate):
+        (WebCore::ResourceHandle::setClientCertificateInfo):
+        * platform/network/curl/ResourceHandleCurlDelegate.cpp:
+        (WebCore::ResourceHandleCurlDelegate::ResourceHandleCurlDelegate):
+        (WebCore::ResourceHandleCurlDelegate::setupRequest):
+        (WebCore::ResourceHandleCurlDelegate::notifyFail):
+        (WebCore::ResourceHandleCurlDelegate::willSetupSslCtx):
+        (WebCore::ResourceHandleCurlDelegate::willSetupSslCtxCallback):
+        * platform/network/curl/ResourceHandleCurlDelegate.h:
+
 2017-09-17  Carlos Garcia Campos  <[email protected]>
 
         REGRESSION(r221974): [Harfbuzz] Test fast/text/international/hebrew-selection.html is failing since r221974

Modified: trunk/Source/WebCore/platform/Curl.cmake (222146 => 222147)


--- trunk/Source/WebCore/platform/Curl.cmake	2017-09-18 15:29:38 UTC (rev 222146)
+++ trunk/Source/WebCore/platform/Curl.cmake	2017-09-18 15:41:15 UTC (rev 222147)
@@ -10,6 +10,8 @@
     platform/network/curl/CurlContext.cpp
     platform/network/curl/CurlDownload.cpp
     platform/network/curl/CurlJobManager.cpp
+    platform/network/curl/CurlSSLHandle.cpp
+    platform/network/curl/CurlSSLVerifier.cpp
     platform/network/curl/DNSCurl.cpp
     platform/network/curl/FormDataStreamCurl.cpp
     platform/network/curl/MultipartHandle.cpp
@@ -17,7 +19,6 @@
     platform/network/curl/ResourceHandleCurl.cpp
     platform/network/curl/ResourceHandleCurlDelegate.cpp
     platform/network/curl/ResourceResponseCurl.cpp
-    platform/network/curl/SSLHandle.cpp
     platform/network/curl/SocketStreamHandleImplCurl.cpp
     platform/network/curl/SynchronousLoaderClientCurl.cpp
 )

Modified: trunk/Source/WebCore/platform/network/curl/CurlContext.cpp (222146 => 222147)


--- trunk/Source/WebCore/platform/network/curl/CurlContext.cpp	2017-09-18 15:29:38 UTC (rev 222146)
+++ trunk/Source/WebCore/platform/network/curl/CurlContext.cpp	2017-09-18 15:41:15 UTC (rev 222147)
@@ -39,35 +39,10 @@
 #include <shlwapi.h>
 #endif
 
-#if USE(CF)
-#include <wtf/RetainPtr.h>
-#endif
-
 using namespace WebCore;
 
 namespace WebCore {
 
-static CString certificatePath()
-{
-    char* envPath = getenv("CURL_CA_BUNDLE_PATH");
-    if (envPath)
-        return envPath;
-
-#if USE(CF)
-    CFBundleRef webKitBundleRef = webKitBundle();
-    if (webKitBundleRef) {
-        RetainPtr<CFURLRef> certURLRef = adoptCF(CFBundleCopyResourceURL(webKitBundleRef, CFSTR("cacert"), CFSTR("pem"), CFSTR("certificates")));
-        if (certURLRef) {
-            char path[MAX_PATH];
-            CFURLGetFileSystemRepresentation(certURLRef.get(), false, reinterpret_cast<UInt8*>(path), MAX_PATH);
-            return path;
-        }
-    }
-#endif
-
-    return CString();
-}
-
 static CString cookieJarPath()
 {
     char* cookieJarPath = getenv("CURL_COOKIE_JAR_PATH");
@@ -106,13 +81,10 @@
 
 CurlContext::CurlContext()
 : m_cookieJarFileName { cookieJarPath() }
-, m_certificatePath { certificatePath() }
 , m_cookieJar { std::make_unique<CookieJarCurlFileSystem>() }
 {
     initCookieSession();
 
-    m_ignoreSSLErrors = getenv("WEBKIT_IGNORE_SSL_ERRORS");
-
 #ifndef NDEBUG
     m_verbose = getenv("DEBUG_CURL");
 
@@ -469,11 +441,10 @@
     curl_easy_setopt(m_handle, CURLOPT_USERPWD, userpass.utf8().data());
 }
 
-void CurlHandle::enableCAInfoIfExists()
+void CurlHandle::setCACertPath(const char* path)
 {
-    const char* certPath = CurlContext::singleton().getCertificatePath();
-    if (certPath)
-        curl_easy_setopt(m_handle, CURLOPT_CAINFO, certPath);
+    if (path)
+        curl_easy_setopt(m_handle, CURLOPT_CAINFO, path);
 }
 
 void CurlHandle::setSslVerifyPeer(VerifyPeer verifyPeer)
@@ -501,16 +472,6 @@
     curl_easy_setopt(m_handle, CURLOPT_KEYPASSWD, password);
 }
 
-void CurlHandle::setSslErrors(unsigned sslErrors)
-{
-    m_sslErrors = sslErrors;
-}
-
-unsigned CurlHandle::getSslErrors()
-{
-    return m_sslErrors;
-}
-
 void CurlHandle::enableCookieJarIfExists()
 {
     const char* cookieJar = CurlContext::singleton().getCookieJarFileName();

Modified: trunk/Source/WebCore/platform/network/curl/CurlContext.h (222146 => 222147)


--- trunk/Source/WebCore/platform/network/curl/CurlContext.h	2017-09-18 15:29:38 UTC (rev 222146)
+++ trunk/Source/WebCore/platform/network/curl/CurlContext.h	2017-09-18 15:41:15 UTC (rev 222147)
@@ -27,6 +27,7 @@
 #pragma once
 
 #include "CookieJarCurl.h"
+#include "CurlSSLHandle.h"
 #include "URL.h"
 
 #include <wtf/Lock.h>
@@ -120,15 +121,14 @@
     void setCookieJarFileName(const char* cookieJarFileName) { m_cookieJarFileName = CString(cookieJarFileName); }
     CookieJarCurl& cookieJar() { return *m_cookieJar; }
 
-    // Certificate
-    const char* getCertificatePath() const { return m_certificatePath.data(); }
-    bool shouldIgnoreSSLErrors() const { return m_ignoreSSLErrors; }
-
     // Proxy
     const ProxyInfo& proxyInfo() const { return m_proxy; }
     void setProxyInfo(const ProxyInfo& info) { m_proxy = info;  }
     void setProxyInfo(const String& host = emptyString(), unsigned long port = 0, CurlProxyType = CurlProxyType::HTTP, const String& username = emptyString(), const String& password = emptyString());
 
+    // SSL
+    CurlSSLHandle& sslHandle() { return m_sslHandle; }
+
 #ifndef NDEBUG
     FILE* getLogFile() const { return m_logFile; }
     bool isVerbose() const { return m_verbose; }
@@ -137,10 +137,9 @@
 private:
     ProxyInfo m_proxy;
     CString m_cookieJarFileName;
-    CString m_certificatePath;
     CurlShareHandle m_shareHandle;
     std::unique_ptr<CookieJarCurl> m_cookieJar;
-    bool m_ignoreSSLErrors { false };
+    CurlSSLHandle m_sslHandle;
 
     CurlContext();
     void initCookieSession();
@@ -263,14 +262,12 @@
     void enableHttpAuthentication(long);
     void setHttpAuthUserPass(const String&, const String&);
 
-    void enableCAInfoIfExists();
+    void setCACertPath(const char*);
     void setSslVerifyPeer(VerifyPeer);
     void setSslVerifyHost(VerifyHost);
     void setSslCert(const char*);
     void setSslCertType(const char*);
     void setSslKeyPassword(const char*);
-    void setSslErrors(unsigned);
-    unsigned getSslErrors();
 
     void enableCookieJarIfExists();
     void setCookieList(const char*);
@@ -309,7 +306,6 @@
     CURL* m_handle { nullptr };
     char m_errorBuffer[CURL_ERROR_SIZE] { };
     CURLcode m_errorCode;
-    unsigned m_sslErrors { 0 };
 
     char* m_url { nullptr };
     void* m_privateData { nullptr };

Modified: trunk/Source/WebCore/platform/network/curl/CurlDownload.cpp (222146 => 222147)


--- trunk/Source/WebCore/platform/network/curl/CurlDownload.cpp	2017-09-18 15:29:38 UTC (rev 222146)
+++ trunk/Source/WebCore/platform/network/curl/CurlDownload.cpp	2017-09-18 15:41:15 UTC (rev 222147)
@@ -31,6 +31,7 @@
 #if USE(CURL)
 
 #include "CurlContext.h"
+#include "CurlSSLHandle.h"
 #include "HTTPHeaderNames.h"
 #include "HTTPParsers.h"
 #include "ResourceRequest.h"
@@ -119,7 +120,8 @@
     m_curlHandle.setWriteCallbackFunction(writeCallback, this);
     m_curlHandle.enableFollowLocation();
     m_curlHandle.enableHttpAuthentication(CURLAUTH_ANY);
-    m_curlHandle.enableCAInfoIfExists();
+    m_curlHandle.setCACertPath(CurlContext::singleton().sslHandle().getCACertPath());
+
 }
 
 void CurlDownload::notifyFinish()

Added: trunk/Source/WebCore/platform/network/curl/CurlSSLHandle.cpp (0 => 222147)


--- trunk/Source/WebCore/platform/network/curl/CurlSSLHandle.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/network/curl/CurlSSLHandle.cpp	2017-09-18 15:41:15 UTC (rev 222147)
@@ -0,0 +1,125 @@
+/*
+ * Copyright (C) 2013 University of Szeged
+ * Copyright (C) 2017 Sony Interactive Entertainment Inc.
+ *
+ * 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 UNIVERSITY OF SZEGED ``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
+ * 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 "CurlSSLHandle.h"
+
+#if USE(CURL)
+
+#if USE(CF)
+#if OS(WINDOWS)
+#include "WebCoreBundleWin.h"
+#endif
+
+#include <wtf/RetainPtr.h>
+#endif
+
+namespace WebCore {
+
+CurlSSLHandle::CurlSSLHandle()
+    : m_caCertPath(getCACertPathEnv())
+{
+    char* ignoreSSLErrors = getenv("WEBKIT_IGNORE_SSL_ERRORS");
+    if (ignoreSSLErrors)
+        m_ignoreSSLErrors = true;
+}
+
+CString CurlSSLHandle::getCACertPathEnv()
+{
+    char* envPath = getenv("CURL_CA_BUNDLE_PATH");
+    if (envPath)
+        return envPath;
+
+#if USE(CF)
+    CFBundleRef webKitBundleRef = webKitBundle();
+    if (webKitBundleRef) {
+        RetainPtr<CFURLRef> certURLRef = adoptCF(CFBundleCopyResourceURL(webKitBundleRef, CFSTR("cacert"), CFSTR("pem"), CFSTR("certificates")));
+        if (certURLRef) {
+            char path[MAX_PATH];
+            CFURLGetFileSystemRepresentation(certURLRef.get(), false, reinterpret_cast<UInt8*>(path), MAX_PATH);
+            return path;
+        }
+    }
+#endif
+
+    return CString();
+}
+
+void CurlSSLHandle::setHostAllowsAnyHTTPSCertificate(const String& hostName)
+{
+    LockHolder mutex(m_mutex);
+
+    ListHashSet<String> certificates;
+    m_allowedHosts.set(hostName, certificates);
+}
+
+bool CurlSSLHandle::isAllowedHTTPSCertificateHost(const String& hostName)
+{
+    LockHolder mutex(m_mutex);
+
+    auto it = m_allowedHosts.find(hostName);
+    return (it != m_allowedHosts.end());
+}
+
+bool CurlSSLHandle::canIgnoredHTTPSCertificate(const String& hostName, const ListHashSet<String>& certificates)
+{
+    LockHolder mutex(m_mutex);
+
+    auto found = m_allowedHosts.find(hostName);
+    if (found == m_allowedHosts.end())
+        return false;
+
+    auto& value = found->value;
+    if (value.isEmpty()) {
+        value = certificates;
+        return true;
+    }
+
+    return std::equal(certificates.begin(), certificates.end(), value.begin());
+}
+
+void CurlSSLHandle::setClientCertificateInfo(const String& hostName, const String& certificate, const String& key)
+{
+    LockHolder mutex(m_mutex);
+
+    ClientCertificate clientInfo(certificate, key);
+    m_allowedClientHosts.set(hostName, clientInfo);
+}
+
+std::optional<CurlSSLHandle::ClientCertificate> CurlSSLHandle::getSSLClientCertificate(const String& hostName)
+{
+    LockHolder mutex(m_mutex);
+
+    auto it = m_allowedClientHosts.find(hostName);
+    if (it == m_allowedClientHosts.end())
+        return std::nullopt;
+
+    return it->value;
+}
+
+}
+
+#endif

Copied: trunk/Source/WebCore/platform/network/curl/CurlSSLHandle.h (from rev 222146, trunk/Source/WebCore/platform/network/curl/SSLHandle.h) (0 => 222147)


--- trunk/Source/WebCore/platform/network/curl/CurlSSLHandle.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/network/curl/CurlSSLHandle.h	2017-09-18 15:41:15 UTC (rev 222147)
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2013 University of Szeged
+ * Copyright (C) 2017 Sony Interactive Entertainment Inc.
+ *
+ * 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 UNIVERSITY OF SZEGED ``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
+ * 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
+
+#if OS(WINDOWS)
+#include <winsock2.h>
+#endif
+
+#include <openssl/ssl.h>
+#include <wtf/HashMap.h>
+#include <wtf/ListHashSet.h>
+#include <wtf/Noncopyable.h>
+#include <wtf/text/StringHash.h>
+
+namespace WebCore {
+
+class CurlSSLHandle {
+    WTF_MAKE_NONCOPYABLE(CurlSSLHandle);
+    friend NeverDestroyed<CurlSSLHandle>;
+
+public:
+    CurlSSLHandle();
+
+    using ClientCertificate = std::pair<String, String>;
+
+    bool shouldIgnoreSSLErrors() const { return m_ignoreSSLErrors; }
+    const char* getCACertPath() const { return m_caCertPath.data(); }
+
+    void setHostAllowsAnyHTTPSCertificate(const String&);
+    bool isAllowedHTTPSCertificateHost(const String&);
+    bool canIgnoredHTTPSCertificate(const String&, const ListHashSet<String>&);
+
+    void setClientCertificateInfo(const String&, const String&, const String&);
+    std::optional<ClientCertificate> getSSLClientCertificate(const String&);
+
+private:
+    CString getCACertPathEnv();
+
+    bool m_ignoreSSLErrors { false };
+    CString m_caCertPath;
+
+    Lock m_mutex;
+    HashMap<String, ListHashSet<String>, ASCIICaseInsensitiveHash> m_allowedHosts;
+    HashMap<String, ClientCertificate, ASCIICaseInsensitiveHash> m_allowedClientHosts;
+};
+
+
+}

Copied: trunk/Source/WebCore/platform/network/curl/CurlSSLVerifier.cpp (from rev 222146, trunk/Source/WebCore/platform/network/curl/SSLHandle.cpp) (0 => 222147)


--- trunk/Source/WebCore/platform/network/curl/CurlSSLVerifier.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/network/curl/CurlSSLVerifier.cpp	2017-09-18 15:41:15 UTC (rev 222147)
@@ -0,0 +1,175 @@
+/*
+ * Copyright (C) 2013 University of Szeged
+ * Copyright (C) 2017 Sony Interactive Entertainment Inc.
+ *
+ * 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 UNIVERSITY OF SZEGED ``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
+ * 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 "CurlSSLVerifier.h"
+
+#if USE(CURL)
+#include "CurlContext.h"
+#include "CurlSSLHandle.h"
+
+namespace WebCore {
+
+void CurlSSLVerifier::setSslCtx(void* sslCtx)
+{
+    if (!sslCtx)
+        return;
+
+    SSL_CTX_set_app_data(static_cast<SSL_CTX*>(sslCtx), this);
+    SSL_CTX_set_verify(static_cast<SSL_CTX*>(sslCtx), SSL_VERIFY_PEER, certVerifyCallback);
+}
+
+int CurlSSLVerifier::certVerifyCallback(int ok, X509_STORE_CTX* storeCtx)
+{
+    // whether the verification of the certificate in question was passed (preverify_ok=1) or not (preverify_ok=0)
+    int certErrCd = X509_STORE_CTX_get_error(storeCtx);
+    if (!certErrCd)
+        return 1;
+
+    SSL* ssl = static_cast<SSL*>(X509_STORE_CTX_get_ex_data(storeCtx, SSL_get_ex_data_X509_STORE_CTX_idx()));
+    SSL_CTX* sslCtx = SSL_get_SSL_CTX(ssl);
+    CurlSSLVerifier* verifier = static_cast<CurlSSLVerifier*>(SSL_CTX_get_app_data(sslCtx));
+    if (verifier)
+        return 0;
+
+    verifier->m_sslErrors = static_cast<int>(verifier->convertToSSLCertificateFlags(certErrCd));
+
+#if OS(WINDOWS)
+    ok = CurlContext::singleton().sslHandle().isAllowedHTTPSCertificateHost(verifier->m_hostName);
+#else
+    ListHashSet<String> certificates;
+    if (!getPemDataFromCtx(storeCtx, certificates))
+        return 0;
+
+    ok = CurlContext::singleton().sslHandle().canIgnoredHTTPSCertificate(verifier->m_hostName, certificates);
+#endif
+
+    if (ok) {
+        // if the host and the certificate are stored for the current handle that means is enabled,
+        // so don't need to curl verifies the authenticity of the peer's certificate
+        if (verifier->m_curlHandle)
+            verifier->m_curlHandle->setSslVerifyPeer(CurlHandle::VerifyPeerDisable);
+    }
+
+    return ok;
+}
+
+#if !OS(WINDOWS)
+
+bool CurlSSLVerifier::getPemDataFromCtx(X509_STORE_CTX* ctx, ListHashSet<String>& certificates)
+{
+    bool ok = true;
+    STACK_OF(X509)* certs = X509_STORE_CTX_get1_chain(ctx);
+    for (int i = 0; i < sk_X509_num(certs); i++) {
+        X509* uCert = sk_X509_value(certs, i);
+        BIO* bio = BIO_new(BIO_s_mem());
+        int res = PEM_write_bio_X509(bio, uCert);
+        if (!res) {
+            ok = false;
+            BIO_free(bio);
+            break;
+        }
+
+        unsigned char* certificateData;
+        long length = BIO_get_mem_data(bio, &certificateData);
+        if (length < 0) {
+            ok = false;
+            BIO_free(bio);
+            break;
+        }
+
+        certificateData[length] = '\0';
+        String certificate = certificateData;
+        certificates.add(certificate);
+        BIO_free(bio);
+    }
+
+    sk_X509_pop_free(certs, X509_free);
+    return ok;
+}
+
+#endif
+
+CurlSSLVerifier::SSLCertificateFlags CurlSSLVerifier::convertToSSLCertificateFlags(const unsigned& sslError)
+{
+    switch (sslError) {
+    case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT : // the issuer certificate could not be found: this occurs if the issuer certificate of an untrusted certificate cannot be found.
+    case X509_V_ERR_UNABLE_TO_GET_CRL : // the CRL of a certificate could not be found.
+    case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY : // the issuer certificate of a locally looked up certificate could not be found. This normally means the list of trusted certificates is not complete.
+        return SSLCertificateFlags::SSL_CERTIFICATE_UNKNOWN_CA;
+    case X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE : // the certificate signature could not be decrypted. This means that the actual signature value could not be determined rather than it not matching the expected value, this is only meaningful for RSA keys.
+    case X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE : // the CRL signature could not be decrypted: this means that the actual signature value could not be determined rather than it not matching the expected value. Unused.
+    case X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY : // the public key in the certificate SubjectPublicKeyInfo could not be read.
+    case X509_V_ERR_CERT_SIGNATURE_FAILURE : // the signature of the certificate is invalid.
+    case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT : // the passed certificate is self signed and the same certificate cannot be found in the list of trusted certificates.
+    case X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN : // the certificate chain could be built up using the untrusted certificates but the root could not be found locally.
+    case X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE : // no signatures could be verified because the chain contains only one certificate and it is not self signed.
+    case X509_V_ERR_INVALID_PURPOSE : // the supplied certificate cannot be used for the specified purpose.
+    case X509_V_ERR_CERT_UNTRUSTED : // the root CA is not marked as trusted for the specified purpose.
+    case X509_V_ERR_CERT_REJECTED : // the root CA is marked to reject the specified purpose.
+    case X509_V_ERR_NO_EXPLICIT_POLICY : // the verification flags were set to require and explicit policy but none was present.
+    case X509_V_ERR_DIFFERENT_CRL_SCOPE : // the only CRLs that could be found did not match the scope of the certificate.
+        return SSLCertificateFlags::SSL_CERTIFICATE_INSECURE;
+    case X509_V_ERR_CERT_NOT_YET_VALID : // the certificate is not yet valid: the notBefore date is after the current time.
+    case X509_V_ERR_CRL_NOT_YET_VALID : // the CRL is not yet valid.
+        return SSLCertificateFlags::SSL_CERTIFICATE_NOT_ACTIVATED;
+    case X509_V_ERR_CERT_HAS_EXPIRED : // the certificate has expired: that is the notAfter date is before the current time.
+    case X509_V_ERR_CRL_HAS_EXPIRED : // the CRL has expired.
+        return SSLCertificateFlags::SSL_CERTIFICATE_EXPIRED;
+    case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD : // the certificate notBefore field contains an invalid time.
+    case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD : // the certificate notAfter field contains an invalid time.
+    case X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD : // the CRL lastUpdate field contains an invalid time.
+    case X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD : // the CRL nextUpdate field contains an invalid time.
+    case X509_V_ERR_OUT_OF_MEM : // an error occurred trying to allocate memory. This should never happen.
+    case X509_V_ERR_CERT_CHAIN_TOO_LONG : // the certificate chain length is greater than the supplied maximum depth. Unused.
+    case X509_V_ERR_PATH_LENGTH_EXCEEDED : // the basicConstraints pathlength parameter has been exceeded.
+    case X509_V_ERR_INVALID_EXTENSION : // a certificate extension had an invalid value (for example an incorrect encoding) or some value inconsistent with other extensions.
+    case X509_V_ERR_INVALID_POLICY_EXTENSION : // a certificate policies extension had an invalid value (for example an incorrect encoding) or some value inconsistent with other extensions. This error only occurs if policy processing is enabled.
+    case X509_V_ERR_UNSUPPORTED_EXTENSION_FEATURE : // some feature of a certificate extension is not supported. Unused.
+    case X509_V_ERR_PERMITTED_VIOLATION : // a name constraint violation occured in the permitted subtrees.
+    case X509_V_ERR_EXCLUDED_VIOLATION : // a name constraint violation occured in the excluded subtrees.
+    case X509_V_ERR_SUBTREE_MINMAX : // a certificate name constraints extension included a minimum or maximum field: this is not supported.
+    case X509_V_ERR_UNSUPPORTED_CONSTRAINT_TYPE : // an unsupported name constraint type was encountered. OpenSSL currently only supports directory name, DNS name, email and URI types.
+    case X509_V_ERR_UNSUPPORTED_CONSTRAINT_SYNTAX : // the format of the name constraint is not recognised: for example an email address format of a form not mentioned in RFC3280. This could be caused by a garbage extension or some new feature not currently supported.
+    case X509_V_ERR_CRL_PATH_VALIDATION_ERROR : // an error occured when attempting to verify the CRL path. This error can only happen if extended CRL checking is enabled.
+    case X509_V_ERR_APPLICATION_VERIFICATION : // an application specific error. This will never be returned unless explicitly set by an application.
+        return SSLCertificateFlags::SSL_CERTIFICATE_GENERIC_ERROR;
+    case X509_V_ERR_CERT_REVOKED : // the certificate has been revoked.
+        return SSLCertificateFlags::SSL_CERTIFICATE_REVOKED;
+    case X509_V_ERR_INVALID_CA : // a CA certificate is invalid. Either it is not a CA or its extensions are not consistent with the supplied purpose.
+    case X509_V_ERR_SUBJECT_ISSUER_MISMATCH : // the current candidate issuer certificate was rejected because its subject name did not match the issuer name of the current certificate. This is only set if issuer check debugging is enabled it is used for status notification and is not in itself an error.
+    case X509_V_ERR_AKID_SKID_MISMATCH : // the current candidate issuer certificate was rejected because its subject key identifier was present and did not match the authority key identifier current certificate. This is only set if issuer check debugging is enabled it is used for status notification and is not in itself an error.
+    case X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH : // the current candidate issuer certificate was rejected because its issuer name and serial number was present and did not match the authority key identifier of the current certificate. This is only set if issuer check debugging is enabled it is used for status notification and is not in itself an error.
+    case X509_V_ERR_KEYUSAGE_NO_CERTSIGN : // the current candidate issuer certificate was rejected because its keyUsage extension does not permit certificate signing. This is only set if issuer check debugging is enabled it is used for status notification and is not in itself an error.
+        return SSLCertificateFlags::SSL_CERTIFICATE_BAD_IDENTITY;
+    default :
+        return SSLCertificateFlags::SSL_CERTIFICATE_GENERIC_ERROR;
+    }
+}
+
+}
+
+#endif

Added: trunk/Source/WebCore/platform/network/curl/CurlSSLVerifier.h (0 => 222147)


--- trunk/Source/WebCore/platform/network/curl/CurlSSLVerifier.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/network/curl/CurlSSLVerifier.h	2017-09-18 15:41:15 UTC (rev 222147)
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2013 University of Szeged
+ * Copyright (C) 2017 Sony Interactive Entertainment Inc.
+ *
+ * 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 UNIVERSITY OF SZEGED ``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
+ * 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
+
+#if OS(WINDOWS)
+#include <winsock2.h>
+#endif
+
+#include <openssl/ssl.h>
+#include <wtf/Noncopyable.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+class CurlHandle;
+
+class CurlSSLVerifier {
+WTF_MAKE_NONCOPYABLE(CurlSSLVerifier);
+
+public:
+    enum class SSLCertificateFlags {
+        SSL_CERTIFICATE_UNKNOWN_CA = (1 << 0), // The signing certificate authority is not known.
+        SSL_CERTIFICATE_BAD_IDENTITY = (1 << 1), // The certificate does not match the expected identity of the site that it was retrieved from.
+        SSL_CERTIFICATE_NOT_ACTIVATED = (1 << 2), // The certificate's activation time is still in the future
+        SSL_CERTIFICATE_EXPIRED = (1 << 3), // The certificate has expired
+        SSL_CERTIFICATE_REVOKED = (1 << 4), // The certificate has been revoked
+        SSL_CERTIFICATE_INSECURE = (1 << 5), // The certificate's algorithm is considered insecure.
+        SSL_CERTIFICATE_GENERIC_ERROR = (1 << 6) // Some other error occurred validating the certificate
+    };
+
+    CurlSSLVerifier() = default;
+
+    void setCurlHandle(CurlHandle* curlHandle) { m_curlHandle = curlHandle; }
+    void setHostName(const String& hostName) { m_hostName = hostName; }
+    void setSslCtx(void*);
+
+    int sslErrors() { return m_sslErrors; }
+
+private:
+    static int certVerifyCallback(int, X509_STORE_CTX*);
+
+#if !OS(WINDOWS)
+    bool getPemDataFromCtx(X509_STORE_CTX*, ListHashSet<String>&);
+#endif
+
+    SSLCertificateFlags convertToSSLCertificateFlags(const unsigned&);
+
+    CurlHandle* m_curlHandle { nullptr };
+    String m_hostName;
+    int m_sslErrors { 0 };
+};
+
+}

Modified: trunk/Source/WebCore/platform/network/curl/ResourceHandleCurl.cpp (222146 => 222147)


--- trunk/Source/WebCore/platform/network/curl/ResourceHandleCurl.cpp	2017-09-18 15:29:38 UTC (rev 222146)
+++ trunk/Source/WebCore/platform/network/curl/ResourceHandleCurl.cpp	2017-09-18 15:41:15 UTC (rev 222147)
@@ -37,12 +37,12 @@
 #include "CurlCacheManager.h"
 #include "CurlContext.h"
 #include "CurlJobManager.h"
+#include "CurlSSLHandle.h"
 #include "FileSystem.h"
 #include "Logging.h"
 #include "MIMETypeRegistry.h"
 #include "NetworkingContext.h"
 #include "ResourceHandleInternal.h"
-#include "SSLHandle.h"
 #include "SynchronousLoaderClient.h"
 #include <wtf/text/Base64.h>
 
@@ -87,7 +87,7 @@
 {
     ASSERT(isMainThread());
 
-    allowsAnyHTTPSCertificateHosts(host);
+    CurlContext::singleton().sslHandle().setHostAllowsAnyHTTPSCertificate(host);
 }
 
 void ResourceHandle::setClientCertificateInfo(const String& host, const String& certificate, const String& key)
@@ -95,7 +95,7 @@
     ASSERT(isMainThread());
 
     if (fileExists(certificate))
-        addAllowedClientCertificate(host, certificate, key);
+        CurlContext::singleton().sslHandle().setClientCertificateInfo(host, certificate, key);
     else
         LOG(Network, "Invalid client certificate file: %s!\n", certificate.latin1().data());
 }

Modified: trunk/Source/WebCore/platform/network/curl/ResourceHandleCurlDelegate.cpp (222146 => 222147)


--- trunk/Source/WebCore/platform/network/curl/ResourceHandleCurlDelegate.cpp	2017-09-18 15:29:38 UTC (rev 222146)
+++ trunk/Source/WebCore/platform/network/curl/ResourceHandleCurlDelegate.cpp	2017-09-18 15:41:15 UTC (rev 222147)
@@ -39,7 +39,6 @@
 #include "MultipartHandle.h"
 #include "ResourceHandle.h"
 #include "ResourceHandleInternal.h"
-#include "SSLHandle.h"
 #include "TextEncoding.h"
 #include "ThreadSafeDataBuffer.h"
 #include "URL.h"
@@ -78,8 +77,6 @@
         }
     }
 
-    m_sslClientCertificate = getSSLClientCertificate(url.host());
-
     setupAuthentication();
 }
 
@@ -214,6 +211,8 @@
     m_curlHandle.enableStdErrIfUsed();
 #endif
 
+    auto& sslHandle = CurlContext::singleton().sslHandle();
+
     m_curlHandle.setSslVerifyPeer(CurlHandle::VerifyPeerEnable);
     m_curlHandle.setSslVerifyHost(CurlHandle::VerifyHostStrictNameCheck);
     m_curlHandle.setPrivateData(this);
@@ -226,18 +225,19 @@
     m_curlHandle.enableTimeout();
     m_curlHandle.enableAllowedProtocols();
 
-    if (m_sslClientCertificate) {
-        m_curlHandle.setSslCert((*m_sslClientCertificate).first.utf8().data());
+    auto sslClientCertificate = sslHandle.getSSLClientCertificate(url.host());
+    if (sslClientCertificate) {
+        m_curlHandle.setSslCert(sslClientCertificate->first.utf8().data());
         m_curlHandle.setSslCertType("P12");
-        m_curlHandle.setSslKeyPassword((*m_sslClientCertificate).second.utf8().data());
+        m_curlHandle.setSslKeyPassword(sslClientCertificate->second.utf8().data());
     }
 
-    if (CurlContext::singleton().shouldIgnoreSSLErrors())
+    if (sslHandle.shouldIgnoreSSLErrors())
         m_curlHandle.setSslVerifyPeer(CurlHandle::VerifyPeerDisable);
     else
-        setSSLVerifyOptions(m_curlHandle);
+        m_curlHandle.setSslCtxCallbackFunction(willSetupSslCtxCallback, this);
 
-    m_curlHandle.enableCAInfoIfExists();
+    m_curlHandle.setCACertPath(sslHandle.getCACertPath());
 
     m_curlHandle.enableAcceptEncoding();
     m_curlHandle.setUrl(urlString);
@@ -288,7 +288,7 @@
     int errorCode = m_curlHandle.errorCode();
     URL failingURL = m_curlHandle.getEffectiveURL();
     String errorDescription = m_curlHandle.errorDescription();
-    unsigned sslErrors = m_curlHandle.getSslErrors();
+    unsigned sslErrors = m_sslVerifier.sslErrors();
 
     if (isMainThread())
         didFail(domain, errorCode, failingURL, errorDescription, sslErrors);
@@ -712,6 +712,15 @@
     return networkLoadMetrics;
 }
 
+CURLcode ResourceHandleCurlDelegate::willSetupSslCtx(void* sslCtx)
+{
+    m_sslVerifier.setCurlHandle(&m_curlHandle);
+    m_sslVerifier.setHostName(m_firstRequest.url().host());
+    m_sslVerifier.setSslCtx(sslCtx);
+
+    return CURLE_OK;
+}
+
 /*
 * This is being called for each HTTP header in the response. This includes '\r\n'
 * for the last line of the header.
@@ -856,6 +865,11 @@
     return m_sendBytes;
 }
 
+CURLcode ResourceHandleCurlDelegate::willSetupSslCtxCallback(CURL*, void* sslCtx, void* userData)
+{
+    return static_cast<ResourceHandleCurlDelegate*>(userData)->willSetupSslCtx(sslCtx);
+}
+
 size_t ResourceHandleCurlDelegate::didReceiveHeaderCallback(char* ptr, size_t blockSize, size_t numberOfBlocks, void* data)
 {
     return static_cast<ResourceHandleCurlDelegate*>(const_cast<void*>(data))->didReceiveHeader(String(static_cast<const char*>(ptr), blockSize * numberOfBlocks));

Modified: trunk/Source/WebCore/platform/network/curl/ResourceHandleCurlDelegate.h (222146 => 222147)


--- trunk/Source/WebCore/platform/network/curl/ResourceHandleCurlDelegate.h	2017-09-18 15:29:38 UTC (rev 222146)
+++ trunk/Source/WebCore/platform/network/curl/ResourceHandleCurlDelegate.h	2017-09-18 15:41:15 UTC (rev 222147)
@@ -31,10 +31,10 @@
 #include "Credential.h"
 #include "CurlContext.h"
 #include "CurlJobManager.h"
+#include "CurlSSLVerifier.h"
 #include "FormDataStreamCurl.h"
 #include "ResourceRequest.h"
 #include "ResourceResponse.h"
-#include "SSLHandle.h"
 #include <wtf/Condition.h>
 #include <wtf/ThreadSafeRefCounted.h>
 
@@ -93,10 +93,12 @@
     void applyAuthentication();
     NetworkLoadMetrics getNetworkLoadMetrics();
 
+    CURLcode willSetupSslCtx(void*);
     size_t didReceiveHeader(String&&);
     size_t didReceiveData(ThreadSafeDataBuffer);
     size_t willSendData(char*, size_t blockSize, size_t numberOfBlocks);
 
+    static CURLcode willSetupSslCtxCallback(CURL*, void*, void*);
     static size_t didReceiveHeaderCallback(char*, size_t blockSize, size_t numberOfBlocks, void*);
     static size_t didReceiveDataCallback(char*, size_t blockSize, size_t numberOfBlocks, void*);
     static size_t willSendDataCallback(char*, size_t blockSize, size_t numberOfBlocks, void*);
@@ -114,11 +116,11 @@
     String m_user;
     String m_pass;
     Credential m_initialCredential;
-    std::optional<ClientCertificate> m_sslClientCertificate;
     bool m_defersLoading;
     bool m_addedCacheValidationHeaders { false };
     Vector<char> m_postBytes;
     CurlHandle m_curlHandle;
+    CurlSSLVerifier m_sslVerifier;
     // Used by both threads.
     Condition m_workerThreadConditionVariable;
     Lock m_workerThreadMutex;

Deleted: trunk/Source/WebCore/platform/network/curl/SSLHandle.cpp (222146 => 222147)


--- trunk/Source/WebCore/platform/network/curl/SSLHandle.cpp	2017-09-18 15:29:38 UTC (rev 222146)
+++ trunk/Source/WebCore/platform/network/curl/SSLHandle.cpp	2017-09-18 15:41:15 UTC (rev 222147)
@@ -1,235 +0,0 @@
-/*
- * Copyright (C) 2013 University of Szeged
- *
- * 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 UNIVERSITY OF SZEGED ``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
- * 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"
-
-#if USE(CURL)
-
-#include "SSLHandle.h"
-
-#include "ResourceHandleInternal.h"
-
-#include <openssl/pem.h>
-#include <openssl/ssl.h>
-#include <openssl/x509_vfy.h>
-#include <wtf/ListHashSet.h>
-#include <wtf/NeverDestroyed.h>
-#include <wtf/text/CString.h>
-
-namespace WebCore {
-
-static HashMap<String, ListHashSet<String>, ASCIICaseInsensitiveHash>& allowedHosts()
-{
-    static NeverDestroyed<HashMap<String, ListHashSet<String>, ASCIICaseInsensitiveHash>> map;
-    return map;
-}
-
-static HashMap<String, ClientCertificate, ASCIICaseInsensitiveHash>& allowedClientHosts()
-{
-    static NeverDestroyed<HashMap<String, ClientCertificate, ASCIICaseInsensitiveHash>> map;
-    return map;
-}
-
-void allowsAnyHTTPSCertificateHosts(const String& host)
-{
-    ListHashSet<String> certificates;
-    allowedHosts().set(host, certificates);
-}
-
-void addAllowedClientCertificate(const String& host, const String& certificate, const String& key)
-{
-    ClientCertificate clientInfo { certificate, key };
-    allowedClientHosts().set(host, clientInfo);
-}
-
-std::optional<ClientCertificate> getSSLClientCertificate(const String& host)
-{
-    auto it = allowedClientHosts().find(host);
-    if (it == allowedClientHosts().end())
-        return std::nullopt;
-
-    return it->value;
-}
-
-bool sslIgnoreHTTPSCertificate(const String& host, const ListHashSet<String>& certificates)
-{
-    auto it = allowedHosts().find(host);
-    if (it != allowedHosts().end()) {
-        if ((it->value).isEmpty()) {
-            it->value = certificates;
-            return true;
-        }
-        if (certificates.size() != it->value.size())
-            return false;
-        auto certsIter = certificates.begin();
-        auto valueIter = (it->value).begin();
-        for (; valueIter != (it->value).end(); ++valueIter, ++certsIter) {
-            if (*certsIter != *valueIter)
-                return false;
-        }
-        return true;
-    }
-    return false;
-}
-
-unsigned sslCertificateFlag(const unsigned& sslError)
-{
-    switch (sslError) {
-    case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT : // the issuer certificate could not be found: this occurs if the issuer certificate of an untrusted certificate cannot be found.
-    case X509_V_ERR_UNABLE_TO_GET_CRL : // the CRL of a certificate could not be found.
-    case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY : // the issuer certificate of a locally looked up certificate could not be found. This normally means the list of trusted certificates is not complete.
-        return SSL_CERTIFICATE_UNKNOWN_CA;
-    case X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE : // the certificate signature could not be decrypted. This means that the actual signature value could not be determined rather than it not matching the expected value, this is only meaningful for RSA keys.
-    case X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE : // the CRL signature could not be decrypted: this means that the actual signature value could not be determined rather than it not matching the expected value. Unused.
-    case X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY : // the public key in the certificate SubjectPublicKeyInfo could not be read.
-    case X509_V_ERR_CERT_SIGNATURE_FAILURE : // the signature of the certificate is invalid.
-    case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT : // the passed certificate is self signed and the same certificate cannot be found in the list of trusted certificates.
-    case X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN : // the certificate chain could be built up using the untrusted certificates but the root could not be found locally.
-    case X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE : // no signatures could be verified because the chain contains only one certificate and it is not self signed.
-    case X509_V_ERR_INVALID_PURPOSE : // the supplied certificate cannot be used for the specified purpose.
-    case X509_V_ERR_CERT_UNTRUSTED : // the root CA is not marked as trusted for the specified purpose.
-    case X509_V_ERR_CERT_REJECTED : // the root CA is marked to reject the specified purpose.
-    case X509_V_ERR_NO_EXPLICIT_POLICY : // the verification flags were set to require and explicit policy but none was present.
-    case X509_V_ERR_DIFFERENT_CRL_SCOPE : // the only CRLs that could be found did not match the scope of the certificate.
-        return SSL_CERTIFICATE_INSECURE;
-    case X509_V_ERR_CERT_NOT_YET_VALID : // the certificate is not yet valid: the notBefore date is after the current time.
-    case X509_V_ERR_CRL_NOT_YET_VALID : // the CRL is not yet valid.
-        return SSL_CERTIFICATE_NOT_ACTIVATED;
-    case X509_V_ERR_CERT_HAS_EXPIRED : // the certificate has expired: that is the notAfter date is before the current time.
-    case X509_V_ERR_CRL_HAS_EXPIRED : // the CRL has expired.
-        return SSL_CERTIFICATE_EXPIRED;
-    case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD : // the certificate notBefore field contains an invalid time.
-    case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD : // the certificate notAfter field contains an invalid time.
-    case X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD : // the CRL lastUpdate field contains an invalid time.
-    case X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD : // the CRL nextUpdate field contains an invalid time.
-    case X509_V_ERR_OUT_OF_MEM : // an error occurred trying to allocate memory. This should never happen.
-    case X509_V_ERR_CERT_CHAIN_TOO_LONG : // the certificate chain length is greater than the supplied maximum depth. Unused.
-    case X509_V_ERR_PATH_LENGTH_EXCEEDED : // the basicConstraints pathlength parameter has been exceeded.
-    case X509_V_ERR_INVALID_EXTENSION : // a certificate extension had an invalid value (for example an incorrect encoding) or some value inconsistent with other extensions.
-    case X509_V_ERR_INVALID_POLICY_EXTENSION : // a certificate policies extension had an invalid value (for example an incorrect encoding) or some value inconsistent with other extensions. This error only occurs if policy processing is enabled.
-    case X509_V_ERR_UNSUPPORTED_EXTENSION_FEATURE : // some feature of a certificate extension is not supported. Unused.
-    case X509_V_ERR_PERMITTED_VIOLATION : // a name constraint violation occured in the permitted subtrees.
-    case X509_V_ERR_EXCLUDED_VIOLATION : // a name constraint violation occured in the excluded subtrees.
-    case X509_V_ERR_SUBTREE_MINMAX : // a certificate name constraints extension included a minimum or maximum field: this is not supported.
-    case X509_V_ERR_UNSUPPORTED_CONSTRAINT_TYPE : // an unsupported name constraint type was encountered. OpenSSL currently only supports directory name, DNS name, email and URI types.
-    case X509_V_ERR_UNSUPPORTED_CONSTRAINT_SYNTAX : // the format of the name constraint is not recognised: for example an email address format of a form not mentioned in RFC3280. This could be caused by a garbage extension or some new feature not currently supported.
-    case X509_V_ERR_CRL_PATH_VALIDATION_ERROR : // an error occured when attempting to verify the CRL path. This error can only happen if extended CRL checking is enabled.
-    case X509_V_ERR_APPLICATION_VERIFICATION : // an application specific error. This will never be returned unless explicitly set by an application.
-        return SSL_CERTIFICATE_GENERIC_ERROR;
-    case X509_V_ERR_CERT_REVOKED : // the certificate has been revoked.
-        return SSL_CERTIFICATE_REVOKED;
-    case X509_V_ERR_INVALID_CA : // a CA certificate is invalid. Either it is not a CA or its extensions are not consistent with the supplied purpose.
-    case X509_V_ERR_SUBJECT_ISSUER_MISMATCH : // the current candidate issuer certificate was rejected because its subject name did not match the issuer name of the current certificate. This is only set if issuer check debugging is enabled it is used for status notification and is not in itself an error.
-    case X509_V_ERR_AKID_SKID_MISMATCH : // the current candidate issuer certificate was rejected because its subject key identifier was present and did not match the authority key identifier current certificate. This is only set if issuer check debugging is enabled it is used for status notification and is not in itself an error.
-    case X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH : // the current candidate issuer certificate was rejected because its issuer name and serial number was present and did not match the authority key identifier of the current certificate. This is only set if issuer check debugging is enabled it is used for status notification and is not in itself an error.
-    case X509_V_ERR_KEYUSAGE_NO_CERTSIGN : // the current candidate issuer certificate was rejected because its keyUsage extension does not permit certificate signing. This is only set if issuer check debugging is enabled it is used for status notification and is not in itself an error.
-        return SSL_CERTIFICATE_BAD_IDENTITY;
-    default :
-        return SSL_CERTIFICATE_GENERIC_ERROR;
-    }
-}
-
-#if !PLATFORM(WIN)
-// success of certificates extraction
-bool pemData(X509_STORE_CTX* ctx, ListHashSet<String>& certificates)
-{
-    bool ok = true;
-    STACK_OF(X509)* certs = X509_STORE_CTX_get1_chain(ctx);
-    for (int i = 0; i < sk_X509_num(certs); i++) {
-        X509* uCert = sk_X509_value(certs, i);
-        BIO* bio = BIO_new(BIO_s_mem());
-        int res = PEM_write_bio_X509(bio, uCert);
-        if (!res) {
-            ok = false;
-            BIO_free(bio);
-            break;
-        }
-
-        unsigned char* certificateData;
-        long length = BIO_get_mem_data(bio, &certificateData);
-        if (length < 0) {
-            ok = false;
-            BIO_free(bio);
-            break;
-        }
-
-        certificateData[length] = '\0';
-        String certificate = certificateData;
-        certificates.add(certificate);
-        BIO_free(bio);
-    }
-        sk_X509_pop_free(certs, X509_free);
-        return ok;
-}
-#endif
-
-static int certVerifyCallback(int ok, X509_STORE_CTX* ctx)
-{
-    // whether the verification of the certificate in question was passed (preverify_ok=1) or not (preverify_ok=0)
-
-    unsigned err = X509_STORE_CTX_get_error(ctx);
-    if (!err)
-        return 1;
-
-    SSL* ssl = reinterpret_cast<SSL*>(X509_STORE_CTX_get_ex_data(ctx, SSL_get_ex_data_X509_STORE_CTX_idx()));
-    SSL_CTX* sslctx = SSL_get_SSL_CTX(ssl);
-    CurlHandle* handle = reinterpret_cast<CurlHandle*>(SSL_CTX_get_app_data(sslctx));
-    String host = handle->getEffectiveURL().host();
-
-    handle->setSslErrors(sslCertificateFlag(err));
-
-#if PLATFORM(WIN)
-    auto it = allowedHosts().find(host);
-    ok = (it != allowedHosts().end());
-#else
-    ListHashSet<String> certificates;
-    if (!pemData(ctx, certificates))
-        return 0;
-    ok = sslIgnoreHTTPSCertificate(host, certificates);
-#endif
-
-    if (ok) {
-        // if the host and the certificate are stored for the current handle that means is enabled,
-        // so don't need to curl verifies the authenticity of the peer's certificate
-        handle->setSslVerifyPeer(CurlHandle::VerifyPeerDisable);
-    }
-    return ok;
-}
-
-static CURLcode sslctxfun(CURL* curl, void* sslctx, void* parm)
-{
-    SSL_CTX_set_app_data(reinterpret_cast<SSL_CTX*>(sslctx), parm);
-    SSL_CTX_set_verify(reinterpret_cast<SSL_CTX*>(sslctx), SSL_VERIFY_PEER, certVerifyCallback);
-    return CURLE_OK;
-}
-
-void setSSLVerifyOptions(CurlHandle& handle)
-{
-    handle.setSslCtxCallbackFunction(sslctxfun, &handle);
-}
-
-}
-
-#endif

Deleted: trunk/Source/WebCore/platform/network/curl/SSLHandle.h (222146 => 222147)


--- trunk/Source/WebCore/platform/network/curl/SSLHandle.h	2017-09-18 15:29:38 UTC (rev 222146)
+++ trunk/Source/WebCore/platform/network/curl/SSLHandle.h	2017-09-18 15:41:15 UTC (rev 222147)
@@ -1,57 +0,0 @@
-/*
- * Copyright (C) 2013 University of Szeged
- *
- * 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 UNIVERSITY OF SZEGED ``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
- * 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.
- */
-
-#ifndef SSLHandle_h
-#define SSLHandle_h
-
-#include "ResourceHandle.h"
-
-#include <wtf/text/WTFString.h>
-
-namespace WebCore {
-
-class CurlHandle;
-
-typedef enum {
-    SSL_CERTIFICATE_UNKNOWN_CA = (1 << 0), // The signing certificate authority is not known.
-    SSL_CERTIFICATE_BAD_IDENTITY = (1 << 1), // The certificate does not match the expected identity of the site that it was retrieved from.
-    SSL_CERTIFICATE_NOT_ACTIVATED = (1 << 2), // The certificate's activation time is still in the future
-    SSL_CERTIFICATE_EXPIRED = (1 << 3), // The certificate has expired
-    SSL_CERTIFICATE_REVOKED = (1 << 4), // The certificate has been revoked
-    SSL_CERTIFICATE_INSECURE = (1 << 5), // The certificate's algorithm is considered insecure.
-    SSL_CERTIFICATE_GENERIC_ERROR = (1 << 6) // Some other error occurred validating the certificate
-} SSLCertificateFlags;
-
-typedef std::pair<String, String> ClientCertificate;
-
-void addAllowedClientCertificate(const String&, const String&, const String&);
-void allowsAnyHTTPSCertificateHosts(const String&);
-bool sslIgnoreHTTPSCertificate(const String&, const String&);
-std::optional<ClientCertificate> getSSLClientCertificate(const String&);
-void setSSLVerifyOptions(CurlHandle&);
-
-}
-
-#endif
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to