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 #include "net/socket/ssl_client_socket_impl.h" | 5 #include "net/socket/ssl_client_socket_impl.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <openssl/bio.h> | 8 #include <openssl/bio.h> |
| 9 #include <openssl/bytestring.h> | 9 #include <openssl/bytestring.h> |
| 10 #include <openssl/err.h> | 10 #include <openssl/err.h> |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 ssl_info.handshake_type == SSLInfo::HANDSHAKE_RESUME); | 187 ssl_info.handshake_type == SSLInfo::HANDSHAKE_RESUME); |
| 188 dict->SetInteger("cipher_suite", SSLConnectionStatusToCipherSuite( | 188 dict->SetInteger("cipher_suite", SSLConnectionStatusToCipherSuite( |
| 189 ssl_info.connection_status)); | 189 ssl_info.connection_status)); |
| 190 | 190 |
| 191 dict->SetString("next_proto", SSLClientSocket::NextProtoToString( | 191 dict->SetString("next_proto", SSLClientSocket::NextProtoToString( |
| 192 socket->GetNegotiatedProtocol())); | 192 socket->GetNegotiatedProtocol())); |
| 193 | 193 |
| 194 return std::move(dict); | 194 return std::move(dict); |
| 195 } | 195 } |
| 196 | 196 |
| 197 int GetBufferSize(const char* field_trial) { | |
| 198 // Get buffer sizes from field trials, if possible. If values not present, | |
| 199 // use default. Also make sure values are in reasonable range. | |
| 200 int buffer_size = kDefaultOpenSSLBufferSize; | |
| 201 #if !defined(OS_NACL) | |
| 202 int override_buffer_size; | |
| 203 if (base::StringToInt(base::FieldTrialList::FindFullName(field_trial), | |
| 204 &override_buffer_size)) { | |
| 205 buffer_size = override_buffer_size; | |
| 206 buffer_size = std::max(buffer_size, 1000); | |
| 207 buffer_size = std::min(buffer_size, 2 * kDefaultOpenSSLBufferSize); | |
| 208 } | |
| 209 #endif // !defined(OS_NACL) | |
| 210 return buffer_size; | |
| 211 } | |
| 212 | |
| 197 } // namespace | 213 } // namespace |
| 198 | 214 |
| 199 class SSLClientSocketImpl::SSLContext { | 215 class SSLClientSocketImpl::SSLContext { |
| 200 public: | 216 public: |
| 201 static SSLContext* GetInstance() { | 217 static SSLContext* GetInstance() { |
| 202 return base::Singleton<SSLContext>::get(); | 218 return base::Singleton<SSLContext>::get(); |
| 203 } | 219 } |
| 204 SSL_CTX* ssl_ctx() { return ssl_ctx_.get(); } | 220 SSL_CTX* ssl_ctx() { return ssl_ctx_.get(); } |
| 205 SSLClientSessionCache* session_cache() { return &session_cache_; } | 221 SSLClientSessionCache* session_cache() { return &session_cache_; } |
| 206 | 222 |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 463 SSLClientSocketImpl::SSLContext* context = | 479 SSLClientSocketImpl::SSLContext* context = |
| 464 SSLClientSocketImpl::SSLContext::GetInstance(); | 480 SSLClientSocketImpl::SSLContext::GetInstance(); |
| 465 context->session_cache()->Flush(); | 481 context->session_cache()->Flush(); |
| 466 } | 482 } |
| 467 | 483 |
| 468 SSLClientSocketImpl::SSLClientSocketImpl( | 484 SSLClientSocketImpl::SSLClientSocketImpl( |
| 469 std::unique_ptr<ClientSocketHandle> transport_socket, | 485 std::unique_ptr<ClientSocketHandle> transport_socket, |
| 470 const HostPortPair& host_and_port, | 486 const HostPortPair& host_and_port, |
| 471 const SSLConfig& ssl_config, | 487 const SSLConfig& ssl_config, |
| 472 const SSLClientSocketContext& context) | 488 const SSLClientSocketContext& context) |
| 473 : transport_send_busy_(false), | 489 : pending_read_error_(kNoPendingResult), |
| 474 transport_recv_busy_(false), | |
| 475 pending_read_error_(kNoPendingResult), | |
| 476 pending_read_ssl_error_(SSL_ERROR_NONE), | 490 pending_read_ssl_error_(SSL_ERROR_NONE), |
| 477 transport_read_error_(OK), | |
| 478 transport_write_error_(OK), | |
| 479 server_cert_chain_(new PeerCertificateChain(NULL)), | 491 server_cert_chain_(new PeerCertificateChain(NULL)), |
| 480 completed_connect_(false), | 492 completed_connect_(false), |
| 481 was_ever_used_(false), | 493 was_ever_used_(false), |
| 482 cert_verifier_(context.cert_verifier), | 494 cert_verifier_(context.cert_verifier), |
| 483 cert_transparency_verifier_(context.cert_transparency_verifier), | 495 cert_transparency_verifier_(context.cert_transparency_verifier), |
| 484 channel_id_service_(context.channel_id_service), | 496 channel_id_service_(context.channel_id_service), |
| 485 tb_was_negotiated_(false), | 497 tb_was_negotiated_(false), |
| 486 tb_negotiated_param_(TB_PARAM_ECDSAP256), | 498 tb_negotiated_param_(TB_PARAM_ECDSAP256), |
| 487 tb_signature_map_(10), | 499 tb_signature_map_(10), |
| 488 transport_(std::move(transport_socket)), | 500 transport_(std::move(transport_socket)), |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 620 return rv > OK ? OK : rv; | 632 return rv > OK ? OK : rv; |
| 621 } | 633 } |
| 622 | 634 |
| 623 void SSLClientSocketImpl::Disconnect() { | 635 void SSLClientSocketImpl::Disconnect() { |
| 624 disconnected_ = true; | 636 disconnected_ = true; |
| 625 | 637 |
| 626 // Shut down anything that may call us back. | 638 // Shut down anything that may call us back. |
| 627 cert_verifier_request_.reset(); | 639 cert_verifier_request_.reset(); |
| 628 channel_id_request_.Cancel(); | 640 channel_id_request_.Cancel(); |
| 629 weak_factory_.InvalidateWeakPtrs(); | 641 weak_factory_.InvalidateWeakPtrs(); |
| 642 transport_adapter_.reset(); | |
| 630 | 643 |
| 631 // Release user callbacks. | 644 // Release user callbacks. |
| 632 user_connect_callback_.Reset(); | 645 user_connect_callback_.Reset(); |
| 633 user_read_callback_.Reset(); | 646 user_read_callback_.Reset(); |
| 634 user_write_callback_.Reset(); | 647 user_write_callback_.Reset(); |
| 635 user_read_buf_ = NULL; | 648 user_read_buf_ = NULL; |
| 636 user_read_buf_len_ = 0; | 649 user_read_buf_len_ = 0; |
| 637 user_write_buf_ = NULL; | 650 user_write_buf_ = NULL; |
| 638 user_write_buf_len_ = 0; | 651 user_write_buf_len_ = 0; |
| 639 | 652 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 657 // disconnected. | 670 // disconnected. |
| 658 if (!completed_connect_ || disconnected_) | 671 if (!completed_connect_ || disconnected_) |
| 659 return false; | 672 return false; |
| 660 // If an asynchronous operation is still pending. | 673 // If an asynchronous operation is still pending. |
| 661 if (user_read_buf_.get() || user_write_buf_.get()) | 674 if (user_read_buf_.get() || user_write_buf_.get()) |
| 662 return false; | 675 return false; |
| 663 | 676 |
| 664 // If there is data read from the network that has not yet been consumed, do | 677 // If there is data read from the network that has not yet been consumed, do |
| 665 // not treat the connection as idle. | 678 // not treat the connection as idle. |
| 666 // | 679 // |
| 667 // Note that this does not check |BIO_pending|, whether there is ciphertext | 680 // Note that this does not check whether there is ciphertext that has not yet |
| 668 // that has not yet been flushed to the network. |Write| returns early, so | 681 // been flushed to the network. |Write| returns early, so this can cause race |
| 669 // this can cause race conditions which cause a socket to not be treated | 682 // conditions which cause a socket to not be treated reusable when it should |
| 670 // reusable when it should be. See https://crbug.com/466147. | 683 // be. See https://crbug.com/466147. |
| 671 if (BIO_wpending(transport_bio_.get()) > 0) | 684 if (transport_adapter_->HasPendingReadData()) |
| 672 return false; | 685 return false; |
| 673 | 686 |
| 674 return transport_->socket()->IsConnectedAndIdle(); | 687 return transport_->socket()->IsConnectedAndIdle(); |
| 675 } | 688 } |
| 676 | 689 |
| 677 int SSLClientSocketImpl::GetPeerAddress(IPEndPoint* addressList) const { | 690 int SSLClientSocketImpl::GetPeerAddress(IPEndPoint* addressList) const { |
| 678 return transport_->socket()->GetPeerAddress(addressList); | 691 return transport_->socket()->GetPeerAddress(addressList); |
| 679 } | 692 } |
| 680 | 693 |
| 681 int SSLClientSocketImpl::GetLocalAddress(IPEndPoint* addressList) const { | 694 int SSLClientSocketImpl::GetLocalAddress(IPEndPoint* addressList) const { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 765 int64_t SSLClientSocketImpl::GetTotalReceivedBytes() const { | 778 int64_t SSLClientSocketImpl::GetTotalReceivedBytes() const { |
| 766 return transport_->socket()->GetTotalReceivedBytes(); | 779 return transport_->socket()->GetTotalReceivedBytes(); |
| 767 } | 780 } |
| 768 | 781 |
| 769 int SSLClientSocketImpl::Read(IOBuffer* buf, | 782 int SSLClientSocketImpl::Read(IOBuffer* buf, |
| 770 int buf_len, | 783 int buf_len, |
| 771 const CompletionCallback& callback) { | 784 const CompletionCallback& callback) { |
| 772 user_read_buf_ = buf; | 785 user_read_buf_ = buf; |
| 773 user_read_buf_len_ = buf_len; | 786 user_read_buf_len_ = buf_len; |
| 774 | 787 |
| 775 int rv = DoReadLoop(); | 788 int rv = DoPayloadRead(); |
| 776 | 789 |
| 777 if (rv == ERR_IO_PENDING) { | 790 if (rv == ERR_IO_PENDING) { |
| 778 user_read_callback_ = callback; | 791 user_read_callback_ = callback; |
| 779 } else { | 792 } else { |
| 780 if (rv > 0) | 793 if (rv > 0) |
| 781 was_ever_used_ = true; | 794 was_ever_used_ = true; |
| 782 user_read_buf_ = NULL; | 795 user_read_buf_ = NULL; |
| 783 user_read_buf_len_ = 0; | 796 user_read_buf_len_ = 0; |
| 784 } | 797 } |
| 785 | 798 |
| 786 return rv; | 799 return rv; |
| 787 } | 800 } |
| 788 | 801 |
| 789 int SSLClientSocketImpl::Write(IOBuffer* buf, | 802 int SSLClientSocketImpl::Write(IOBuffer* buf, |
| 790 int buf_len, | 803 int buf_len, |
| 791 const CompletionCallback& callback) { | 804 const CompletionCallback& callback) { |
| 792 user_write_buf_ = buf; | 805 user_write_buf_ = buf; |
| 793 user_write_buf_len_ = buf_len; | 806 user_write_buf_len_ = buf_len; |
| 794 | 807 |
| 795 int rv = DoWriteLoop(); | 808 int rv = DoPayloadWrite(); |
| 796 | 809 |
| 797 if (rv == ERR_IO_PENDING) { | 810 if (rv == ERR_IO_PENDING) { |
| 798 user_write_callback_ = callback; | 811 user_write_callback_ = callback; |
| 799 } else { | 812 } else { |
| 800 if (rv > 0) | 813 if (rv > 0) |
| 801 was_ever_used_ = true; | 814 was_ever_used_ = true; |
| 802 user_write_buf_ = NULL; | 815 user_write_buf_ = NULL; |
| 803 user_write_buf_len_ = 0; | 816 user_write_buf_len_ = 0; |
| 804 } | 817 } |
| 805 | 818 |
| 806 return rv; | 819 return rv; |
| 807 } | 820 } |
| 808 | 821 |
| 809 int SSLClientSocketImpl::SetReceiveBufferSize(int32_t size) { | 822 int SSLClientSocketImpl::SetReceiveBufferSize(int32_t size) { |
| 810 return transport_->socket()->SetReceiveBufferSize(size); | 823 return transport_->socket()->SetReceiveBufferSize(size); |
| 811 } | 824 } |
| 812 | 825 |
| 813 int SSLClientSocketImpl::SetSendBufferSize(int32_t size) { | 826 int SSLClientSocketImpl::SetSendBufferSize(int32_t size) { |
| 814 return transport_->socket()->SetSendBufferSize(size); | 827 return transport_->socket()->SetSendBufferSize(size); |
| 815 } | 828 } |
| 816 | 829 |
| 830 void SSLClientSocketImpl::OnReadReady() { | |
| 831 // During a renegotiation, either Read or Write calls may be blocked on a | |
| 832 // transport read. | |
| 833 RetryAllOperations(); | |
| 834 } | |
| 835 | |
| 836 void SSLClientSocketImpl::OnWriteReady() { | |
| 837 // During a renegotiation, either Read or Write calls may be blocked on a | |
| 838 // transport read. | |
| 839 RetryAllOperations(); | |
| 840 } | |
| 841 | |
| 817 int SSLClientSocketImpl::Init() { | 842 int SSLClientSocketImpl::Init() { |
| 818 DCHECK(!ssl_); | 843 DCHECK(!ssl_); |
| 819 DCHECK(!transport_bio_); | |
| 820 | 844 |
| 821 #if defined(USE_NSS_CERTS) | 845 #if defined(USE_NSS_CERTS) |
| 822 if (ssl_config_.cert_io_enabled) { | 846 if (ssl_config_.cert_io_enabled) { |
| 823 // TODO(davidben): Move this out of SSLClientSocket. See | 847 // TODO(davidben): Move this out of SSLClientSocket. See |
| 824 // https://crbug.com/539520. | 848 // https://crbug.com/539520. |
| 825 EnsureNSSHttpIOInit(); | 849 EnsureNSSHttpIOInit(); |
| 826 } | 850 } |
| 827 #endif | 851 #endif |
| 828 | 852 |
| 829 SSLContext* context = SSLContext::GetInstance(); | 853 SSLContext* context = SSLContext::GetInstance(); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 842 if (!unused.AssignFromIPLiteral(host_and_port_.host()) && | 866 if (!unused.AssignFromIPLiteral(host_and_port_.host()) && |
| 843 !SSL_set_tlsext_host_name(ssl_.get(), host_and_port_.host().c_str())) { | 867 !SSL_set_tlsext_host_name(ssl_.get(), host_and_port_.host().c_str())) { |
| 844 return ERR_UNEXPECTED; | 868 return ERR_UNEXPECTED; |
| 845 } | 869 } |
| 846 | 870 |
| 847 bssl::UniquePtr<SSL_SESSION> session = | 871 bssl::UniquePtr<SSL_SESSION> session = |
| 848 context->session_cache()->Lookup(GetSessionCacheKey()); | 872 context->session_cache()->Lookup(GetSessionCacheKey()); |
| 849 if (session) | 873 if (session) |
| 850 SSL_set_session(ssl_.get(), session.get()); | 874 SSL_set_session(ssl_.get(), session.get()); |
| 851 | 875 |
| 852 // Get read and write buffer sizes from field trials, if possible. If values | 876 transport_adapter_.reset(new SocketBIOAdapter( |
| 853 // not present, use default. Also make sure values are in reasonable range. | 877 transport_->socket(), GetBufferSize("SSLBufferSizeRecv"), |
| 854 int send_buffer_size = kDefaultOpenSSLBufferSize; | 878 GetBufferSize("SSLBufferSizeSend"), this)); |
| 855 #if !defined(OS_NACL) | 879 BIO* transport_bio = transport_adapter_->bio(); |
| 856 int override_send_buffer_size; | 880 SSL_set_bio(ssl_.get(), transport_bio, transport_bio); |
| 857 if (base::StringToInt(base::FieldTrialList::FindFullName("SSLBufferSizeSend"), | 881 BIO_up_ref(transport_bio); // SSL_set_bio retains one reference. |
|
Ryan Sleevi
2016/10/12 23:30:27
I'm not sure that the comment sufficiently explain
davidben
2016/10/13 23:40:13
SSL_set_bio and friends take ownership. I've switc
| |
| 858 &override_send_buffer_size)) { | |
| 859 send_buffer_size = override_send_buffer_size; | |
| 860 send_buffer_size = std::max(send_buffer_size, 1000); | |
| 861 send_buffer_size = | |
| 862 std::min(send_buffer_size, 2 * kDefaultOpenSSLBufferSize); | |
| 863 } | |
| 864 #endif // !defined(OS_NACL) | |
| 865 send_buffer_ = new GrowableIOBuffer(); | |
| 866 send_buffer_->SetCapacity(send_buffer_size); | |
| 867 | |
| 868 int recv_buffer_size = kDefaultOpenSSLBufferSize; | |
| 869 #if !defined(OS_NACL) | |
| 870 int override_recv_buffer_size; | |
| 871 if (base::StringToInt(base::FieldTrialList::FindFullName("SSLBufferSizeRecv"), | |
| 872 &override_recv_buffer_size)) { | |
| 873 recv_buffer_size = override_recv_buffer_size; | |
| 874 recv_buffer_size = std::max(recv_buffer_size, 1000); | |
| 875 recv_buffer_size = | |
| 876 std::min(recv_buffer_size, 2 * kDefaultOpenSSLBufferSize); | |
| 877 } | |
| 878 #endif // !defined(OS_NACL) | |
| 879 recv_buffer_ = new GrowableIOBuffer(); | |
| 880 recv_buffer_->SetCapacity(recv_buffer_size); | |
| 881 | |
| 882 BIO* ssl_bio = NULL; | |
| 883 | |
| 884 // SSLClientSocketImpl retains ownership of the BIO buffers. | |
| 885 BIO* transport_bio_raw; | |
| 886 if (!BIO_new_bio_pair_external_buf( | |
| 887 &ssl_bio, send_buffer_->capacity(), | |
| 888 reinterpret_cast<uint8_t*>(send_buffer_->data()), &transport_bio_raw, | |
| 889 recv_buffer_->capacity(), | |
| 890 reinterpret_cast<uint8_t*>(recv_buffer_->data()))) | |
| 891 return ERR_UNEXPECTED; | |
| 892 transport_bio_.reset(transport_bio_raw); | |
| 893 DCHECK(ssl_bio); | |
| 894 DCHECK(transport_bio_); | |
| 895 | |
| 896 // Install a callback on OpenSSL's end to plumb transport errors through. | |
| 897 BIO_set_callback(ssl_bio, &SSLClientSocketImpl::BIOCallback); | |
| 898 BIO_set_callback_arg(ssl_bio, reinterpret_cast<char*>(this)); | |
| 899 | |
| 900 SSL_set_bio(ssl_.get(), ssl_bio, ssl_bio); | |
| 901 | 882 |
| 902 DCHECK_LT(SSL3_VERSION, ssl_config_.version_min); | 883 DCHECK_LT(SSL3_VERSION, ssl_config_.version_min); |
| 903 DCHECK_LT(SSL3_VERSION, ssl_config_.version_max); | 884 DCHECK_LT(SSL3_VERSION, ssl_config_.version_max); |
| 904 if (!SSL_set_min_proto_version(ssl_.get(), ssl_config_.version_min) || | 885 if (!SSL_set_min_proto_version(ssl_.get(), ssl_config_.version_min) || |
| 905 !SSL_set_max_proto_version(ssl_.get(), ssl_config_.version_max)) { | 886 !SSL_set_max_proto_version(ssl_.get(), ssl_config_.version_max)) { |
| 906 return ERR_UNEXPECTED; | 887 return ERR_UNEXPECTED; |
| 907 } | 888 } |
| 908 | 889 |
| 909 // OpenSSL defaults some options to on, others to off. To avoid ambiguity, | 890 // OpenSSL defaults some options to on, others to off. To avoid ambiguity, |
| 910 // set everything we care about to an absolute value. | 891 // set everything we care about to an absolute value. |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1018 void SSLClientSocketImpl::DoWriteCallback(int rv) { | 999 void SSLClientSocketImpl::DoWriteCallback(int rv) { |
| 1019 // Since Run may result in Write being called, clear |user_write_callback_| | 1000 // Since Run may result in Write being called, clear |user_write_callback_| |
| 1020 // up front. | 1001 // up front. |
| 1021 if (rv > 0) | 1002 if (rv > 0) |
| 1022 was_ever_used_ = true; | 1003 was_ever_used_ = true; |
| 1023 user_write_buf_ = NULL; | 1004 user_write_buf_ = NULL; |
| 1024 user_write_buf_len_ = 0; | 1005 user_write_buf_len_ = 0; |
| 1025 base::ResetAndReturn(&user_write_callback_).Run(rv); | 1006 base::ResetAndReturn(&user_write_callback_).Run(rv); |
| 1026 } | 1007 } |
| 1027 | 1008 |
| 1028 bool SSLClientSocketImpl::DoTransportIO() { | |
| 1029 bool network_moved = false; | |
| 1030 int rv; | |
| 1031 // Read and write as much data as possible. The loop is necessary because | |
| 1032 // Write() may return synchronously. | |
| 1033 do { | |
| 1034 rv = BufferSend(); | |
| 1035 if (rv != ERR_IO_PENDING && rv != 0) | |
| 1036 network_moved = true; | |
| 1037 } while (rv > 0); | |
| 1038 if (transport_read_error_ == OK && BufferRecv() != ERR_IO_PENDING) | |
| 1039 network_moved = true; | |
| 1040 return network_moved; | |
| 1041 } | |
| 1042 | |
| 1043 // TODO(cbentzel): Remove including "base/threading/thread_local.h" and | 1009 // TODO(cbentzel): Remove including "base/threading/thread_local.h" and |
| 1044 // g_first_run_completed once crbug.com/424386 is fixed. | 1010 // g_first_run_completed once crbug.com/424386 is fixed. |
| 1045 base::LazyInstance<base::ThreadLocalBoolean>::Leaky g_first_run_completed = | 1011 base::LazyInstance<base::ThreadLocalBoolean>::Leaky g_first_run_completed = |
| 1046 LAZY_INSTANCE_INITIALIZER; | 1012 LAZY_INSTANCE_INITIALIZER; |
| 1047 | 1013 |
| 1048 int SSLClientSocketImpl::DoHandshake() { | 1014 int SSLClientSocketImpl::DoHandshake() { |
| 1049 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); | 1015 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); |
| 1050 | 1016 |
| 1051 int rv; | 1017 int rv; |
| 1052 | 1018 |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1320 } | 1286 } |
| 1321 | 1287 |
| 1322 void SSLClientSocketImpl::OnHandshakeIOComplete(int result) { | 1288 void SSLClientSocketImpl::OnHandshakeIOComplete(int result) { |
| 1323 int rv = DoHandshakeLoop(result); | 1289 int rv = DoHandshakeLoop(result); |
| 1324 if (rv != ERR_IO_PENDING) { | 1290 if (rv != ERR_IO_PENDING) { |
| 1325 LogConnectEndEvent(rv); | 1291 LogConnectEndEvent(rv); |
| 1326 DoConnectCallback(rv); | 1292 DoConnectCallback(rv); |
| 1327 } | 1293 } |
| 1328 } | 1294 } |
| 1329 | 1295 |
| 1330 void SSLClientSocketImpl::OnSendComplete(int result) { | |
| 1331 if (next_handshake_state_ == STATE_HANDSHAKE) { | |
| 1332 // In handshake phase. | |
| 1333 OnHandshakeIOComplete(result); | |
| 1334 return; | |
| 1335 } | |
| 1336 | |
| 1337 // During a renegotiation, a Read call may also be blocked on a transport | |
| 1338 // write, so retry both operations. | |
| 1339 PumpReadWriteEvents(); | |
| 1340 } | |
| 1341 | |
| 1342 void SSLClientSocketImpl::OnRecvComplete(int result) { | |
| 1343 TRACE_EVENT0("net", "SSLClientSocketImpl::OnRecvComplete"); | |
| 1344 if (next_handshake_state_ == STATE_HANDSHAKE) { | |
| 1345 // In handshake phase. | |
| 1346 OnHandshakeIOComplete(result); | |
| 1347 return; | |
| 1348 } | |
| 1349 | |
| 1350 // Network layer received some data, check if client requested to read | |
| 1351 // decrypted data. | |
| 1352 if (!user_read_buf_.get()) | |
| 1353 return; | |
| 1354 | |
| 1355 int rv = DoReadLoop(); | |
| 1356 if (rv != ERR_IO_PENDING) | |
| 1357 DoReadCallback(rv); | |
| 1358 } | |
| 1359 | |
| 1360 int SSLClientSocketImpl::DoHandshakeLoop(int last_io_result) { | 1296 int SSLClientSocketImpl::DoHandshakeLoop(int last_io_result) { |
| 1361 TRACE_EVENT0("net", "SSLClientSocketImpl::DoHandshakeLoop"); | 1297 TRACE_EVENT0("net", "SSLClientSocketImpl::DoHandshakeLoop"); |
| 1362 int rv = last_io_result; | 1298 int rv = last_io_result; |
| 1363 do { | 1299 do { |
| 1364 // Default to STATE_NONE for next state. | 1300 // Default to STATE_NONE for next state. |
| 1365 // (This is a quirk carried over from the windows | 1301 // (This is a quirk carried over from the windows |
| 1366 // implementation. It makes reading the logs a bit harder.) | 1302 // implementation. It makes reading the logs a bit harder.) |
| 1367 // State handlers can and often do call GotoState just | 1303 // State handlers can and often do call GotoState just |
| 1368 // to stay in the current state. | 1304 // to stay in the current state. |
| 1369 State state = next_handshake_state_; | 1305 State state = next_handshake_state_; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 1388 break; | 1324 break; |
| 1389 case STATE_VERIFY_CERT_COMPLETE: | 1325 case STATE_VERIFY_CERT_COMPLETE: |
| 1390 rv = DoVerifyCertComplete(rv); | 1326 rv = DoVerifyCertComplete(rv); |
| 1391 break; | 1327 break; |
| 1392 case STATE_NONE: | 1328 case STATE_NONE: |
| 1393 default: | 1329 default: |
| 1394 rv = ERR_UNEXPECTED; | 1330 rv = ERR_UNEXPECTED; |
| 1395 NOTREACHED() << "unexpected state" << state; | 1331 NOTREACHED() << "unexpected state" << state; |
| 1396 break; | 1332 break; |
| 1397 } | 1333 } |
| 1398 | |
| 1399 bool network_moved = DoTransportIO(); | |
| 1400 if (network_moved && next_handshake_state_ == STATE_HANDSHAKE) { | |
| 1401 // In general we exit the loop if rv is ERR_IO_PENDING. In this | |
| 1402 // special case we keep looping even if rv is ERR_IO_PENDING because | |
| 1403 // the transport IO may allow DoHandshake to make progress. | |
| 1404 rv = OK; // This causes us to stay in the loop. | |
| 1405 } | |
| 1406 } while (rv != ERR_IO_PENDING && next_handshake_state_ != STATE_NONE); | 1334 } while (rv != ERR_IO_PENDING && next_handshake_state_ != STATE_NONE); |
| 1407 return rv; | 1335 return rv; |
| 1408 } | 1336 } |
| 1409 | 1337 |
| 1410 int SSLClientSocketImpl::DoReadLoop() { | |
| 1411 bool network_moved; | |
| 1412 int rv; | |
| 1413 do { | |
| 1414 rv = DoPayloadRead(); | |
| 1415 network_moved = DoTransportIO(); | |
| 1416 } while (rv == ERR_IO_PENDING && network_moved); | |
| 1417 | |
| 1418 return rv; | |
| 1419 } | |
| 1420 | |
| 1421 int SSLClientSocketImpl::DoWriteLoop() { | |
| 1422 bool network_moved; | |
| 1423 int rv; | |
| 1424 do { | |
| 1425 rv = DoPayloadWrite(); | |
| 1426 network_moved = DoTransportIO(); | |
| 1427 } while (rv == ERR_IO_PENDING && network_moved); | |
| 1428 | |
| 1429 return rv; | |
| 1430 } | |
| 1431 | |
| 1432 int SSLClientSocketImpl::DoPayloadRead() { | 1338 int SSLClientSocketImpl::DoPayloadRead() { |
| 1433 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); | 1339 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); |
| 1434 | 1340 |
| 1435 DCHECK_LT(0, user_read_buf_len_); | 1341 DCHECK_LT(0, user_read_buf_len_); |
| 1436 DCHECK(user_read_buf_.get()); | 1342 DCHECK(user_read_buf_.get()); |
| 1437 | 1343 |
| 1438 int rv; | 1344 int rv; |
| 1439 if (pending_read_error_ != kNoPendingResult) { | 1345 if (pending_read_error_ != kNoPendingResult) { |
| 1440 rv = pending_read_error_; | 1346 rv = pending_read_error_; |
| 1441 pending_read_error_ = kNoPendingResult; | 1347 pending_read_error_ = kNoPendingResult; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1498 pending_read_error_ = 0; | 1404 pending_read_error_ = 0; |
| 1499 } | 1405 } |
| 1500 | 1406 |
| 1501 if (total_bytes_read > 0) { | 1407 if (total_bytes_read > 0) { |
| 1502 // Return any bytes read to the caller. The error will be deferred to the | 1408 // Return any bytes read to the caller. The error will be deferred to the |
| 1503 // next call of DoPayloadRead. | 1409 // next call of DoPayloadRead. |
| 1504 rv = total_bytes_read; | 1410 rv = total_bytes_read; |
| 1505 | 1411 |
| 1506 // Do not treat insufficient data as an error to return in the next call to | 1412 // Do not treat insufficient data as an error to return in the next call to |
| 1507 // DoPayloadRead() - instead, let the call fall through to check SSL_read() | 1413 // DoPayloadRead() - instead, let the call fall through to check SSL_read() |
| 1508 // again. This is because DoTransportIO() may complete in between the next | 1414 // again. The transport may have data available by then. |
| 1509 // call to DoPayloadRead(), and thus it is important to check SSL_read() on | |
| 1510 // subsequent invocations to see if a complete record may now be read. | |
| 1511 if (pending_read_error_ == ERR_IO_PENDING) | 1415 if (pending_read_error_ == ERR_IO_PENDING) |
| 1512 pending_read_error_ = kNoPendingResult; | 1416 pending_read_error_ = kNoPendingResult; |
| 1513 } else { | 1417 } else { |
| 1514 // No bytes were returned. Return the pending read error immediately. | 1418 // No bytes were returned. Return the pending read error immediately. |
| 1515 DCHECK_NE(kNoPendingResult, pending_read_error_); | 1419 DCHECK_NE(kNoPendingResult, pending_read_error_); |
| 1516 rv = pending_read_error_; | 1420 rv = pending_read_error_; |
| 1517 pending_read_error_ = kNoPendingResult; | 1421 pending_read_error_ = kNoPendingResult; |
| 1518 } | 1422 } |
| 1519 | 1423 |
| 1520 if (rv >= 0) { | 1424 if (rv >= 0) { |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 1548 int net_error = MapLastOpenSSLError(ssl_error, err_tracer, &error_info); | 1452 int net_error = MapLastOpenSSLError(ssl_error, err_tracer, &error_info); |
| 1549 | 1453 |
| 1550 if (net_error != ERR_IO_PENDING) { | 1454 if (net_error != ERR_IO_PENDING) { |
| 1551 net_log_.AddEvent( | 1455 net_log_.AddEvent( |
| 1552 NetLogEventType::SSL_WRITE_ERROR, | 1456 NetLogEventType::SSL_WRITE_ERROR, |
| 1553 CreateNetLogOpenSSLErrorCallback(net_error, ssl_error, error_info)); | 1457 CreateNetLogOpenSSLErrorCallback(net_error, ssl_error, error_info)); |
| 1554 } | 1458 } |
| 1555 return net_error; | 1459 return net_error; |
| 1556 } | 1460 } |
| 1557 | 1461 |
| 1558 void SSLClientSocketImpl::PumpReadWriteEvents() { | 1462 void SSLClientSocketImpl::RetryAllOperations() { |
| 1463 // SSL_do_handshake, SSL_read, and SSL_write may all be retried when blocked, | |
| 1464 // so retry all operations for simplicity. (Otherwise, SSL_get_error for each | |
| 1465 // operation may be remembered to retry only the blocked ones.) | |
| 1466 | |
| 1467 if (next_handshake_state_ == STATE_HANDSHAKE) { | |
| 1468 // In handshake phase. The parameter to OnHandshakeIOComplete is unused. | |
| 1469 OnHandshakeIOComplete(OK); | |
| 1470 return; | |
| 1471 } | |
| 1472 | |
| 1559 int rv_read = ERR_IO_PENDING; | 1473 int rv_read = ERR_IO_PENDING; |
| 1560 int rv_write = ERR_IO_PENDING; | 1474 int rv_write = ERR_IO_PENDING; |
| 1561 bool network_moved; | 1475 if (user_read_buf_) |
| 1562 do { | 1476 rv_read = DoPayloadRead(); |
| 1563 if (user_read_buf_.get()) | 1477 if (user_write_buf_) |
| 1564 rv_read = DoPayloadRead(); | 1478 rv_write = DoPayloadWrite(); |
| 1565 if (user_write_buf_.get()) | |
| 1566 rv_write = DoPayloadWrite(); | |
| 1567 network_moved = DoTransportIO(); | |
| 1568 } while (rv_read == ERR_IO_PENDING && rv_write == ERR_IO_PENDING && | |
| 1569 (user_read_buf_.get() || user_write_buf_.get()) && network_moved); | |
| 1570 | 1479 |
| 1571 // Performing the Read callback may cause |this| to be deleted. If this | 1480 // Performing the Read callback may cause |this| to be deleted. If this |
| 1572 // happens, the Write callback should not be invoked. Guard against this by | 1481 // happens, the Write callback should not be invoked. Guard against this by |
| 1573 // holding a WeakPtr to |this| and ensuring it's still valid. | 1482 // holding a WeakPtr to |this| and ensuring it's still valid. |
| 1574 base::WeakPtr<SSLClientSocketImpl> guard(weak_factory_.GetWeakPtr()); | 1483 base::WeakPtr<SSLClientSocketImpl> guard(weak_factory_.GetWeakPtr()); |
| 1575 if (user_read_buf_.get() && rv_read != ERR_IO_PENDING) | 1484 if (rv_read != ERR_IO_PENDING) |
| 1576 DoReadCallback(rv_read); | 1485 DoReadCallback(rv_read); |
| 1577 | 1486 |
| 1578 if (!guard.get()) | 1487 if (!guard.get()) |
| 1579 return; | 1488 return; |
| 1580 | 1489 |
| 1581 if (user_write_buf_.get() && rv_write != ERR_IO_PENDING) | 1490 if (rv_write != ERR_IO_PENDING) |
| 1582 DoWriteCallback(rv_write); | 1491 DoWriteCallback(rv_write); |
| 1583 } | 1492 } |
| 1584 | 1493 |
| 1585 int SSLClientSocketImpl::BufferSend(void) { | |
| 1586 if (transport_send_busy_) | |
| 1587 return ERR_IO_PENDING; | |
| 1588 | |
| 1589 size_t buffer_read_offset; | |
| 1590 uint8_t* read_buf; | |
| 1591 size_t max_read; | |
| 1592 int status = BIO_zero_copy_get_read_buf(transport_bio_.get(), &read_buf, | |
| 1593 &buffer_read_offset, &max_read); | |
| 1594 DCHECK_EQ(status, 1); // Should never fail. | |
| 1595 if (!max_read) | |
| 1596 return 0; // Nothing pending in the OpenSSL write BIO. | |
| 1597 CHECK_EQ(read_buf, reinterpret_cast<uint8_t*>(send_buffer_->StartOfBuffer())); | |
| 1598 CHECK_LT(buffer_read_offset, static_cast<size_t>(send_buffer_->capacity())); | |
| 1599 send_buffer_->set_offset(buffer_read_offset); | |
| 1600 | |
| 1601 int rv = transport_->socket()->Write( | |
| 1602 send_buffer_.get(), max_read, | |
| 1603 base::Bind(&SSLClientSocketImpl::BufferSendComplete, | |
| 1604 base::Unretained(this))); | |
| 1605 if (rv == ERR_IO_PENDING) { | |
| 1606 transport_send_busy_ = true; | |
| 1607 } else { | |
| 1608 TransportWriteComplete(rv); | |
| 1609 } | |
| 1610 return rv; | |
| 1611 } | |
| 1612 | |
| 1613 int SSLClientSocketImpl::BufferRecv(void) { | |
| 1614 if (transport_recv_busy_) | |
| 1615 return ERR_IO_PENDING; | |
| 1616 | |
| 1617 // Determine how much was requested from |transport_bio_| that was not | |
| 1618 // actually available. | |
| 1619 size_t requested = BIO_ctrl_get_read_request(transport_bio_.get()); | |
| 1620 if (requested == 0) { | |
| 1621 // This is not a perfect match of error codes, as no operation is | |
| 1622 // actually pending. However, returning 0 would be interpreted as | |
| 1623 // a possible sign of EOF, which is also an inappropriate match. | |
| 1624 return ERR_IO_PENDING; | |
| 1625 } | |
| 1626 | |
| 1627 // Known Issue: While only reading |requested| data is the more correct | |
| 1628 // implementation, it has the downside of resulting in frequent reads: | |
| 1629 // One read for the SSL record header (~5 bytes) and one read for the SSL | |
| 1630 // record body. Rather than issuing these reads to the underlying socket | |
| 1631 // (and constantly allocating new IOBuffers), a single Read() request to | |
| 1632 // fill |transport_bio_| is issued. As long as an SSL client socket cannot | |
| 1633 // be gracefully shutdown (via SSL close alerts) and re-used for non-SSL | |
| 1634 // traffic, this over-subscribed Read()ing will not cause issues. | |
| 1635 | |
| 1636 size_t buffer_write_offset; | |
| 1637 uint8_t* write_buf; | |
| 1638 size_t max_write; | |
| 1639 int status = BIO_zero_copy_get_write_buf(transport_bio_.get(), &write_buf, | |
| 1640 &buffer_write_offset, &max_write); | |
| 1641 DCHECK_EQ(status, 1); // Should never fail. | |
| 1642 if (!max_write) | |
| 1643 return ERR_IO_PENDING; | |
| 1644 | |
| 1645 CHECK_EQ(write_buf, | |
| 1646 reinterpret_cast<uint8_t*>(recv_buffer_->StartOfBuffer())); | |
| 1647 CHECK_LT(buffer_write_offset, static_cast<size_t>(recv_buffer_->capacity())); | |
| 1648 | |
| 1649 recv_buffer_->set_offset(buffer_write_offset); | |
| 1650 int rv = transport_->socket()->Read( | |
| 1651 recv_buffer_.get(), max_write, | |
| 1652 base::Bind(&SSLClientSocketImpl::BufferRecvComplete, | |
| 1653 base::Unretained(this))); | |
| 1654 if (rv == ERR_IO_PENDING) { | |
| 1655 transport_recv_busy_ = true; | |
| 1656 } else { | |
| 1657 rv = TransportReadComplete(rv); | |
| 1658 } | |
| 1659 return rv; | |
| 1660 } | |
| 1661 | |
| 1662 void SSLClientSocketImpl::BufferSendComplete(int result) { | |
| 1663 TransportWriteComplete(result); | |
| 1664 OnSendComplete(result); | |
| 1665 } | |
| 1666 | |
| 1667 void SSLClientSocketImpl::BufferRecvComplete(int result) { | |
| 1668 result = TransportReadComplete(result); | |
| 1669 OnRecvComplete(result); | |
| 1670 } | |
| 1671 | |
| 1672 void SSLClientSocketImpl::TransportWriteComplete(int result) { | |
| 1673 DCHECK(ERR_IO_PENDING != result); | |
| 1674 int bytes_written = 0; | |
| 1675 if (result < 0) { | |
| 1676 // Record the error. Save it to be reported in a future read or write on | |
| 1677 // transport_bio_'s peer. | |
| 1678 transport_write_error_ = result; | |
| 1679 } else { | |
| 1680 bytes_written = result; | |
| 1681 } | |
| 1682 DCHECK_GE(send_buffer_->RemainingCapacity(), bytes_written); | |
| 1683 int ret = | |
| 1684 BIO_zero_copy_get_read_buf_done(transport_bio_.get(), bytes_written); | |
| 1685 DCHECK_EQ(1, ret); | |
| 1686 transport_send_busy_ = false; | |
| 1687 } | |
| 1688 | |
| 1689 int SSLClientSocketImpl::TransportReadComplete(int result) { | |
| 1690 DCHECK(ERR_IO_PENDING != result); | |
| 1691 // If an EOF, canonicalize to ERR_CONNECTION_CLOSED here so MapOpenSSLError | |
| 1692 // does not report success. | |
| 1693 if (result == 0) | |
| 1694 result = ERR_CONNECTION_CLOSED; | |
| 1695 int bytes_read = 0; | |
| 1696 if (result < 0) { | |
| 1697 // Received an error. Save it to be reported in a future read on | |
| 1698 // transport_bio_'s peer. | |
| 1699 transport_read_error_ = result; | |
| 1700 } else { | |
| 1701 bytes_read = result; | |
| 1702 } | |
| 1703 DCHECK_GE(recv_buffer_->RemainingCapacity(), bytes_read); | |
| 1704 int ret = BIO_zero_copy_get_write_buf_done(transport_bio_.get(), bytes_read); | |
| 1705 DCHECK_EQ(1, ret); | |
| 1706 transport_recv_busy_ = false; | |
| 1707 return result; | |
| 1708 } | |
| 1709 | |
| 1710 int SSLClientSocketImpl::VerifyCT() { | 1494 int SSLClientSocketImpl::VerifyCT() { |
| 1711 const uint8_t* sct_list_raw; | 1495 const uint8_t* sct_list_raw; |
| 1712 size_t sct_list_len; | 1496 size_t sct_list_len; |
| 1713 SSL_get0_signed_cert_timestamp_list(ssl_.get(), &sct_list_raw, &sct_list_len); | 1497 SSL_get0_signed_cert_timestamp_list(ssl_.get(), &sct_list_raw, &sct_list_len); |
| 1714 std::string sct_list; | 1498 std::string sct_list; |
| 1715 if (sct_list_len > 0) | 1499 if (sct_list_len > 0) |
| 1716 sct_list.assign(reinterpret_cast<const char*>(sct_list_raw), sct_list_len); | 1500 sct_list.assign(reinterpret_cast<const char*>(sct_list_raw), sct_list_len); |
| 1717 | 1501 |
| 1718 // Note that this is a completely synchronous operation: The CT Log Verifier | 1502 // Note that this is a completely synchronous operation: The CT Log Verifier |
| 1719 // gets all the data it needs for SCT verification and does not do any | 1503 // gets all the data it needs for SCT verification and does not do any |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1899 return 0; | 1683 return 0; |
| 1900 } | 1684 } |
| 1901 if (old_der != new_der) { | 1685 if (old_der != new_der) { |
| 1902 LOG(ERROR) << "Server certificate changed between handshakes"; | 1686 LOG(ERROR) << "Server certificate changed between handshakes"; |
| 1903 return 0; | 1687 return 0; |
| 1904 } | 1688 } |
| 1905 | 1689 |
| 1906 return 1; | 1690 return 1; |
| 1907 } | 1691 } |
| 1908 | 1692 |
| 1909 long SSLClientSocketImpl::MaybeReplayTransportError(BIO* bio, | |
| 1910 int cmd, | |
| 1911 const char* argp, | |
| 1912 int argi, | |
| 1913 long argl, | |
| 1914 long retvalue) { | |
| 1915 if (cmd == (BIO_CB_READ | BIO_CB_RETURN) && retvalue <= 0) { | |
| 1916 // If there is no more data in the buffer, report any pending errors that | |
| 1917 // were observed. Note that both the readbuf and the writebuf are checked | |
| 1918 // for errors, since the application may have encountered a socket error | |
| 1919 // while writing that would otherwise not be reported until the application | |
| 1920 // attempted to write again - which it may never do. See | |
| 1921 // https://crbug.com/249848. | |
| 1922 if (transport_read_error_ != OK) { | |
| 1923 OpenSSLPutNetError(FROM_HERE, transport_read_error_); | |
| 1924 return -1; | |
| 1925 } | |
| 1926 if (transport_write_error_ != OK) { | |
| 1927 OpenSSLPutNetError(FROM_HERE, transport_write_error_); | |
| 1928 return -1; | |
| 1929 } | |
| 1930 } else if (cmd == BIO_CB_WRITE) { | |
| 1931 // Because of the write buffer, this reports a failure from the previous | |
| 1932 // write payload. If the current payload fails to write, the error will be | |
| 1933 // reported in a future write or read to |bio|. | |
| 1934 if (transport_write_error_ != OK) { | |
| 1935 OpenSSLPutNetError(FROM_HERE, transport_write_error_); | |
| 1936 return -1; | |
| 1937 } | |
| 1938 } | |
| 1939 return retvalue; | |
| 1940 } | |
| 1941 | |
| 1942 // static | |
| 1943 long SSLClientSocketImpl::BIOCallback(BIO* bio, | |
| 1944 int cmd, | |
| 1945 const char* argp, | |
| 1946 int argi, | |
| 1947 long argl, | |
| 1948 long retvalue) { | |
| 1949 SSLClientSocketImpl* socket = | |
| 1950 reinterpret_cast<SSLClientSocketImpl*>(BIO_get_callback_arg(bio)); | |
| 1951 CHECK(socket); | |
| 1952 return socket->MaybeReplayTransportError(bio, cmd, argp, argi, argl, | |
| 1953 retvalue); | |
| 1954 } | |
| 1955 | |
| 1956 void SSLClientSocketImpl::MaybeCacheSession() { | 1693 void SSLClientSocketImpl::MaybeCacheSession() { |
| 1957 // Only cache the session once both a new session has been established and the | 1694 // Only cache the session once both a new session has been established and the |
| 1958 // certificate has been verified. Due to False Start, these events may happen | 1695 // certificate has been verified. Due to False Start, these events may happen |
| 1959 // in either order. | 1696 // in either order. |
| 1960 if (!pending_session_ || !certificate_verified_) | 1697 if (!pending_session_ || !certificate_verified_) |
| 1961 return; | 1698 return; |
| 1962 | 1699 |
| 1963 SSLContext::GetInstance()->session_cache()->Insert(GetSessionCacheKey(), | 1700 SSLContext::GetInstance()->session_cache()->Insert(GetSessionCacheKey(), |
| 1964 pending_session_.get()); | 1701 pending_session_.get()); |
| 1965 pending_session_ = nullptr; | 1702 pending_session_ = nullptr; |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2080 DCHECK_EQ(ERR_IO_PENDING, signature_result_); | 1817 DCHECK_EQ(ERR_IO_PENDING, signature_result_); |
| 2081 DCHECK(signature_.empty()); | 1818 DCHECK(signature_.empty()); |
| 2082 DCHECK(ssl_config_.client_private_key); | 1819 DCHECK(ssl_config_.client_private_key); |
| 2083 | 1820 |
| 2084 net_log_.EndEventWithNetErrorCode(NetLogEventType::SSL_PRIVATE_KEY_OP, error); | 1821 net_log_.EndEventWithNetErrorCode(NetLogEventType::SSL_PRIVATE_KEY_OP, error); |
| 2085 | 1822 |
| 2086 signature_result_ = error; | 1823 signature_result_ = error; |
| 2087 if (signature_result_ == OK) | 1824 if (signature_result_ == OK) |
| 2088 signature_ = signature; | 1825 signature_ = signature; |
| 2089 | 1826 |
| 2090 if (next_handshake_state_ == STATE_HANDSHAKE) { | |
| 2091 OnHandshakeIOComplete(signature_result_); | |
| 2092 return; | |
| 2093 } | |
| 2094 | |
| 2095 // During a renegotiation, either Read or Write calls may be blocked on an | 1827 // During a renegotiation, either Read or Write calls may be blocked on an |
| 2096 // asynchronous private key operation. | 1828 // asynchronous private key operation. |
| 2097 PumpReadWriteEvents(); | 1829 RetryAllOperations(); |
| 2098 } | 1830 } |
| 2099 | 1831 |
| 2100 int SSLClientSocketImpl::TokenBindingAdd(const uint8_t** out, | 1832 int SSLClientSocketImpl::TokenBindingAdd(const uint8_t** out, |
| 2101 size_t* out_len, | 1833 size_t* out_len, |
| 2102 int* out_alert_value) { | 1834 int* out_alert_value) { |
| 2103 if (ssl_config_.token_binding_params.empty()) { | 1835 if (ssl_config_.token_binding_params.empty()) { |
| 2104 return 0; | 1836 return 0; |
| 2105 } | 1837 } |
| 2106 bssl::ScopedCBB output; | 1838 bssl::ScopedCBB output; |
| 2107 CBB parameters_list; | 1839 CBB parameters_list; |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2245 if (ERR_GET_REASON(info->error_code) == SSL_R_TLSV1_ALERT_ACCESS_DENIED && | 1977 if (ERR_GET_REASON(info->error_code) == SSL_R_TLSV1_ALERT_ACCESS_DENIED && |
| 2246 !certificate_requested_) { | 1978 !certificate_requested_) { |
| 2247 net_error = ERR_SSL_PROTOCOL_ERROR; | 1979 net_error = ERR_SSL_PROTOCOL_ERROR; |
| 2248 } | 1980 } |
| 2249 } | 1981 } |
| 2250 | 1982 |
| 2251 return net_error; | 1983 return net_error; |
| 2252 } | 1984 } |
| 2253 | 1985 |
| 2254 } // namespace net | 1986 } // namespace net |
| OLD | NEW |