| 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/socket/ssl_client_socket_pool.h" | 5 #include "net/socket/ssl_client_socket_pool.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/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 if (error_response_info_.headers.get()) { | 240 if (error_response_info_.headers.get()) { |
| 241 handle->set_pending_http_proxy_connection( | 241 handle->set_pending_http_proxy_connection( |
| 242 transport_socket_handle_.release()); | 242 transport_socket_handle_.release()); |
| 243 } | 243 } |
| 244 handle->set_ssl_error_response_info(error_response_info_); | 244 handle->set_ssl_error_response_info(error_response_info_); |
| 245 if (!connect_timing_.ssl_start.is_null()) | 245 if (!connect_timing_.ssl_start.is_null()) |
| 246 handle->set_is_ssl_error(true); | 246 handle->set_is_ssl_error(true); |
| 247 } | 247 } |
| 248 | 248 |
| 249 void SSLConnectJob::OnIOComplete(int result) { | 249 void SSLConnectJob::OnIOComplete(int result) { |
| 250 // TODO(pkasting): Remove ScopedTracker below once crbug.com/455884 is fixed. | |
| 251 tracked_objects::ScopedTracker tracking_profile( | |
| 252 FROM_HERE_WITH_EXPLICIT_FUNCTION("455884 SSLConnectJob::OnIOComplete")); | |
| 253 int rv = DoLoop(result); | 250 int rv = DoLoop(result); |
| 254 if (rv != ERR_IO_PENDING) | 251 if (rv != ERR_IO_PENDING) |
| 255 NotifyDelegateOfCompletion(rv); // Deletes |this|. | 252 NotifyDelegateOfCompletion(rv); // Deletes |this|. |
| 256 } | 253 } |
| 257 | 254 |
| 258 int SSLConnectJob::DoLoop(int result) { | 255 int SSLConnectJob::DoLoop(int result) { |
| 259 DCHECK_NE(next_state_, STATE_NONE); | 256 DCHECK_NE(next_state_, STATE_NONE); |
| 260 | 257 |
| 261 int rv = result; | 258 int rv = result; |
| 262 do { | 259 do { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 NOTREACHED() << "bad state"; | 298 NOTREACHED() << "bad state"; |
| 302 rv = ERR_FAILED; | 299 rv = ERR_FAILED; |
| 303 break; | 300 break; |
| 304 } | 301 } |
| 305 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); | 302 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); |
| 306 | 303 |
| 307 return rv; | 304 return rv; |
| 308 } | 305 } |
| 309 | 306 |
| 310 int SSLConnectJob::DoTransportConnect() { | 307 int SSLConnectJob::DoTransportConnect() { |
| 311 // TODO(pkasting): Remove ScopedTracker below once crbug.com/455884 is fixed. | |
| 312 tracked_objects::ScopedTracker tracking_profile( | |
| 313 FROM_HERE_WITH_EXPLICIT_FUNCTION( | |
| 314 "455884 SSLConnectJob::DoTransportConnect")); | |
| 315 DCHECK(transport_pool_); | 308 DCHECK(transport_pool_); |
| 316 | 309 |
| 317 next_state_ = STATE_TRANSPORT_CONNECT_COMPLETE; | 310 next_state_ = STATE_TRANSPORT_CONNECT_COMPLETE; |
| 318 transport_socket_handle_.reset(new ClientSocketHandle()); | 311 transport_socket_handle_.reset(new ClientSocketHandle()); |
| 319 scoped_refptr<TransportSocketParams> direct_params = | 312 scoped_refptr<TransportSocketParams> direct_params = |
| 320 params_->GetDirectConnectionParams(); | 313 params_->GetDirectConnectionParams(); |
| 321 return transport_socket_handle_->Init(group_name(), | 314 return transport_socket_handle_->Init(group_name(), |
| 322 direct_params, | 315 direct_params, |
| 323 priority(), | 316 priority(), |
| 324 io_callback_, | 317 io_callback_, |
| 325 transport_pool_, | 318 transport_pool_, |
| 326 net_log()); | 319 net_log()); |
| 327 } | 320 } |
| 328 | 321 |
| 329 int SSLConnectJob::DoTransportConnectComplete(int result) { | 322 int SSLConnectJob::DoTransportConnectComplete(int result) { |
| 330 if (result == OK) | 323 if (result == OK) |
| 331 next_state_ = STATE_CREATE_SSL_SOCKET; | 324 next_state_ = STATE_CREATE_SSL_SOCKET; |
| 332 | 325 |
| 333 return result; | 326 return result; |
| 334 } | 327 } |
| 335 | 328 |
| 336 int SSLConnectJob::DoSOCKSConnect() { | 329 int SSLConnectJob::DoSOCKSConnect() { |
| 337 // TODO(pkasting): Remove ScopedTracker below once crbug.com/455884 is fixed. | |
| 338 tracked_objects::ScopedTracker tracking_profile( | |
| 339 FROM_HERE_WITH_EXPLICIT_FUNCTION("455884 SSLConnectJob::DoSOCKSConnect")); | |
| 340 DCHECK(socks_pool_); | 330 DCHECK(socks_pool_); |
| 341 next_state_ = STATE_SOCKS_CONNECT_COMPLETE; | 331 next_state_ = STATE_SOCKS_CONNECT_COMPLETE; |
| 342 transport_socket_handle_.reset(new ClientSocketHandle()); | 332 transport_socket_handle_.reset(new ClientSocketHandle()); |
| 343 scoped_refptr<SOCKSSocketParams> socks_proxy_params = | 333 scoped_refptr<SOCKSSocketParams> socks_proxy_params = |
| 344 params_->GetSocksProxyConnectionParams(); | 334 params_->GetSocksProxyConnectionParams(); |
| 345 return transport_socket_handle_->Init(group_name(), | 335 return transport_socket_handle_->Init(group_name(), |
| 346 socks_proxy_params, | 336 socks_proxy_params, |
| 347 priority(), | 337 priority(), |
| 348 io_callback_, | 338 io_callback_, |
| 349 socks_pool_, | 339 socks_pool_, |
| 350 net_log()); | 340 net_log()); |
| 351 } | 341 } |
| 352 | 342 |
| 353 int SSLConnectJob::DoSOCKSConnectComplete(int result) { | 343 int SSLConnectJob::DoSOCKSConnectComplete(int result) { |
| 354 if (result == OK) | 344 if (result == OK) |
| 355 next_state_ = STATE_CREATE_SSL_SOCKET; | 345 next_state_ = STATE_CREATE_SSL_SOCKET; |
| 356 | 346 |
| 357 return result; | 347 return result; |
| 358 } | 348 } |
| 359 | 349 |
| 360 int SSLConnectJob::DoTunnelConnect() { | 350 int SSLConnectJob::DoTunnelConnect() { |
| 361 // TODO(pkasting): Remove ScopedTracker below once crbug.com/455884 is fixed. | |
| 362 tracked_objects::ScopedTracker tracking_profile( | |
| 363 FROM_HERE_WITH_EXPLICIT_FUNCTION( | |
| 364 "455884 SSLConnectJob::DoTunnelConnect")); | |
| 365 DCHECK(http_proxy_pool_); | 351 DCHECK(http_proxy_pool_); |
| 366 next_state_ = STATE_TUNNEL_CONNECT_COMPLETE; | 352 next_state_ = STATE_TUNNEL_CONNECT_COMPLETE; |
| 367 | 353 |
| 368 transport_socket_handle_.reset(new ClientSocketHandle()); | 354 transport_socket_handle_.reset(new ClientSocketHandle()); |
| 369 scoped_refptr<HttpProxySocketParams> http_proxy_params = | 355 scoped_refptr<HttpProxySocketParams> http_proxy_params = |
| 370 params_->GetHttpProxyConnectionParams(); | 356 params_->GetHttpProxyConnectionParams(); |
| 371 return transport_socket_handle_->Init(group_name(), | 357 return transport_socket_handle_->Init(group_name(), |
| 372 http_proxy_params, | 358 http_proxy_params, |
| 373 priority(), | 359 priority(), |
| 374 io_callback_, | 360 io_callback_, |
| 375 http_proxy_pool_, | 361 http_proxy_pool_, |
| 376 net_log()); | 362 net_log()); |
| 377 } | 363 } |
| 378 | 364 |
| 379 int SSLConnectJob::DoTunnelConnectComplete(int result) { | 365 int SSLConnectJob::DoTunnelConnectComplete(int result) { |
| 380 // TODO(pkasting): Remove ScopedTracker below once crbug.com/455884 is fixed. | |
| 381 tracked_objects::ScopedTracker tracking_profile( | |
| 382 FROM_HERE_WITH_EXPLICIT_FUNCTION( | |
| 383 "455884 SSLConnectJob::DoTunnelConnectComplete")); | |
| 384 // Extract the information needed to prompt for appropriate proxy | 366 // Extract the information needed to prompt for appropriate proxy |
| 385 // authentication so that when ClientSocketPoolBaseHelper calls | 367 // authentication so that when ClientSocketPoolBaseHelper calls |
| 386 // |GetAdditionalErrorState|, we can easily set the state. | 368 // |GetAdditionalErrorState|, we can easily set the state. |
| 387 if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED) { | 369 if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED) { |
| 388 error_response_info_ = transport_socket_handle_->ssl_error_response_info(); | 370 error_response_info_ = transport_socket_handle_->ssl_error_response_info(); |
| 389 } else if (result == ERR_PROXY_AUTH_REQUESTED || | 371 } else if (result == ERR_PROXY_AUTH_REQUESTED || |
| 390 result == ERR_HTTPS_PROXY_TUNNEL_RESPONSE) { | 372 result == ERR_HTTPS_PROXY_TUNNEL_RESPONSE) { |
| 391 StreamSocket* socket = transport_socket_handle_->socket(); | 373 StreamSocket* socket = transport_socket_handle_->socket(); |
| 392 ProxyClientSocket* tunnel_socket = static_cast<ProxyClientSocket*>(socket); | 374 ProxyClientSocket* tunnel_socket = static_cast<ProxyClientSocket*>(socket); |
| 393 error_response_info_ = *tunnel_socket->GetConnectResponseInfo(); | 375 error_response_info_ = *tunnel_socket->GetConnectResponseInfo(); |
| 394 } | 376 } |
| 395 if (result < 0) | 377 if (result < 0) |
| 396 return result; | 378 return result; |
| 397 next_state_ = STATE_CREATE_SSL_SOCKET; | 379 next_state_ = STATE_CREATE_SSL_SOCKET; |
| 398 return result; | 380 return result; |
| 399 } | 381 } |
| 400 | 382 |
| 401 int SSLConnectJob::DoCreateSSLSocket() { | 383 int SSLConnectJob::DoCreateSSLSocket() { |
| 402 // TODO(pkasting): Remove ScopedTracker below once crbug.com/455884 is fixed. | 384 // TODO(pkasting): Remove ScopedTracker below once crbug.com/462815 is fixed. |
| 403 tracked_objects::ScopedTracker tracking_profile( | 385 tracked_objects::ScopedTracker tracking_profile( |
| 404 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 386 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 405 "455884 SSLConnectJob::DoCreateSSLSocket")); | 387 "462815 SSLConnectJob::DoCreateSSLSocket")); |
| 406 next_state_ = STATE_CHECK_FOR_RESUME; | 388 next_state_ = STATE_CHECK_FOR_RESUME; |
| 407 | 389 |
| 408 // Reset the timeout to just the time allowed for the SSL handshake. | 390 // Reset the timeout to just the time allowed for the SSL handshake. |
| 409 ResetTimer(base::TimeDelta::FromSeconds(kSSLHandshakeTimeoutInSeconds)); | 391 ResetTimer(base::TimeDelta::FromSeconds(kSSLHandshakeTimeoutInSeconds)); |
| 410 | 392 |
| 411 // If the handle has a fresh socket, get its connect start and DNS times. | 393 // If the handle has a fresh socket, get its connect start and DNS times. |
| 412 // This should always be the case. | 394 // This should always be the case. |
| 413 const LoadTimingInfo::ConnectTiming& socket_connect_timing = | 395 const LoadTimingInfo::ConnectTiming& socket_connect_timing = |
| 414 transport_socket_handle_->connect_timing(); | 396 transport_socket_handle_->connect_timing(); |
| 415 if (!transport_socket_handle_->is_reused() && | 397 if (!transport_socket_handle_->is_reused() && |
| (...skipping 12 matching lines...) Expand all Loading... |
| 428 params_->ssl_config(), | 410 params_->ssl_config(), |
| 429 context_); | 411 context_); |
| 430 | 412 |
| 431 if (!ssl_socket_->InSessionCache()) | 413 if (!ssl_socket_->InSessionCache()) |
| 432 messenger_ = get_messenger_callback_.Run(ssl_socket_->GetSessionCacheKey()); | 414 messenger_ = get_messenger_callback_.Run(ssl_socket_->GetSessionCacheKey()); |
| 433 | 415 |
| 434 return OK; | 416 return OK; |
| 435 } | 417 } |
| 436 | 418 |
| 437 int SSLConnectJob::DoCheckForResume() { | 419 int SSLConnectJob::DoCheckForResume() { |
| 438 // TODO(pkasting): Remove ScopedTracker below once crbug.com/455884 is fixed. | |
| 439 tracked_objects::ScopedTracker tracking_profile( | |
| 440 FROM_HERE_WITH_EXPLICIT_FUNCTION( | |
| 441 "455884 SSLConnectJob::DoCheckForResume")); | |
| 442 next_state_ = STATE_SSL_CONNECT; | 420 next_state_ = STATE_SSL_CONNECT; |
| 443 | 421 |
| 444 if (!messenger_) | 422 if (!messenger_) |
| 445 return OK; | 423 return OK; |
| 446 | 424 |
| 447 if (messenger_->CanProceed(ssl_socket_.get())) { | 425 if (messenger_->CanProceed(ssl_socket_.get())) { |
| 448 messenger_->MonitorConnectionResult(ssl_socket_.get()); | 426 messenger_->MonitorConnectionResult(ssl_socket_.get()); |
| 449 // The SSLConnectJob no longer needs access to the messenger after this | 427 // The SSLConnectJob no longer needs access to the messenger after this |
| 450 // point. | 428 // point. |
| 451 messenger_ = NULL; | 429 messenger_ = NULL; |
| 452 return OK; | 430 return OK; |
| 453 } | 431 } |
| 454 | 432 |
| 455 messenger_->AddPendingSocket(ssl_socket_.get(), | 433 messenger_->AddPendingSocket(ssl_socket_.get(), |
| 456 base::Bind(&SSLConnectJob::ResumeSSLConnection, | 434 base::Bind(&SSLConnectJob::ResumeSSLConnection, |
| 457 weak_factory_.GetWeakPtr())); | 435 weak_factory_.GetWeakPtr())); |
| 458 | 436 |
| 459 return ERR_IO_PENDING; | 437 return ERR_IO_PENDING; |
| 460 } | 438 } |
| 461 | 439 |
| 462 int SSLConnectJob::DoSSLConnect() { | 440 int SSLConnectJob::DoSSLConnect() { |
| 463 // TODO(pkasting): Remove ScopedTracker below once crbug.com/455884 is fixed. | 441 // TODO(pkasting): Remove ScopedTracker below once crbug.com/462813 is fixed. |
| 464 tracked_objects::ScopedTracker tracking_profile( | 442 tracked_objects::ScopedTracker tracking_profile( |
| 465 FROM_HERE_WITH_EXPLICIT_FUNCTION("455884 SSLConnectJob::DoSSLConnect")); | 443 FROM_HERE_WITH_EXPLICIT_FUNCTION("462813 SSLConnectJob::DoSSLConnect")); |
| 466 next_state_ = STATE_SSL_CONNECT_COMPLETE; | 444 next_state_ = STATE_SSL_CONNECT_COMPLETE; |
| 467 | 445 |
| 468 connect_timing_.ssl_start = base::TimeTicks::Now(); | 446 connect_timing_.ssl_start = base::TimeTicks::Now(); |
| 469 | 447 |
| 470 return ssl_socket_->Connect(io_callback_); | 448 return ssl_socket_->Connect(io_callback_); |
| 471 } | 449 } |
| 472 | 450 |
| 473 int SSLConnectJob::DoSSLConnectComplete(int result) { | 451 int SSLConnectJob::DoSSLConnectComplete(int result) { |
| 474 // TODO(pkasting): Remove ScopedTracker below once crbug.com/455884 is fixed. | |
| 475 tracked_objects::ScopedTracker tracking_profile( | |
| 476 FROM_HERE_WITH_EXPLICIT_FUNCTION( | |
| 477 "455884 SSLConnectJob::DoSSLConnectComplete")); | |
| 478 connect_timing_.ssl_end = base::TimeTicks::Now(); | 452 connect_timing_.ssl_end = base::TimeTicks::Now(); |
| 479 | 453 |
| 480 SSLClientSocket::NextProtoStatus status = | 454 SSLClientSocket::NextProtoStatus status = |
| 481 SSLClientSocket::kNextProtoUnsupported; | 455 SSLClientSocket::kNextProtoUnsupported; |
| 482 std::string proto; | 456 std::string proto; |
| 483 // GetNextProto will fail and and trigger a NOTREACHED if we pass in a socket | 457 // GetNextProto will fail and and trigger a NOTREACHED if we pass in a socket |
| 484 // that hasn't had SSL_ImportFD called on it. If we get a certificate error | 458 // that hasn't had SSL_ImportFD called on it. If we get a certificate error |
| 485 // here, then we know that we called SSL_ImportFD. | 459 // here, then we know that we called SSL_ImportFD. |
| 486 if (result == OK || IsCertificateError(result)) { | 460 if (result == OK || IsCertificateError(result)) { |
| 487 status = ssl_socket_->GetNextProto(&proto); | 461 status = ssl_socket_->GetNextProto(&proto); |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 883 CHECK(it != messenger_map_.end()); | 857 CHECK(it != messenger_map_.end()); |
| 884 delete it->second; | 858 delete it->second; |
| 885 messenger_map_.erase(it); | 859 messenger_map_.erase(it); |
| 886 } | 860 } |
| 887 | 861 |
| 888 void SSLClientSocketPool::OnSSLConfigChanged() { | 862 void SSLClientSocketPool::OnSSLConfigChanged() { |
| 889 FlushWithError(ERR_NETWORK_CHANGED); | 863 FlushWithError(ERR_NETWORK_CHANGED); |
| 890 } | 864 } |
| 891 | 865 |
| 892 } // namespace net | 866 } // namespace net |
| OLD | NEW |