OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // See "SSPI Sample Application" at | 5 // See "SSPI Sample Application" at |
6 // http://msdn.microsoft.com/en-us/library/aa918273.aspx | 6 // http://msdn.microsoft.com/en-us/library/aa918273.aspx |
7 // and "NTLM Security Support Provider" at | 7 // and "NTLM Security Support Provider" at |
8 // http://msdn.microsoft.com/en-us/library/aa923611.aspx. | 8 // http://msdn.microsoft.com/en-us/library/aa923611.aspx. |
9 | 9 |
10 #include "net/http/http_auth_handler_ntlm.h" | 10 #include "net/http/http_auth_handler_ntlm.h" |
11 | 11 |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
14 #include "net/base/net_util.h" | 14 #include "net/base/net_util.h" |
15 #include "net/http/http_auth_sspi_win.h" | 15 #include "net/http/http_auth_sspi_win.h" |
16 #include "net/http/url_security_manager.h" | 16 #include "net/http/url_security_manager.h" |
17 | 17 |
18 #pragma comment(lib, "secur32.lib") | 18 #pragma comment(lib, "secur32.lib") |
19 | 19 |
20 namespace net { | 20 namespace net { |
21 | 21 |
22 HttpAuthHandlerNTLM::HttpAuthHandlerNTLM( | 22 HttpAuthHandlerNTLM::HttpAuthHandlerNTLM( |
23 SSPILibrary* sspi_library, ULONG max_token_length, | 23 SSPILibrary* sspi_library, |
| 24 ULONG max_token_length, |
24 URLSecurityManager* url_security_manager) | 25 URLSecurityManager* url_security_manager) |
25 : auth_sspi_(sspi_library, "NTLM", NTLMSP_NAME, max_token_length), | 26 : HttpAuthHandler("ntlm"), |
26 url_security_manager_(url_security_manager) { | 27 auth_sspi_(sspi_library, "NTLM", NTLMSP_NAME, max_token_length), |
27 } | 28 url_security_manager_(url_security_manager) {} |
28 | 29 |
29 HttpAuthHandlerNTLM::~HttpAuthHandlerNTLM() { | 30 HttpAuthHandlerNTLM::~HttpAuthHandlerNTLM() {} |
30 } | |
31 | 31 |
32 // Require identity on first pass instead of second. | 32 // Require identity on first pass instead of second. |
33 bool HttpAuthHandlerNTLM::NeedsIdentity() { | 33 bool HttpAuthHandlerNTLM::NeedsIdentity() { |
34 return auth_sspi_.NeedsIdentity(); | 34 return auth_sspi_.NeedsIdentity(); |
35 } | 35 } |
36 | 36 |
37 bool HttpAuthHandlerNTLM::AllowsDefaultCredentials() { | 37 bool HttpAuthHandlerNTLM::AllowsDefaultCredentials() { |
38 if (target_ == HttpAuth::AUTH_PROXY) | 38 if (target_ == HttpAuth::AUTH_PROXY) |
39 return true; | 39 return true; |
40 if (!url_security_manager_) | 40 if (!url_security_manager_) |
41 return false; | 41 return false; |
42 return url_security_manager_->CanUseDefaultCredentials(origin_); | 42 return url_security_manager_->CanUseDefaultCredentials(origin_); |
43 } | 43 } |
44 | 44 |
45 HttpAuthHandlerNTLM::Factory::Factory() | 45 HttpAuthHandlerNTLM::Factory::Factory() |
46 : max_token_length_(0), | 46 : max_token_length_(0), |
47 is_unsupported_(false) { | 47 is_unsupported_(false) { |
48 } | 48 } |
49 | 49 |
50 HttpAuthHandlerNTLM::Factory::~Factory() { | 50 HttpAuthHandlerNTLM::Factory::~Factory() { |
51 } | 51 } |
52 | 52 |
53 int HttpAuthHandlerNTLM::Factory::CreateAuthHandler( | 53 scoped_ptr<HttpAuthHandler> |
54 const HttpAuthChallengeTokenizer& challenge, | 54 HttpAuthHandlerNTLM::Factory::CreateAuthHandlerForScheme( |
55 HttpAuth::Target target, | 55 const std::string& scheme) { |
56 const GURL& origin, | 56 DCHECK(HttpAuth::IsValidNormalizedScheme(scheme)); |
57 CreateReason reason, | 57 if (scheme != "ntlm" || is_unsupported_) |
58 int digest_nonce_count, | 58 return scoped_ptr<HttpAuthHandler>(); |
59 const BoundNetLog& net_log, | |
60 scoped_ptr<HttpAuthHandler>* handler) { | |
61 if (is_unsupported_ || reason == CREATE_PREEMPTIVE) | |
62 return ERR_UNSUPPORTED_AUTH_SCHEME; | |
63 if (max_token_length_ == 0) { | 59 if (max_token_length_ == 0) { |
64 int rv = DetermineMaxTokenLength(sspi_library_.get(), NTLMSP_NAME, | 60 int rv = DetermineMaxTokenLength(sspi_library_.get(), NTLMSP_NAME, |
65 &max_token_length_); | 61 &max_token_length_); |
66 if (rv == ERR_UNSUPPORTED_AUTH_SCHEME) | 62 if (rv == ERR_UNSUPPORTED_AUTH_SCHEME) |
67 is_unsupported_ = true; | 63 is_unsupported_ = true; |
68 if (rv != OK) | 64 if (rv != OK) |
69 return rv; | 65 return scoped_ptr<HttpAuthHandler>(); |
70 } | 66 } |
71 // TODO(cbentzel): Move towards model of parsing in the factory | 67 // TODO(cbentzel): Move towards model of parsing in the factory |
72 // method and only constructing when valid. | 68 // method and only constructing when valid. |
73 scoped_ptr<HttpAuthHandler> tmp_handler( | 69 return make_scoped_ptr(new HttpAuthHandlerNTLM( |
74 new HttpAuthHandlerNTLM(sspi_library_.get(), max_token_length_, | 70 sspi_library_.get(), max_token_length_, url_security_manager())); |
75 url_security_manager())); | |
76 int result = | |
77 tmp_handler->HandleInitialChallenge(challenge, target, origin, net_log); | |
78 if (result == OK) | |
79 handler->swap(tmp_handler); | |
80 return result; | |
81 } | 71 } |
82 | 72 |
83 } // namespace net | 73 } // namespace net |
OLD | NEW |