Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(249)

Side by Side Diff: net/http/http_auth_handler_negotiate.cc

Issue 8340026: Use AuthCredentials throughout the network stack instead of username/password. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Reduce password zapping Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/logging.h" 7 #include "base/logging.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/stringprintf.h" 9 #include "base/stringprintf.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 : auth_system_(auth_library, "Negotiate", NEGOSSP_NAME, max_token_length), 98 : auth_system_(auth_library, "Negotiate", NEGOSSP_NAME, max_token_length),
99 #elif defined(OS_POSIX) 99 #elif defined(OS_POSIX)
100 : auth_system_(auth_library, "Negotiate", CHROME_GSS_KRB5_MECH_OID_DESC), 100 : auth_system_(auth_library, "Negotiate", CHROME_GSS_KRB5_MECH_OID_DESC),
101 #endif 101 #endif
102 disable_cname_lookup_(disable_cname_lookup), 102 disable_cname_lookup_(disable_cname_lookup),
103 use_port_(use_port), 103 use_port_(use_port),
104 ALLOW_THIS_IN_INITIALIZER_LIST(io_callback_( 104 ALLOW_THIS_IN_INITIALIZER_LIST(io_callback_(
105 this, &HttpAuthHandlerNegotiate::OnIOComplete)), 105 this, &HttpAuthHandlerNegotiate::OnIOComplete)),
106 resolver_(resolver), 106 resolver_(resolver),
107 already_called_(false), 107 already_called_(false),
108 has_username_and_password_(false), 108 has_credentials_(false),
109 user_callback_(NULL), 109 user_callback_(NULL),
110 auth_token_(NULL), 110 auth_token_(NULL),
111 next_state_(STATE_NONE), 111 next_state_(STATE_NONE),
112 url_security_manager_(url_security_manager) { 112 url_security_manager_(url_security_manager) {
113 } 113 }
114 114
115 HttpAuthHandlerNegotiate::~HttpAuthHandlerNegotiate() { 115 HttpAuthHandlerNegotiate::~HttpAuthHandlerNegotiate() {
116 } 116 }
117 117
118 std::wstring HttpAuthHandlerNegotiate::CreateSPN( 118 std::wstring HttpAuthHandlerNegotiate::CreateSPN(
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 auth_system_.Delegate(); 205 auth_system_.Delegate();
206 auth_scheme_ = HttpAuth::AUTH_SCHEME_NEGOTIATE; 206 auth_scheme_ = HttpAuth::AUTH_SCHEME_NEGOTIATE;
207 score_ = 4; 207 score_ = 4;
208 properties_ = ENCRYPTS_IDENTITY | IS_CONNECTION_BASED; 208 properties_ = ENCRYPTS_IDENTITY | IS_CONNECTION_BASED;
209 HttpAuth::AuthorizationResult auth_result = 209 HttpAuth::AuthorizationResult auth_result =
210 auth_system_.ParseChallenge(challenge); 210 auth_system_.ParseChallenge(challenge);
211 return (auth_result == HttpAuth::AUTHORIZATION_RESULT_ACCEPT); 211 return (auth_result == HttpAuth::AUTHORIZATION_RESULT_ACCEPT);
212 } 212 }
213 213
214 int HttpAuthHandlerNegotiate::GenerateAuthTokenImpl( 214 int HttpAuthHandlerNegotiate::GenerateAuthTokenImpl(
215 const string16* username, 215 const AuthCredentials* credentials,
216 const string16* password,
217 const HttpRequestInfo* request, 216 const HttpRequestInfo* request,
218 OldCompletionCallback* callback, 217 OldCompletionCallback* callback,
219 std::string* auth_token) { 218 std::string* auth_token) {
220 DCHECK(user_callback_ == NULL); 219 DCHECK(user_callback_ == NULL);
221 DCHECK((username == NULL) == (password == NULL));
222 DCHECK(auth_token_ == NULL); 220 DCHECK(auth_token_ == NULL);
223 auth_token_ = auth_token; 221 auth_token_ = auth_token;
224 if (already_called_) { 222 if (already_called_) {
225 DCHECK((!has_username_and_password_ && username == NULL) || 223 DCHECK((!has_credentials_ && credentials == NULL) ||
226 (has_username_and_password_ && *username == username_ && 224 (has_credentials_ && credentials->Equals(credentials_)));
227 *password == password_));
228 next_state_ = STATE_GENERATE_AUTH_TOKEN; 225 next_state_ = STATE_GENERATE_AUTH_TOKEN;
229 } else { 226 } else {
230 already_called_ = true; 227 already_called_ = true;
231 if (username) { 228 if (credentials) {
232 has_username_and_password_ = true; 229 has_credentials_ = true;
233 username_ = *username; 230 credentials_ = *credentials;
234 password_ = *password;
235 } 231 }
236 next_state_ = STATE_RESOLVE_CANONICAL_NAME; 232 next_state_ = STATE_RESOLVE_CANONICAL_NAME;
237 } 233 }
238 int rv = DoLoop(OK); 234 int rv = DoLoop(OK);
239 if (rv == ERR_IO_PENDING) 235 if (rv == ERR_IO_PENDING)
240 user_callback_ = callback; 236 user_callback_ = callback;
241 return rv; 237 return rv;
242 } 238 }
243 239
244 void HttpAuthHandlerNegotiate::OnIOComplete(int result) { 240 void HttpAuthHandlerNegotiate::OnIOComplete(int result) {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 } 308 }
313 309
314 next_state_ = STATE_GENERATE_AUTH_TOKEN; 310 next_state_ = STATE_GENERATE_AUTH_TOKEN;
315 spn_ = CreateSPN(address_list_, origin_); 311 spn_ = CreateSPN(address_list_, origin_);
316 address_list_ = AddressList(); 312 address_list_ = AddressList();
317 return rv; 313 return rv;
318 } 314 }
319 315
320 int HttpAuthHandlerNegotiate::DoGenerateAuthToken() { 316 int HttpAuthHandlerNegotiate::DoGenerateAuthToken() {
321 next_state_ = STATE_GENERATE_AUTH_TOKEN_COMPLETE; 317 next_state_ = STATE_GENERATE_AUTH_TOKEN_COMPLETE;
322 string16* username = has_username_and_password_ ? &username_ : NULL; 318 AuthCredentials* credentials = has_credentials_ ? &credentials_ : NULL;
323 string16* password = has_username_and_password_ ? &password_ : NULL;
324 // TODO(cbentzel): This should possibly be done async. 319 // TODO(cbentzel): This should possibly be done async.
325 return auth_system_.GenerateAuthToken(username, password, spn_, auth_token_); 320 return auth_system_.GenerateAuthToken(credentials, spn_, auth_token_);
326 } 321 }
327 322
328 int HttpAuthHandlerNegotiate::DoGenerateAuthTokenComplete(int rv) { 323 int HttpAuthHandlerNegotiate::DoGenerateAuthTokenComplete(int rv) {
329 DCHECK_NE(ERR_IO_PENDING, rv); 324 DCHECK_NE(ERR_IO_PENDING, rv);
330 auth_token_ = NULL; 325 auth_token_ = NULL;
331 return rv; 326 return rv;
332 } 327 }
333 328
334 bool HttpAuthHandlerNegotiate::CanDelegate() const { 329 bool HttpAuthHandlerNegotiate::CanDelegate() const {
335 // TODO(cbentzel): Should delegation be allowed on proxies? 330 // TODO(cbentzel): Should delegation be allowed on proxies?
336 if (target_ == HttpAuth::AUTH_PROXY) 331 if (target_ == HttpAuth::AUTH_PROXY)
337 return false; 332 return false;
338 if (!url_security_manager_) 333 if (!url_security_manager_)
339 return false; 334 return false;
340 return url_security_manager_->CanDelegate(origin_); 335 return url_security_manager_->CanDelegate(origin_);
341 } 336 }
342 337
343 } // namespace net 338 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698