- Revision
- 187367
- Author
- [email protected]
- Date
- 2015-07-24 15:43:42 -0700 (Fri, 24 Jul 2015)
Log Message
[Cocoa] Clean up server trust handling in ResourceHandle.
https://bugs.webkit.org/show_bug.cgi?id=147277
rdar://problem/21394410
Reviewed by Brady Eidson.
* platform/network/ProtectionSpaceBase.h: (WebCore::ProtectionSpaceBase::isPasswordBased):
* platform/network/ProtectionSpaceBase.cpp: (WebCore::ProtectionSpaceBase::isPasswordBased):
Added. This is somewhat weak, as authentication schemes could change, but I couldn't find
any better way.
* platform/network/ResourceHandle.h:
* platform/network/cf/ResourceHandleCFNet.cpp:
(WebCore::ResourceHandle::didReceiveAuthenticationChallenge):
(WebCore::ResourceHandle::tryHandlePasswordBasedAuthentication):
* platform/network/mac/ResourceHandleMac.mm:
(WebCore::ResourceHandle::didReceiveAuthenticationChallenge):
(WebCore::ResourceHandle::tryHandlePasswordBasedAuthentication):
Factored out password handling, and made sure to not try that for server trust.
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (187366 => 187367)
--- trunk/Source/WebCore/ChangeLog 2015-07-24 22:25:52 UTC (rev 187366)
+++ trunk/Source/WebCore/ChangeLog 2015-07-24 22:43:42 UTC (rev 187367)
@@ -1,3 +1,25 @@
+2015-07-24 Alexey Proskuryakov <[email protected]>
+
+ [Cocoa] Clean up server trust handling in ResourceHandle.
+ https://bugs.webkit.org/show_bug.cgi?id=147277
+ rdar://problem/21394410
+
+ Reviewed by Brady Eidson.
+
+ * platform/network/ProtectionSpaceBase.h: (WebCore::ProtectionSpaceBase::isPasswordBased):
+ * platform/network/ProtectionSpaceBase.cpp: (WebCore::ProtectionSpaceBase::isPasswordBased):
+ Added. This is somewhat weak, as authentication schemes could change, but I couldn't find
+ any better way.
+
+ * platform/network/ResourceHandle.h:
+ * platform/network/cf/ResourceHandleCFNet.cpp:
+ (WebCore::ResourceHandle::didReceiveAuthenticationChallenge):
+ (WebCore::ResourceHandle::tryHandlePasswordBasedAuthentication):
+ * platform/network/mac/ResourceHandleMac.mm:
+ (WebCore::ResourceHandle::didReceiveAuthenticationChallenge):
+ (WebCore::ResourceHandle::tryHandlePasswordBasedAuthentication):
+ Factored out password handling, and made sure to not try that for server trust.
+
2015-07-24 Zalan Bujtas <[email protected]>
[iOS]: Inline video controls are blurry on scaled-down pages on non-retina devices.
Modified: trunk/Source/WebCore/platform/network/ProtectionSpaceBase.cpp (187366 => 187367)
--- trunk/Source/WebCore/platform/network/ProtectionSpaceBase.cpp 2015-07-24 22:25:52 UTC (rev 187366)
+++ trunk/Source/WebCore/platform/network/ProtectionSpaceBase.cpp 2015-07-24 22:43:42 UTC (rev 187367)
@@ -100,6 +100,24 @@
m_authenticationScheme == ProtectionSpaceAuthenticationSchemeHTTPDigest);
}
+bool ProtectionSpaceBase::isPasswordBased() const
+{
+ switch (m_authenticationScheme) {
+ case ProtectionSpaceAuthenticationSchemeDefault:
+ case ProtectionSpaceAuthenticationSchemeHTTPBasic:
+ case ProtectionSpaceAuthenticationSchemeHTTPDigest:
+ case ProtectionSpaceAuthenticationSchemeHTMLForm:
+ case ProtectionSpaceAuthenticationSchemeNTLM:
+ case ProtectionSpaceAuthenticationSchemeNegotiate:
+ return true;
+ case ProtectionSpaceAuthenticationSchemeClientCertificateRequested:
+ case ProtectionSpaceAuthenticationSchemeServerTrustEvaluationRequested:
+ case ProtectionSpaceAuthenticationSchemeUnknown:
+ return false;
+ }
+}
+
+
bool ProtectionSpaceBase::compare(const ProtectionSpace& a, const ProtectionSpace& b)
{
if (a.host() != b.host())
Modified: trunk/Source/WebCore/platform/network/ProtectionSpaceBase.h (187366 => 187367)
--- trunk/Source/WebCore/platform/network/ProtectionSpaceBase.h 2015-07-24 22:25:52 UTC (rev 187366)
+++ trunk/Source/WebCore/platform/network/ProtectionSpaceBase.h 2015-07-24 22:43:42 UTC (rev 187367)
@@ -68,6 +68,7 @@
WEBCORE_EXPORT ProtectionSpaceAuthenticationScheme authenticationScheme() const;
bool receivesCredentialSecurely() const;
+ bool isPasswordBased() const;
bool encodingRequiresPlatformData() const { return false; }
Modified: trunk/Source/WebCore/platform/network/ResourceHandle.h (187366 => 187367)
--- trunk/Source/WebCore/platform/network/ResourceHandle.h 2015-07-24 22:25:52 UTC (rev 187366)
+++ trunk/Source/WebCore/platform/network/ResourceHandle.h 2015-07-24 22:43:42 UTC (rev 187367)
@@ -118,6 +118,10 @@
virtual void receivedChallengeRejection(const AuthenticationChallenge&) override;
#endif
+#if PLATFORM(COCOA) || USE(CFNETWORK)
+ bool tryHandlePasswordBasedAuthentication(const AuthenticationChallenge&);
+#endif
+
#if PLATFORM(COCOA) && USE(PROTECTION_SPACE_AUTH_CALLBACK)
bool canAuthenticateAgainstProtectionSpace(const ProtectionSpace&);
#endif
Modified: trunk/Source/WebCore/platform/network/cf/ResourceHandleCFNet.cpp (187366 => 187367)
--- trunk/Source/WebCore/platform/network/cf/ResourceHandleCFNet.cpp 2015-07-24 22:25:52 UTC (rev 187366)
+++ trunk/Source/WebCore/platform/network/cf/ResourceHandleCFNet.cpp 2015-07-24 22:43:42 UTC (rev 187367)
@@ -347,6 +347,24 @@
}
#endif
+ if (tryHandlePasswordBasedAuthentication(challenge))
+ return;
+
+ d->m_currentWebChallenge = challenge;
+
+ if (client())
+ client()->didReceiveAuthenticationChallenge(this, d->m_currentWebChallenge);
+ else {
+ clearAuthentication();
+ CFURLConnectionPerformDefaultHandlingForChallenge(d->m_connection.get(), challenge.cfURLAuthChallengeRef());
+ }
+}
+
+bool ResourceHandle::tryHandlePasswordBasedAuthentication(const AuthenticationChallenge& challenge)
+{
+ if (!challenge.protectionSpace().isPasswordBased())
+ return false;
+
if (!d->m_user.isNull() && !d->m_pass.isNull()) {
RetainPtr<CFURLCredentialRef> cfCredential = adoptCF(CFURLCredentialCreate(kCFAllocatorDefault, d->m_user.createCFString().get(), d->m_pass.createCFString().get(), 0, kCFURLCredentialPersistenceNone));
#if PLATFORM(COCOA)
@@ -364,7 +382,7 @@
d->m_user = String();
d->m_pass = String();
// FIXME: Per the specification, the user shouldn't be asked for credentials if there were incorrect ones provided explicitly.
- return;
+ return true;
}
if (!client() || client()->shouldUseCredentialStorage(this)) {
@@ -389,15 +407,12 @@
RetainPtr<CFURLCredentialRef> cfCredential = adoptCF(createCF(credential));
CFURLConnectionUseCredential(d->m_connection.get(), cfCredential.get(), challenge.cfURLAuthChallengeRef());
#endif
- return;
+ return true;
}
}
}
- d->m_currentWebChallenge = challenge;
-
- if (client())
- client()->didReceiveAuthenticationChallenge(this, d->m_currentWebChallenge);
+ return false;
}
#if USE(PROTECTION_SPACE_AUTH_CALLBACK)
Modified: trunk/Source/WebCore/platform/network/mac/ResourceHandleMac.mm (187366 => 187367)
--- trunk/Source/WebCore/platform/network/mac/ResourceHandleMac.mm 2015-07-24 22:25:52 UTC (rev 187366)
+++ trunk/Source/WebCore/platform/network/mac/ResourceHandleMac.mm 2015-07-24 22:43:42 UTC (rev 187367)
@@ -542,6 +542,42 @@
return;
}
+ if (tryHandlePasswordBasedAuthentication(challenge))
+ return;
+
+#if PLATFORM(IOS)
+ // If the challenge is for a proxy protection space, look for default credentials in
+ // the keychain. CFNetwork used to handle this until WebCore was changed to always
+ // return NO to -connectionShouldUseCredentialStorage: for <rdar://problem/7704943>.
+ if (!challenge.previousFailureCount() && challenge.protectionSpace().isProxy()) {
+ NSURLAuthenticationChallenge *macChallenge = mac(challenge);
+ if (NSURLCredential *credential = [[NSURLCredentialStorage sharedCredentialStorage] defaultCredentialForProtectionSpace:[macChallenge protectionSpace]]) {
+ [challenge.sender() useCredential:credential forAuthenticationChallenge:macChallenge];
+ return;
+ }
+ }
+#endif // PLATFORM(IOS)
+
+ d->m_currentMacChallenge = challenge.nsURLAuthenticationChallenge();
+ d->m_currentWebChallenge = core(d->m_currentMacChallenge);
+ d->m_currentWebChallenge.setAuthenticationClient(this);
+
+ // FIXME: Several concurrent requests can return with the an authentication challenge for the same protection space.
+ // We should avoid making additional client calls for the same protection space when already waiting for the user,
+ // because typing the same credentials several times is annoying.
+ if (client())
+ client()->didReceiveAuthenticationChallenge(this, d->m_currentWebChallenge);
+ else {
+ clearAuthentication();
+ [challenge.sender() performDefaultHandlingForAuthenticationChallenge:challenge.nsURLAuthenticationChallenge()];
+ }
+}
+
+bool ResourceHandle::tryHandlePasswordBasedAuthentication(const AuthenticationChallenge& challenge)
+{
+ if (!challenge.protectionSpace().isPasswordBased())
+ return false;
+
if (!d->m_user.isNull() && !d->m_pass.isNull()) {
NSURLCredential *credential = [[NSURLCredential alloc] initWithUser:d->m_user
password:d->m_pass
@@ -553,7 +589,7 @@
// FIXME: Per the specification, the user shouldn't be asked for credentials if there were incorrect ones provided explicitly.
d->m_user = String();
d->m_pass = String();
- return;
+ return true;
}
// FIXME: Do not use the sync version of shouldUseCredentialStorage when the client returns true from usesAsyncCallbacks.
@@ -574,33 +610,12 @@
d->m_context->storageSession().credentialStorage().set(credential, challenge.protectionSpace(), challenge.failureResponse().url());
}
[challenge.sender() useCredential:credential.nsCredential() forAuthenticationChallenge:mac(challenge)];
- return;
+ return true;
}
}
}
-#if PLATFORM(IOS)
- // If the challenge is for a proxy protection space, look for default credentials in
- // the keychain. CFNetwork used to handle this until WebCore was changed to always
- // return NO to -connectionShouldUseCredentialStorage: for <rdar://problem/7704943>.
- if (!challenge.previousFailureCount() && challenge.protectionSpace().isProxy()) {
- NSURLAuthenticationChallenge *macChallenge = mac(challenge);
- if (NSURLCredential *credential = [[NSURLCredentialStorage sharedCredentialStorage] defaultCredentialForProtectionSpace:[macChallenge protectionSpace]]) {
- [challenge.sender() useCredential:credential forAuthenticationChallenge:macChallenge];
- return;
- }
- }
-#endif // PLATFORM(IOS)
-
- d->m_currentMacChallenge = challenge.nsURLAuthenticationChallenge();
- d->m_currentWebChallenge = core(d->m_currentMacChallenge);
- d->m_currentWebChallenge.setAuthenticationClient(this);
-
- // FIXME: Several concurrent requests can return with the an authentication challenge for the same protection space.
- // We should avoid making additional client calls for the same protection space when already waiting for the user,
- // because typing the same credentials several times is annoying.
- if (client())
- client()->didReceiveAuthenticationChallenge(this, d->m_currentWebChallenge);
+ return false;
}
void ResourceHandle::didCancelAuthenticationChallenge(const AuthenticationChallenge& challenge)
@@ -617,6 +632,7 @@
bool ResourceHandle::canAuthenticateAgainstProtectionSpace(const ProtectionSpace& protectionSpace)
{
if (client()->usesAsyncCallbacks()) {
+ // FIXME: This check for client() being null makes no sense.
if (client())
client()->canAuthenticateAgainstProtectionSpaceAsync(this, protectionSpace);
else