| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 is_unsupported_ = true; | 54 is_unsupported_ = true; |
| 55 if (rv != OK) | 55 if (rv != OK) |
| 56 return rv; | 56 return rv; |
| 57 } | 57 } |
| 58 // TODO(cbentzel): Move towards model of parsing in the factory | 58 // TODO(cbentzel): Move towards model of parsing in the factory |
| 59 // method and only constructing when valid. | 59 // method and only constructing when valid. |
| 60 scoped_ptr<HttpAuthHandler> tmp_handler( | 60 scoped_ptr<HttpAuthHandler> tmp_handler( |
| 61 new HttpAuthHandlerNegotiate(auth_library_.get(), max_token_length_, | 61 new HttpAuthHandlerNegotiate(auth_library_.get(), max_token_length_, |
| 62 url_security_manager(), resolver_, | 62 url_security_manager(), resolver_, |
| 63 disable_cname_lookup_, use_port_)); | 63 disable_cname_lookup_, use_port_)); |
| 64 if (!tmp_handler->InitFromChallenge(challenge, target, origin, net_log)) | 64 #elif defined(OS_ANDROID) |
| 65 return ERR_INVALID_RESPONSE; | 65 if (is_unsupported_ || auth_library_->empty() || reason == CREATE_PREEMPTIVE) |
| 66 handler->swap(tmp_handler); | 66 return ERR_UNSUPPORTED_AUTH_SCHEME; |
| 67 return OK; | 67 // TODO(cbentzel): Move towards model of parsing in the factory |
| 68 // method and only constructing when valid. |
| 69 scoped_ptr<HttpAuthHandler> tmp_handler(new HttpAuthHandlerNegotiate( |
| 70 auth_library_.get(), url_security_manager(), resolver_, |
| 71 disable_cname_lookup_, use_port_)); |
| 68 #elif defined(OS_POSIX) | 72 #elif defined(OS_POSIX) |
| 69 if (is_unsupported_) | 73 if (is_unsupported_) |
| 70 return ERR_UNSUPPORTED_AUTH_SCHEME; | 74 return ERR_UNSUPPORTED_AUTH_SCHEME; |
| 71 if (!auth_library_->Init()) { | 75 if (!auth_library_->Init()) { |
| 72 is_unsupported_ = true; | 76 is_unsupported_ = true; |
| 73 return ERR_UNSUPPORTED_AUTH_SCHEME; | 77 return ERR_UNSUPPORTED_AUTH_SCHEME; |
| 74 } | 78 } |
| 75 // TODO(ahendrickson): Move towards model of parsing in the factory | 79 // TODO(ahendrickson): Move towards model of parsing in the factory |
| 76 // method and only constructing when valid. | 80 // method and only constructing when valid. |
| 77 scoped_ptr<HttpAuthHandler> tmp_handler( | 81 scoped_ptr<HttpAuthHandler> tmp_handler( |
| 78 new HttpAuthHandlerNegotiate(auth_library_.get(), url_security_manager(), | 82 new HttpAuthHandlerNegotiate(auth_library_.get(), url_security_manager(), |
| 79 resolver_, disable_cname_lookup_, | 83 resolver_, disable_cname_lookup_, |
| 80 use_port_)); | 84 use_port_)); |
| 85 #endif |
| 81 if (!tmp_handler->InitFromChallenge(challenge, target, origin, net_log)) | 86 if (!tmp_handler->InitFromChallenge(challenge, target, origin, net_log)) |
| 82 return ERR_INVALID_RESPONSE; | 87 return ERR_INVALID_RESPONSE; |
| 83 handler->swap(tmp_handler); | 88 handler->swap(tmp_handler); |
| 84 return OK; | 89 return OK; |
| 85 #endif | |
| 86 } | 90 } |
| 87 | 91 |
| 88 HttpAuthHandlerNegotiate::HttpAuthHandlerNegotiate( | 92 HttpAuthHandlerNegotiate::HttpAuthHandlerNegotiate( |
| 89 AuthLibrary* auth_library, | 93 AuthLibrary* auth_library, |
| 90 #if defined(OS_WIN) | 94 #if defined(OS_WIN) |
| 91 ULONG max_token_length, | 95 ULONG max_token_length, |
| 92 #endif | 96 #endif |
| 93 URLSecurityManager* url_security_manager, | 97 URLSecurityManager* url_security_manager, |
| 94 HostResolver* resolver, | 98 HostResolver* resolver, |
| 95 bool disable_cname_lookup, | 99 bool disable_cname_lookup, |
| 96 bool use_port) | 100 bool use_port) |
| 97 #if defined(OS_WIN) | 101 #if defined(OS_ANDROID) |
| 102 : auth_system_(*auth_library), |
| 103 #elif defined(OS_WIN) |
| 98 : auth_system_(auth_library, "Negotiate", NEGOSSP_NAME, max_token_length), | 104 : auth_system_(auth_library, "Negotiate", NEGOSSP_NAME, max_token_length), |
| 99 #elif defined(OS_POSIX) | 105 #elif defined(OS_POSIX) |
| 100 : auth_system_(auth_library, "Negotiate", CHROME_GSS_SPNEGO_MECH_OID_DESC), | 106 : auth_system_(auth_library, "Negotiate", CHROME_GSS_SPNEGO_MECH_OID_DESC), |
| 101 #endif | 107 #endif |
| 102 disable_cname_lookup_(disable_cname_lookup), | 108 disable_cname_lookup_(disable_cname_lookup), |
| 103 use_port_(use_port), | 109 use_port_(use_port), |
| 104 resolver_(resolver), | 110 resolver_(resolver), |
| 105 already_called_(false), | 111 already_called_(false), |
| 106 has_credentials_(false), | 112 has_credentials_(false), |
| 107 auth_token_(NULL), | 113 auth_token_(NULL), |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 | 314 |
| 309 next_state_ = STATE_GENERATE_AUTH_TOKEN; | 315 next_state_ = STATE_GENERATE_AUTH_TOKEN; |
| 310 spn_ = CreateSPN(address_list_, origin_); | 316 spn_ = CreateSPN(address_list_, origin_); |
| 311 address_list_ = AddressList(); | 317 address_list_ = AddressList(); |
| 312 return rv; | 318 return rv; |
| 313 } | 319 } |
| 314 | 320 |
| 315 int HttpAuthHandlerNegotiate::DoGenerateAuthToken() { | 321 int HttpAuthHandlerNegotiate::DoGenerateAuthToken() { |
| 316 next_state_ = STATE_GENERATE_AUTH_TOKEN_COMPLETE; | 322 next_state_ = STATE_GENERATE_AUTH_TOKEN_COMPLETE; |
| 317 AuthCredentials* credentials = has_credentials_ ? &credentials_ : NULL; | 323 AuthCredentials* credentials = has_credentials_ ? &credentials_ : NULL; |
| 318 // TODO(cbentzel): This should possibly be done async. | 324 return auth_system_.GenerateAuthToken( |
| 319 return auth_system_.GenerateAuthToken(credentials, spn_, auth_token_); | 325 credentials, spn_, auth_token_, |
| 326 base::Bind(&HttpAuthHandlerNegotiate::OnIOComplete, |
| 327 base::Unretained(this))); |
| 320 } | 328 } |
| 321 | 329 |
| 322 int HttpAuthHandlerNegotiate::DoGenerateAuthTokenComplete(int rv) { | 330 int HttpAuthHandlerNegotiate::DoGenerateAuthTokenComplete(int rv) { |
| 323 DCHECK_NE(ERR_IO_PENDING, rv); | 331 DCHECK_NE(ERR_IO_PENDING, rv); |
| 324 auth_token_ = NULL; | 332 auth_token_ = NULL; |
| 325 return rv; | 333 return rv; |
| 326 } | 334 } |
| 327 | 335 |
| 328 bool HttpAuthHandlerNegotiate::CanDelegate() const { | 336 bool HttpAuthHandlerNegotiate::CanDelegate() const { |
| 329 // TODO(cbentzel): Should delegation be allowed on proxies? | 337 // TODO(cbentzel): Should delegation be allowed on proxies? |
| 330 if (target_ == HttpAuth::AUTH_PROXY) | 338 if (target_ == HttpAuth::AUTH_PROXY) |
| 331 return false; | 339 return false; |
| 332 if (!url_security_manager_) | 340 if (!url_security_manager_) |
| 333 return false; | 341 return false; |
| 334 return url_security_manager_->CanDelegate(origin_); | 342 return url_security_manager_->CanDelegate(origin_); |
| 335 } | 343 } |
| 336 | 344 |
| 337 } // namespace net | 345 } // namespace net |
| OLD | NEW |