Index: net/socket/ssl_client_socket_openssl.cc |
diff --git a/net/socket/ssl_client_socket_openssl.cc b/net/socket/ssl_client_socket_openssl.cc |
index 4ff8d438e965b1fdf0b5b7f8b4ecdb75e1d14d66..be5cbd47a7ec67ab7a7bdfd84d3971e2dc04ed5f 100644 |
--- a/net/socket/ssl_client_socket_openssl.cc |
+++ b/net/socket/ssl_client_socket_openssl.cc |
@@ -87,15 +87,6 @@ int GetNetSSLVersion(SSL* ssl) { |
} |
} |
-// Compute a unique key string for the SSL session cache. |socket| is an |
-// input socket object. Return a string. |
-std::string GetSocketSessionCacheKey(const SSLClientSocketOpenSSL& socket) { |
- std::string result = socket.host_and_port().ToString(); |
- result.append("/"); |
- result.append(socket.ssl_session_cache_shard()); |
- return result; |
-} |
- |
} // namespace |
class SSLClientSocketOpenSSL::SSLContext { |
@@ -139,7 +130,7 @@ class SSLClientSocketOpenSSL::SSLContext { |
static std::string GetSessionCacheKey(const SSL* ssl) { |
SSLClientSocketOpenSSL* socket = GetInstance()->GetClientSocketFromSSL(ssl); |
DCHECK(socket); |
- return GetSocketSessionCacheKey(*socket); |
+ return socket->GetSessionCacheKey(); |
} |
static SSLSessionCacheOpenSSL::Config kDefaultSessionCacheConfig; |
@@ -360,12 +351,34 @@ SSLClientSocketOpenSSL::SSLClientSocketOpenSSL( |
npn_status_(kNextProtoUnsupported), |
channel_id_request_return_value_(ERR_UNEXPECTED), |
channel_id_xtn_negotiated_(false), |
- net_log_(transport_->socket()->NetLog()) {} |
+ net_log_(transport_->socket()->NetLog()) { |
+} |
SSLClientSocketOpenSSL::~SSLClientSocketOpenSSL() { |
Disconnect(); |
} |
+bool SSLClientSocketOpenSSL::InSessionCache() const { |
+ SSLContext* context = SSLContext::GetInstance(); |
+ std::string cache_key = GetSessionCacheKey(); |
+ return context->session_cache()->SSLSessionIsInCache(cache_key); |
+} |
+ |
+void SSLClientSocketOpenSSL::SetHandshakeSuccessCallback( |
+ const base::Closure& callback) { |
+ success_callback_ = callback; |
mmenke
2014/07/22 16:24:11
optional: I think using one handshake complete ca
wtc
2014/07/23 02:03:26
I believe all three reviewers suggested this. Mack
mshelley
2014/07/23 03:49:56
Ryan and Wan-Teh have suggested this as well. My p
mshelley
2014/07/23 03:49:56
Since we decided to treat failures and successes i
|
+ SSLContext* context = SSLContext::GetInstance(); |
+ context->session_cache()->SetSessionAddedCallback( |
+ ssl_, |
+ base::Bind(&SSLClientSocketOpenSSL::OnHandshakeSuccess, |
+ base::Unretained(this))); |
+} |
+ |
+void SSLClientSocketOpenSSL::SetHandshakeFailureCallback( |
+ const base::Closure& callback) { |
+ error_callback_ = callback; |
+} |
+ |
void SSLClientSocketOpenSSL::GetSSLCertRequestInfo( |
SSLCertRequestInfo* cert_request_info) { |
cert_request_info->host_and_port = host_and_port_; |
@@ -432,11 +445,17 @@ int SSLClientSocketOpenSSL::Connect(const CompletionCallback& callback) { |
net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SSL_CONNECT, rv); |
} |
+ if (rv < OK && rv != ERR_IO_PENDING) |
+ OnHandshakeFailure(); |
+ |
return rv > OK ? OK : rv; |
} |
void SSLClientSocketOpenSSL::Disconnect() { |
+ OnHandshakeFailure(); |
if (ssl_) { |
+ SSLContext* context = SSLContext::GetInstance(); |
+ context->session_cache()->RemoveSessionAddedCallback(ssl_); |
// Calling SSL_shutdown prevents the session from being marked as |
// unresumable. |
SSL_shutdown(ssl_); |
@@ -612,6 +631,12 @@ int SSLClientSocketOpenSSL::Read(IOBuffer* buf, |
user_read_buf_len_ = 0; |
} |
+ if (rv < 0 && rv != ERR_IO_PENDING) { |
+ // Failure of a write attempt may indicate a failed false start |
+ // connection. |
+ OnHandshakeFailure(); |
+ } |
+ |
return rv; |
} |
@@ -632,6 +657,12 @@ int SSLClientSocketOpenSSL::Write(IOBuffer* buf, |
user_write_buf_len_ = 0; |
} |
+ if (rv < 0 && rv != ERR_IO_PENDING) { |
+ // Failure of a write attempt may indicate a failed false start |
+ // connection. |
+ OnHandshakeFailure(); |
+ } |
+ |
return rv; |
} |
@@ -658,7 +689,7 @@ int SSLClientSocketOpenSSL::Init() { |
return ERR_UNEXPECTED; |
trying_cached_session_ = context->session_cache()->SetSSLSessionWithKey( |
- ssl_, GetSocketSessionCacheKey(*this)); |
+ ssl_, GetSessionCacheKey()); |
BIO* ssl_bio = NULL; |
// 0 => use default buffer sizes. |
@@ -775,6 +806,21 @@ void SSLClientSocketOpenSSL::DoWriteCallback(int rv) { |
base::ResetAndReturn(&user_write_callback_).Run(rv); |
} |
+std::string SSLClientSocketOpenSSL::GetSessionCacheKey() const { |
+ return CreateSessionCacheKey(host_and_port_, ssl_session_cache_shard_); |
+} |
+ |
+void SSLClientSocketOpenSSL::OnHandshakeSuccess() { |
+ error_callback_.Reset(); |
+ base::ResetAndReturn(&success_callback_).Run(); |
+} |
+ |
+void SSLClientSocketOpenSSL::OnHandshakeFailure() { |
+ if (!error_callback_.is_null()) |
+ success_callback_.Reset(); |
+ base::ResetAndReturn(&error_callback_).Run(); |
mmenke
2014/07/22 16:24:11
This should be:
if (!error_callback_.is_null()) {
mshelley
2014/07/23 03:49:56
Done.
|
+} |
+ |
bool SSLClientSocketOpenSSL::DoTransportIO() { |
bool network_moved = false; |
int rv; |
@@ -924,6 +970,8 @@ void SSLClientSocketOpenSSL::OnHandshakeIOComplete(int result) { |
if (rv != ERR_IO_PENDING) { |
net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SSL_CONNECT, rv); |
DoConnectCallback(rv); |
+ if (rv < OK) |
+ OnHandshakeFailure(); |
mmenke
2014/07/22 16:24:11
This call isn't needed - we call OnHandshakeFailur
mshelley
2014/07/23 03:49:56
In response to Ryan's comment on line 1052 of http
|
} |
} |
@@ -1014,7 +1062,9 @@ int SSLClientSocketOpenSSL::DoHandshakeLoop(int last_io_result) { |
// the transport IO may allow DoHandshake to make progress. |
rv = OK; // This causes us to stay in the loop. |
} |
+ |
mmenke
2014/07/22 16:24:11
nit: Generally, we don't have extra line breaks a
mshelley
2014/07/23 03:49:56
Done.
|
} while (rv != ERR_IO_PENDING && next_handshake_state_ != STATE_NONE); |
+ |
return rv; |
} |
@@ -1116,7 +1166,6 @@ int SSLClientSocketOpenSSL::DoPayloadRead() { |
int SSLClientSocketOpenSSL::DoPayloadWrite() { |
crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); |
int rv = SSL_write(ssl_, user_write_buf_->data(), user_write_buf_len_); |
- |
if (rv >= 0) { |
net_log_.AddByteTransferEvent(NetLog::TYPE_SSL_SOCKET_BYTES_SENT, rv, |
user_write_buf_->data()); |