AuthenticationCF.cpp [plain text]
#include "config.h"
#include "AuthenticationCF.h"
#if USE(CFURLCONNECTION)
#include "AuthenticationChallenge.h"
#include "AuthenticationClient.h"
#include "Credential.h"
#include "ProtectionSpace.h"
#include <CFNetwork/CFURLAuthChallengePriv.h>
#include <CFNetwork/CFURLCredentialPriv.h>
#include <CFNetwork/CFURLProtectionSpacePriv.h>
namespace WebCore {
AuthenticationChallenge::AuthenticationChallenge(const ProtectionSpace& protectionSpace, const Credential& proposedCredential, unsigned previousFailureCount, const ResourceResponse& response, const ResourceError& error)
: AuthenticationChallengeBase(protectionSpace, proposedCredential, previousFailureCount, response, error)
{
}
AuthenticationChallenge::AuthenticationChallenge(CFURLAuthChallengeRef cfChallenge, AuthenticationClient* authenticationClient)
: AuthenticationChallengeBase(core(CFURLAuthChallengeGetProtectionSpace(cfChallenge)), core(CFURLAuthChallengeGetProposedCredential(cfChallenge)),
CFURLAuthChallengeGetPreviousFailureCount(cfChallenge), (CFURLResponseRef)CFURLAuthChallengeGetFailureResponse(cfChallenge), CFURLAuthChallengeGetError(cfChallenge))
, m_authenticationClient(authenticationClient)
, m_cfChallenge(cfChallenge)
{
}
void AuthenticationChallenge::setAuthenticationClient(AuthenticationClient* client)
{
m_authenticationClient = client;
}
AuthenticationClient* AuthenticationChallenge::authenticationClient() const
{
return m_authenticationClient.get();
}
bool AuthenticationChallenge::platformCompare(const AuthenticationChallenge& a, const AuthenticationChallenge& b)
{
if (a.authenticationClient() != b.authenticationClient())
return false;
if (a.cfURLAuthChallengeRef() != b.cfURLAuthChallengeRef())
return false;
return true;
}
CFURLAuthChallengeRef createCF(const AuthenticationChallenge& coreChallenge)
{
RetainPtr<CFURLCredentialRef> credential = adoptCF(createCF(coreChallenge.proposedCredential()));
RetainPtr<CFURLProtectionSpaceRef> protectionSpace = adoptCF(createCF(coreChallenge.protectionSpace()));
CFURLAuthChallengeRef result = CFURLAuthChallengeCreate(0, protectionSpace.get(), credential.get(), coreChallenge.previousFailureCount(), coreChallenge.failureResponse().cfURLResponse(), coreChallenge.error());
return result;
}
CFURLCredentialRef createCF(const Credential& coreCredential)
{
CFURLCredentialPersistence persistence = kCFURLCredentialPersistenceNone;
switch (coreCredential.persistence()) {
case CredentialPersistenceNone:
break;
case CredentialPersistenceForSession:
persistence = kCFURLCredentialPersistenceForSession;
break;
case CredentialPersistencePermanent:
persistence = kCFURLCredentialPersistencePermanent;
break;
default:
ASSERT_NOT_REACHED();
}
return CFURLCredentialCreate(0, coreCredential.user().createCFString().get(), coreCredential.password().createCFString().get(), 0, persistence);
}
CFURLProtectionSpaceRef createCF(const ProtectionSpace& coreSpace)
{
CFURLProtectionSpaceServerType serverType = kCFURLProtectionSpaceServerHTTP;
switch (coreSpace.serverType()) {
case ProtectionSpaceServerHTTP:
serverType = kCFURLProtectionSpaceServerHTTP;
break;
case ProtectionSpaceServerHTTPS:
serverType = kCFURLProtectionSpaceServerHTTPS;
break;
case ProtectionSpaceServerFTP:
serverType = kCFURLProtectionSpaceServerFTP;
break;
case ProtectionSpaceServerFTPS:
serverType = kCFURLProtectionSpaceServerFTPS;
break;
case ProtectionSpaceProxyHTTP:
serverType = kCFURLProtectionSpaceProxyHTTP;
break;
case ProtectionSpaceProxyHTTPS:
serverType = kCFURLProtectionSpaceProxyHTTPS;
break;
case ProtectionSpaceProxyFTP:
serverType = kCFURLProtectionSpaceProxyFTP;
break;
case ProtectionSpaceProxySOCKS:
serverType = kCFURLProtectionSpaceProxySOCKS;
break;
default:
ASSERT_NOT_REACHED();
}
CFURLProtectionSpaceAuthenticationScheme scheme = kCFURLProtectionSpaceAuthenticationSchemeDefault;
switch (coreSpace.authenticationScheme()) {
case ProtectionSpaceAuthenticationSchemeDefault:
scheme = kCFURLProtectionSpaceAuthenticationSchemeDefault;
break;
case ProtectionSpaceAuthenticationSchemeHTTPBasic:
scheme = kCFURLProtectionSpaceAuthenticationSchemeHTTPBasic;
break;
case ProtectionSpaceAuthenticationSchemeHTTPDigest:
scheme = kCFURLProtectionSpaceAuthenticationSchemeHTTPDigest;
break;
case ProtectionSpaceAuthenticationSchemeHTMLForm:
scheme = kCFURLProtectionSpaceAuthenticationSchemeHTMLForm;
break;
case ProtectionSpaceAuthenticationSchemeNTLM:
scheme = kCFURLProtectionSpaceAuthenticationSchemeNTLM;
break;
case ProtectionSpaceAuthenticationSchemeNegotiate:
scheme = kCFURLProtectionSpaceAuthenticationSchemeNegotiate;
break;
#if USE(PROTECTION_SPACE_AUTH_CALLBACK)
case ProtectionSpaceAuthenticationSchemeServerTrustEvaluationRequested:
scheme = kCFURLProtectionSpaceAuthenticationSchemeServerTrustEvaluationRequested;
break;
case ProtectionSpaceAuthenticationSchemeClientCertificateRequested:
scheme = kCFURLProtectionSpaceAuthenticationSchemeClientCertificateRequested;
break;
#endif
default:
ASSERT_NOT_REACHED();
}
return CFURLProtectionSpaceCreate(0, coreSpace.host().createCFString().get(), coreSpace.port(), serverType, coreSpace.realm().createCFString().get(), scheme);
}
Credential core(CFURLCredentialRef cfCredential)
{
if (!cfCredential)
return Credential();
CredentialPersistence persistence = CredentialPersistenceNone;
switch (CFURLCredentialGetPersistence(cfCredential)) {
case kCFURLCredentialPersistenceNone:
break;
case kCFURLCredentialPersistenceForSession:
persistence = CredentialPersistenceForSession;
break;
case kCFURLCredentialPersistencePermanent:
persistence = CredentialPersistencePermanent;
break;
default:
ASSERT_NOT_REACHED();
}
RetainPtr<CFStringRef> password = adoptCF(CFURLCredentialCopyPassword(cfCredential));
return Credential(CFURLCredentialGetUsername(cfCredential), password.get(), persistence);
}
ProtectionSpace core(CFURLProtectionSpaceRef cfSpace)
{
ProtectionSpaceServerType serverType = ProtectionSpaceServerHTTP;
switch (CFURLProtectionSpaceGetServerType(cfSpace)) {
case kCFURLProtectionSpaceServerHTTP:
break;
case kCFURLProtectionSpaceServerHTTPS:
serverType = ProtectionSpaceServerHTTPS;
break;
case kCFURLProtectionSpaceServerFTP:
serverType = ProtectionSpaceServerFTP;
break;
case kCFURLProtectionSpaceServerFTPS:
serverType = ProtectionSpaceServerFTPS;
break;
case kCFURLProtectionSpaceProxyHTTP:
serverType = ProtectionSpaceProxyHTTP;
break;
case kCFURLProtectionSpaceProxyHTTPS:
serverType = ProtectionSpaceProxyHTTPS;
break;
case kCFURLProtectionSpaceProxyFTP:
serverType = ProtectionSpaceProxyFTP;
break;
case kCFURLProtectionSpaceProxySOCKS:
serverType = ProtectionSpaceProxySOCKS;
break;
default:
ASSERT_NOT_REACHED();
}
ProtectionSpaceAuthenticationScheme scheme = ProtectionSpaceAuthenticationSchemeDefault;
switch (CFURLProtectionSpaceGetAuthenticationScheme(cfSpace)) {
case kCFURLProtectionSpaceAuthenticationSchemeDefault:
scheme = ProtectionSpaceAuthenticationSchemeDefault;
break;
case kCFURLProtectionSpaceAuthenticationSchemeHTTPBasic:
scheme = ProtectionSpaceAuthenticationSchemeHTTPBasic;
break;
case kCFURLProtectionSpaceAuthenticationSchemeHTTPDigest:
scheme = ProtectionSpaceAuthenticationSchemeHTTPDigest;
break;
case kCFURLProtectionSpaceAuthenticationSchemeHTMLForm:
scheme = ProtectionSpaceAuthenticationSchemeHTMLForm;
break;
case kCFURLProtectionSpaceAuthenticationSchemeNTLM:
scheme = ProtectionSpaceAuthenticationSchemeNTLM;
break;
case kCFURLProtectionSpaceAuthenticationSchemeNegotiate:
scheme = ProtectionSpaceAuthenticationSchemeNegotiate;
break;
#if USE(PROTECTION_SPACE_AUTH_CALLBACK)
case kCFURLProtectionSpaceAuthenticationSchemeClientCertificateRequested:
scheme = ProtectionSpaceAuthenticationSchemeClientCertificateRequested;
break;
case kCFURLProtectionSpaceAuthenticationSchemeServerTrustEvaluationRequested:
scheme = ProtectionSpaceAuthenticationSchemeServerTrustEvaluationRequested;
break;
#endif
default:
scheme = ProtectionSpaceAuthenticationSchemeUnknown;
ASSERT_NOT_REACHED();
}
return ProtectionSpace(CFURLProtectionSpaceGetHost(cfSpace),
CFURLProtectionSpaceGetPort(cfSpace),
serverType,
CFURLProtectionSpaceGetRealm(cfSpace),
scheme);
}
}
#endif // USE(CFURLCONNECTION)