Changeset 249192 in webkit


Ignore:
Timestamp:
Aug 28, 2019 3:15:36 AM (5 years ago)
Author:
Claudio Saavedra
Message:

[GTK][WPE] Implement HSTS for the soup network backend
https://bugs.webkit.org/show_bug.cgi?id=192074

Reviewed by Carlos Garcia Campos.

libsoup 2.67.1 introduced HSTS support via a SoupSessionFeature.
Add support to the soup network backend by adding the feature to
SoupNetworkSession and handling HSTS protocol upgrades, by
propagating the scheme change further to clients. This patch adds
the HSTS feature unconditionally, but it still possible to add
a boolean property to the web context class if desired.

Additionally, add API to the WebKitWebsiteDataManager to specify
the directory where the HSTS database is saved. If the directory
is not set or if the data manager is ephemeral, use a
non-persistent, memory only HSTS enforcer.

Implement as well the methods needed to clean-up and delete HSTS
Source/WebCore:

policies from the storage and expose the feature in GTK+ MiniBrowser's
about:data.

  • platform/network/soup/GUniquePtrSoup.h:
  • platform/network/soup/SoupNetworkSession.cpp:

(WebCore::hstsStorageDirectory):
(WebCore::SoupNetworkSession::SoupNetworkSession):
(WebCore::SoupNetworkSession::setHSTSPersistentStorage):
(WebCore::SoupNetworkSession::setupHSTSEnforcer):
(WebCore::SoupNetworkSession::getHostNamesWithHSTSCache):
(WebCore::SoupNetworkSession::deleteHSTSCacheForHostNames):
(WebCore::SoupNetworkSession::clearHSTSCache):

  • platform/network/soup/SoupNetworkSession.h:

Source/WebKit:

policies from the storage and expose the feature in GTK+
MiniBrowser's about:data.

  • NetworkProcess/NetworkProcess.cpp:

(WebKit::NetworkProcess::fetchWebsiteData):
(WebKit::NetworkProcess::deleteWebsiteData):
(WebKit::NetworkProcess::deleteWebsiteDataForOrigins):
(WebKit::NetworkProcess::deleteWebsiteDataForRegistrableDomains):
(WebKit::NetworkProcess::registrableDomainsWithWebsiteData):

  • NetworkProcess/NetworkProcess.h:

(WebKit::NetworkProcess::suppressesConnectionTerminationOnSystemChange const):

  • NetworkProcess/soup/NetworkDataTaskSoup.cpp:

(WebKit::NetworkDataTaskSoup::createRequest):
(WebKit::NetworkDataTaskSoup::clearRequest):
(WebKit::NetworkDataTaskSoup::shouldAllowHSTSPolicySetting const):
(WebKit::NetworkDataTaskSoup::shouldAllowHSTSProtocolUpgrade const):
(WebKit::NetworkDataTaskSoup::protocolUpgradedViaHSTS):
(WebKit::NetworkDataTaskSoup::hstsEnforced):

  • NetworkProcess/soup/NetworkDataTaskSoup.h:
  • NetworkProcess/soup/NetworkProcessSoup.cpp:

(WebKit::NetworkProcess::getHostNamesWithHSTSCache):
(WebKit::NetworkProcess::deleteHSTSCacheForHostNames):
(WebKit::NetworkProcess::clearHSTSCache):
(WebKit::NetworkProcess::platformInitializeNetworkProcess):

  • UIProcess/API/APIWebsiteDataStore.h:
  • UIProcess/API/glib/APIWebsiteDataStoreGLib.cpp:

(API::WebsiteDataStore::defaultHSTSDirectory):

  • UIProcess/API/glib/WebKitWebContext.cpp:

(webkitWebContextConstructed):

  • UIProcess/API/glib/WebKitWebsiteData.cpp:

(recordContainsSupportedDataTypes):
(toWebKitWebsiteDataTypes):

  • UIProcess/API/glib/WebKitWebsiteDataManager.cpp:

(webkitWebsiteDataManagerGetProperty):
(webkitWebsiteDataManagerSetProperty):
(webkitWebsiteDataManagerConstructed):
(webkit_website_data_manager_class_init):
(webkitWebsiteDataManagerGetDataStore):
(webkit_website_data_manager_get_hsts_cache_directory):
(toWebsiteDataTypes):

  • UIProcess/API/gtk/WebKitWebsiteData.h:
  • UIProcess/API/gtk/WebKitWebsiteDataManager.h:
  • UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt:
  • UIProcess/API/wpe/WebKitWebsiteData.h:
  • UIProcess/API/wpe/WebKitWebsiteDataManager.h:
  • UIProcess/API/wpe/docs/wpe-1.0-sections.txt:
  • UIProcess/WebsiteData/WebsiteDataStoreConfiguration.cpp:

(WebKit::WebsiteDataStoreConfiguration::copy):

  • UIProcess/WebsiteData/WebsiteDataStoreConfiguration.h:

(WebKit::WebsiteDataStoreConfiguration::hstsStorageDirectory const):
(WebKit::WebsiteDataStoreConfiguration::setHSTSStorageDirectory):

Tools:

policies from the storage and expose the feature in GTK+
MiniBrowser's about:data.

  • MiniBrowser/gtk/main.c:

(gotWebsiteDataCallback):

  • TestWebKitAPI/Tests/WebKitGLib/TestWebsiteData.cpp:

(serverCallback):
(testWebsiteDataConfiguration):
(testWebsiteDataEphemeral):
(prepopulateHstsData):
(testWebsiteDataHsts):
(beforeAll):

  • TestWebKitAPI/glib/WebKitGLib/TestMain.h:

(Test::Test):

  • gtk/jhbuild.modules: Bump libsoup to 2.67.91 for the new APIs
  • wpe/jhbuild.modules: Ditto
  • MiniBrowser/gtk/main.c:

(gotWebsiteDataCallback):

