Skip to content

Commit

Permalink
Port CredentialPersistence to the new serialization format
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=264661

Reviewed by Chris Dumez.

Remove EnumTraits for CredentialPersistence and
port the enum to a serializable format.

* Source/WebCore/platform/network/CredentialBase.cpp:
(WebCore::CredentialBase::CredentialBase):
* Source/WebCore/platform/network/CredentialBase.h:
(): Deleted.
* Source/WebCore/platform/network/cocoa/CredentialCocoa.mm:
(WebCore::toNSURLCredentialPersistence):
(WebCore::toCredentialPersistence):
* Source/WebCore/platform/network/mac/ResourceHandleMac.mm:
(WebCore::ResourceHandle::createNSURLConnection):
(WebCore::ResourceHandle::tryHandlePasswordBasedAuthentication):
(WebCore::ResourceHandle::receivedCredential):
* Source/WebCore/platform/network/soup/NetworkStorageSessionSoup.cpp:
(WebCore::NetworkStorageSession::getCredentialFromPersistentStorage):
* Source/WebKit/NetworkProcess/cocoa/NetworkDataTaskCocoa.mm:
(WebKit::NetworkDataTaskCocoa::NetworkDataTaskCocoa):
(WebKit::NetworkDataTaskCocoa::tryPasswordBasedAuthentication):
* Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.mm:
(WebKit::CompletionHandler<void):
* Source/WebKit/NetworkProcess/curl/NetworkDataTaskCurl.cpp:
(WebKit::NetworkDataTaskCurl::NetworkDataTaskCurl):
(WebKit::NetworkDataTaskCurl::tryHttpAuthentication):
(WebKit::NetworkDataTaskCurl::tryProxyAuthentication):
(WebKit::NetworkDataTaskCurl::tryServerTrustEvaluation):
* Source/WebKit/NetworkProcess/soup/NetworkDataTaskSoup.cpp:
(WebKit::NetworkDataTaskSoup::NetworkDataTaskSoup):
(WebKit::NetworkDataTaskSoup::authenticate):
(WebKit::NetworkDataTaskSoup::continueAuthenticate):
* Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in:
* Source/WebKit/UIProcess/API/C/WKAPICast.h:
(WebKit::toCredentialPersistence):
* Source/WebKit/UIProcess/API/glib/WebKitCredential.cpp:
(toWebKitCredentialPersistence):
(toWebCoreCredentialPersistence):
* Source/WebKit/UIProcess/API/gtk/WebKitAuthenticationDialog.cpp:
(okButtonClicked):

Canonical link: https://commits.webkit.org/270599@main
  • Loading branch information
