| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // TODO(ukai): code is similar with http_network_transaction.cc. We should | 5 // TODO(ukai): code is similar with http_network_transaction.cc. We should |
| 6 // think about ways to share code, if possible. | 6 // think about ways to share code, if possible. |
| 7 | 7 |
| 8 #include "net/socket_stream/socket_stream.h" | 8 #include "net/socket_stream/socket_stream.h" |
| 9 | 9 |
| 10 #include <set> | 10 #include <set> |
| (...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 607 auth_identity_.username = entry->username(); | 607 auth_identity_.username = entry->username(); |
| 608 auth_identity_.password = entry->password(); | 608 auth_identity_.password = entry->password(); |
| 609 auth_handler_.swap(handler_preemptive); | 609 auth_handler_.swap(handler_preemptive); |
| 610 } | 610 } |
| 611 } | 611 } |
| 612 } | 612 } |
| 613 | 613 |
| 614 // Support basic authentication scheme only, because we don't have | 614 // Support basic authentication scheme only, because we don't have |
| 615 // HttpRequestInfo. | 615 // HttpRequestInfo. |
| 616 // TODO(ukai): Add support other authentication scheme. | 616 // TODO(ukai): Add support other authentication scheme. |
| 617 if (auth_handler_.get() && auth_handler_->scheme() == "basic") { | 617 if (auth_handler_.get() && |
| 618 auth_handler_->auth_scheme() == HttpAuth::AUTH_SCHEME_BASIC) { |
| 618 HttpRequestInfo request_info; | 619 HttpRequestInfo request_info; |
| 619 std::string auth_token; | 620 std::string auth_token; |
| 620 int rv = auth_handler_->GenerateAuthToken( | 621 int rv = auth_handler_->GenerateAuthToken( |
| 621 &auth_identity_.username, | 622 &auth_identity_.username, |
| 622 &auth_identity_.password, | 623 &auth_identity_.password, |
| 623 &request_info, | 624 &request_info, |
| 624 NULL, | 625 NULL, |
| 625 &auth_token); | 626 &auth_token); |
| 626 // TODO(cbentzel): Support async auth handlers. | 627 // TODO(cbentzel): Support async auth handlers. |
| 627 DCHECK_NE(ERR_IO_PENDING, rv); | 628 DCHECK_NE(ERR_IO_PENDING, rv); |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 return OK; | 743 return OK; |
| 743 case 407: // Proxy Authentication Required. | 744 case 407: // Proxy Authentication Required. |
| 744 result = HandleAuthChallenge(headers.get()); | 745 result = HandleAuthChallenge(headers.get()); |
| 745 if (result == ERR_PROXY_AUTH_UNSUPPORTED && | 746 if (result == ERR_PROXY_AUTH_UNSUPPORTED && |
| 746 auth_handler_.get() && delegate_) { | 747 auth_handler_.get() && delegate_) { |
| 747 DCHECK(!proxy_info_.is_empty()); | 748 DCHECK(!proxy_info_.is_empty()); |
| 748 auth_info_ = new AuthChallengeInfo; | 749 auth_info_ = new AuthChallengeInfo; |
| 749 auth_info_->is_proxy = true; | 750 auth_info_->is_proxy = true; |
| 750 auth_info_->host_and_port = | 751 auth_info_->host_and_port = |
| 751 ASCIIToWide(proxy_info_.proxy_server().host_port_pair().ToString()); | 752 ASCIIToWide(proxy_info_.proxy_server().host_port_pair().ToString()); |
| 752 auth_info_->scheme = ASCIIToWide(auth_handler_->scheme()); | 753 auth_info_->scheme = ASCIIToWide( |
| 754 HttpAuth::GetSchemeName(auth_handler_->auth_scheme())); |
| 753 auth_info_->realm = ASCIIToWide(auth_handler_->realm()); | 755 auth_info_->realm = ASCIIToWide(auth_handler_->realm()); |
| 754 // Wait until RestartWithAuth or Close is called. | 756 // Wait until RestartWithAuth or Close is called. |
| 755 MessageLoop::current()->PostTask( | 757 MessageLoop::current()->PostTask( |
| 756 FROM_HERE, | 758 FROM_HERE, |
| 757 NewRunnableMethod(this, &SocketStream::DoAuthRequired)); | 759 NewRunnableMethod(this, &SocketStream::DoAuthRequired)); |
| 758 next_state_ = STATE_AUTH_REQUIRED; | 760 next_state_ = STATE_AUTH_REQUIRED; |
| 759 return ERR_IO_PENDING; | 761 return ERR_IO_PENDING; |
| 760 } | 762 } |
| 761 default: | 763 default: |
| 762 break; | 764 break; |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 937 VLOG(1) << "The proxy " << auth_origin << " requested auth"; | 939 VLOG(1) << "The proxy " << auth_origin << " requested auth"; |
| 938 | 940 |
| 939 // TODO(cbentzel): Since SocketStream only suppports basic authentication | 941 // TODO(cbentzel): Since SocketStream only suppports basic authentication |
| 940 // right now, another challenge is always treated as a rejection. | 942 // right now, another challenge is always treated as a rejection. |
| 941 // Ultimately this should be converted to use HttpAuthController like the | 943 // Ultimately this should be converted to use HttpAuthController like the |
| 942 // HttpNetworkTransaction has. | 944 // HttpNetworkTransaction has. |
| 943 if (auth_handler_.get() && !auth_identity_.invalid) { | 945 if (auth_handler_.get() && !auth_identity_.invalid) { |
| 944 if (auth_identity_.source != HttpAuth::IDENT_SRC_PATH_LOOKUP) | 946 if (auth_identity_.source != HttpAuth::IDENT_SRC_PATH_LOOKUP) |
| 945 auth_cache_.Remove(auth_origin, | 947 auth_cache_.Remove(auth_origin, |
| 946 auth_handler_->realm(), | 948 auth_handler_->realm(), |
| 947 auth_handler_->scheme(), | 949 auth_handler_->auth_scheme(), |
| 948 auth_identity_.username, | 950 auth_identity_.username, |
| 949 auth_identity_.password); | 951 auth_identity_.password); |
| 950 auth_handler_.reset(); | 952 auth_handler_.reset(); |
| 951 auth_identity_ = HttpAuth::Identity(); | 953 auth_identity_ = HttpAuth::Identity(); |
| 952 } | 954 } |
| 953 | 955 |
| 954 auth_identity_.invalid = true; | 956 auth_identity_.invalid = true; |
| 955 std::set<std::string> disabled_schemes; | 957 std::set<HttpAuth::Scheme> disabled_schemes; |
| 956 HttpAuth::ChooseBestChallenge(http_auth_handler_factory_, headers, | 958 HttpAuth::ChooseBestChallenge(http_auth_handler_factory_, headers, |
| 957 HttpAuth::AUTH_PROXY, | 959 HttpAuth::AUTH_PROXY, |
| 958 auth_origin, disabled_schemes, | 960 auth_origin, disabled_schemes, |
| 959 net_log_, &auth_handler_); | 961 net_log_, &auth_handler_); |
| 960 if (!auth_handler_.get()) { | 962 if (!auth_handler_.get()) { |
| 961 LOG(ERROR) << "Can't perform auth to the proxy " << auth_origin; | 963 LOG(ERROR) << "Can't perform auth to the proxy " << auth_origin; |
| 962 return ERR_TUNNEL_CONNECTION_FAILED; | 964 return ERR_TUNNEL_CONNECTION_FAILED; |
| 963 } | 965 } |
| 964 if (auth_handler_->NeedsIdentity()) { | 966 if (auth_handler_->NeedsIdentity()) { |
| 965 // We only support basic authentication scheme now. | 967 // We only support basic authentication scheme now. |
| 966 // TODO(ukai): Support other authentication scheme. | 968 // TODO(ukai): Support other authentication scheme. |
| 967 HttpAuthCache::Entry* entry = | 969 HttpAuthCache::Entry* entry = auth_cache_.Lookup( |
| 968 auth_cache_.Lookup(auth_origin, auth_handler_->realm(), "basic"); | 970 auth_origin, auth_handler_->realm(), HttpAuth::AUTH_SCHEME_BASIC); |
| 969 if (entry) { | 971 if (entry) { |
| 970 auth_identity_.source = HttpAuth::IDENT_SRC_REALM_LOOKUP; | 972 auth_identity_.source = HttpAuth::IDENT_SRC_REALM_LOOKUP; |
| 971 auth_identity_.invalid = false; | 973 auth_identity_.invalid = false; |
| 972 auth_identity_.username = entry->username(); | 974 auth_identity_.username = entry->username(); |
| 973 auth_identity_.password = entry->password(); | 975 auth_identity_.password = entry->password(); |
| 974 // Restart with auth info. | 976 // Restart with auth info. |
| 975 } | 977 } |
| 976 return ERR_PROXY_AUTH_UNSUPPORTED; | 978 return ERR_PROXY_AUTH_UNSUPPORTED; |
| 977 } else { | 979 } else { |
| 978 auth_identity_.invalid = false; | 980 auth_identity_.invalid = false; |
| 979 } | 981 } |
| 980 return ERR_TUNNEL_CONNECTION_FAILED; | 982 return ERR_TUNNEL_CONNECTION_FAILED; |
| 981 } | 983 } |
| 982 | 984 |
| 983 void SocketStream::DoAuthRequired() { | 985 void SocketStream::DoAuthRequired() { |
| 984 if (delegate_ && auth_info_.get()) | 986 if (delegate_ && auth_info_.get()) |
| 985 delegate_->OnAuthRequired(this, auth_info_.get()); | 987 delegate_->OnAuthRequired(this, auth_info_.get()); |
| 986 else | 988 else |
| 987 DoLoop(net::ERR_UNEXPECTED); | 989 DoLoop(net::ERR_UNEXPECTED); |
| 988 } | 990 } |
| 989 | 991 |
| 990 void SocketStream::DoRestartWithAuth() { | 992 void SocketStream::DoRestartWithAuth() { |
| 991 DCHECK_EQ(next_state_, STATE_AUTH_REQUIRED); | 993 DCHECK_EQ(next_state_, STATE_AUTH_REQUIRED); |
| 992 auth_cache_.Add(ProxyAuthOrigin(), | 994 auth_cache_.Add(ProxyAuthOrigin(), |
| 993 auth_handler_->realm(), | 995 auth_handler_->realm(), |
| 994 auth_handler_->scheme(), | 996 auth_handler_->auth_scheme(), |
| 995 auth_handler_->challenge(), | 997 auth_handler_->challenge(), |
| 996 auth_identity_.username, | 998 auth_identity_.username, |
| 997 auth_identity_.password, | 999 auth_identity_.password, |
| 998 std::string()); | 1000 std::string()); |
| 999 | 1001 |
| 1000 tunnel_request_headers_ = NULL; | 1002 tunnel_request_headers_ = NULL; |
| 1001 tunnel_request_headers_bytes_sent_ = 0; | 1003 tunnel_request_headers_bytes_sent_ = 0; |
| 1002 tunnel_response_headers_ = NULL; | 1004 tunnel_response_headers_ = NULL; |
| 1003 tunnel_response_headers_capacity_ = 0; | 1005 tunnel_response_headers_capacity_ = 0; |
| 1004 tunnel_response_headers_len_ = 0; | 1006 tunnel_response_headers_len_ = 0; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1027 | 1029 |
| 1028 SSLConfigService* SocketStream::ssl_config_service() const { | 1030 SSLConfigService* SocketStream::ssl_config_service() const { |
| 1029 return context_->ssl_config_service(); | 1031 return context_->ssl_config_service(); |
| 1030 } | 1032 } |
| 1031 | 1033 |
| 1032 ProxyService* SocketStream::proxy_service() const { | 1034 ProxyService* SocketStream::proxy_service() const { |
| 1033 return context_->proxy_service(); | 1035 return context_->proxy_service(); |
| 1034 } | 1036 } |
| 1035 | 1037 |
| 1036 } // namespace net | 1038 } // namespace net |
| OLD | NEW |