diff options
author | wtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-29 18:02:36 +0000 |
---|---|---|
committer | wtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-29 18:02:36 +0000 |
commit | d7f166387b66955c2e5b967a3cc7467fad072e73 (patch) | |
tree | 7a5c47a5e65f90afb2eca5bbb4c0d6c08f5dc625 /net/http/url_security_manager_win.cc | |
parent | 5452d7e80ce2df298e15e6a5e17effcb26a51bf2 (diff) | |
download | chromium_src-d7f166387b66955c2e5b967a3cc7467fad072e73.zip chromium_src-d7f166387b66955c2e5b967a3cc7467fad072e73.tar.gz chromium_src-d7f166387b66955c2e5b967a3cc7467fad072e73.tar.bz2 |
On Windows, use IInternetSecurityManager to determine if it's OK
to send the default credentials to a server, without prompting the
user for permission, for HTTP NTLM or Negotiate authentication.
It is always OK to send the default credentials to a proxy without
prompting the user.
Rename the AllowDefaultCredentials method of HttpAuthHandler to
SupportsDefaultCredentials and redefine it to simply return if
the authentication scheme supports the use of default credentials,
as opposed to whether we may use the default credentials for a
particular server or proxy.
This CL contains the changes by cbentzel in
http://codereview.chromium.org/1082001.
R=cbentzel,cpu,stoyan
BUG=29596
TEST=none
Review URL: http://codereview.chromium.org/1343003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42960 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http/url_security_manager_win.cc')
-rw-r--r-- | net/http/url_security_manager_win.cc | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/net/http/url_security_manager_win.cc b/net/http/url_security_manager_win.cc new file mode 100644 index 0000000..b3abb05 --- /dev/null +++ b/net/http/url_security_manager_win.cc @@ -0,0 +1,101 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "net/http/url_security_manager.h" + +#include <urlmon.h> +#pragma comment(lib, "urlmon.lib") + +#include "base/scoped_comptr_win.h" +#include "base/string_util.h" +#include "googleurl/src/gurl.h" + +// The Windows implementation of URLSecurityManager uses WinINet/IE's +// URL security zone manager. See the MSDN page "URL Security Zones" at +// http://msdn.microsoft.com/en-us/library/ms537021(VS.85).aspx for more +// info on the Internet Security Manager and Internet Zone Manager objects. + +namespace net { + +class URLSecurityManagerWin : public URLSecurityManager { + public: + URLSecurityManagerWin(); + + // URLSecurityManager methods: + virtual bool CanUseDefaultCredentials(const GURL& auth_origin) const; + + private: + ScopedComPtr<IInternetSecurityManager> security_manager_; +}; + +URLSecurityManagerWin::URLSecurityManagerWin() { + HRESULT hr = CoInternetCreateSecurityManager(NULL, + security_manager_.Receive(), + NULL); + DCHECK(SUCCEEDED(hr)); +} + + +bool URLSecurityManagerWin::CanUseDefaultCredentials( + const GURL& auth_origin) const { + if (!security_manager_) { + NOTREACHED(); // The code in the constructor failed. + return false; + } + + std::wstring url_w = ASCIIToWide(auth_origin.spec()); + DWORD policy = 0; + HRESULT hr; + hr = security_manager_->ProcessUrlAction(url_w.c_str(), + URLACTION_CREDENTIALS_USE, + reinterpret_cast<BYTE*>(&policy), + sizeof(policy), NULL, 0, + PUAF_NOUI, 0); + if (FAILED(hr)) { + LOG(ERROR) << "IInternetSecurityManager::ProcessUrlAction failed: " << hr; + return false; + } + + // Four possible policies for URLACTION_CREDENTIALS_USE. See the MSDN page + // "About URL Security Zones" at + // http://msdn.microsoft.com/en-us/library/ms537183(VS.85).aspx + switch (policy) { + case URLPOLICY_CREDENTIALS_SILENT_LOGON_OK: + return true; + case URLPOLICY_CREDENTIALS_CONDITIONAL_PROMPT: { + // This policy means "prompt the user for permission if the resource is + // not located in the Intranet zone". TODO(wtc): Note that it's + // prompting for permission (to use the default credentials), as opposed + // to prompting the user to enter a user name and password. + + // URLZONE_LOCAL_MACHINE 0 + // URLZONE_INTRANET 1 + // URLZONE_TRUSTED 2 + // URLZONE_INTERNET 3 + // URLZONE_UNTRUSTED 4 + DWORD zone = 0; + hr = security_manager_->MapUrlToZone(url_w.c_str(), &zone, 0); + if (FAILED(hr)) { + LOG(ERROR) << "IInternetSecurityManager::MapUrlToZone failed: " << hr; + return false; + } + return zone <= URLZONE_INTRANET; + } + case URLPOLICY_CREDENTIALS_MUST_PROMPT_USER: + return false; + case URLPOLICY_CREDENTIALS_ANONYMOUS_ONLY: + // TODO(wtc): we should fail the authentication. + return false; + default: + NOTREACHED(); + return false; + } +} + +// static +URLSecurityManager* URLSecurityManager::Create() { + return new URLSecurityManagerWin; +} + +} // namespace net |