diff options
Diffstat (limited to 'WebCore/platform/network/mac')
5 files changed, 147 insertions, 44 deletions
diff --git a/WebCore/platform/network/mac/AuthenticationChallenge.h b/WebCore/platform/network/mac/AuthenticationChallenge.h index e8f3a2d..d74a92c 100644 --- a/WebCore/platform/network/mac/AuthenticationChallenge.h +++ b/WebCore/platform/network/mac/AuthenticationChallenge.h @@ -37,21 +37,25 @@ class NSURLAuthenticationChallenge; namespace WebCore { +class AuthenticationClient; + class AuthenticationChallenge : public AuthenticationChallengeBase { public: - AuthenticationChallenge() {} + AuthenticationChallenge() { } AuthenticationChallenge(const ProtectionSpace& protectionSpace, const Credential& proposedCredential, unsigned previousFailureCount, const ResourceResponse& response, const ResourceError& error); AuthenticationChallenge(NSURLAuthenticationChallenge *); id sender() const { return m_sender.get(); } - NSURLAuthenticationChallenge *nsURLAuthenticationChallenge() const { return m_macChallenge.get(); } + NSURLAuthenticationChallenge *nsURLAuthenticationChallenge() const { return m_nsChallenge.get(); } + + void setAuthenticationClient(AuthenticationClient*); // Changes sender to one that invokes client methods. private: friend class AuthenticationChallengeBase; static bool platformCompare(const AuthenticationChallenge& a, const AuthenticationChallenge& b); - RetainPtr<id> m_sender; - RetainPtr<NSURLAuthenticationChallenge *> m_macChallenge; + RetainPtr<id> m_sender; // Always the same as [m_macChallenge.get() sender], cached here for performance. + RetainPtr<NSURLAuthenticationChallenge *> m_nsChallenge; }; } diff --git a/WebCore/platform/network/mac/AuthenticationMac.mm b/WebCore/platform/network/mac/AuthenticationMac.mm index 93725d5..ea06ecd 100644 --- a/WebCore/platform/network/mac/AuthenticationMac.mm +++ b/WebCore/platform/network/mac/AuthenticationMac.mm @@ -26,6 +26,7 @@ #import "AuthenticationMac.h" #import "AuthenticationChallenge.h" +#import "AuthenticationClient.h" #import "Credential.h" #import "ProtectionSpace.h" @@ -33,6 +34,51 @@ #import <Foundation/NSURLCredential.h> #import <Foundation/NSURLProtectionSpace.h> +using namespace WebCore; + +@interface WebCoreAuthenticationClientAsChallengeSender : NSObject <NSURLAuthenticationChallengeSender> +{ + AuthenticationClient* m_client; +} +- (id)initWithAuthenticationClient:(AuthenticationClient*)client; +- (void)detachClient; +@end + +@implementation WebCoreAuthenticationClientAsChallengeSender + +- (id)initWithAuthenticationClient:(AuthenticationClient*)client +{ + self = [self init]; + if (!self) + return nil; + m_client = client; + return self; +} + +- (void)detachClient +{ + m_client = 0; +} + +- (void)useCredential:(NSURLCredential *)credential forAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge +{ + if (m_client) + m_client->receivedCredential(core(challenge), core(credential)); +} + +- (void)continueWithoutCredentialForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge +{ + if (m_client) + m_client->receivedRequestToContinueWithoutCredential(core(challenge)); +} + +- (void)cancelAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge +{ + if (m_client) + m_client->receivedCancellation(core(challenge)); +} + +@end namespace WebCore { @@ -49,17 +95,28 @@ AuthenticationChallenge::AuthenticationChallenge(const ProtectionSpace& protecti { } -AuthenticationChallenge::AuthenticationChallenge(NSURLAuthenticationChallenge *macChallenge) - : AuthenticationChallengeBase(core([macChallenge protectionSpace]), - core([macChallenge proposedCredential]), - [macChallenge previousFailureCount], - [macChallenge failureResponse], - [macChallenge error]) - , m_sender([macChallenge sender]) - , m_macChallenge(macChallenge) +AuthenticationChallenge::AuthenticationChallenge(NSURLAuthenticationChallenge *challenge) + : AuthenticationChallengeBase(core([challenge protectionSpace]), + core([challenge proposedCredential]), + [challenge previousFailureCount], + [challenge failureResponse], + [challenge error]) + , m_sender([challenge sender]) + , m_nsChallenge(challenge) { } +void AuthenticationChallenge::setAuthenticationClient(AuthenticationClient* client) +{ + if (client) { + m_sender.adoptNS([[WebCoreAuthenticationClientAsChallengeSender alloc] initWithAuthenticationClient:client]); + m_nsChallenge.adoptNS([[NSURLAuthenticationChallenge alloc] initWithAuthenticationChallenge:m_nsChallenge.get() sender:m_sender.get()]); + } else { + if ([m_sender.get() isMemberOfClass:[WebCoreAuthenticationClientAsChallengeSender class]]) + [(WebCoreAuthenticationClientAsChallengeSender *)m_sender.get() detachClient]; + } +} + bool AuthenticationChallenge::platformCompare(const AuthenticationChallenge& a, const AuthenticationChallenge& b) { if (a.sender() != b.sender()) @@ -131,6 +188,11 @@ NSURLProtectionSpace *mac(const ProtectionSpace& coreSpace) case ProtectionSpaceAuthenticationSchemeHTMLForm: method = NSURLAuthenticationMethodHTMLForm; break; +#if !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD) + case ProtectionSpaceAuthenticationSchemeNTLM: + method = NSURLAuthenticationMethodNTLM; + break; +#endif default: ASSERT_NOT_REACHED(); } @@ -167,6 +229,15 @@ NSURLCredential *mac(const Credential& coreCredential) ASSERT_NOT_REACHED(); } +#if CERTIFICATE_CREDENTIALS_SUPPORTED + if (coreCredential.type() == CredentialTypeClientCertificate) { + return [[[NSURLCredential alloc] initWithIdentity:coreCredential.identity() + certificates:(NSArray *)coreCredential.certificates() + persistence:persistence] + autorelease]; + } +#endif + return [[[NSURLCredential alloc] initWithUser:coreCredential.user() password:coreCredential.password() persistence:persistence] @@ -218,6 +289,10 @@ ProtectionSpace core(NSURLProtectionSpace *macSpace) scheme = ProtectionSpaceAuthenticationSchemeHTTPDigest; else if ([method isEqualToString:NSURLAuthenticationMethodHTMLForm]) scheme = ProtectionSpaceAuthenticationSchemeHTMLForm; +#if !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD) + else if ([method isEqualToString:NSURLAuthenticationMethodNTLM]) + scheme = ProtectionSpaceAuthenticationSchemeNTLM; +#endif else ASSERT_NOT_REACHED(); @@ -240,6 +315,12 @@ Credential core(NSURLCredential *macCredential) default: ASSERT_NOT_REACHED(); } + +#if CERTIFICATE_CREDENTIALS_SUPPORTED + SecIdentityRef identity = [macCredential identity]; + if (identity) + return Credential(identity, (CFArrayRef)[macCredential certificates], persistence); +#endif return Credential([macCredential user], [macCredential password], persistence); } diff --git a/WebCore/platform/network/mac/CredentialStorageMac.mm b/WebCore/platform/network/mac/CredentialStorageMac.mm new file mode 100644 index 0000000..66e94e9 --- /dev/null +++ b/WebCore/platform/network/mac/CredentialStorageMac.mm @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * + * 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 APPLE INC. AND ITS CONTRIBUTORS ``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 ITS 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 "CredentialStorage.h" + +#include "AuthenticationMac.h" +#include "Credential.h" + +namespace WebCore { + +Credential CredentialStorage::getFromPersistentStorage(const ProtectionSpace& protectionSpace) +{ + NSURLCredential *credential = [[NSURLCredentialStorage sharedCredentialStorage] defaultCredentialForProtectionSpace:mac(protectionSpace)]; + return credential ? core(credential) : Credential(); +} + +} // namespace WebCore diff --git a/WebCore/platform/network/mac/NetworkStateNotifierMac.cpp b/WebCore/platform/network/mac/NetworkStateNotifierMac.cpp index c0918a4..2045eb3 100644 --- a/WebCore/platform/network/mac/NetworkStateNotifierMac.cpp +++ b/WebCore/platform/network/mac/NetworkStateNotifierMac.cpp @@ -28,10 +28,10 @@ #include <SystemConfiguration/SystemConfiguration.h> -#ifdef BUILDING_ON_TIGER -// This function is available on Tiger, but not declared in the CFRunLoop.h header on Tiger. -extern "C" CFRunLoopRef CFRunLoopGetMain(); -#endif +#ifdef BUILDING_ON_TIGER +// This function is available on Tiger, but not declared in the CFRunLoop.h header on Tiger. +extern "C" CFRunLoopRef CFRunLoopGetMain(); +#endif namespace WebCore { diff --git a/WebCore/platform/network/mac/ResourceHandleMac.mm b/WebCore/platform/network/mac/ResourceHandleMac.mm index 3630b30..360425e 100644 --- a/WebCore/platform/network/mac/ResourceHandleMac.mm +++ b/WebCore/platform/network/mac/ResourceHandleMac.mm @@ -55,7 +55,7 @@ typedef int NSInteger; using namespace WebCore; -@interface WebCoreResourceHandleAsDelegate : NSObject <NSURLAuthenticationChallengeSender> +@interface WebCoreResourceHandleAsDelegate : NSObject { ResourceHandle* m_handle; } @@ -138,6 +138,7 @@ ResourceHandleInternal::~ResourceHandleInternal() ResourceHandle::~ResourceHandle() { releaseDelegate(); + d->m_currentWebChallenge.setAuthenticationClient(0); LOG(Network, "Handle %p destroyed", this); } @@ -511,10 +512,8 @@ void ResourceHandle::didReceiveAuthenticationChallenge(const AuthenticationChall #endif d->m_currentMacChallenge = challenge.nsURLAuthenticationChallenge(); - NSURLAuthenticationChallenge *webChallenge = [[NSURLAuthenticationChallenge alloc] initWithAuthenticationChallenge:d->m_currentMacChallenge - sender:(id<NSURLAuthenticationChallengeSender>)delegate()]; - d->m_currentWebChallenge = core(webChallenge); - [webChallenge release]; + d->m_currentWebChallenge = core(d->m_currentMacChallenge); + d->m_currentWebChallenge.setAuthenticationClient(this); if (client()) client()->didReceiveAuthenticationChallenge(this, d->m_currentWebChallenge); @@ -523,8 +522,8 @@ void ResourceHandle::didReceiveAuthenticationChallenge(const AuthenticationChall void ResourceHandle::didCancelAuthenticationChallenge(const AuthenticationChallenge& challenge) { ASSERT(d->m_currentMacChallenge); + ASSERT(d->m_currentMacChallenge == challenge.nsURLAuthenticationChallenge()); ASSERT(!d->m_currentWebChallenge.isNull()); - ASSERT(d->m_currentWebChallenge == challenge); if (client()) client()->didCancelAuthenticationChallenge(this, challenge); @@ -547,7 +546,7 @@ void ResourceHandle::receivedCredential(const AuthenticationChallenge& challenge // 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). // <rdar://problem/6867598> gallery.me.com is temporarily whitelisted, so that QuickTime plug-in could see the credentials. - Credential webCredential(credential.user(), credential.password(), CredentialPersistenceNone); + Credential webCredential(credential, CredentialPersistenceNone); KURL urlToStore; if (challenge.failureResponse().httpStatusCode() == 401) urlToStore = d->m_request.url(); @@ -868,27 +867,6 @@ void ResourceHandle::receivedCancellation(const AuthenticationChallenge& challen return newResponse; } -- (void)useCredential:(NSURLCredential *)credential forAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge -{ - if (!m_handle) - return; - m_handle->receivedCredential(core(challenge), core(credential)); -} - -- (void)continueWithoutCredentialForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge -{ - if (!m_handle) - return; - m_handle->receivedRequestToContinueWithoutCredential(core(challenge)); -} - -- (void)cancelAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge -{ - if (!m_handle) - return; - m_handle->receivedCancellation(core(challenge)); -} - @end #ifndef BUILDING_ON_TIGER |