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 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 367 handshake_succeeded_(false), | 367 handshake_succeeded_(false), |
| 368 marked_session_as_good_(false), | 368 marked_session_as_good_(false), |
| 369 transport_security_state_(context.transport_security_state), | 369 transport_security_state_(context.transport_security_state), |
| 370 net_log_(transport_->socket()->NetLog()) { | 370 net_log_(transport_->socket()->NetLog()) { |
| 371 } | 371 } |
| 372 | 372 |
| 373 SSLClientSocketOpenSSL::~SSLClientSocketOpenSSL() { | 373 SSLClientSocketOpenSSL::~SSLClientSocketOpenSSL() { |
| 374 Disconnect(); | 374 Disconnect(); |
| 375 } | 375 } |
| 376 | 376 |
| 377 // Compute a unique key string for the SSL session cache. | |
| 378 // Return a string. | |
|
wtc
2014/08/12 14:51:01
I remember I asked you to revise this comment befo
mshelley
2014/08/12 21:47:01
Done.
| |
| 379 std::string SSLClientSocketOpenSSL::GetSessionCacheKey() const { | |
| 380 std::string result = host_and_port_.ToString(); | |
| 381 result.append("/"); | |
| 382 result.append(ssl_session_cache_shard_); | |
| 383 return result; | |
| 384 } | |
| 385 | |
| 377 bool SSLClientSocketOpenSSL::InSessionCache() const { | 386 bool SSLClientSocketOpenSSL::InSessionCache() const { |
| 378 SSLContext* context = SSLContext::GetInstance(); | 387 SSLContext* context = SSLContext::GetInstance(); |
| 379 std::string cache_key = GetSessionCacheKey(); | 388 std::string cache_key = GetSessionCacheKey(); |
| 380 return context->session_cache()->SSLSessionIsInCache(cache_key); | 389 return context->session_cache()->SSLSessionIsInCache(cache_key); |
| 381 } | 390 } |
| 382 | 391 |
| 383 void SSLClientSocketOpenSSL::SetHandshakeCompletionCallback( | 392 void SSLClientSocketOpenSSL::SetHandshakeCompletionCallback( |
| 384 const base::Closure& callback) { | 393 const base::Closure& callback) { |
| 385 handshake_completion_callback_ = callback; | 394 handshake_completion_callback_ = callback; |
| 386 } | 395 } |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 632 int buf_len, | 641 int buf_len, |
| 633 const CompletionCallback& callback) { | 642 const CompletionCallback& callback) { |
| 634 user_read_buf_ = buf; | 643 user_read_buf_ = buf; |
| 635 user_read_buf_len_ = buf_len; | 644 user_read_buf_len_ = buf_len; |
| 636 | 645 |
| 637 int rv = DoReadLoop(OK); | 646 int rv = DoReadLoop(OK); |
| 638 | 647 |
| 639 if (rv == ERR_IO_PENDING) { | 648 if (rv == ERR_IO_PENDING) { |
| 640 user_read_callback_ = callback; | 649 user_read_callback_ = callback; |
| 641 } else { | 650 } else { |
| 642 if (rv > 0) | 651 if (rv > 0) { |
| 643 was_ever_used_ = true; | 652 was_ever_used_ = true; |
| 653 } else if (rv < 0) { | |
| 654 // Failure of a read attempt may indicate a failed false start | |
| 655 // connection. | |
| 656 OnHandshakeCompletion(); | |
| 657 } | |
|
Ryan Sleevi
2014/08/12 00:27:42
This should be / is a separate CL, right?
wtc
2014/08/12 14:51:00
This is a merge error. The current code is on line
mshelley
2014/08/12 21:47:01
Done.
| |
| 644 user_read_buf_ = NULL; | 658 user_read_buf_ = NULL; |
| 645 user_read_buf_len_ = 0; | 659 user_read_buf_len_ = 0; |
| 646 if (rv <= 0) { | 660 if (rv <= 0) { |
| 647 // Failure of a read attempt may indicate a failed false start | 661 // Failure of a read attempt may indicate a failed false start |
| 648 // connection. | 662 // connection. |
| 649 OnHandshakeCompletion(); | 663 OnHandshakeCompletion(); |
| 650 } | 664 } |
| 651 } | 665 } |
| 652 | 666 |
| 653 return rv; | 667 return rv; |
| 654 } | 668 } |
| 655 | 669 |
| 656 int SSLClientSocketOpenSSL::Write(IOBuffer* buf, | 670 int SSLClientSocketOpenSSL::Write(IOBuffer* buf, |
| 657 int buf_len, | 671 int buf_len, |
| 658 const CompletionCallback& callback) { | 672 const CompletionCallback& callback) { |
| 659 user_write_buf_ = buf; | 673 user_write_buf_ = buf; |
| 660 user_write_buf_len_ = buf_len; | 674 user_write_buf_len_ = buf_len; |
| 661 | 675 |
| 662 int rv = DoWriteLoop(OK); | 676 int rv = DoWriteLoop(OK); |
| 663 | 677 |
| 664 if (rv == ERR_IO_PENDING) { | 678 if (rv == ERR_IO_PENDING) { |
| 665 user_write_callback_ = callback; | 679 user_write_callback_ = callback; |
| 666 } else { | 680 } else { |
| 667 if (rv > 0) | 681 if (rv > 0) { |
| 668 was_ever_used_ = true; | 682 was_ever_used_ = true; |
| 683 } else { | |
| 684 // Failure of a write attempt may indicate a failed false start | |
| 685 // connection. | |
| 686 OnHandshakeCompletion(); | |
| 687 } | |
|
wtc
2014/08/12 14:51:01
Please undo this change.
mshelley
2014/08/12 21:47:01
Done.
| |
| 669 user_write_buf_ = NULL; | 688 user_write_buf_ = NULL; |
| 670 user_write_buf_len_ = 0; | 689 user_write_buf_len_ = 0; |
| 671 if (rv < 0) { | 690 if (rv < 0) { |
| 672 // Failure of a write attempt may indicate a failed false start | 691 // Failure of a write attempt may indicate a failed false start |
| 673 // connection. | 692 // connection. |
| 674 OnHandshakeCompletion(); | 693 OnHandshakeCompletion(); |
| 675 } | 694 } |
| 676 } | 695 } |
| 677 | 696 |
| 678 return rv; | 697 return rv; |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 838 user_write_buf_ = NULL; | 857 user_write_buf_ = NULL; |
| 839 user_write_buf_len_ = 0; | 858 user_write_buf_len_ = 0; |
| 840 if (rv < 0) { | 859 if (rv < 0) { |
| 841 // Failure of a write attempt may indicate a failed false start | 860 // Failure of a write attempt may indicate a failed false start |
| 842 // connection. | 861 // connection. |
| 843 OnHandshakeCompletion(); | 862 OnHandshakeCompletion(); |
| 844 } | 863 } |
| 845 base::ResetAndReturn(&user_write_callback_).Run(rv); | 864 base::ResetAndReturn(&user_write_callback_).Run(rv); |
| 846 } | 865 } |
| 847 | 866 |
| 848 std::string SSLClientSocketOpenSSL::GetSessionCacheKey() const { | |
| 849 return CreateSessionCacheKey(host_and_port_, ssl_session_cache_shard_); | |
| 850 } | |
| 851 | |
| 852 void SSLClientSocketOpenSSL::OnHandshakeCompletion() { | 867 void SSLClientSocketOpenSSL::OnHandshakeCompletion() { |
| 853 if (!handshake_completion_callback_.is_null()) | 868 if (!handshake_completion_callback_.is_null()) |
| 854 base::ResetAndReturn(&handshake_completion_callback_).Run(); | 869 base::ResetAndReturn(&handshake_completion_callback_).Run(); |
| 855 } | 870 } |
| 856 | 871 |
| 857 bool SSLClientSocketOpenSSL::DoTransportIO() { | 872 bool SSLClientSocketOpenSSL::DoTransportIO() { |
| 858 bool network_moved = false; | 873 bool network_moved = false; |
| 859 int rv; | 874 int rv; |
| 860 // Read and write as much data as possible. The loop is necessary because | 875 // Read and write as much data as possible. The loop is necessary because |
| 861 // Write() may return synchronously. | 876 // Write() may return synchronously. |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1072 c.Run(rv > OK ? OK : rv); | 1087 c.Run(rv > OK ? OK : rv); |
| 1073 } | 1088 } |
| 1074 } | 1089 } |
| 1075 | 1090 |
| 1076 X509Certificate* SSLClientSocketOpenSSL::UpdateServerCert() { | 1091 X509Certificate* SSLClientSocketOpenSSL::UpdateServerCert() { |
| 1077 server_cert_chain_->Reset(SSL_get_peer_cert_chain(ssl_)); | 1092 server_cert_chain_->Reset(SSL_get_peer_cert_chain(ssl_)); |
| 1078 server_cert_ = server_cert_chain_->AsOSChain(); | 1093 server_cert_ = server_cert_chain_->AsOSChain(); |
| 1079 | 1094 |
| 1080 if (!server_cert_chain_->IsValid()) | 1095 if (!server_cert_chain_->IsValid()) |
| 1081 DVLOG(1) << "UpdateServerCert received invalid certificate chain from peer"; | 1096 DVLOG(1) << "UpdateServerCert received invalid certificate chain from peer"; |
| 1082 | |
|
wtc
2014/08/12 14:51:01
This is probably a merge error. I seem to remember
| |
| 1083 return server_cert_.get(); | 1097 return server_cert_.get(); |
| 1084 } | 1098 } |
| 1085 | 1099 |
| 1086 void SSLClientSocketOpenSSL::OnHandshakeIOComplete(int result) { | 1100 void SSLClientSocketOpenSSL::OnHandshakeIOComplete(int result) { |
| 1087 int rv = DoHandshakeLoop(result); | 1101 int rv = DoHandshakeLoop(result); |
| 1088 if (rv != ERR_IO_PENDING) { | 1102 if (rv != ERR_IO_PENDING) { |
| 1089 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SSL_CONNECT, rv); | 1103 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SSL_CONNECT, rv); |
| 1090 DoConnectCallback(rv); | 1104 DoConnectCallback(rv); |
| 1091 } | 1105 } |
| 1092 } | 1106 } |
| (...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1635 if (handshake_succeeded_ && marked_session_as_good_) | 1649 if (handshake_succeeded_ && marked_session_as_good_) |
| 1636 OnHandshakeCompletion(); | 1650 OnHandshakeCompletion(); |
| 1637 } | 1651 } |
| 1638 | 1652 |
| 1639 scoped_refptr<X509Certificate> | 1653 scoped_refptr<X509Certificate> |
| 1640 SSLClientSocketOpenSSL::GetUnverifiedServerCertificateChain() const { | 1654 SSLClientSocketOpenSSL::GetUnverifiedServerCertificateChain() const { |
| 1641 return server_cert_; | 1655 return server_cert_; |
| 1642 } | 1656 } |
| 1643 | 1657 |
| 1644 } // namespace net | 1658 } // namespace net |
| OLD | NEW |