csaavedra committed Nov 11, 2023
1 parent e55ad89 commit 0ddbf5c
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 58 deletions.
2 changes: 1 addition & 1 deletion Source/WebCore/platform/network/CredentialBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace WebCore {
CredentialBase::CredentialBase()
: m_user(emptyString())
, m_password(emptyString())
, m_persistence(CredentialPersistenceNone)
, m_persistence(CredentialPersistence::None)
{
}

Expand Down
22 changes: 4 additions & 18 deletions Source/WebCore/platform/network/CredentialBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,16 @@

#pragma once

#include <wtf/EnumTraits.h>
#include <wtf/text/WTFString.h>

namespace WebCore {

class Credential;

enum CredentialPersistence {
CredentialPersistenceNone,
CredentialPersistenceForSession,
CredentialPersistencePermanent
enum class CredentialPersistence : uint8_t {
None,
ForSession,
Permanent
};

class CredentialBase {
Expand Down Expand Up @@ -69,16 +68,3 @@ class CredentialBase {
inline bool operator==(const Credential& a, const Credential& b) { return CredentialBase::compare(a, b); }

} // namespace WebCore

namespace WTF {

template<> struct EnumTraits<WebCore::CredentialPersistence> {
using values = EnumValues<
WebCore::CredentialPersistence,
WebCore::CredentialPersistence::CredentialPersistenceNone,
WebCore::CredentialPersistence::CredentialPersistenceForSession,
WebCore::CredentialPersistence::CredentialPersistencePermanent
>;
};

} // namespace WTF
14 changes: 7 additions & 7 deletions Source/WebCore/platform/network/cocoa/CredentialCocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
static NSURLCredentialPersistence toNSURLCredentialPersistence(CredentialPersistence persistence)
{
switch (persistence) {
case CredentialPersistenceNone:
case CredentialPersistence::None:
return NSURLCredentialPersistenceNone;
case CredentialPersistenceForSession:
case CredentialPersistence::ForSession:
return NSURLCredentialPersistenceForSession;
case CredentialPersistencePermanent:
case CredentialPersistence::Permanent:
return NSURLCredentialPersistencePermanent;
}

Expand All @@ -47,16 +47,16 @@ static CredentialPersistence toCredentialPersistence(NSURLCredentialPersistence
{
switch (persistence) {
case NSURLCredentialPersistenceNone:
return CredentialPersistenceNone;
return CredentialPersistence::None;
case NSURLCredentialPersistenceForSession:
return CredentialPersistenceForSession;
return CredentialPersistence::ForSession;
case NSURLCredentialPersistencePermanent:
case NSURLCredentialPersistenceSynchronizable:
return CredentialPersistencePermanent;
return CredentialPersistence::Permanent;
}

ASSERT_NOT_REACHED();
return CredentialPersistenceNone;
return CredentialPersistence::None;
}

Credential::Credential(const Credential& original, CredentialPersistence persistence)
Expand Down
8 changes: 4 additions & 4 deletions Source/WebCore/platform/network/mac/ResourceHandleMac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ static bool synchronousWillSendRequestEnabled()
// This makes it possible to implement logout by sending an XMLHttpRequest with known incorrect credentials, and aborting it immediately
// (so that an authentication dialog doesn't pop up).
if (auto* networkStorageSession = d->m_context->storageSession())
networkStorageSession->credentialStorage().set(firstRequest().cachePartition(), Credential(d->m_user, d->m_password, CredentialPersistenceNone), firstRequest().url());
networkStorageSession->credentialStorage().set(firstRequest().cachePartition(), Credential(d->m_user, d->m_password, CredentialPersistence::None), firstRequest().url());
}
}

Expand Down Expand Up @@ -554,7 +554,7 @@ static bool synchronousWillSendRequestEnabled()
if (auto* networkStorageSession = d->m_context->storageSession())
credential = networkStorageSession->credentialStorage().get(d->m_partition, challenge.protectionSpace());
if (!credential.isEmpty() && credential != d->m_initialCredential) {
ASSERT(credential.persistence() == CredentialPersistenceNone);
ASSERT(credential.persistence() == CredentialPersistence::None);
if (challenge.failureResponse().httpStatusCode() == 401) {
// Store the credential back, possibly adding it as a default for this directory.
if (auto* networkStorageSession = d->m_context->storageSession())
Expand Down Expand Up @@ -593,10 +593,10 @@ static bool synchronousWillSendRequestEnabled()
return;
}

if (credential.persistence() == CredentialPersistenceForSession && challenge.protectionSpace().authenticationScheme() != ProtectionSpace::AuthenticationScheme::ServerTrustEvaluationRequested) {
if (credential.persistence() == CredentialPersistence::ForSession && challenge.protectionSpace().authenticationScheme() != ProtectionSpace::AuthenticationScheme::ServerTrustEvaluationRequested) {
// Manage per-session credentials internally, because once NSURLCredentialPersistenceForSession is used, there is no way
// to ignore it for a particular request (short of removing it altogether).
Credential webCredential(credential, CredentialPersistenceNone);
Credential webCredential(credential, CredentialPersistence::None);
URL urlToStore;
if (challenge.failureResponse().httpStatusCode() == 401)
urlToStore = challenge.failureResponse().url();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ void NetworkStorageSession::getCredentialFromPersistentStorage(const ProtectionS
size_t length;
GRefPtr<SecretValue> secretValue = adoptGRef(secret_item_get_secret(secretItem.get()));
const char* passwordData = secret_value_get(secretValue.get(), &length);
data->completionHandler(Credential(user, String::fromUTF8(passwordData, length), CredentialPersistencePermanent));
data->completionHandler(Credential(user, String::fromUTF8(passwordData, length), CredentialPersistence::Permanent));
}, data.release());
#else
UNUSED_PARAM(protectionSpace);
Expand Down
6 changes: 3 additions & 3 deletions Source/WebKit/NetworkProcess/cocoa/NetworkDataTaskCocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ static float toNSURLSessionTaskPriority(WebCore::ResourceLoadPriority priority)
if (m_user.isEmpty() && m_password.isEmpty())
m_initialCredential = storageSession->credentialStorage().get(m_partition, url);
else
storageSession->credentialStorage().set(m_partition, WebCore::Credential(m_user, m_password, WebCore::CredentialPersistenceNone), url);
storageSession->credentialStorage().set(m_partition, WebCore::Credential(m_user, m_password, WebCore::CredentialPersistence::None), url);
}
}

Expand Down Expand Up @@ -498,7 +498,7 @@ static float toNSURLSessionTaskPriority(WebCore::ResourceLoadPriority priority)
return false;

if (!m_user.isEmpty() || !m_password.isEmpty()) {
auto persistence = m_storedCredentialsPolicy == WebCore::StoredCredentialsPolicy::Use ? WebCore::CredentialPersistenceForSession : WebCore::CredentialPersistenceNone;
auto persistence = m_storedCredentialsPolicy == WebCore::StoredCredentialsPolicy::Use ? WebCore::CredentialPersistence::ForSession : WebCore::CredentialPersistence::None;
completionHandler(AuthenticationChallengeDisposition::UseCredential, WebCore::Credential(m_user, m_password, persistence));
m_user = String();
m_password = String();
Expand All @@ -517,7 +517,7 @@ static float toNSURLSessionTaskPriority(WebCore::ResourceLoadPriority priority)
if (!challenge.previousFailureCount()) {
auto credential = m_session->networkStorageSession() ? m_session->networkStorageSession()->credentialStorage().get(m_partition, challenge.protectionSpace()) : WebCore::Credential();
if (!credential.isEmpty() && credential != m_initialCredential) {
ASSERT(credential.persistence() == WebCore::CredentialPersistenceNone);
ASSERT(credential.persistence() == WebCore::CredentialPersistence::None);
if (challenge.failureResponse().httpStatusCode() == 401) {
// Store the credential back, possibly adding it as a default for this directory.
if (auto* storageSession = m_session->networkStorageSession())
Expand Down
4 changes: 2 additions & 2 deletions Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1807,8 +1807,8 @@ static void activateSessionCleanup(NetworkSessionCocoa& session, const NetworkSe
#else
UNUSED_PARAM(taskIdentifier);
#endif
if (credential.persistence() == WebCore::CredentialPersistenceForSession && authenticationChallenge.protectionSpace().isPasswordBased()) {
WebCore::Credential nonPersistentCredential(credential.user(), credential.password(), WebCore::CredentialPersistenceNone);
if (credential.persistence() == WebCore::CredentialPersistence::ForSession && authenticationChallenge.protectionSpace().isPasswordBased()) {
WebCore::Credential nonPersistentCredential(credential.user(), credential.password(), WebCore::CredentialPersistence::None);
URL urlToStore;
if (authenticationChallenge.failureResponse().httpStatusCode() == 401)
urlToStore = authenticationChallenge.failureResponse().url();
Expand Down
12 changes: 6 additions & 6 deletions Source/WebKit/NetworkProcess/curl/NetworkDataTaskCurl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ NetworkDataTaskCurl::NetworkDataTaskCurl(NetworkSession& session, NetworkDataTas
if (m_user.isEmpty() && m_password.isEmpty())
m_initialCredential = m_session->networkStorageSession()->credentialStorage().get(m_partition, request.url());
else
m_session->networkStorageSession()->credentialStorage().set(m_partition, Credential(m_user, m_password, CredentialPersistenceNone), request.url());
m_session->networkStorageSession()->credentialStorage().set(m_partition, Credential(m_user, m_password, CredentialPersistence::None), request.url());
}
}

Expand Down Expand Up @@ -416,7 +416,7 @@ void NetworkDataTaskCurl::willPerformHTTPRedirection()
void NetworkDataTaskCurl::tryHttpAuthentication(AuthenticationChallenge&& challenge)
{
if (!m_user.isNull() && !m_password.isNull()) {
auto persistence = m_storedCredentialsPolicy == WebCore::StoredCredentialsPolicy::Use ? WebCore::CredentialPersistenceForSession : WebCore::CredentialPersistenceNone;
auto persistence = m_storedCredentialsPolicy == WebCore::StoredCredentialsPolicy::Use ? WebCore::CredentialPersistence::ForSession : WebCore::CredentialPersistence::None;
restartWithCredential(challenge.protectionSpace(), Credential(m_user, m_password, persistence));
m_user = String();
m_password = String();
Expand All @@ -434,7 +434,7 @@ void NetworkDataTaskCurl::tryHttpAuthentication(AuthenticationChallenge&& challe
if (!challenge.previousFailureCount()) {
auto credential = m_session->networkStorageSession()->credentialStorage().get(m_partition, challenge.protectionSpace());
if (!credential.isEmpty() && credential != m_initialCredential) {
ASSERT(credential.persistence() == CredentialPersistenceNone);
ASSERT(credential.persistence() == CredentialPersistence::None);
if (challenge.failureResponse().isUnauthorized()) {
// Store the credential back, possibly adding it as a default for this directory.
m_session->networkStorageSession()->credentialStorage().set(m_partition, credential, challenge.protectionSpace(), challenge.failureResponse().url());
Expand All @@ -457,7 +457,7 @@ void NetworkDataTaskCurl::tryHttpAuthentication(AuthenticationChallenge&& challe

if (disposition == AuthenticationChallengeDisposition::UseCredential && !credential.isEmpty()) {
if (m_storedCredentialsPolicy == StoredCredentialsPolicy::Use) {
if (credential.persistence() == CredentialPersistenceForSession || credential.persistence() == CredentialPersistencePermanent)
if (credential.persistence() == CredentialPersistence::ForSession || credential.persistence() == CredentialPersistence::Permanent)
m_session->networkStorageSession()->credentialStorage().set(m_partition, credential, challenge.protectionSpace(), challenge.failureResponse().url());
}

Expand Down Expand Up @@ -485,7 +485,7 @@ void NetworkDataTaskCurl::tryProxyAuthentication(WebCore::AuthenticationChalleng
CurlContext::singleton().setProxyUserPass(credential.user(), credential.password());
CurlContext::singleton().setDefaultProxyAuthMethod();

auto requestCredential = m_curlRequest ? Credential(m_curlRequest->user(), m_curlRequest->password(), CredentialPersistenceNone) : Credential();
auto requestCredential = m_curlRequest ? Credential(m_curlRequest->user(), m_curlRequest->password(), CredentialPersistence::None) : Credential();
restartWithCredential(challenge.protectionSpace(), requestCredential);
return;
}
Expand All @@ -501,7 +501,7 @@ void NetworkDataTaskCurl::tryServerTrustEvaluation(AuthenticationChallenge&& cha
return;

if (disposition == AuthenticationChallengeDisposition::UseCredential && !credential.isEmpty()) {
auto requestCredential = m_curlRequest ? Credential(m_curlRequest->user(), m_curlRequest->password(), CredentialPersistenceNone) : Credential();
auto requestCredential = m_curlRequest ? Credential(m_curlRequest->user(), m_curlRequest->password(), CredentialPersistence::None) : Credential();
restartWithCredential(challenge.protectionSpace(), requestCredential);
return;
}
Expand Down
8 changes: 4 additions & 4 deletions Source/WebKit/NetworkProcess/soup/NetworkDataTaskSoup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ NetworkDataTaskSoup::NetworkDataTaskSoup(NetworkSession& session, NetworkDataTas
if (m_user.isEmpty() && m_password.isEmpty())
m_initialCredential = m_session->networkStorageSession()->credentialStorage().get(m_partition, request.url());
else
m_session->networkStorageSession()->credentialStorage().set(m_partition, Credential(m_user, m_password, CredentialPersistenceNone), request.url());
m_session->networkStorageSession()->credentialStorage().set(m_partition, Credential(m_user, m_password, CredentialPersistence::None), request.url());
}
applyAuthenticationToRequest(request);
}
Expand Down Expand Up @@ -742,7 +742,7 @@ void NetworkDataTaskSoup::authenticate(AuthenticationChallenge&& challenge)
if (!challenge.previousFailureCount()) {
auto credential = m_session->networkStorageSession()->credentialStorage().get(m_partition, challenge.protectionSpace());
if (!credential.isEmpty() && credential != m_initialCredential) {
ASSERT(credential.persistence() == CredentialPersistenceNone);
ASSERT(credential.persistence() == CredentialPersistence::None);

if (isAuthenticationFailureStatusCode(challenge.failureResponse().httpStatusCode())) {
// Store the credential back, possibly adding it as a default for this directory.
Expand Down Expand Up @@ -801,10 +801,10 @@ void NetworkDataTaskSoup::continueAuthenticate(AuthenticationChallenge&& challen
// because once we authenticate via libsoup, there is no way to ignore it for a particular request. Right now,
// we place the credentials in the store even though libsoup will never fire the authenticate signal again for
// this protection space.
if (credential.persistence() == CredentialPersistenceForSession || credential.persistence() == CredentialPersistencePermanent)
if (credential.persistence() == CredentialPersistence::ForSession || credential.persistence() == CredentialPersistence::Permanent)
m_session->networkStorageSession()->credentialStorage().set(m_partition, credential, challenge.protectionSpace(), challenge.failureResponse().url());

if (credential.persistence() == CredentialPersistencePermanent && persistentCredentialStorageEnabled()) {
if (credential.persistence() == CredentialPersistence::Permanent && persistentCredentialStorageEnabled()) {
m_protectionSpaceForPersistentStorage = challenge.protectionSpace();
m_credentialForPersistentStorage = credential;
}
Expand Down
6 changes: 6 additions & 0 deletions Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in
Original file line number Diff line number Diff line change
Expand Up @@ -6690,3 +6690,9 @@ enum class WebCore::ResourceErrorBaseType : uint8_t {
Cancellation,
Timeout,
}

enum class WebCore::CredentialPersistence : uint8_t {
None,
ForSession,
Permanent,
}
8 changes: 4 additions & 4 deletions Source/WebKit/UIProcess/API/C/WKAPICast.h
Original file line number Diff line number Diff line change
Expand Up @@ -347,13 +347,13 @@ inline WebCore::CredentialPersistence toCredentialPersistence(WKCredentialPersis
{
switch (type) {
case kWKCredentialPersistenceNone:
return WebCore::CredentialPersistenceNone;
return WebCore::CredentialPersistence::None;
case kWKCredentialPersistenceForSession:
return WebCore::CredentialPersistenceForSession;
return WebCore::CredentialPersistence::ForSession;
case kWKCredentialPersistencePermanent:
return WebCore::CredentialPersistencePermanent;
return WebCore::CredentialPersistence::Permanent;
default:
return WebCore::CredentialPersistenceNone;
return WebCore::CredentialPersistence::None;
}
}

Expand Down
14 changes: 7 additions & 7 deletions Source/WebKit/UIProcess/API/glib/WebKitCredential.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ G_DEFINE_BOXED_TYPE(WebKitCredential, webkit_credential, webkit_credential_copy,
static inline WebKitCredentialPersistence toWebKitCredentialPersistence(WebCore::CredentialPersistence corePersistence)
{
switch (corePersistence) {
case WebCore::CredentialPersistenceNone:
case WebCore::CredentialPersistence::None:
return WEBKIT_CREDENTIAL_PERSISTENCE_NONE;
case WebCore::CredentialPersistenceForSession:
case WebCore::CredentialPersistence::ForSession:
return WEBKIT_CREDENTIAL_PERSISTENCE_FOR_SESSION;
case WebCore::CredentialPersistencePermanent:
case WebCore::CredentialPersistence::Permanent:
return WEBKIT_CREDENTIAL_PERSISTENCE_PERMANENT;
default:
ASSERT_NOT_REACHED();
Expand All @@ -66,14 +66,14 @@ static inline WebCore::CredentialPersistence toWebCoreCredentialPersistence(WebK
{
switch (kitPersistence) {
case WEBKIT_CREDENTIAL_PERSISTENCE_NONE:
return WebCore::CredentialPersistenceNone;
return WebCore::CredentialPersistence::None;
case WEBKIT_CREDENTIAL_PERSISTENCE_FOR_SESSION:
return WebCore::CredentialPersistenceForSession;
return WebCore::CredentialPersistence::ForSession;
case WEBKIT_CREDENTIAL_PERSISTENCE_PERMANENT:
return WebCore::CredentialPersistencePermanent;
return WebCore::CredentialPersistence::Permanent;
default:
ASSERT_NOT_REACHED();
return WebCore::CredentialPersistenceNone;
return WebCore::CredentialPersistence::None;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ static void okButtonClicked(GtkButton*, WebKitAuthenticationDialog* authDialog)
#endif

WebCore::CredentialPersistence persistence = rememberPassword && priv->credentialStorageMode == AllowPersistentStorage ?
WebCore::CredentialPersistencePermanent : WebCore::CredentialPersistenceForSession;
WebCore::CredentialPersistence::Permanent : WebCore::CredentialPersistence::ForSession;

// FIXME: Use a stack allocated WebKitCredential.
WebKitCredential* credential = webkitCredentialCreate(WebCore::Credential(String::fromUTF8(username), String::fromUTF8(password), persistence));
Expand Down

0 comments on commit 0ddbf5c

Please sign in to comment.