| 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_proxy_client_socket.h" | 5 #include "net/http/http_proxy_client_socket.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/profiler/scoped_tracker.h" | 9 #include "base/profiler/scoped_tracker.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 DCHECK_EQ(OK, rv); | 359 DCHECK_EQ(OK, rv); |
| 360 net_log_.BeginEvent( | 360 net_log_.BeginEvent( |
| 361 NetLog::TYPE_HTTP_TRANSACTION_TUNNEL_READ_HEADERS); | 361 NetLog::TYPE_HTTP_TRANSACTION_TUNNEL_READ_HEADERS); |
| 362 rv = DoReadHeaders(); | 362 rv = DoReadHeaders(); |
| 363 break; | 363 break; |
| 364 case STATE_READ_HEADERS_COMPLETE: | 364 case STATE_READ_HEADERS_COMPLETE: |
| 365 rv = DoReadHeadersComplete(rv); | 365 rv = DoReadHeadersComplete(rv); |
| 366 net_log_.EndEventWithNetErrorCode( | 366 net_log_.EndEventWithNetErrorCode( |
| 367 NetLog::TYPE_HTTP_TRANSACTION_TUNNEL_READ_HEADERS, rv); | 367 NetLog::TYPE_HTTP_TRANSACTION_TUNNEL_READ_HEADERS, rv); |
| 368 break; | 368 break; |
| 369 case STATE_HANDLE_PROXY_AUTH_CHALLENGE: |
| 370 rv = DoHandleProxyAuthChallenge(); |
| 371 break; |
| 372 case STATE_HANDLE_PROXY_AUTH_CHALLENGE_COMPLETE: |
| 373 rv = DoHandleProxyAuthChallengeComplete(rv); |
| 374 break; |
| 369 case STATE_DRAIN_BODY: | 375 case STATE_DRAIN_BODY: |
| 370 DCHECK_EQ(OK, rv); | 376 DCHECK_EQ(OK, rv); |
| 371 rv = DoDrainBody(); | 377 rv = DoDrainBody(); |
| 372 break; | 378 break; |
| 373 case STATE_DRAIN_BODY_COMPLETE: | 379 case STATE_DRAIN_BODY_COMPLETE: |
| 374 rv = DoDrainBodyComplete(rv); | 380 rv = DoDrainBodyComplete(rv); |
| 375 break; | 381 break; |
| 376 case STATE_TCP_RESTART: | 382 case STATE_TCP_RESTART: |
| 377 DCHECK_EQ(OK, rv); | 383 DCHECK_EQ(OK, rv); |
| 378 rv = DoTCPRestart(); | 384 rv = DoTCPRestart(); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 } | 505 } |
| 500 | 506 |
| 501 redirect_has_load_timing_info_ = transport_->GetLoadTimingInfo( | 507 redirect_has_load_timing_info_ = transport_->GetLoadTimingInfo( |
| 502 http_stream_parser_->IsConnectionReused(), | 508 http_stream_parser_->IsConnectionReused(), |
| 503 &redirect_load_timing_info_); | 509 &redirect_load_timing_info_); |
| 504 transport_.reset(); | 510 transport_.reset(); |
| 505 http_stream_parser_.reset(); | 511 http_stream_parser_.reset(); |
| 506 return ERR_HTTPS_PROXY_TUNNEL_RESPONSE; | 512 return ERR_HTTPS_PROXY_TUNNEL_RESPONSE; |
| 507 | 513 |
| 508 case 407: // Proxy Authentication Required | 514 case 407: // Proxy Authentication Required |
| 509 // We need this status code to allow proxy authentication. Our | 515 next_state_ = STATE_HANDLE_PROXY_AUTH_CHALLENGE; |
| 510 // authentication code is smart enough to avoid being tricked by an | 516 return OK; |
| 511 // active network attacker. | |
| 512 // The next state is intentionally not set as it should be STATE_NONE; | |
| 513 if (!SanitizeProxyAuth(&response_)) { | |
| 514 LogBlockedTunnelResponse(); | |
| 515 return ERR_TUNNEL_CONNECTION_FAILED; | |
| 516 } | |
| 517 return HandleProxyAuthChallenge(auth_.get(), &response_, net_log_); | |
| 518 | 517 |
| 519 default: | 518 default: |
| 520 // Ignore response to avoid letting the proxy impersonate the target | 519 // Ignore response to avoid letting the proxy impersonate the target |
| 521 // server. (See http://crbug.com/137891.) | 520 // server. (See http://crbug.com/137891.) |
| 522 // We lose something by doing this. We have seen proxy 403, 404, and | 521 // We lose something by doing this. We have seen proxy 403, 404, and |
| 523 // 501 response bodies that contain a useful error message. For | 522 // 501 response bodies that contain a useful error message. For |
| 524 // example, Squid uses a 404 response to report the DNS error: "The | 523 // example, Squid uses a 404 response to report the DNS error: "The |
| 525 // domain name does not exist." | 524 // domain name does not exist." |
| 526 LogBlockedTunnelResponse(); | 525 LogBlockedTunnelResponse(); |
| 527 return ERR_TUNNEL_CONNECTION_FAILED; | 526 return ERR_TUNNEL_CONNECTION_FAILED; |
| 528 } | 527 } |
| 529 } | 528 } |
| 530 | 529 |
| 530 int HttpProxyClientSocket::DoHandleProxyAuthChallenge() { |
| 531 if (!SanitizeProxyAuth(&response_)) { |
| 532 LogBlockedTunnelResponse(); |
| 533 return ERR_TUNNEL_CONNECTION_FAILED; |
| 534 } |
| 535 next_state_ = STATE_HANDLE_PROXY_AUTH_CHALLENGE_COMPLETE; |
| 536 return auth_->HandleAuthChallenge(response_, io_callback_, net_log_); |
| 537 } |
| 538 |
| 539 int HttpProxyClientSocket::DoHandleProxyAuthChallengeComplete(int result) { |
| 540 if (result != OK) |
| 541 return result; |
| 542 if (auth_->HaveAuthHandler()) { |
| 543 response_.auth_challenge = auth_->auth_info(); |
| 544 return ERR_PROXY_AUTH_REQUESTED; |
| 545 } |
| 546 return ERR_PROXY_AUTH_UNSUPPORTED; |
| 547 } |
| 548 |
| 531 int HttpProxyClientSocket::DoDrainBody() { | 549 int HttpProxyClientSocket::DoDrainBody() { |
| 532 DCHECK(drain_buf_.get()); | 550 DCHECK(drain_buf_.get()); |
| 533 DCHECK(transport_->is_initialized()); | 551 DCHECK(transport_->is_initialized()); |
| 534 next_state_ = STATE_DRAIN_BODY_COMPLETE; | 552 next_state_ = STATE_DRAIN_BODY_COMPLETE; |
| 535 return http_stream_parser_->ReadResponseBody( | 553 return http_stream_parser_->ReadResponseBody( |
| 536 drain_buf_.get(), kDrainBodyBufferSize, io_callback_); | 554 drain_buf_.get(), kDrainBodyBufferSize, io_callback_); |
| 537 } | 555 } |
| 538 | 556 |
| 539 int HttpProxyClientSocket::DoDrainBodyComplete(int result) { | 557 int HttpProxyClientSocket::DoDrainBodyComplete(int result) { |
| 540 if (result < 0) | 558 if (result < 0) |
| (...skipping 20 matching lines...) Expand all Loading... |
| 561 "462784 HttpProxyClientSocket::DoTCPRestartComplete")); | 579 "462784 HttpProxyClientSocket::DoTCPRestartComplete")); |
| 562 | 580 |
| 563 if (result != OK) | 581 if (result != OK) |
| 564 return result; | 582 return result; |
| 565 | 583 |
| 566 next_state_ = STATE_GENERATE_AUTH_TOKEN; | 584 next_state_ = STATE_GENERATE_AUTH_TOKEN; |
| 567 return result; | 585 return result; |
| 568 } | 586 } |
| 569 | 587 |
| 570 } // namespace net | 588 } // namespace net |
| OLD | NEW |