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 #include "net/http/http_auth_handler_ntlm.h" | 5 #include "net/http/http_auth_handler_ntlm.h" |
6 | 6 |
7 #if !defined(NTLM_SSPI) | 7 #if !defined(NTLM_SSPI) |
8 #include "base/base64.h" | 8 #include "base/base64.h" |
9 #endif | 9 #endif |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.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_challenge_tokenizer.h" | 15 #include "net/http/http_auth_challenge_tokenizer.h" |
16 | 16 |
17 namespace net { | 17 namespace net { |
18 | 18 |
19 HttpAuth::AuthorizationResult HttpAuthHandlerNTLM::HandleAnotherChallenge( | 19 HttpAuth::AuthorizationResult HttpAuthHandlerNTLM::HandleAnotherChallenge( |
20 const HttpAuthChallengeTokenizer& challenge) { | 20 const HttpAuthChallengeTokenizer& challenge) { |
21 return ParseChallenge(challenge, false); | 21 return ParseChallenge(challenge, false); |
22 } | 22 } |
23 | 23 |
24 int HttpAuthHandlerNTLM::Init(const HttpAuthChallengeTokenizer& tok) { | 24 int HttpAuthHandlerNTLM::Init(const HttpAuthChallengeTokenizer& tok) { |
25 auth_scheme_ = "ntlm"; | |
26 return ParseChallenge(tok, true) == HttpAuth::AUTHORIZATION_RESULT_ACCEPT | 25 return ParseChallenge(tok, true) == HttpAuth::AUTHORIZATION_RESULT_ACCEPT |
27 ? OK | 26 ? OK |
28 : ERR_INVALID_RESPONSE; | 27 : ERR_INVALID_RESPONSE; |
29 } | 28 } |
30 | 29 |
31 int HttpAuthHandlerNTLM::GenerateAuthTokenImpl( | 30 int HttpAuthHandlerNTLM::GenerateAuthTokenImpl( |
32 const AuthCredentials* credentials, | 31 const AuthCredentials* credentials, |
33 const HttpRequestInfo& request, | 32 const HttpRequestInfo& request, |
34 const CompletionCallback& callback, | 33 const CompletionCallback& callback, |
35 std::string* auth_token) { | 34 std::string* auth_token) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 *auth_token = std::string("NTLM ") + encode_output; | 94 *auth_token = std::string("NTLM ") + encode_output; |
96 return OK; | 95 return OK; |
97 #endif | 96 #endif |
98 } | 97 } |
99 | 98 |
100 // The NTLM challenge header looks like: | 99 // The NTLM challenge header looks like: |
101 // WWW-Authenticate: NTLM auth-data | 100 // WWW-Authenticate: NTLM auth-data |
102 HttpAuth::AuthorizationResult HttpAuthHandlerNTLM::ParseChallenge( | 101 HttpAuth::AuthorizationResult HttpAuthHandlerNTLM::ParseChallenge( |
103 const HttpAuthChallengeTokenizer& tok, | 102 const HttpAuthChallengeTokenizer& tok, |
104 bool initial_challenge) { | 103 bool initial_challenge) { |
| 104 DCHECK(tok.SchemeIs("ntlm")); |
105 #if defined(NTLM_SSPI) | 105 #if defined(NTLM_SSPI) |
106 // auth_sspi_ contains state for whether or not this is the initial challenge. | 106 // auth_sspi_ contains state for whether or not this is the initial challenge. |
107 return auth_sspi_.ParseChallenge(tok); | 107 return auth_sspi_.ParseChallenge(tok); |
108 #else | 108 #else |
109 // TODO(cbentzel): Most of the logic between SSPI, GSSAPI, and portable NTLM | 109 // TODO(cbentzel): Most of the logic between SSPI, GSSAPI, and portable NTLM |
110 // authentication parsing could probably be shared - just need to know if | 110 // authentication parsing could probably be shared - just need to know if |
111 // there was previously a challenge round. | 111 // there was previously a challenge round. |
112 // TODO(cbentzel): Write a test case to validate that auth_data_ is left empty | 112 // TODO(cbentzel): Write a test case to validate that auth_data_ is left empty |
113 // in all failure conditions. | 113 // in all failure conditions. |
114 auth_data_.clear(); | 114 auth_data_.clear(); |
(...skipping 19 matching lines...) Expand all Loading... |
134 | 134 |
135 // static | 135 // static |
136 std::string HttpAuthHandlerNTLM::CreateSPN(const GURL& origin) { | 136 std::string HttpAuthHandlerNTLM::CreateSPN(const GURL& origin) { |
137 // The service principal name of the destination server. See | 137 // The service principal name of the destination server. See |
138 // http://msdn.microsoft.com/en-us/library/ms677949%28VS.85%29.aspx | 138 // http://msdn.microsoft.com/en-us/library/ms677949%28VS.85%29.aspx |
139 std::string target("HTTP/"); | 139 std::string target("HTTP/"); |
140 target.append(GetHostAndPort(origin)); | 140 target.append(GetHostAndPort(origin)); |
141 return target; | 141 return target; |
142 } | 142 } |
143 | 143 |
| 144 // None of the implementations support pre-emptive authentication for NTLM. |
| 145 scoped_ptr<HttpAuthHandler> |
| 146 HttpAuthHandlerNTLM::Factory::CreateAndInitPreemptiveAuthHandler( |
| 147 HttpAuthCache::Entry* cache_entry, |
| 148 const HttpAuthChallengeTokenizer& tokenizer, |
| 149 HttpAuth::Target target, |
| 150 const BoundNetLog& net_log) { |
| 151 return scoped_ptr<HttpAuthHandler>(); |
| 152 } |
| 153 |
144 } // namespace net | 154 } // namespace net |
OLD | NEW |