Location:
trunk
Files:
29 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r249191 r249192  
     12019-08-28  Claudio Saavedra  <csaavedra@igalia.com>
     2
     3        [GTK][WPE] Implement HSTS for the soup network backend
     4        https://bugs.webkit.org/show_bug.cgi?id=192074
     5
     6        Reviewed by Carlos Garcia Campos.
     7
     8        libsoup 2.67.1 introduced HSTS support via a SoupSessionFeature.
     9        Add support to the soup network backend by adding the feature to
     10        SoupNetworkSession and handling HSTS protocol upgrades, by
     11        propagating the scheme change further to clients. This patch adds
     12        the HSTS feature unconditionally, but it still possible to add
     13        a boolean property to the web context class if desired.
     14
     15        Additionally, add API to the WebKitWebsiteDataManager to specify
     16        the directory where the HSTS database is saved. If the directory
     17        is not set or if the data manager is ephemeral, use a
     18        non-persistent, memory only HSTS enforcer.
     19
     20        Implement as well the methods needed to clean-up and delete HSTS
     21        policies from the storage and expose the feature in GTK+ MiniBrowser's
     22        about:data.
     23
     24        * platform/network/soup/GUniquePtrSoup.h:
     25        * platform/network/soup/SoupNetworkSession.cpp:
     26        (WebCore::hstsStorageDirectory):
     27        (WebCore::SoupNetworkSession::SoupNetworkSession):
     28        (WebCore::SoupNetworkSession::setHSTSPersistentStorage):
     29        (WebCore::SoupNetworkSession::setupHSTSEnforcer):
     30        (WebCore::SoupNetworkSession::getHostNamesWithHSTSCache):
     31        (WebCore::SoupNetworkSession::deleteHSTSCacheForHostNames):
     32        (WebCore::SoupNetworkSession::clearHSTSCache):
     33        * platform/network/soup/SoupNetworkSession.h:
     34
    1352019-08-28  Said Abou-Hallawa  <sabouhallawa@apple.com>
    236
  • trunk/Source/WebCore/platform/network/soup/GUniquePtrSoup.h

    r238851 r249192  
    3333WTF_DEFINE_GPTR_DELETER(SoupMessageHeaders, soup_message_headers_free)
    3434WTF_DEFINE_GPTR_DELETER(SoupBuffer, soup_buffer_free)
     35#if SOUP_CHECK_VERSION(2, 67, 1)
     36WTF_DEFINE_GPTR_DELETER(SoupHSTSPolicy, soup_hsts_policy_free)
     37#endif
    3538
    3639} // namespace WTF
  • trunk/Source/WebCore/platform/network/soup/SoupNetworkSession.cpp

    r248102 r249192  
    6060}
    6161
     62static CString& hstsStorageDirectory()
     63{
     64    static NeverDestroyed<CString> directory;
     65    return directory.get();
     66}
     67
    6268#if !LOG_DISABLED
    6369inline static void soupLogPrinter(SoupLogger*, SoupLoggerLogLevel, char direction, const char* data, gpointer)
     
    109115SoupNetworkSession::SoupNetworkSession(PAL::SessionID sessionID)
    110116    : m_soupSession(adoptGRef(soup_session_new()))
     117    , m_sessionID(sessionID)
    111118{
    112119    // Values taken from http://www.browserscope.org/ following
     
    133140        setAcceptLanguages(initialAcceptLanguages());
    134141
    135     if (soup_auth_negotiate_supported() && !sessionID.isEphemeral()) {
     142    if (soup_auth_negotiate_supported() && !m_sessionID.isEphemeral()) {
    136143        g_object_set(m_soupSession.get(),
    137144            SOUP_SESSION_ADD_FEATURE_BY_TYPE, SOUP_TYPE_AUTH_NEGOTIATE,
     
    142149        setupProxy();
    143150    setupLogger();
     151    setupHSTSEnforcer();
    144152}
    145153
     
    168176{
    169177    return SOUP_COOKIE_JAR(soup_session_get_feature(m_soupSession.get(), SOUP_TYPE_COOKIE_JAR));
     178}
     179
     180void SoupNetworkSession::setHSTSPersistentStorage(const CString& directory)
     181{
     182    hstsStorageDirectory() = directory;
     183}
     184
     185void SoupNetworkSession::setupHSTSEnforcer()
     186{
     187#if SOUP_CHECK_VERSION(2, 67, 1)
     188    if (soup_session_has_feature(m_soupSession.get(), SOUP_TYPE_HSTS_ENFORCER))
     189        soup_session_remove_feature_by_type(m_soupSession.get(), SOUP_TYPE_HSTS_ENFORCER);
     190
     191    GRefPtr<SoupHSTSEnforcer> enforcer;
     192    if (m_sessionID.isEphemeral() || hstsStorageDirectory().isNull())
     193        enforcer = adoptGRef(soup_hsts_enforcer_new());
     194    else {
     195        if (FileSystem::makeAllDirectories(hstsStorageDirectory().data())) {
     196            CString storagePath = FileSystem::fileSystemRepresentation(hstsStorageDirectory().data());
     197            GUniquePtr<char> dbFilename(g_build_filename(storagePath.data(), "hsts-storage.sqlite", nullptr));
     198            enforcer = adoptGRef(soup_hsts_enforcer_db_new(dbFilename.get()));
     199        } else {
     200            RELEASE_LOG_ERROR("Unable to create the HSTS storage directory \"%s\". Using a memory enforcer instead.", hstsStorageDirectory.data());
     201            enforcer = adoptGRef(soup_hsts_enforcer_new());
     202        }
     203    }
     204    soup_session_add_feature(m_soupSession.get(), SOUP_SESSION_FEATURE(enforcer.get()));
     205#endif
     206}
     207
     208void SoupNetworkSession::getHostNamesWithHSTSCache(HashSet<String>& hostNames)
     209{
     210#if SOUP_CHECK_VERSION(2, 67, 91)
     211    SoupHSTSEnforcer* enforcer = SOUP_HSTS_ENFORCER(soup_session_get_feature(m_soupSession.get(), SOUP_TYPE_HSTS_ENFORCER));
     212    if (!enforcer)
     213        return;
     214
     215    GUniquePtr<GList> domains(soup_hsts_enforcer_get_domains(enforcer, FALSE));
     216    for (GList* iter = domains.get(); iter; iter = iter->next) {
     217        GUniquePtr<gchar> domain(static_cast<gchar*>(iter->data));
     218        hostNames.add(String::fromUTF8(domain.get()));
     219    }
     220#else
     221    UNUSED_PARAM(hostNames);
     222#endif
     223}
     224
     225void SoupNetworkSession::deleteHSTSCacheForHostNames(const Vector<String>& hostNames)
     226{
     227#if SOUP_CHECK_VERSION(2, 67, 1)
     228    SoupHSTSEnforcer* enforcer = SOUP_HSTS_ENFORCER(soup_session_get_feature(m_soupSession.get(), SOUP_TYPE_HSTS_ENFORCER));
     229    if (!enforcer)
     230        return;
     231
     232    for (const auto& hostName : hostNames) {
     233        GUniquePtr<SoupHSTSPolicy> policy(soup_hsts_policy_new(hostName.utf8().data(), SOUP_HSTS_POLICY_MAX_AGE_PAST, FALSE));
     234        soup_hsts_enforcer_set_policy(enforcer, policy.get());
     235    }
     236#else
     237    UNUSED_PARAM(hostNames);
     238#endif
     239}
     240
     241void SoupNetworkSession::clearHSTSCache(WallTime modifiedSince)
     242{
     243#if SOUP_CHECK_VERSION(2, 67, 91)
     244    SoupHSTSEnforcer* enforcer = SOUP_HSTS_ENFORCER(soup_session_get_feature(m_soupSession.get(), SOUP_TYPE_HSTS_ENFORCER));
     245    if (!enforcer)
     246        return;
     247
     248    GUniquePtr<GList> policies(soup_hsts_enforcer_get_policies(enforcer, FALSE));
     249    for (GList* iter = policies.get(); iter != nullptr; iter = iter->next) {
     250        GUniquePtr<SoupHSTSPolicy> policy(static_cast<SoupHSTSPolicy*>(iter->data));
     251        auto modified = soup_date_to_time_t(policy.get()->expires) - policy.get()->max_age;
     252        if (modified >= modifiedSince.secondsSinceEpoch().seconds()) {
     253            GUniquePtr<SoupHSTSPolicy> newPolicy(soup_hsts_policy_new(policy.get()->domain, SOUP_HSTS_POLICY_MAX_AGE_PAST, FALSE));
     254            soup_hsts_enforcer_set_policy(enforcer, newPolicy.get());
     255        }
     256    }
     257#else
     258    UNUSED_PARAM(modifiedSince);
     259#endif
    170260}
    171261
  • trunk/Source/WebCore/platform/network/soup/SoupNetworkSession.h

    r248010 r249192  
    5858    SoupCookieJar* cookieJar() const;
    5959
     60    static void setHSTSPersistentStorage(const CString& hstsStorageDirectory);
     61    void setupHSTSEnforcer();
     62
    6063    static void clearOldSoupCache(const String& cacheDirectory);
    6164
     
    7376    void setupCustomProtocols();
    7477
     78    void getHostNamesWithHSTSCache(HashSet<String>&);
     79    void deleteHSTSCacheForHostNames(const Vector<String>&);
     80    void clearHSTSCache(WallTime);
     81
    7582private:
    7683    void setupLogger();
    7784
    7885    GRefPtr<SoupSession> m_soupSession;
     86    PAL::SessionID m_sessionID;
    7987};
    8088
  • trunk/Source/WebKit/ChangeLog

    r249175 r249192  
     12019-08-28  Claudio Saavedra  <csaavedra@igalia.com>
     2
     3        [GTK][WPE] Implement HSTS for the soup network backend
     4        https://bugs.webkit.org/show_bug.cgi?id=192074
     5
     6        Reviewed by Carlos Garcia Campos.
     7
     8        libsoup 2.67.1 introduced HSTS support via a SoupSessionFeature.
     9        Add support to the soup network backend by adding the feature to
     10        SoupNetworkSession and handling HSTS protocol upgrades, by
     11        propagating the scheme change further to clients. This patch adds
     12        the HSTS feature unconditionally, but it still possible to add
     13        a boolean property to the web context class if desired.
     14
     15        Additionally, add API to the WebKitWebsiteDataManager to specify
     16        the directory where the HSTS database is saved. If the directory
     17        is not set or if the data manager is ephemeral, use a
     18        non-persistent, memory only HSTS enforcer.
     19
     20        Implement as well the methods needed to clean-up and delete HSTS
     21        policies from the storage and expose the feature in GTK+
     22        MiniBrowser's about:data.
     23
     24        * NetworkProcess/NetworkProcess.cpp:
     25        (WebKit::NetworkProcess::fetchWebsiteData):
     26        (WebKit::NetworkProcess::deleteWebsiteData):
     27        (WebKit::NetworkProcess::deleteWebsiteDataForOrigins):
     28        (WebKit::NetworkProcess::deleteWebsiteDataForRegistrableDomains):
     29        (WebKit::NetworkProcess::registrableDomainsWithWebsiteData):
     30        * NetworkProcess/NetworkProcess.h:
     31        (WebKit::NetworkProcess::suppressesConnectionTerminationOnSystemChange const):
     32        * NetworkProcess/soup/NetworkDataTaskSoup.cpp:
     33        (WebKit::NetworkDataTaskSoup::createRequest):
     34        (WebKit::NetworkDataTaskSoup::clearRequest):
     35        (WebKit::NetworkDataTaskSoup::shouldAllowHSTSPolicySetting const):
     36        (WebKit::NetworkDataTaskSoup::shouldAllowHSTSProtocolUpgrade const):
     37        (WebKit::NetworkDataTaskSoup::protocolUpgradedViaHSTS):
     38        (WebKit::NetworkDataTaskSoup::hstsEnforced):
     39        * NetworkProcess/soup/NetworkDataTaskSoup.h:
     40        * NetworkProcess/soup/NetworkProcessSoup.cpp:
     41        (WebKit::NetworkProcess::getHostNamesWithHSTSCache):
     42        (WebKit::NetworkProcess::deleteHSTSCacheForHostNames):
     43        (WebKit::NetworkProcess::clearHSTSCache):
     44        (WebKit::NetworkProcess::platformInitializeNetworkProcess):
     45        * UIProcess/API/APIWebsiteDataStore.h:
     46        * UIProcess/API/glib/APIWebsiteDataStoreGLib.cpp:
     47        (API::WebsiteDataStore::defaultHSTSDirectory):
     48        * UIProcess/API/glib/WebKitWebContext.cpp:
     49        (webkitWebContextConstructed):
     50        * UIProcess/API/glib/WebKitWebsiteData.cpp:
     51        (recordContainsSupportedDataTypes):
     52        (toWebKitWebsiteDataTypes):
     53        * UIProcess/API/glib/WebKitWebsiteDataManager.cpp:
     54        (webkitWebsiteDataManagerGetProperty):
     55        (webkitWebsiteDataManagerSetProperty):
     56        (webkitWebsiteDataManagerConstructed):
     57        (webkit_website_data_manager_class_init):
     58        (webkitWebsiteDataManagerGetDataStore):
     59        (webkit_website_data_manager_get_hsts_cache_directory):
     60        (toWebsiteDataTypes):
     61        * UIProcess/API/gtk/WebKitWebsiteData.h:
     62        * UIProcess/API/gtk/WebKitWebsiteDataManager.h:
     63        * UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt:
     64        * UIProcess/API/wpe/WebKitWebsiteData.h:
     65        * UIProcess/API/wpe/WebKitWebsiteDataManager.h:
     66        * UIProcess/API/wpe/docs/wpe-1.0-sections.txt:
     67        * UIProcess/WebsiteData/WebsiteDataStoreConfiguration.cpp:
     68        (WebKit::WebsiteDataStoreConfiguration::copy):
     69        * UIProcess/WebsiteData/WebsiteDataStoreConfiguration.h:
     70        (WebKit::WebsiteDataStoreConfiguration::hstsStorageDirectory const):
     71        (WebKit::WebsiteDataStoreConfiguration::setHSTSStorageDirectory):
     72
    1732019-08-27  Mark Lam  <mark.lam@apple.com>
    274
  • trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp

    r248959 r249192  
    13501350    }
    13511351
    1352 #if PLATFORM(COCOA)
     1352#if PLATFORM(COCOA) || USE(SOUP)
    13531353    if (websiteDataTypes.contains(WebsiteDataType::HSTSCache)) {
    13541354        if (auto* networkStorageSession = storageSession(sessionID))
     
    13901390void NetworkProcess::deleteWebsiteData(PAL::SessionID sessionID, OptionSet<WebsiteDataType> websiteDataTypes, WallTime modifiedSince, uint64_t callbackID)
    13911391{
    1392 #if PLATFORM(COCOA)
     1392#if PLATFORM(COCOA) || USE(SOUP)
    13931393    if (websiteDataTypes.contains(WebsiteDataType::HSTSCache)) {
    13941394        if (auto* networkStorageSession = storageSession(sessionID))
     
    14911491    }
    14921492
    1493 #if PLATFORM(COCOA)
     1493#if PLATFORM(COCOA) || USE(SOUP)
    14941494    if (websiteDataTypes.contains(WebsiteDataType::HSTSCache)) {
    14951495        if (auto* networkStorageSession = storageSession(sessionID))
     
    16731673
    16741674    Vector<String> hostnamesWithHSTSToDelete;
    1675 #if PLATFORM(COCOA)
     1675#if PLATFORM(COCOA) || USE(SOUP)
    16761676    if (websiteDataTypes.contains(WebsiteDataType::HSTSCache)) {
    16771677        if (auto* networkStorageSession = storageSession(sessionID)) {
     
    18541854   
    18551855    Vector<String> hostnamesWithHSTSToDelete;
    1856 #if PLATFORM(COCOA)
     1856#if PLATFORM(COCOA) || USE(SOUP)
    18571857    if (websiteDataTypes.contains(WebsiteDataType::HSTSCache)) {
    18581858        if (auto* networkStorageSession = storageSession(sessionID))
  • trunk/Source/WebKit/NetworkProcess/NetworkProcess.h

    r248956 r249192  
    194194#if PLATFORM(COCOA)
    195195    RetainPtr<CFDataRef> sourceApplicationAuditData() const;
     196    bool suppressesConnectionTerminationOnSystemChange() const { return m_suppressesConnectionTerminationOnSystemChange; }
     197#endif
     198#if PLATFORM(COCOA) || USE(SOUP)
    196199    void getHostNamesWithHSTSCache(WebCore::NetworkStorageSession&, HashSet<String>&);
    197200    void deleteHSTSCacheForHostNames(WebCore::NetworkStorageSession&, const Vector<String>&);
    198201    void clearHSTSCache(WebCore::NetworkStorageSession&, WallTime modifiedSince);
    199     bool suppressesConnectionTerminationOnSystemChange() const { return m_suppressesConnectionTerminationOnSystemChange; }
    200202#endif
    201203
  • trunk/Source/WebKit/NetworkProcess/soup/NetworkDataTaskSoup.cpp

    r248846 r249192  
    3939#include <WebCore/MIMETypeRegistry.h>
    4040#include <WebCore/NetworkStorageSession.h>
     41#include <WebCore/PublicSuffix.h>
    4142#include <WebCore/SharedBuffer.h>
    4243#include <WebCore/SoupNetworkSession.h>
     
    147148#endif
    148149    }
     150
     151#if SOUP_CHECK_VERSION(2, 67, 1)
     152    if ((m_currentRequest.url().protocolIs("https") && !shouldAllowHSTSPolicySetting()) || (m_currentRequest.url().protocolIs("http") && !shouldAllowHSTSProtocolUpgrade()))
     153        soup_message_disable_feature(soupMessage.get(), SOUP_TYPE_HSTS_ENFORCER);
     154    else
     155        g_signal_connect(soup_session_get_feature(static_cast<NetworkSessionSoup&>(*m_session).soupSession(), SOUP_TYPE_HSTS_ENFORCER), "hsts-enforced", G_CALLBACK(hstsEnforced), this);
     156#endif
    149157
    150158    // Make sure we have an Accept header for subresources; some sites want this to serve some of their subresources.
     
    193201        m_soupMessage = nullptr;
    194202    }
    195     if (m_session)
     203    if (m_session) {
    196204        g_signal_handlers_disconnect_matched(static_cast<NetworkSessionSoup&>(*m_session).soupSession(), G_SIGNAL_MATCH_DATA, 0, 0, nullptr, nullptr, this);
     205#if SOUP_CHECK_VERSION(2, 67, 1)
     206        g_signal_handlers_disconnect_by_data(soup_session_get_feature(static_cast<NetworkSessionSoup&>(*m_session).soupSession(), SOUP_TYPE_HSTS_ENFORCER), this);
     207#endif
     208    }
    197209}
    198210
     
    10611073}
    10621074
     1075#if SOUP_CHECK_VERSION(2, 67, 1)
     1076bool NetworkDataTaskSoup::shouldAllowHSTSPolicySetting() const
     1077{
     1078    // Follow Apple's HSTS abuse mitigation 1:
     1079    //  "Limit HSTS State to the Hostname, or the Top Level Domain + 1"
     1080    if (isTopLevelNavigation() || hostsAreEqual(m_currentRequest.url(), m_currentRequest.firstPartyForCookies()) || isPublicSuffix(m_currentRequest.url().host().toStringWithoutCopying()))
     1081        return true;
     1082
     1083    return false;
     1084}
     1085
     1086bool NetworkDataTaskSoup::shouldAllowHSTSProtocolUpgrade() const
     1087{
     1088    // Follow Apple's HSTS abuse mitgation 2:
     1089    // "Ignore HSTS State for Subresource Requests to Blocked Domains"
     1090    if (!isTopLevelNavigation() && !m_currentRequest.allowCookies())
     1091        return false;
     1092
     1093    return true;
     1094}
     1095
     1096void NetworkDataTaskSoup::protocolUpgradedViaHSTS(SoupMessage* soupMessage)
     1097{
     1098    m_response = ResourceResponse::syntheticRedirectResponse(m_currentRequest.url(), soupURIToURL(soup_message_get_uri(soupMessage)));
     1099    continueHTTPRedirection();
     1100}
     1101
     1102void NetworkDataTaskSoup::hstsEnforced(SoupHSTSEnforcer*, SoupMessage* soupMessage, NetworkDataTaskSoup* task)
     1103{
     1104    if (task->state() == State::Canceling || task->state() == State::Completed || !task->m_client) {
     1105        task->clearRequest();
     1106        return;
     1107    }
     1108
     1109    if (soupMessage == task->m_soupMessage.get())
     1110        task->protocolUpgradedViaHSTS(soupMessage);
     1111}
     1112#endif
     1113
    10631114void NetworkDataTaskSoup::didStartRequest()
    10641115{
  • trunk/Source/WebKit/NetworkProcess/soup/NetworkDataTaskSoup.h

    r241317 r249192  
    113113    static void requestStartedCallback(SoupSession*, SoupMessage*, SoupSocket*, NetworkDataTaskSoup*);
    114114#endif
     115#if SOUP_CHECK_VERSION(2, 67, 1)
     116    bool shouldAllowHSTSPolicySetting() const;
     117    bool shouldAllowHSTSProtocolUpgrade() const;
     118    void protocolUpgradedViaHSTS(SoupMessage*);
     119    static void hstsEnforced(SoupHSTSEnforcer*, SoupMessage*, NetworkDataTaskSoup*);
     120#endif
    115121    void didStartRequest();
    116122    static void restartedCallback(SoupMessage*, NetworkDataTaskSoup*);
  • trunk/Source/WebKit/NetworkProcess/soup/NetworkProcessSoup.cpp

    r248999 r249192  
    9696}
    9797
     98void NetworkProcess::getHostNamesWithHSTSCache(WebCore::NetworkStorageSession& storageSession, HashSet<String>& hostNames)
     99{
     100    const auto* session = static_cast<NetworkSessionSoup*>(networkSession(storageSession.sessionID()));
     101    session->soupNetworkSession().getHostNamesWithHSTSCache(hostNames);
     102}
     103
     104void NetworkProcess::deleteHSTSCacheForHostNames(WebCore::NetworkStorageSession& storageSession, const Vector<String>& hostNames)
     105{
     106    const auto* session = static_cast<NetworkSessionSoup*>(networkSession(storageSession.sessionID()));
     107    session->soupNetworkSession().deleteHSTSCacheForHostNames(hostNames);
     108}
     109
     110void NetworkProcess::clearHSTSCache(WebCore::NetworkStorageSession& storageSession, WallTime modifiedSince)
     111{
     112    const auto* session = static_cast<NetworkSessionSoup*>(networkSession(storageSession.sessionID()));
     113    session->soupNetworkSession().clearHSTSCache(modifiedSince);
     114}
     115
    98116void NetworkProcess::userPreferredLanguagesChanged(const Vector<String>& languages)
    99117{
     
    130148
    131149    setIgnoreTLSErrors(parameters.ignoreTLSErrors);
     150
     151    if (!parameters.hstsStorageDirectory.isEmpty())
     152        SoupNetworkSession::setHSTSPersistentStorage(parameters.hstsStorageDirectory.utf8());
     153    forEachNetworkSession([](const auto& session) {
     154        static_cast<const NetworkSessionSoup&>(session).soupNetworkSession().setupHSTSEnforcer();
     155    });
    132156}
    133157
  • trunk/Source/WebKit/UIProcess/API/APIWebsiteDataStore.h

    r242203 r249192  
    6767    static WTF::String defaultDeviceIdHashSaltsStorageDirectory();
    6868    static WTF::String defaultWebSQLDatabaseDirectory();
     69#if USE(GLIB)
     70    static WTF::String defaultHSTSDirectory();
     71#endif
    6972    static WTF::String defaultResourceLoadStatisticsDirectory();
    7073    static WTF::String defaultJavaScriptConfigurationDirectory();
  • trunk/Source/WebKit/UIProcess/API/glib/APIWebsiteDataStoreGLib.cpp

    r246790 r249192  
    8383{
    8484    return websiteDataDirectoryFileSystemRepresentation(BASE_DIRECTORY G_DIR_SEPARATOR_S "databases");
     85}
     86
     87WTF::String WebsiteDataStore::defaultHSTSDirectory()
     88{
     89    return websiteDataDirectoryFileSystemRepresentation(BASE_DIRECTORY G_DIR_SEPARATOR_S);
    8590}
    8691
  • trunk/Source/WebKit/UIProcess/API/glib/WebKitWebContext.cpp

    r248846 r249192  
    342342        configuration.setApplicationCacheDirectory(FileSystem::stringFromFileSystemRepresentation(webkit_website_data_manager_get_offline_application_cache_directory(priv->websiteDataManager.get())));
    343343        configuration.setIndexedDBDatabaseDirectory(FileSystem::stringFromFileSystemRepresentation(webkit_website_data_manager_get_indexeddb_directory(priv->websiteDataManager.get())));
     344        configuration.setHSTSStorageDirectory(FileSystem::stringFromFileSystemRepresentation(webkit_website_data_manager_get_hsts_cache_directory(priv->websiteDataManager.get())));
    344345ALLOW_DEPRECATED_DECLARATIONS_BEGIN
    345346        configuration.setWebSQLDatabaseDirectory(FileSystem::stringFromFileSystemRepresentation(webkit_website_data_manager_get_websql_directory(priv->websiteDataManager.get())));
  • trunk/Source/WebKit/UIProcess/API/glib/WebKitWebsiteData.cpp

    r237031 r249192  
    7474        WebsiteDataType::WebSQLDatabases,
    7575        WebsiteDataType::IndexedDBDatabases,
     76        WebsiteDataType::HSTSCache,
    7677#if ENABLE(NETSCAPE_PLUGIN_API)
    7778        WebsiteDataType::PlugInData,
     
    99100    if (types.contains(WebsiteDataType::IndexedDBDatabases))
    100101        returnValue |= WEBKIT_WEBSITE_DATA_INDEXEDDB_DATABASES;
     102    if (types.contains(WebsiteDataType::HSTSCache))
     103        returnValue |= WEBKIT_WEBSITE_DATA_HSTS_CACHE;
    101104#if ENABLE(NETSCAPE_PLUGIN_API)
    102105    if (types.contains(WebsiteDataType::PlugInData))
  • trunk/Source/WebKit/UIProcess/API/glib/WebKitWebsiteDataManager.cpp

    r248293 r249192  
    8585    PROP_INDEXEDDB_DIRECTORY,
    8686    PROP_WEBSQL_DIRECTORY,
     87    PROP_HSTS_CACHE_DIRECTORY,
    8788    PROP_IS_EPHEMERAL
    8889};
     
    102103    GUniquePtr<char> indexedDBDirectory;
    103104    GUniquePtr<char> webSQLDirectory;
     105    GUniquePtr<char> hstsCacheDirectory;
    104106
    105107    GRefPtr<WebKitCookieManager> cookieManager;
     
    137139        ALLOW_DEPRECATED_DECLARATIONS_END
    138140        break;
     141    case PROP_HSTS_CACHE_DIRECTORY:
     142        g_value_set_string(value, webkit_website_data_manager_get_hsts_cache_directory(manager));
     143        break;
    139144    case PROP_IS_EPHEMERAL:
    140145        g_value_set_boolean(value, webkit_website_data_manager_is_ephemeral(manager));
     
    170175    case PROP_WEBSQL_DIRECTORY:
    171176        manager->priv->webSQLDirectory.reset(g_value_dup_string(value));
     177        break;
     178    case PROP_HSTS_CACHE_DIRECTORY:
     179        manager->priv->hstsCacheDirectory.reset(g_value_dup_string(value));
    172180        break;
    173181    case PROP_IS_EPHEMERAL:
     
    199207        if (!priv->applicationCacheDirectory)
    200208            priv->applicationCacheDirectory.reset(g_build_filename(priv->baseCacheDirectory.get(), "applications", nullptr));
     209        if (!priv->hstsCacheDirectory)
     210            priv->hstsCacheDirectory.reset(g_strdup(priv->baseCacheDirectory.get()));
    201211    }
    202212}
     
    334344
    335345    /**
     346     * WebKitWebsiteDataManager:hsts-cache-directory:
     347     *
     348     * The directory where the HTTP Strict-Transport-Security (HSTS) cache will be stored.
     349     *
     350     * Since: 2.26
     351     */
     352    g_object_class_install_property(
     353        gObjectClass,
     354        PROP_HSTS_CACHE_DIRECTORY,
     355        g_param_spec_string(
     356            "hsts-cache-directory",
     357            _("HSTS Cache Directory"),
     358            _("The directory where the HTTP Strict-Transport-Security cache will be stored"),
     359            nullptr,
     360            static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)));
     361
     362    /**
    336363     * WebKitWebsiteDataManager:is-ephemeral:
    337364     *
     
    375402        configuration->setWebSQLDatabaseDirectory(!priv->webSQLDirectory ?
    376403            API::WebsiteDataStore::defaultWebSQLDatabaseDirectory() : FileSystem::stringFromFileSystemRepresentation(priv->webSQLDirectory.get()));
     404        configuration->setHSTSStorageDirectory(!priv->hstsCacheDirectory ?
     405            API::WebsiteDataStore::defaultHSTSDirectory() : FileSystem::stringFromFileSystemRepresentation(priv->hstsCacheDirectory.get()));
    377406        configuration->setMediaKeysStorageDirectory(API::WebsiteDataStore::defaultMediaKeysStorageDirectory());
    378407        priv->websiteDataStore = API::WebsiteDataStore::createLegacy(WTFMove(configuration));
     
    611640        priv->webSQLDirectory.reset(g_strdup(API::WebsiteDataStore::defaultWebSQLDatabaseDirectory().utf8().data()));
    612641    return priv->webSQLDirectory.get();
     642}
     643
     644/**
     645 * webkit_website_data_manager_get_hsts_cache_directory:
     646 * @manager: a #WebKitWebsiteDataManager
     647 *
     648 * Get the #WebKitWebsiteDataManager:hsts-cache-directory property.
     649 *
     650 * Returns: (allow-none): the directory where the HSTS cache is stored or %NULL if @manager is ephemeral.
     651 *
     652 * Since: 2.26
     653 */
     654const gchar* webkit_website_data_manager_get_hsts_cache_directory(WebKitWebsiteDataManager* manager)
     655{
     656    g_return_val_if_fail(WEBKIT_IS_WEBSITE_DATA_MANAGER(manager), nullptr);
     657
     658    WebKitWebsiteDataManagerPrivate* priv = manager->priv;
     659    if (priv->websiteDataStore && !priv->websiteDataStore->isPersistent())
     660        return nullptr;
     661
     662    if (!priv->hstsCacheDirectory)
     663        priv->hstsCacheDirectory.reset(g_strdup(API::WebsiteDataStore::defaultHSTSDirectory().utf8().data()));
     664    return priv->hstsCacheDirectory.get();
    613665}
    614666
     
    650702    if (types & WEBKIT_WEBSITE_DATA_INDEXEDDB_DATABASES)
    651703        returnValue.add(WebsiteDataType::IndexedDBDatabases);
     704    if (types & WEBKIT_WEBSITE_DATA_HSTS_CACHE)
     705        returnValue.add(WebsiteDataType::HSTSCache);
    652706#if ENABLE(NETSCAPE_PLUGIN_API)
    653707    if (types & WEBKIT_WEBSITE_DATA_PLUGIN_DATA)
  • trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebsiteData.h

    r246353 r249192  
    4646 * @WEBKIT_WEBSITE_DATA_COOKIES: Cookies.
    4747 * @WEBKIT_WEBSITE_DATA_DEVICE_ID_HASH_SALT: Hash salt used to generate the device ids used by webpages. Since 2.24
     48 * @WEBKIT_WEBSITE_DATA_HSTS_CACHE: HSTS cache. Since 2.26
    4849 * @WEBKIT_WEBSITE_DATA_ALL: All types.
    4950 *
     
    6364    WEBKIT_WEBSITE_DATA_COOKIES                   = 1 << 8,
    6465    WEBKIT_WEBSITE_DATA_DEVICE_ID_HASH_SALT       = 1 << 9,
    65     WEBKIT_WEBSITE_DATA_ALL                       = (1 << 10) - 1
     66    WEBKIT_WEBSITE_DATA_HSTS_CACHE                = 1 << 10,
     67    WEBKIT_WEBSITE_DATA_ALL                       = (1 << 11) - 1
    6668} WebKitWebsiteDataTypes;
    6769
  • trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebsiteDataManager.h

    r246353 r249192  
    9191webkit_website_data_manager_get_websql_directory                      (WebKitWebsiteDataManager *manager);
    9292
     93WEBKIT_API const gchar *
     94webkit_website_data_manager_get_hsts_cache_directory                  (WebKitWebsiteDataManager *manager);
     95
    9396WEBKIT_API WebKitCookieManager *
    9497webkit_website_data_manager_get_cookie_manager                        (WebKitWebsiteDataManager *manager);
  • trunk/Source/WebKit/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt

    r245176 r249192  
    14041404webkit_website_data_manager_get_indexeddb_directory
    14051405webkit_website_data_manager_get_websql_directory
     1406webkit_website_data_manager_get_hsts_cache_directory
    14061407webkit_website_data_manager_get_cookie_manager
    14071408webkit_website_data_manager_fetch
  • trunk/Source/WebKit/UIProcess/API/wpe/WebKitWebsiteData.h

    r246353 r249192  
    4646 * @WEBKIT_WEBSITE_DATA_COOKIES: Cookies.
    4747 * @WEBKIT_WEBSITE_DATA_DEVICE_ID_HASH_SALT: Hash salt used to generate the device ids used by webpages. Since 2.24
     48 * @WEBKIT_WEBSITE_DATA_HSTS_CACHE: HSTS cache. Since 2.26
    4849 * @WEBKIT_WEBSITE_DATA_ALL: All types.
    4950 *
     
    6364    WEBKIT_WEBSITE_DATA_COOKIES                   = 1 << 8,
    6465    WEBKIT_WEBSITE_DATA_DEVICE_ID_HASH_SALT       = 1 << 9,
    65     WEBKIT_WEBSITE_DATA_ALL                       = (1 << 10) - 1
     66    WEBKIT_WEBSITE_DATA_HSTS_CACHE                = 1 << 10,
     67    WEBKIT_WEBSITE_DATA_ALL                       = (1 << 11) - 1
    6668} WebKitWebsiteDataTypes;
    6769
  • trunk/Source/WebKit/UIProcess/API/wpe/WebKitWebsiteDataManager.h

    r246353 r249192  
    9191webkit_website_data_manager_get_websql_directory                      (WebKitWebsiteDataManager *manager);
    9292
     93WEBKIT_API const gchar *
     94webkit_website_data_manager_get_hsts_cache_directory                  (WebKitWebsiteDataManager *manager);
     95
    9396WEBKIT_API WebKitCookieManager *
    9497webkit_website_data_manager_get_cookie_manager                        (WebKitWebsiteDataManager *manager);
  • trunk/Source/WebKit/UIProcess/API/wpe/docs/wpe-1.0-sections.txt

    r244260 r249192  
    12781278webkit_website_data_manager_get_indexeddb_directory
    12791279webkit_website_data_manager_get_websql_directory
     1280webkit_website_data_manager_get_hsts_cache_directory
    12801281webkit_website_data_manager_get_cookie_manager
    12811282webkit_website_data_manager_fetch
  • trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStoreConfiguration.cpp

    r247476 r249192  
    5151    copy->m_serviceWorkerRegistrationDirectory = this->m_serviceWorkerRegistrationDirectory;
    5252    copy->m_webSQLDatabaseDirectory = this->m_webSQLDatabaseDirectory;
     53#if USE(GLIB)
     54    copy->m_hstsStorageDirectory = this->m_hstsStorageDirectory;
     55#endif
    5356    copy->m_localStorageDirectory = this->m_localStorageDirectory;
    5457    copy->m_mediaKeysStorageDirectory = this->m_mediaKeysStorageDirectory;
  • trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStoreConfiguration.h

    r247476 r249192  
    6262    const String& webSQLDatabaseDirectory() const { return m_webSQLDatabaseDirectory; }
    6363    void setWebSQLDatabaseDirectory(String&& directory) { m_webSQLDatabaseDirectory = WTFMove(directory); }
    64 
     64#if USE(GLIB) // According to r245075 this will eventually move here.
     65    const String& hstsStorageDirectory() const { return m_hstsStorageDirectory; }
     66    void setHSTSStorageDirectory(String&& directory) { m_hstsStorageDirectory = WTFMove(directory); }
     67#endif
    6568    const String& localStorageDirectory() const { return m_localStorageDirectory; }
    6669    void setLocalStorageDirectory(String&& directory) { m_localStorageDirectory = WTFMove(directory); }
     
    119122    String m_serviceWorkerRegistrationDirectory;
    120123    String m_webSQLDatabaseDirectory;
     124#if USE(GLIB)
     125    String m_hstsStorageDirectory;
     126#endif
    121127    String m_localStorageDirectory;
    122128    String m_mediaKeysStorageDirectory;
  • trunk/Tools/ChangeLog

    r249190 r249192  
     12019-08-02  Claudio Saavedra  <csaavedra@igalia.com>
     2
     3        [GTK][WPE] Implement HSTS for the soup network backend
     4        https://bugs.webkit.org/show_bug.cgi?id=192074
     5
     6        Reviewed by Carlos Garcia Campos.
     7
     8        libsoup 2.67.1 introduced HSTS support via a SoupSessionFeature.
     9        Add support to the soup network backend by adding the feature to
     10        SoupNetworkSession and handling HSTS protocol upgrades, by
     11        propagating the scheme change further to clients. This patch adds
     12        the HSTS feature unconditionally, but it still possible to add
     13        a boolean property to the web context class if desired.
     14
     15        Additionally, add API to the WebKitWebsiteDataManager to specify
     16        the directory where the HSTS database is saved. If the directory
     17        is not set or if the data manager is ephemeral, use a
     18        non-persistent, memory only HSTS enforcer.
     19
     20        Implement as well the methods needed to clean-up and delete HSTS
     21        policies from the storage and expose the feature in GTK+
     22        MiniBrowser's about:data.
     23
     24        * MiniBrowser/gtk/main.c:
     25        (gotWebsiteDataCallback):
     26        * TestWebKitAPI/Tests/WebKitGLib/TestWebsiteData.cpp:
     27        (serverCallback):
     28        (testWebsiteDataConfiguration):
     29        (testWebsiteDataEphemeral):
     30        (prepopulateHstsData):
     31        (testWebsiteDataHsts):
     32        (beforeAll):
     33        * TestWebKitAPI/glib/WebKitGLib/TestMain.h:
     34        (Test::Test):
     35        * gtk/jhbuild.modules: Bump libsoup to 2.67.91 for the new APIs
     36        * wpe/jhbuild.modules: Ditto
     37        * MiniBrowser/gtk/main.c:
     38        (gotWebsiteDataCallback):
     39
    1402019-08-27  James Darpinian  <jdarpinian@google.com>
    241
  • trunk/Tools/MiniBrowser/gtk/main.c

    r249004 r249192  
    419419    aboutDataFillTable(result, dataRequest, dataList, "Plugins Data", WEBKIT_WEBSITE_DATA_PLUGIN_DATA, NULL, pageID);
    420420    aboutDataFillTable(result, dataRequest, dataList, "Offline Web Applications Cache", WEBKIT_WEBSITE_DATA_OFFLINE_APPLICATION_CACHE, webkit_website_data_manager_get_offline_application_cache_directory(manager), pageID);
     421    aboutDataFillTable(result, dataRequest, dataList, "HSTS Cache", WEBKIT_WEBSITE_DATA_HSTS_CACHE, webkit_website_data_manager_get_hsts_cache_directory(manager), pageID);
    421422
    422423    result = g_string_append(result, "</body></html>");
  • trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestWebsiteData.cpp

    r248435 r249192  
    2020#include "config.h"
    2121
     22#include <WebCore/GUniquePtrSoup.h>
    2223#include "WebKitTestServer.h"
    2324#include "WebViewTest.h"
     
    3637        static const char* emptyHTML = "<html><body></body></html>";
    3738        soup_message_headers_replace(message->response_headers, "Set-Cookie", "foo=bar; Max-Age=60");
     39        soup_message_headers_replace(message->response_headers, "Strict-Transport-Security", "max-age=3600");
    3840        soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, emptyHTML, strlen(emptyHTML));
    3941        soup_message_body_complete(message->response_body);
     
    163165    g_assert_true(g_file_test(diskCacheDirectory.get(), G_FILE_TEST_IS_DIR));
    164166
    165     // Clear all persistent caches, since the data dir is common to all test cases.
     167    GUniquePtr<char> hstsCacheDirectory(g_build_filename(Test::dataDirectory(), "hsts", nullptr));
     168    g_assert_cmpstr(hstsCacheDirectory.get(), ==, webkit_website_data_manager_get_hsts_cache_directory(test->m_manager));
     169    g_assert_true(g_file_test(hstsCacheDirectory.get(), G_FILE_TEST_IS_DIR));
     170
     171    // Clear all persistent caches, since the data dir is common to all test cases. Note: not cleaning the HSTS cache here as its data
     172    // is needed for the HSTS tests, where data cleaning will be tested.
    166173    static const WebKitWebsiteDataTypes persistentCaches = static_cast<WebKitWebsiteDataTypes>(WEBKIT_WEBSITE_DATA_DISK_CACHE | WEBKIT_WEBSITE_DATA_LOCAL_STORAGE
    167174        | WEBKIT_WEBSITE_DATA_INDEXEDDB_DATABASES | WEBKIT_WEBSITE_DATA_OFFLINE_APPLICATION_CACHE | WEBKIT_WEBSITE_DATA_DEVICE_ID_HASH_SALT);
     
    177184    g_assert_cmpstr(webkit_website_data_manager_get_disk_cache_directory(test->m_manager), !=, webkit_website_data_manager_get_disk_cache_directory(defaultManager));
    178185    g_assert_cmpstr(webkit_website_data_manager_get_offline_application_cache_directory(test->m_manager), !=, webkit_website_data_manager_get_offline_application_cache_directory(defaultManager));
     186    g_assert_cmpstr(webkit_website_data_manager_get_hsts_cache_directory(test->m_manager), !=, webkit_website_data_manager_get_hsts_cache_directory(defaultManager));
    179187
    180188    // Using Test::dataDirectory() we get the default configuration but for a differrent prefix.
     
    223231    g_assert_null(webkit_website_data_manager_get_offline_application_cache_directory(manager.get()));
    224232    g_assert_null(webkit_website_data_manager_get_indexeddb_directory(manager.get()));
     233    g_assert_null(webkit_website_data_manager_get_hsts_cache_directory(manager.get()));
    225234
    226235    // Configuration is ignored when is-ephemeral is used.
     
    484493}
    485494
     495#if SOUP_CHECK_VERSION(2, 67, 91)
     496static void prepopulateHstsData()
     497{
     498    // HSTS headers will be ignored in this test because the spec forbids STS policies from being honored for hosts with
     499    // an IP address instead of a domain. In order to be able to test the data manager API with HSTS website data, we
     500    // prepopulate the HSTS storage using the libsoup API directly.
     501
     502    GUniquePtr<char> hstsCacheDirectory(g_build_filename(Test::dataDirectory(), "hsts", nullptr));
     503    GUniquePtr<char> hstsDatabase(g_build_filename(hstsCacheDirectory.get(), "hsts-storage.sqlite", nullptr));
     504    g_mkdir_with_parents(hstsCacheDirectory.get(), 0700);
     505
     506    GRefPtr<SoupHSTSEnforcer> enforcer = adoptGRef(soup_hsts_enforcer_db_new(hstsDatabase.get()));
     507    GUniquePtr<SoupHSTSPolicy> policy(soup_hsts_policy_new("webkitgtk.org", 3600, true));
     508    soup_hsts_enforcer_set_policy(enforcer.get(), policy.get());
     509
     510    policy.reset(soup_hsts_policy_new("webkit.org", 3600, true));
     511    soup_hsts_enforcer_set_policy(enforcer.get(), policy.get());
     512}
     513
     514static void testWebsiteDataHsts(WebsiteDataTest* test, gconstpointer)
     515{
     516    GList* dataList = test->fetch(WEBKIT_WEBSITE_DATA_HSTS_CACHE);
     517    g_assert_cmpuint(g_list_length(dataList), ==, 2);
     518    WebKitWebsiteData* data = static_cast<WebKitWebsiteData*>(dataList->data);
     519    g_assert_cmpuint(webkit_website_data_get_types(data), ==, WEBKIT_WEBSITE_DATA_HSTS_CACHE);
     520    // HSTS data size is unknown.
     521    g_assert_cmpuint(webkit_website_data_get_size(data, WEBKIT_WEBSITE_DATA_HSTS_CACHE), ==, 0);
     522
     523    GList removeList = { data, nullptr, nullptr };
     524    test->remove(WEBKIT_WEBSITE_DATA_HSTS_CACHE, &removeList);
     525    dataList = test->fetch(WEBKIT_WEBSITE_DATA_HSTS_CACHE);
     526    g_assert_cmpuint(g_list_length(dataList), ==, 1);
     527    data = static_cast<WebKitWebsiteData*>(dataList->data);
     528    g_assert_cmpuint(webkit_website_data_get_types(data), ==, WEBKIT_WEBSITE_DATA_HSTS_CACHE);
     529
     530    // Remove all HSTS data.
     531    test->clear(WEBKIT_WEBSITE_DATA_HSTS_CACHE, 0);
     532    g_assert_null(test->fetch(WEBKIT_WEBSITE_DATA_HSTS_CACHE));
     533}
     534#endif
     535
    486536static void testWebsiteDataCookies(WebsiteDataTest* test, gconstpointer)
    487537{
     
    571621    kServer = new WebKitTestServer();
    572622    kServer->run(serverCallback);
     623
     624#if SOUP_CHECK_VERSION(2, 67, 91)
     625    prepopulateHstsData();
     626#endif
    573627
    574628    WebsiteDataTest::add("WebKitWebsiteData", "configuration", testWebsiteDataConfiguration);
     
    579633    WebsiteDataTest::add("WebKitWebsiteData", "appcache", testWebsiteDataAppcache);
    580634    WebsiteDataTest::add("WebKitWebsiteData", "cookies", testWebsiteDataCookies);
     635#if SOUP_CHECK_VERSION(2, 67, 91)
     636    WebsiteDataTest::add("WebKitWebsiteData", "hsts", testWebsiteDataHsts);
     637#endif
    581638    WebsiteDataTest::add("WebKitWebsiteData", "deviceidhashsalt", testWebsiteDataDeviceIdHashSalt);
    582639}
  • trunk/Tools/TestWebKitAPI/glib/WebKitGLib/TestMain.h

    r245618 r249192  
    122122        GUniquePtr<char> applicationCacheDirectory(g_build_filename(dataDirectory(), "appcache", nullptr));
    123123        GUniquePtr<char> webSQLDirectory(g_build_filename(dataDirectory(), "websql", nullptr));
     124        GUniquePtr<char> hstsDirectory(g_build_filename(dataDirectory(), "hsts", nullptr));
    124125        GRefPtr<WebKitWebsiteDataManager> websiteDataManager = adoptGRef(webkit_website_data_manager_new(
    125126            "local-storage-directory", localStorageDirectory.get(), "indexeddb-directory", indexedDBDirectory.get(),
    126127            "disk-cache-directory", diskCacheDirectory.get(), "offline-application-cache-directory", applicationCacheDirectory.get(),
    127             "websql-directory", webSQLDirectory.get(), nullptr));
     128            "websql-directory", webSQLDirectory.get(), "hsts-cache-directory", hstsDirectory.get(), nullptr));
    128129
    129130        m_webContext = adoptGRef(webkit_web_context_new_with_website_data_manager(websiteDataManager.get()));
  • trunk/Tools/gtk/jhbuild.modules

    r248099 r249192  
    239239      <dep package="libpsl"/>
    240240    </dependencies>
    241     <branch module="/pub/GNOME/sources/libsoup/2.67/libsoup-${version}.tar.xz" version="2.67.90"
    242             repo="ftp.gnome.org"
    243             hash="sha256:303686002bd7d7bf93204eebe0d5ec9f5d57d071e3411e2304d6f8bcfa97ef79">
     241    <branch module="/pub/GNOME/sources/libsoup/2.67/libsoup-${version}.tar.xz" version="2.67.91"
     242            repo="ftp.gnome.org"
     243            hash="sha256:390b5b28263d3bdf9866fa694346caa5e4bcb986e014e3383e9b6130b706f3da">
    244244    </branch>
    245245  </meson>
  • trunk/Tools/wpe/jhbuild.modules

    r248767 r249192  
    101101      <dep package="libpsl"/>
    102102    </dependencies>
    103     <branch module="/pub/GNOME/sources/libsoup/2.67/libsoup-${version}.tar.xz" version="2.67.90"
    104             repo="ftp.gnome.org"
    105             hash="sha256:303686002bd7d7bf93204eebe0d5ec9f5d57d071e3411e2304d6f8bcfa97ef79">
     103    <branch module="/pub/GNOME/sources/libsoup/2.67/libsoup-${version}.tar.xz" version="2.67.91"
     104            repo="ftp.gnome.org"
     105            hash="sha256:390b5b28263d3bdf9866fa694346caa5e4bcb986e014e3383e9b6130b706f3da">
    106106    </branch>
    107107  </meson>
Note: See TracChangeset for help on using the changeset viewer.