Chromium Code Reviews| 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 // OpenSSL binding for SSLClientSocket. The class layout and general principle | 5 // OpenSSL binding for SSLClientSocket. The class layout and general principle |
| 6 // of operation is derived from SSLClientSocketNSS. | 6 // of operation is derived from SSLClientSocketNSS. |
| 7 | 7 |
| 8 #include "net/socket/ssl_client_socket_openssl.h" | 8 #include "net/socket/ssl_client_socket_openssl.h" |
| 9 | 9 |
| 10 #include <errno.h> | 10 #include <errno.h> |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 return SSL_CONNECTION_VERSION_TLS1; | 88 return SSL_CONNECTION_VERSION_TLS1; |
| 89 case 0x0302: | 89 case 0x0302: |
| 90 return SSL_CONNECTION_VERSION_TLS1_1; | 90 return SSL_CONNECTION_VERSION_TLS1_1; |
| 91 case 0x0303: | 91 case 0x0303: |
| 92 return SSL_CONNECTION_VERSION_TLS1_2; | 92 return SSL_CONNECTION_VERSION_TLS1_2; |
| 93 default: | 93 default: |
| 94 return SSL_CONNECTION_VERSION_UNKNOWN; | 94 return SSL_CONNECTION_VERSION_UNKNOWN; |
| 95 } | 95 } |
| 96 } | 96 } |
| 97 | 97 |
| 98 // Compute a unique key string for the SSL session cache. |socket| is an | |
| 99 // input socket object. Return a string. | |
| 100 std::string GetSocketSessionCacheKey(const SSLClientSocketOpenSSL& socket) { | |
| 101 std::string result = socket.host_and_port().ToString(); | |
| 102 result.append("/"); | |
| 103 result.append(socket.ssl_session_cache_shard()); | |
| 104 return result; | |
| 105 } | |
| 106 | |
| 107 void FreeX509Stack(STACK_OF(X509) * ptr) { | 98 void FreeX509Stack(STACK_OF(X509) * ptr) { |
| 108 sk_X509_pop_free(ptr, X509_free); | 99 sk_X509_pop_free(ptr, X509_free); |
| 109 } | 100 } |
| 110 | 101 |
| 111 ScopedX509 OSCertHandleToOpenSSL( | 102 ScopedX509 OSCertHandleToOpenSSL( |
| 112 X509Certificate::OSCertHandle os_handle) { | 103 X509Certificate::OSCertHandle os_handle) { |
| 113 #if defined(USE_OPENSSL_CERTS) | 104 #if defined(USE_OPENSSL_CERTS) |
| 114 return ScopedX509(X509Certificate::DupOSCertHandle(os_handle)); | 105 return ScopedX509(X509Certificate::DupOSCertHandle(os_handle)); |
| 115 #else // !defined(USE_OPENSSL_CERTS) | 106 #else // !defined(USE_OPENSSL_CERTS) |
| 116 std::string der_encoded; | 107 std::string der_encoded; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 // It would be better if the callback were not a global setting, | 148 // It would be better if the callback were not a global setting, |
| 158 // but that is an OpenSSL issue. | 149 // but that is an OpenSSL issue. |
| 159 SSL_CTX_set_next_proto_select_cb(ssl_ctx_.get(), SelectNextProtoCallback, | 150 SSL_CTX_set_next_proto_select_cb(ssl_ctx_.get(), SelectNextProtoCallback, |
| 160 NULL); | 151 NULL); |
| 161 ssl_ctx_->tlsext_channel_id_enabled_new = 1; | 152 ssl_ctx_->tlsext_channel_id_enabled_new = 1; |
| 162 } | 153 } |
| 163 | 154 |
| 164 static std::string GetSessionCacheKey(const SSL* ssl) { | 155 static std::string GetSessionCacheKey(const SSL* ssl) { |
| 165 SSLClientSocketOpenSSL* socket = GetInstance()->GetClientSocketFromSSL(ssl); | 156 SSLClientSocketOpenSSL* socket = GetInstance()->GetClientSocketFromSSL(ssl); |
| 166 DCHECK(socket); | 157 DCHECK(socket); |
| 167 return GetSocketSessionCacheKey(*socket); | 158 return socket->GetSessionCacheKey(); |
| 168 } | 159 } |
| 169 | 160 |
| 170 static SSLSessionCacheOpenSSL::Config kDefaultSessionCacheConfig; | 161 static SSLSessionCacheOpenSSL::Config kDefaultSessionCacheConfig; |
| 171 | 162 |
| 172 static int ClientCertCallback(SSL* ssl, X509** x509, EVP_PKEY** pkey) { | 163 static int ClientCertCallback(SSL* ssl, X509** x509, EVP_PKEY** pkey) { |
| 173 SSLClientSocketOpenSSL* socket = GetInstance()->GetClientSocketFromSSL(ssl); | 164 SSLClientSocketOpenSSL* socket = GetInstance()->GetClientSocketFromSSL(ssl); |
| 174 CHECK(socket); | 165 CHECK(socket); |
| 175 return socket->ClientCertRequestCallback(ssl, x509, pkey); | 166 return socket->ClientCertRequestCallback(ssl, x509, pkey); |
| 176 } | 167 } |
| 177 | 168 |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 365 ssl_(NULL), | 356 ssl_(NULL), |
| 366 transport_bio_(NULL), | 357 transport_bio_(NULL), |
| 367 transport_(transport_socket.Pass()), | 358 transport_(transport_socket.Pass()), |
| 368 host_and_port_(host_and_port), | 359 host_and_port_(host_and_port), |
| 369 ssl_config_(ssl_config), | 360 ssl_config_(ssl_config), |
| 370 ssl_session_cache_shard_(context.ssl_session_cache_shard), | 361 ssl_session_cache_shard_(context.ssl_session_cache_shard), |
| 371 trying_cached_session_(false), | 362 trying_cached_session_(false), |
| 372 next_handshake_state_(STATE_NONE), | 363 next_handshake_state_(STATE_NONE), |
| 373 npn_status_(kNextProtoUnsupported), | 364 npn_status_(kNextProtoUnsupported), |
| 374 channel_id_xtn_negotiated_(false), | 365 channel_id_xtn_negotiated_(false), |
| 375 net_log_(transport_->socket()->NetLog()) {} | 366 net_log_(transport_->socket()->NetLog()) { |
| 367 } | |
| 376 | 368 |
| 377 SSLClientSocketOpenSSL::~SSLClientSocketOpenSSL() { | 369 SSLClientSocketOpenSSL::~SSLClientSocketOpenSSL() { |
| 378 Disconnect(); | 370 Disconnect(); |
| 379 } | 371 } |
| 380 | 372 |
| 373 bool SSLClientSocketOpenSSL::InSessionCache() const { | |
| 374 SSLContext* context = SSLContext::GetInstance(); | |
| 375 std::string cache_key = GetSessionCacheKey(); | |
| 376 return context->session_cache()->SSLSessionIsInCache(cache_key); | |
| 377 } | |
| 378 | |
| 379 void SSLClientSocketOpenSSL::SetHandshakeCompletionCallback( | |
| 380 const base::Closure& callback) { | |
| 381 handshake_completion_callback_ = callback; | |
| 382 } | |
| 383 | |
| 381 void SSLClientSocketOpenSSL::GetSSLCertRequestInfo( | 384 void SSLClientSocketOpenSSL::GetSSLCertRequestInfo( |
| 382 SSLCertRequestInfo* cert_request_info) { | 385 SSLCertRequestInfo* cert_request_info) { |
| 383 cert_request_info->host_and_port = host_and_port_; | 386 cert_request_info->host_and_port = host_and_port_; |
| 384 cert_request_info->cert_authorities = cert_authorities_; | 387 cert_request_info->cert_authorities = cert_authorities_; |
| 385 cert_request_info->cert_key_types = cert_key_types_; | 388 cert_request_info->cert_key_types = cert_key_types_; |
| 386 } | 389 } |
| 387 | 390 |
| 388 SSLClientSocket::NextProtoStatus SSLClientSocketOpenSSL::GetNextProto( | 391 SSLClientSocket::NextProtoStatus SSLClientSocketOpenSSL::GetNextProto( |
| 389 std::string* proto) { | 392 std::string* proto, |
| 393 std::string* sever_protos) { | |
|
wtc
2014/07/31 23:05:24
IMPORTANT: is this part of the CL?
mshelley
2014/08/02 23:59:15
Done.
| |
| 390 *proto = npn_proto_; | 394 *proto = npn_proto_; |
| 391 return npn_status_; | 395 return npn_status_; |
| 392 } | 396 } |
| 393 | 397 |
| 394 ChannelIDService* | 398 ChannelIDService* |
| 395 SSLClientSocketOpenSSL::GetChannelIDService() const { | 399 SSLClientSocketOpenSSL::GetChannelIDService() const { |
| 396 return channel_id_service_; | 400 return channel_id_service_; |
| 397 } | 401 } |
| 398 | 402 |
| 399 int SSLClientSocketOpenSSL::ExportKeyingMaterial( | 403 int SSLClientSocketOpenSSL::ExportKeyingMaterial( |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 420 int SSLClientSocketOpenSSL::GetTLSUniqueChannelBinding(std::string* out) { | 424 int SSLClientSocketOpenSSL::GetTLSUniqueChannelBinding(std::string* out) { |
| 421 NOTIMPLEMENTED(); | 425 NOTIMPLEMENTED(); |
| 422 return ERR_NOT_IMPLEMENTED; | 426 return ERR_NOT_IMPLEMENTED; |
| 423 } | 427 } |
| 424 | 428 |
| 425 int SSLClientSocketOpenSSL::Connect(const CompletionCallback& callback) { | 429 int SSLClientSocketOpenSSL::Connect(const CompletionCallback& callback) { |
| 426 net_log_.BeginEvent(NetLog::TYPE_SSL_CONNECT); | 430 net_log_.BeginEvent(NetLog::TYPE_SSL_CONNECT); |
| 427 | 431 |
| 428 // Set up new ssl object. | 432 // Set up new ssl object. |
| 429 int rv = Init(); | 433 int rv = Init(); |
| 434 | |
|
wtc
2014/07/31 23:05:25
Nit: remove this blank line.
mshelley
2014/08/02 23:59:15
Done.
| |
| 430 if (rv != OK) { | 435 if (rv != OK) { |
| 431 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SSL_CONNECT, rv); | 436 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SSL_CONNECT, rv); |
| 432 return rv; | 437 return rv; |
| 433 } | 438 } |
| 434 | 439 |
| 440 if (!handshake_completion_callback_.is_null()) { | |
| 441 SSLContext* context = SSLContext::GetInstance(); | |
| 442 context->session_cache()->SetSessionAddedCallback( | |
| 443 ssl_, | |
| 444 base::Bind(&SSLClientSocketOpenSSL::OnHandshakeCompletion, | |
| 445 base::Unretained(this))); | |
| 446 } | |
| 447 | |
| 435 // Set SSL to client mode. Handshake happens in the loop below. | 448 // Set SSL to client mode. Handshake happens in the loop below. |
| 436 SSL_set_connect_state(ssl_); | 449 SSL_set_connect_state(ssl_); |
| 437 | 450 |
| 438 GotoState(STATE_HANDSHAKE); | 451 GotoState(STATE_HANDSHAKE); |
| 439 rv = DoHandshakeLoop(OK); | 452 rv = DoHandshakeLoop(OK); |
| 440 if (rv == ERR_IO_PENDING) { | 453 if (rv == ERR_IO_PENDING) { |
| 441 user_connect_callback_ = callback; | 454 user_connect_callback_ = callback; |
| 442 } else { | 455 } else { |
| 443 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SSL_CONNECT, rv); | 456 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SSL_CONNECT, rv); |
| 457 if (rv < OK) | |
| 458 OnHandshakeCompletion(); | |
| 444 } | 459 } |
| 445 | 460 |
| 446 return rv > OK ? OK : rv; | 461 return rv > OK ? OK : rv; |
| 447 } | 462 } |
| 448 | 463 |
| 449 void SSLClientSocketOpenSSL::Disconnect() { | 464 void SSLClientSocketOpenSSL::Disconnect() { |
| 465 // If a handshake was pending (Connect() had been called), notify interested | |
| 466 // parties that it's been aborted now. If the handshake had already | |
| 467 // completed,f | |
| 468 // this is a no-op. | |
|
wtc
2014/07/31 23:05:24
Please fix this comment.
mshelley
2014/08/02 23:59:15
Done.
| |
| 469 OnHandshakeCompletion(); | |
| 450 if (ssl_) { | 470 if (ssl_) { |
| 471 SSLContext* context = SSLContext::GetInstance(); | |
| 472 context->session_cache()->RemoveSessionAddedCallback(ssl_); | |
| 451 // Calling SSL_shutdown prevents the session from being marked as | 473 // Calling SSL_shutdown prevents the session from being marked as |
| 452 // unresumable. | 474 // unresumable. |
| 453 SSL_shutdown(ssl_); | 475 SSL_shutdown(ssl_); |
| 454 SSL_free(ssl_); | 476 SSL_free(ssl_); |
| 455 ssl_ = NULL; | 477 ssl_ = NULL; |
| 456 } | 478 } |
| 457 if (transport_bio_) { | 479 if (transport_bio_) { |
| 458 BIO_free_all(transport_bio_); | 480 BIO_free_all(transport_bio_); |
| 459 transport_bio_ = NULL; | 481 transport_bio_ = NULL; |
| 460 } | 482 } |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 618 | 640 |
| 619 int rv = DoReadLoop(OK); | 641 int rv = DoReadLoop(OK); |
| 620 | 642 |
| 621 if (rv == ERR_IO_PENDING) { | 643 if (rv == ERR_IO_PENDING) { |
| 622 user_read_callback_ = callback; | 644 user_read_callback_ = callback; |
| 623 } else { | 645 } else { |
| 624 if (rv > 0) | 646 if (rv > 0) |
| 625 was_ever_used_ = true; | 647 was_ever_used_ = true; |
| 626 user_read_buf_ = NULL; | 648 user_read_buf_ = NULL; |
| 627 user_read_buf_len_ = 0; | 649 user_read_buf_len_ = 0; |
| 650 if (rv <= 0) { | |
| 651 // Failure of a read attempt may indicate a failed false start | |
| 652 // connection. | |
| 653 OnHandshakeCompletion(); | |
| 654 } | |
| 628 } | 655 } |
| 629 | 656 |
| 630 return rv; | 657 return rv; |
| 631 } | 658 } |
| 632 | 659 |
| 633 int SSLClientSocketOpenSSL::Write(IOBuffer* buf, | 660 int SSLClientSocketOpenSSL::Write(IOBuffer* buf, |
| 634 int buf_len, | 661 int buf_len, |
| 635 const CompletionCallback& callback) { | 662 const CompletionCallback& callback) { |
| 636 user_write_buf_ = buf; | 663 user_write_buf_ = buf; |
| 637 user_write_buf_len_ = buf_len; | 664 user_write_buf_len_ = buf_len; |
| 638 | 665 |
| 639 int rv = DoWriteLoop(OK); | 666 int rv = DoWriteLoop(OK); |
| 640 | 667 |
| 641 if (rv == ERR_IO_PENDING) { | 668 if (rv == ERR_IO_PENDING) { |
| 642 user_write_callback_ = callback; | 669 user_write_callback_ = callback; |
| 643 } else { | 670 } else { |
| 644 if (rv > 0) | 671 if (rv > 0) |
| 645 was_ever_used_ = true; | 672 was_ever_used_ = true; |
| 646 user_write_buf_ = NULL; | 673 user_write_buf_ = NULL; |
| 647 user_write_buf_len_ = 0; | 674 user_write_buf_len_ = 0; |
| 675 if (rv < 0) { | |
| 676 // Failure of a write attempt may indicate a failed false start | |
| 677 // connection. | |
| 678 OnHandshakeCompletion(); | |
| 679 } | |
| 648 } | 680 } |
| 649 | 681 |
| 650 return rv; | 682 return rv; |
| 651 } | 683 } |
| 652 | 684 |
| 653 int SSLClientSocketOpenSSL::SetReceiveBufferSize(int32 size) { | 685 int SSLClientSocketOpenSSL::SetReceiveBufferSize(int32 size) { |
| 654 return transport_->socket()->SetReceiveBufferSize(size); | 686 return transport_->socket()->SetReceiveBufferSize(size); |
| 655 } | 687 } |
| 656 | 688 |
| 657 int SSLClientSocketOpenSSL::SetSendBufferSize(int32 size) { | 689 int SSLClientSocketOpenSSL::SetSendBufferSize(int32 size) { |
| 658 return transport_->socket()->SetSendBufferSize(size); | 690 return transport_->socket()->SetSendBufferSize(size); |
| 659 } | 691 } |
| 660 | 692 |
| 661 int SSLClientSocketOpenSSL::Init() { | 693 int SSLClientSocketOpenSSL::Init() { |
| 662 DCHECK(!ssl_); | 694 DCHECK(!ssl_); |
| 663 DCHECK(!transport_bio_); | 695 DCHECK(!transport_bio_); |
| 664 | 696 |
| 665 SSLContext* context = SSLContext::GetInstance(); | 697 SSLContext* context = SSLContext::GetInstance(); |
| 666 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); | 698 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); |
| 667 | 699 |
| 668 ssl_ = SSL_new(context->ssl_ctx()); | 700 ssl_ = SSL_new(context->ssl_ctx()); |
| 669 if (!ssl_ || !context->SetClientSocketForSSL(ssl_, this)) | 701 if (!ssl_ || !context->SetClientSocketForSSL(ssl_, this)) |
| 670 return ERR_UNEXPECTED; | 702 return ERR_UNEXPECTED; |
| 671 | 703 |
| 672 if (!SSL_set_tlsext_host_name(ssl_, host_and_port_.host().c_str())) | 704 if (!SSL_set_tlsext_host_name(ssl_, host_and_port_.host().c_str())) |
| 673 return ERR_UNEXPECTED; | 705 return ERR_UNEXPECTED; |
| 674 | 706 |
| 675 trying_cached_session_ = context->session_cache()->SetSSLSessionWithKey( | 707 trying_cached_session_ = context->session_cache()->SetSSLSessionWithKey( |
| 676 ssl_, GetSocketSessionCacheKey(*this)); | 708 ssl_, GetSessionCacheKey()); |
| 677 | 709 |
| 678 BIO* ssl_bio = NULL; | 710 BIO* ssl_bio = NULL; |
| 679 // 0 => use default buffer sizes. | 711 // 0 => use default buffer sizes. |
| 680 if (!BIO_new_bio_pair(&ssl_bio, 0, &transport_bio_, 0)) | 712 if (!BIO_new_bio_pair(&ssl_bio, 0, &transport_bio_, 0)) |
| 681 return ERR_UNEXPECTED; | 713 return ERR_UNEXPECTED; |
| 682 DCHECK(ssl_bio); | 714 DCHECK(ssl_bio); |
| 683 DCHECK(transport_bio_); | 715 DCHECK(transport_bio_); |
| 684 | 716 |
| 685 // Install a callback on OpenSSL's end to plumb transport errors through. | 717 // Install a callback on OpenSSL's end to plumb transport errors through. |
| 686 BIO_set_callback(ssl_bio, &SSLClientSocketOpenSSL::BIOCallback); | 718 BIO_set_callback(ssl_bio, &SSLClientSocketOpenSSL::BIOCallback); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 784 return OK; | 816 return OK; |
| 785 } | 817 } |
| 786 | 818 |
| 787 void SSLClientSocketOpenSSL::DoReadCallback(int rv) { | 819 void SSLClientSocketOpenSSL::DoReadCallback(int rv) { |
| 788 // Since Run may result in Read being called, clear |user_read_callback_| | 820 // Since Run may result in Read being called, clear |user_read_callback_| |
| 789 // up front. | 821 // up front. |
| 790 if (rv > 0) | 822 if (rv > 0) |
| 791 was_ever_used_ = true; | 823 was_ever_used_ = true; |
| 792 user_read_buf_ = NULL; | 824 user_read_buf_ = NULL; |
| 793 user_read_buf_len_ = 0; | 825 user_read_buf_len_ = 0; |
| 826 if (rv <= 0) { | |
| 827 // Failure of a read attempt may indicate a failed false start | |
| 828 // connection. | |
| 829 OnHandshakeCompletion(); | |
| 830 } | |
| 794 base::ResetAndReturn(&user_read_callback_).Run(rv); | 831 base::ResetAndReturn(&user_read_callback_).Run(rv); |
| 795 } | 832 } |
| 796 | 833 |
| 797 void SSLClientSocketOpenSSL::DoWriteCallback(int rv) { | 834 void SSLClientSocketOpenSSL::DoWriteCallback(int rv) { |
| 798 // Since Run may result in Write being called, clear |user_write_callback_| | 835 // Since Run may result in Write being called, clear |user_write_callback_| |
| 799 // up front. | 836 // up front. |
| 800 if (rv > 0) | 837 if (rv > 0) |
| 801 was_ever_used_ = true; | 838 was_ever_used_ = true; |
| 802 user_write_buf_ = NULL; | 839 user_write_buf_ = NULL; |
| 803 user_write_buf_len_ = 0; | 840 user_write_buf_len_ = 0; |
| 841 if (rv < 0) { | |
| 842 // Failure of a write attempt may indicate a failed false start | |
| 843 // connection. | |
| 844 OnHandshakeCompletion(); | |
| 845 } | |
| 804 base::ResetAndReturn(&user_write_callback_).Run(rv); | 846 base::ResetAndReturn(&user_write_callback_).Run(rv); |
| 805 } | 847 } |
| 806 | 848 |
| 849 std::string SSLClientSocketOpenSSL::GetSessionCacheKey() const { | |
| 850 return CreateSessionCacheKey(host_and_port_, ssl_session_cache_shard_); | |
| 851 } | |
| 852 | |
| 853 void SSLClientSocketOpenSSL::OnHandshakeCompletion() { | |
| 854 if (!handshake_completion_callback_.is_null()) | |
| 855 base::ResetAndReturn(&handshake_completion_callback_).Run(); | |
| 856 } | |
| 857 | |
| 807 bool SSLClientSocketOpenSSL::DoTransportIO() { | 858 bool SSLClientSocketOpenSSL::DoTransportIO() { |
| 808 bool network_moved = false; | 859 bool network_moved = false; |
| 809 int rv; | 860 int rv; |
| 810 // Read and write as much data as possible. The loop is necessary because | 861 // Read and write as much data as possible. The loop is necessary because |
| 811 // Write() may return synchronously. | 862 // Write() may return synchronously. |
| 812 do { | 863 do { |
| 813 rv = BufferSend(); | 864 rv = BufferSend(); |
| 814 if (rv != ERR_IO_PENDING && rv != 0) | 865 if (rv != ERR_IO_PENDING && rv != 0) |
| 815 network_moved = true; | 866 network_moved = true; |
| 816 } while (rv > 0); | 867 } while (rv > 0); |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 989 << " (" << result << ")"; | 1040 << " (" << result << ")"; |
| 990 } | 1041 } |
| 991 | 1042 |
| 992 completed_handshake_ = true; | 1043 completed_handshake_ = true; |
| 993 // Exit DoHandshakeLoop and return the result to the caller to Connect. | 1044 // Exit DoHandshakeLoop and return the result to the caller to Connect. |
| 994 DCHECK_EQ(STATE_NONE, next_handshake_state_); | 1045 DCHECK_EQ(STATE_NONE, next_handshake_state_); |
| 995 return result; | 1046 return result; |
| 996 } | 1047 } |
| 997 | 1048 |
| 998 void SSLClientSocketOpenSSL::DoConnectCallback(int rv) { | 1049 void SSLClientSocketOpenSSL::DoConnectCallback(int rv) { |
| 1050 if (rv < OK) | |
| 1051 OnHandshakeCompletion(); | |
| 999 if (!user_connect_callback_.is_null()) { | 1052 if (!user_connect_callback_.is_null()) { |
| 1000 CompletionCallback c = user_connect_callback_; | 1053 CompletionCallback c = user_connect_callback_; |
| 1001 user_connect_callback_.Reset(); | 1054 user_connect_callback_.Reset(); |
| 1002 c.Run(rv > OK ? OK : rv); | 1055 c.Run(rv > OK ? OK : rv); |
| 1003 } | 1056 } |
| 1004 } | 1057 } |
| 1005 | 1058 |
| 1006 X509Certificate* SSLClientSocketOpenSSL::UpdateServerCert() { | 1059 X509Certificate* SSLClientSocketOpenSSL::UpdateServerCert() { |
| 1007 server_cert_chain_->Reset(SSL_get_peer_cert_chain(ssl_)); | 1060 server_cert_chain_->Reset(SSL_get_peer_cert_chain(ssl_)); |
| 1008 server_cert_ = server_cert_chain_->AsOSChain(); | 1061 server_cert_ = server_cert_chain_->AsOSChain(); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1109 } | 1162 } |
| 1110 | 1163 |
| 1111 bool network_moved = DoTransportIO(); | 1164 bool network_moved = DoTransportIO(); |
| 1112 if (network_moved && next_handshake_state_ == STATE_HANDSHAKE) { | 1165 if (network_moved && next_handshake_state_ == STATE_HANDSHAKE) { |
| 1113 // In general we exit the loop if rv is ERR_IO_PENDING. In this | 1166 // In general we exit the loop if rv is ERR_IO_PENDING. In this |
| 1114 // special case we keep looping even if rv is ERR_IO_PENDING because | 1167 // special case we keep looping even if rv is ERR_IO_PENDING because |
| 1115 // the transport IO may allow DoHandshake to make progress. | 1168 // the transport IO may allow DoHandshake to make progress. |
| 1116 rv = OK; // This causes us to stay in the loop. | 1169 rv = OK; // This causes us to stay in the loop. |
| 1117 } | 1170 } |
| 1118 } while (rv != ERR_IO_PENDING && next_handshake_state_ != STATE_NONE); | 1171 } while (rv != ERR_IO_PENDING && next_handshake_state_ != STATE_NONE); |
| 1172 | |
| 1119 return rv; | 1173 return rv; |
| 1120 } | 1174 } |
| 1121 | 1175 |
| 1122 int SSLClientSocketOpenSSL::DoReadLoop(int result) { | 1176 int SSLClientSocketOpenSSL::DoReadLoop(int result) { |
| 1123 if (result < 0) | 1177 if (result < 0) |
| 1124 return result; | 1178 return result; |
| 1125 | 1179 |
| 1126 bool network_moved; | 1180 bool network_moved; |
| 1127 int rv; | 1181 int rv; |
| 1128 do { | 1182 do { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1210 if (rv >= 0) { | 1264 if (rv >= 0) { |
| 1211 net_log_.AddByteTransferEvent(NetLog::TYPE_SSL_SOCKET_BYTES_RECEIVED, rv, | 1265 net_log_.AddByteTransferEvent(NetLog::TYPE_SSL_SOCKET_BYTES_RECEIVED, rv, |
| 1212 user_read_buf_->data()); | 1266 user_read_buf_->data()); |
| 1213 } | 1267 } |
| 1214 return rv; | 1268 return rv; |
| 1215 } | 1269 } |
| 1216 | 1270 |
| 1217 int SSLClientSocketOpenSSL::DoPayloadWrite() { | 1271 int SSLClientSocketOpenSSL::DoPayloadWrite() { |
| 1218 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); | 1272 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); |
| 1219 int rv = SSL_write(ssl_, user_write_buf_->data(), user_write_buf_len_); | 1273 int rv = SSL_write(ssl_, user_write_buf_->data(), user_write_buf_len_); |
| 1220 | |
| 1221 if (rv >= 0) { | 1274 if (rv >= 0) { |
| 1222 net_log_.AddByteTransferEvent(NetLog::TYPE_SSL_SOCKET_BYTES_SENT, rv, | 1275 net_log_.AddByteTransferEvent(NetLog::TYPE_SSL_SOCKET_BYTES_SENT, rv, |
| 1223 user_write_buf_->data()); | 1276 user_write_buf_->data()); |
| 1224 return rv; | 1277 return rv; |
| 1225 } | 1278 } |
| 1226 | 1279 |
| 1227 int err = SSL_get_error(ssl_, rv); | 1280 int err = SSL_get_error(ssl_, rv); |
| 1228 return MapOpenSSLError(err, err_tracer); | 1281 return MapOpenSSLError(err, err_tracer); |
| 1229 } | 1282 } |
| 1230 | 1283 |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1539 return socket->MaybeReplayTransportError( | 1592 return socket->MaybeReplayTransportError( |
| 1540 bio, cmd, argp, argi, argl, retvalue); | 1593 bio, cmd, argp, argi, argl, retvalue); |
| 1541 } | 1594 } |
| 1542 | 1595 |
| 1543 scoped_refptr<X509Certificate> | 1596 scoped_refptr<X509Certificate> |
| 1544 SSLClientSocketOpenSSL::GetUnverifiedServerCertificateChain() const { | 1597 SSLClientSocketOpenSSL::GetUnverifiedServerCertificateChain() const { |
| 1545 return server_cert_; | 1598 return server_cert_; |
| 1546 } | 1599 } |
| 1547 | 1600 |
| 1548 } // namespace net | 1601 } // namespace net |
| OLD | NEW |