AuthenticationManager.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. * Copyright (C) 2010, 2013 Apple Inc. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. * 1. Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * 2. Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
  14. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  15. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  16. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
  17. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  18. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  19. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  20. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  21. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  22. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  23. * THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #include "config.h"
  26. #include "AuthenticationManager.h"
  27. #include "AuthenticationManagerMessages.h"
  28. #include "ChildProcess.h"
  29. #include "Download.h"
  30. #include "DownloadProxyMessages.h"
  31. #include "WebCoreArgumentCoders.h"
  32. #include "WebFrame.h"
  33. #include "WebPage.h"
  34. #include "WebPageProxyMessages.h"
  35. #include <WebCore/AuthenticationChallenge.h>
  36. #include <WebCore/AuthenticationClient.h>
  37. #if ENABLE(NETWORK_PROCESS)
  38. #include "NetworkProcessProxyMessages.h"
  39. #endif
  40. using namespace WebCore;
  41. namespace WebKit {
  42. static uint64_t generateAuthenticationChallengeID()
  43. {
  44. ASSERT(isMainThread());
  45. static int64_t uniqueAuthenticationChallengeID;
  46. return ++uniqueAuthenticationChallengeID;
  47. }
  48. const char* AuthenticationManager::supplementName()
  49. {
  50. return "AuthenticationManager";
  51. }
  52. AuthenticationManager::AuthenticationManager(ChildProcess* process)
  53. : m_process(process)
  54. {
  55. m_process->addMessageReceiver(Messages::AuthenticationManager::messageReceiverName(), this);
  56. }
  57. uint64_t AuthenticationManager::establishIdentifierForChallenge(const WebCore::AuthenticationChallenge& authenticationChallenge)
  58. {
  59. ASSERT(isMainThread());
  60. uint64_t challengeID = generateAuthenticationChallengeID();
  61. m_challenges.set(challengeID, authenticationChallenge);
  62. return challengeID;
  63. }
  64. void AuthenticationManager::didReceiveAuthenticationChallenge(WebFrame* frame, const AuthenticationChallenge& authenticationChallenge)
  65. {
  66. ASSERT(frame);
  67. ASSERT(frame->page());
  68. m_process->send(Messages::WebPageProxy::DidReceiveAuthenticationChallenge(frame->frameID(), authenticationChallenge, establishIdentifierForChallenge(authenticationChallenge)), frame->page()->pageID());
  69. }
  70. #if ENABLE(NETWORK_PROCESS)
  71. void AuthenticationManager::didReceiveAuthenticationChallenge(uint64_t pageID, uint64_t frameID, const AuthenticationChallenge& authenticationChallenge)
  72. {
  73. ASSERT(pageID);
  74. ASSERT(frameID);
  75. m_process->send(Messages::NetworkProcessProxy::DidReceiveAuthenticationChallenge(pageID, frameID, authenticationChallenge, establishIdentifierForChallenge(authenticationChallenge)));
  76. }
  77. #endif
  78. void AuthenticationManager::didReceiveAuthenticationChallenge(Download* download, const AuthenticationChallenge& authenticationChallenge)
  79. {
  80. download->send(Messages::DownloadProxy::DidReceiveAuthenticationChallenge(authenticationChallenge, establishIdentifierForChallenge(authenticationChallenge)));
  81. }
  82. // Currently, only Mac knows how to respond to authentication challenges with certificate info.
  83. #if !USE(SECURITY_FRAMEWORK)
  84. bool AuthenticationManager::tryUsePlatformCertificateInfoForChallenge(const WebCore::AuthenticationChallenge&, const PlatformCertificateInfo&)
  85. {
  86. return false;
  87. }
  88. #endif
  89. void AuthenticationManager::useCredentialForChallenge(uint64_t challengeID, const Credential& credential, const PlatformCertificateInfo& certificateInfo)
  90. {
  91. ASSERT(isMainThread());
  92. AuthenticationChallenge challenge = m_challenges.take(challengeID);
  93. ASSERT(!challenge.isNull());
  94. if (tryUsePlatformCertificateInfoForChallenge(challenge, certificateInfo))
  95. return;
  96. AuthenticationClient* coreClient = challenge.authenticationClient();
  97. if (!coreClient) {
  98. // This authentication challenge comes from a download.
  99. Download::receivedCredential(challenge, credential);
  100. return;
  101. }
  102. coreClient->receivedCredential(challenge, credential);
  103. }
  104. void AuthenticationManager::continueWithoutCredentialForChallenge(uint64_t challengeID)
  105. {
  106. ASSERT(isMainThread());
  107. AuthenticationChallenge challenge = m_challenges.take(challengeID);
  108. ASSERT(!challenge.isNull());
  109. AuthenticationClient* coreClient = challenge.authenticationClient();
  110. if (!coreClient) {
  111. // This authentication challenge comes from a download.
  112. Download::receivedRequestToContinueWithoutCredential(challenge);
  113. return;
  114. }
  115. coreClient->receivedRequestToContinueWithoutCredential(challenge);
  116. }
  117. void AuthenticationManager::cancelChallenge(uint64_t challengeID)
  118. {
  119. ASSERT(isMainThread());
  120. AuthenticationChallenge challenge = m_challenges.take(challengeID);
  121. ASSERT(!challenge.isNull());
  122. AuthenticationClient* coreClient = challenge.authenticationClient();
  123. if (!coreClient) {
  124. // This authentication challenge comes from a download.
  125. Download::receivedCancellation(challenge);
  126. return;
  127. }
  128. coreClient->receivedCancellation(challenge);
  129. }
  130. } // namespace WebKit