| 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_negotiate.h" | 5 #include "net/http/http_auth_handler_negotiate.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 #if defined(OS_WIN) | 99 #if defined(OS_WIN) |
| 100 : auth_system_(auth_library, "Negotiate", NEGOSSP_NAME, max_token_length), | 100 : auth_system_(auth_library, "Negotiate", NEGOSSP_NAME, max_token_length), |
| 101 #elif defined(OS_POSIX) | 101 #elif defined(OS_POSIX) |
| 102 : auth_system_(auth_library, "Negotiate", CHROME_GSS_KRB5_MECH_OID_DESC), | 102 : auth_system_(auth_library, "Negotiate", CHROME_GSS_KRB5_MECH_OID_DESC), |
| 103 #endif | 103 #endif |
| 104 disable_cname_lookup_(disable_cname_lookup), | 104 disable_cname_lookup_(disable_cname_lookup), |
| 105 use_port_(use_port), | 105 use_port_(use_port), |
| 106 resolver_(resolver), | 106 resolver_(resolver), |
| 107 already_called_(false), | 107 already_called_(false), |
| 108 has_credentials_(false), | 108 has_credentials_(false), |
| 109 user_callback_(NULL), | |
| 110 auth_token_(NULL), | 109 auth_token_(NULL), |
| 111 next_state_(STATE_NONE), | 110 next_state_(STATE_NONE), |
| 112 url_security_manager_(url_security_manager) { | 111 url_security_manager_(url_security_manager) { |
| 113 } | 112 } |
| 114 | 113 |
| 115 HttpAuthHandlerNegotiate::~HttpAuthHandlerNegotiate() { | 114 HttpAuthHandlerNegotiate::~HttpAuthHandlerNegotiate() { |
| 116 } | 115 } |
| 117 | 116 |
| 118 std::wstring HttpAuthHandlerNegotiate::CreateSPN( | 117 std::wstring HttpAuthHandlerNegotiate::CreateSPN( |
| 119 const AddressList& address_list, const GURL& origin) { | 118 const AddressList& address_list, const GURL& origin) { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 auth_system_.Delegate(); | 204 auth_system_.Delegate(); |
| 206 auth_scheme_ = HttpAuth::AUTH_SCHEME_NEGOTIATE; | 205 auth_scheme_ = HttpAuth::AUTH_SCHEME_NEGOTIATE; |
| 207 score_ = 4; | 206 score_ = 4; |
| 208 properties_ = ENCRYPTS_IDENTITY | IS_CONNECTION_BASED; | 207 properties_ = ENCRYPTS_IDENTITY | IS_CONNECTION_BASED; |
| 209 HttpAuth::AuthorizationResult auth_result = | 208 HttpAuth::AuthorizationResult auth_result = |
| 210 auth_system_.ParseChallenge(challenge); | 209 auth_system_.ParseChallenge(challenge); |
| 211 return (auth_result == HttpAuth::AUTHORIZATION_RESULT_ACCEPT); | 210 return (auth_result == HttpAuth::AUTHORIZATION_RESULT_ACCEPT); |
| 212 } | 211 } |
| 213 | 212 |
| 214 int HttpAuthHandlerNegotiate::GenerateAuthTokenImpl( | 213 int HttpAuthHandlerNegotiate::GenerateAuthTokenImpl( |
| 215 const AuthCredentials* credentials, | 214 const AuthCredentials* credentials, const HttpRequestInfo* request, |
| 216 const HttpRequestInfo* request, | 215 const CompletionCallback& callback, std::string* auth_token) { |
| 217 OldCompletionCallback* callback, | 216 DCHECK(callback_.is_null()); |
| 218 std::string* auth_token) { | |
| 219 DCHECK(user_callback_ == NULL); | |
| 220 DCHECK(auth_token_ == NULL); | 217 DCHECK(auth_token_ == NULL); |
| 221 auth_token_ = auth_token; | 218 auth_token_ = auth_token; |
| 222 if (already_called_) { | 219 if (already_called_) { |
| 223 DCHECK((!has_credentials_ && credentials == NULL) || | 220 DCHECK((!has_credentials_ && credentials == NULL) || |
| 224 (has_credentials_ && credentials->Equals(credentials_))); | 221 (has_credentials_ && credentials->Equals(credentials_))); |
| 225 next_state_ = STATE_GENERATE_AUTH_TOKEN; | 222 next_state_ = STATE_GENERATE_AUTH_TOKEN; |
| 226 } else { | 223 } else { |
| 227 already_called_ = true; | 224 already_called_ = true; |
| 228 if (credentials) { | 225 if (credentials) { |
| 229 has_credentials_ = true; | 226 has_credentials_ = true; |
| 230 credentials_ = *credentials; | 227 credentials_ = *credentials; |
| 231 } | 228 } |
| 232 next_state_ = STATE_RESOLVE_CANONICAL_NAME; | 229 next_state_ = STATE_RESOLVE_CANONICAL_NAME; |
| 233 } | 230 } |
| 234 int rv = DoLoop(OK); | 231 int rv = DoLoop(OK); |
| 235 if (rv == ERR_IO_PENDING) | 232 if (rv == ERR_IO_PENDING) |
| 236 user_callback_ = callback; | 233 callback_ = callback; |
| 237 return rv; | 234 return rv; |
| 238 } | 235 } |
| 239 | 236 |
| 240 void HttpAuthHandlerNegotiate::OnIOComplete(int result) { | 237 void HttpAuthHandlerNegotiate::OnIOComplete(int result) { |
| 241 int rv = DoLoop(result); | 238 int rv = DoLoop(result); |
| 242 if (rv != ERR_IO_PENDING) | 239 if (rv != ERR_IO_PENDING) |
| 243 DoCallback(rv); | 240 DoCallback(rv); |
| 244 } | 241 } |
| 245 | 242 |
| 246 void HttpAuthHandlerNegotiate::DoCallback(int rv) { | 243 void HttpAuthHandlerNegotiate::DoCallback(int rv) { |
| 247 DCHECK(rv != ERR_IO_PENDING); | 244 DCHECK(rv != ERR_IO_PENDING); |
| 248 DCHECK(user_callback_); | 245 DCHECK(!callback_.is_null()); |
| 249 OldCompletionCallback* callback = user_callback_; | 246 CompletionCallback callback = callback_; |
| 250 user_callback_ = NULL; | 247 callback_.Reset(); |
| 251 callback->Run(rv); | 248 callback.Run(rv); |
| 252 } | 249 } |
| 253 | 250 |
| 254 int HttpAuthHandlerNegotiate::DoLoop(int result) { | 251 int HttpAuthHandlerNegotiate::DoLoop(int result) { |
| 255 DCHECK(next_state_ != STATE_NONE); | 252 DCHECK(next_state_ != STATE_NONE); |
| 256 | 253 |
| 257 int rv = result; | 254 int rv = result; |
| 258 do { | 255 do { |
| 259 State state = next_state_; | 256 State state = next_state_; |
| 260 next_state_ = STATE_NONE; | 257 next_state_ = STATE_NONE; |
| 261 switch (state) { | 258 switch (state) { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 bool HttpAuthHandlerNegotiate::CanDelegate() const { | 329 bool HttpAuthHandlerNegotiate::CanDelegate() const { |
| 333 // TODO(cbentzel): Should delegation be allowed on proxies? | 330 // TODO(cbentzel): Should delegation be allowed on proxies? |
| 334 if (target_ == HttpAuth::AUTH_PROXY) | 331 if (target_ == HttpAuth::AUTH_PROXY) |
| 335 return false; | 332 return false; |
| 336 if (!url_security_manager_) | 333 if (!url_security_manager_) |
| 337 return false; | 334 return false; |
| 338 return url_security_manager_->CanDelegate(origin_); | 335 return url_security_manager_->CanDelegate(origin_); |
| 339 } | 336 } |
| 340 | 337 |
| 341 } // namespace net | 338 } // namespace net |
| OLD | NEW |