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 16 matching lines...) Expand all Loading... | |
27 #include "crypto/scoped_openssl_types.h" | 27 #include "crypto/scoped_openssl_types.h" |
28 #include "net/base/net_errors.h" | 28 #include "net/base/net_errors.h" |
29 #include "net/cert/cert_policy_enforcer.h" | 29 #include "net/cert/cert_policy_enforcer.h" |
30 #include "net/cert/cert_verifier.h" | 30 #include "net/cert/cert_verifier.h" |
31 #include "net/cert/ct_ev_whitelist.h" | 31 #include "net/cert/ct_ev_whitelist.h" |
32 #include "net/cert/ct_verifier.h" | 32 #include "net/cert/ct_verifier.h" |
33 #include "net/cert/single_request_cert_verifier.h" | 33 #include "net/cert/single_request_cert_verifier.h" |
34 #include "net/cert/x509_certificate_net_log_param.h" | 34 #include "net/cert/x509_certificate_net_log_param.h" |
35 #include "net/cert/x509_util_openssl.h" | 35 #include "net/cert/x509_util_openssl.h" |
36 #include "net/http/transport_security_state.h" | 36 #include "net/http/transport_security_state.h" |
37 #include "net/socket/ssl_session_cache_openssl.h" | |
38 #include "net/ssl/scoped_openssl_types.h" | 37 #include "net/ssl/scoped_openssl_types.h" |
39 #include "net/ssl/ssl_cert_request_info.h" | 38 #include "net/ssl/ssl_cert_request_info.h" |
39 #include "net/ssl/ssl_client_session_cache_openssl.h" | |
40 #include "net/ssl/ssl_connection_status_flags.h" | 40 #include "net/ssl/ssl_connection_status_flags.h" |
41 #include "net/ssl/ssl_info.h" | 41 #include "net/ssl/ssl_info.h" |
42 | 42 |
43 #if defined(OS_WIN) | 43 #if defined(OS_WIN) |
44 #include "base/win/windows_version.h" | 44 #include "base/win/windows_version.h" |
45 #endif | 45 #endif |
46 | 46 |
47 #if defined(USE_OPENSSL_CERTS) | 47 #if defined(USE_OPENSSL_CERTS) |
48 #include "net/ssl/openssl_client_key_store.h" | 48 #include "net/ssl/openssl_client_key_store.h" |
49 #else | 49 #else |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
157 return false; | 157 return false; |
158 #endif | 158 #endif |
159 } | 159 } |
160 | 160 |
161 } // namespace | 161 } // namespace |
162 | 162 |
163 class SSLClientSocketOpenSSL::SSLContext { | 163 class SSLClientSocketOpenSSL::SSLContext { |
164 public: | 164 public: |
165 static SSLContext* GetInstance() { return Singleton<SSLContext>::get(); } | 165 static SSLContext* GetInstance() { return Singleton<SSLContext>::get(); } |
166 SSL_CTX* ssl_ctx() { return ssl_ctx_.get(); } | 166 SSL_CTX* ssl_ctx() { return ssl_ctx_.get(); } |
167 SSLSessionCacheOpenSSL* session_cache() { return &session_cache_; } | 167 SSLClientSessionCacheOpenSSL* session_cache() { return &session_cache_; } |
168 | 168 |
169 SSLClientSocketOpenSSL* GetClientSocketFromSSL(const SSL* ssl) { | 169 SSLClientSocketOpenSSL* GetClientSocketFromSSL(const SSL* ssl) { |
170 DCHECK(ssl); | 170 DCHECK(ssl); |
171 SSLClientSocketOpenSSL* socket = static_cast<SSLClientSocketOpenSSL*>( | 171 SSLClientSocketOpenSSL* socket = static_cast<SSLClientSocketOpenSSL*>( |
172 SSL_get_ex_data(ssl, ssl_socket_data_index_)); | 172 SSL_get_ex_data(ssl, ssl_socket_data_index_)); |
173 DCHECK(socket); | 173 DCHECK(socket); |
174 return socket; | 174 return socket; |
175 } | 175 } |
176 | 176 |
177 bool SetClientSocketForSSL(SSL* ssl, SSLClientSocketOpenSSL* socket) { | 177 bool SetClientSocketForSSL(SSL* ssl, SSLClientSocketOpenSSL* socket) { |
178 return SSL_set_ex_data(ssl, ssl_socket_data_index_, socket) != 0; | 178 return SSL_set_ex_data(ssl, ssl_socket_data_index_, socket) != 0; |
179 } | 179 } |
180 | 180 |
181 private: | 181 private: |
182 friend struct DefaultSingletonTraits<SSLContext>; | 182 friend struct DefaultSingletonTraits<SSLContext>; |
183 | 183 |
184 SSLContext() { | 184 SSLContext() : session_cache_(SSLClientSessionCacheOpenSSL::Config()) { |
185 crypto::EnsureOpenSSLInit(); | 185 crypto::EnsureOpenSSLInit(); |
186 ssl_socket_data_index_ = SSL_get_ex_new_index(0, 0, 0, 0, 0); | 186 ssl_socket_data_index_ = SSL_get_ex_new_index(0, 0, 0, 0, 0); |
187 DCHECK_NE(ssl_socket_data_index_, -1); | 187 DCHECK_NE(ssl_socket_data_index_, -1); |
188 ssl_ctx_.reset(SSL_CTX_new(SSLv23_client_method())); | 188 ssl_ctx_.reset(SSL_CTX_new(SSLv23_client_method())); |
189 session_cache_.Reset(ssl_ctx_.get(), kDefaultSessionCacheConfig); | |
190 SSL_CTX_set_cert_verify_callback(ssl_ctx_.get(), CertVerifyCallback, NULL); | 189 SSL_CTX_set_cert_verify_callback(ssl_ctx_.get(), CertVerifyCallback, NULL); |
191 SSL_CTX_set_cert_cb(ssl_ctx_.get(), ClientCertRequestCallback, NULL); | 190 SSL_CTX_set_cert_cb(ssl_ctx_.get(), ClientCertRequestCallback, NULL); |
192 SSL_CTX_set_verify(ssl_ctx_.get(), SSL_VERIFY_PEER, NULL); | 191 SSL_CTX_set_verify(ssl_ctx_.get(), SSL_VERIFY_PEER, NULL); |
193 // This stops |SSL_shutdown| from generating the close_notify message, which | 192 // This stops |SSL_shutdown| from generating the close_notify message, which |
194 // is currently not sent on the network. | 193 // is currently not sent on the network. |
195 // TODO(haavardm): Remove setting quiet shutdown once 118366 is fixed. | 194 // TODO(haavardm): Remove setting quiet shutdown once 118366 is fixed. |
196 SSL_CTX_set_quiet_shutdown(ssl_ctx_.get(), 1); | 195 SSL_CTX_set_quiet_shutdown(ssl_ctx_.get(), 1); |
197 // TODO(kristianm): Only select this if ssl_config_.next_proto is not empty. | 196 // TODO(kristianm): Only select this if ssl_config_.next_proto is not empty. |
198 // It would be better if the callback were not a global setting, | 197 // It would be better if the callback were not a global setting, |
199 // but that is an OpenSSL issue. | 198 // but that is an OpenSSL issue. |
200 SSL_CTX_set_next_proto_select_cb(ssl_ctx_.get(), SelectNextProtoCallback, | 199 SSL_CTX_set_next_proto_select_cb(ssl_ctx_.get(), SelectNextProtoCallback, |
201 NULL); | 200 NULL); |
202 ssl_ctx_->tlsext_channel_id_enabled_new = 1; | 201 ssl_ctx_->tlsext_channel_id_enabled_new = 1; |
203 | 202 |
203 // Set up the session cache. NO_INTERNAL_STORE disables OpenSSL's builtin | |
204 // cache, and NO_AUTO_CLEAR disables the call to SSL_CTX_flush_sessions | |
205 // every 256 connections. (This number is hard-coded in the library and | |
206 // can't be changed.) | |
207 SSL_CTX_set_session_cache_mode(ssl_ctx_.get(), | |
208 SSL_SESS_CACHE_CLIENT | | |
209 SSL_SESS_CACHE_NO_INTERNAL_STORE | | |
210 SSL_SESS_CACHE_NO_AUTO_CLEAR); | |
211 | |
204 scoped_ptr<base::Environment> env(base::Environment::Create()); | 212 scoped_ptr<base::Environment> env(base::Environment::Create()); |
205 std::string ssl_keylog_file; | 213 std::string ssl_keylog_file; |
206 if (env->GetVar("SSLKEYLOGFILE", &ssl_keylog_file) && | 214 if (env->GetVar("SSLKEYLOGFILE", &ssl_keylog_file) && |
207 !ssl_keylog_file.empty()) { | 215 !ssl_keylog_file.empty()) { |
208 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); | 216 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); |
209 BIO* bio = BIO_new_file(ssl_keylog_file.c_str(), "a"); | 217 BIO* bio = BIO_new_file(ssl_keylog_file.c_str(), "a"); |
210 if (!bio) { | 218 if (!bio) { |
211 LOG(ERROR) << "Failed to open " << ssl_keylog_file; | 219 LOG(ERROR) << "Failed to open " << ssl_keylog_file; |
212 ERR_print_errors_cb(&LogErrorCallback, NULL); | 220 ERR_print_errors_cb(&LogErrorCallback, NULL); |
213 } else { | 221 } else { |
214 SSL_CTX_set_keylog_bio(ssl_ctx_.get(), bio); | 222 SSL_CTX_set_keylog_bio(ssl_ctx_.get(), bio); |
215 } | 223 } |
216 } | 224 } |
217 } | 225 } |
218 | 226 |
219 static std::string GetSessionCacheKey(const SSL* ssl) { | |
220 SSLClientSocketOpenSSL* socket = GetInstance()->GetClientSocketFromSSL(ssl); | |
221 DCHECK(socket); | |
222 return socket->GetSessionCacheKey(); | |
223 } | |
224 | |
225 static SSLSessionCacheOpenSSL::Config kDefaultSessionCacheConfig; | |
226 | |
227 static int ClientCertRequestCallback(SSL* ssl, void* arg) { | 227 static int ClientCertRequestCallback(SSL* ssl, void* arg) { |
228 SSLClientSocketOpenSSL* socket = GetInstance()->GetClientSocketFromSSL(ssl); | 228 SSLClientSocketOpenSSL* socket = GetInstance()->GetClientSocketFromSSL(ssl); |
229 DCHECK(socket); | 229 DCHECK(socket); |
230 return socket->ClientCertRequestCallback(ssl); | 230 return socket->ClientCertRequestCallback(ssl); |
231 } | 231 } |
232 | 232 |
233 static int CertVerifyCallback(X509_STORE_CTX *store_ctx, void *arg) { | 233 static int CertVerifyCallback(X509_STORE_CTX *store_ctx, void *arg) { |
234 SSL* ssl = reinterpret_cast<SSL*>(X509_STORE_CTX_get_ex_data( | 234 SSL* ssl = reinterpret_cast<SSL*>(X509_STORE_CTX_get_ex_data( |
235 store_ctx, SSL_get_ex_data_X509_STORE_CTX_idx())); | 235 store_ctx, SSL_get_ex_data_X509_STORE_CTX_idx())); |
236 SSLClientSocketOpenSSL* socket = GetInstance()->GetClientSocketFromSSL(ssl); | 236 SSLClientSocketOpenSSL* socket = GetInstance()->GetClientSocketFromSSL(ssl); |
237 CHECK(socket); | 237 CHECK(socket); |
238 | 238 |
239 return socket->CertVerifyCallback(store_ctx); | 239 return socket->CertVerifyCallback(store_ctx); |
240 } | 240 } |
241 | 241 |
242 static int SelectNextProtoCallback(SSL* ssl, | 242 static int SelectNextProtoCallback(SSL* ssl, |
243 unsigned char** out, unsigned char* outlen, | 243 unsigned char** out, unsigned char* outlen, |
244 const unsigned char* in, | 244 const unsigned char* in, |
245 unsigned int inlen, void* arg) { | 245 unsigned int inlen, void* arg) { |
246 SSLClientSocketOpenSSL* socket = GetInstance()->GetClientSocketFromSSL(ssl); | 246 SSLClientSocketOpenSSL* socket = GetInstance()->GetClientSocketFromSSL(ssl); |
247 return socket->SelectNextProtoCallback(out, outlen, in, inlen); | 247 return socket->SelectNextProtoCallback(out, outlen, in, inlen); |
248 } | 248 } |
249 | 249 |
250 // This is the index used with SSL_get_ex_data to retrieve the owner | 250 // This is the index used with SSL_get_ex_data to retrieve the owner |
251 // SSLClientSocketOpenSSL object from an SSL instance. | 251 // SSLClientSocketOpenSSL object from an SSL instance. |
252 int ssl_socket_data_index_; | 252 int ssl_socket_data_index_; |
253 | 253 |
254 ScopedSSL_CTX ssl_ctx_; | 254 ScopedSSL_CTX ssl_ctx_; |
255 // |session_cache_| must be destroyed before |ssl_ctx_|. | 255 |
256 SSLSessionCacheOpenSSL session_cache_; | 256 // TODO(davidben): Use a separate cache per URLRequestContext. |
257 // https://crbug.com/458365 | |
258 // | |
259 // TODO(davidben): Sessions should be invalidated on fatal | |
260 // alerts. https://crbug.com/466352 | |
261 SSLClientSessionCacheOpenSSL session_cache_; | |
257 }; | 262 }; |
258 | 263 |
259 // PeerCertificateChain is a helper object which extracts the certificate | 264 // PeerCertificateChain is a helper object which extracts the certificate |
260 // chain, as given by the server, from an OpenSSL socket and performs the needed | 265 // chain, as given by the server, from an OpenSSL socket and performs the needed |
261 // resource management. The first element of the chain is the leaf certificate | 266 // resource management. The first element of the chain is the leaf certificate |
262 // and the other elements are in the order given by the server. | 267 // and the other elements are in the order given by the server. |
263 class SSLClientSocketOpenSSL::PeerCertificateChain { | 268 class SSLClientSocketOpenSSL::PeerCertificateChain { |
264 public: | 269 public: |
265 explicit PeerCertificateChain(STACK_OF(X509)* chain) { Reset(chain); } | 270 explicit PeerCertificateChain(STACK_OF(X509)* chain) { Reset(chain); } |
266 PeerCertificateChain(const PeerCertificateChain& other) { *this = other; } | 271 PeerCertificateChain(const PeerCertificateChain& other) { *this = other; } |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
331 if (!x509_util::GetDER(x, &der)) | 336 if (!x509_util::GetDER(x, &der)) |
332 return NULL; | 337 return NULL; |
333 der_chain.push_back(der); | 338 der_chain.push_back(der); |
334 } | 339 } |
335 | 340 |
336 return make_scoped_refptr(X509Certificate::CreateFromDERCertChain(der_chain)); | 341 return make_scoped_refptr(X509Certificate::CreateFromDERCertChain(der_chain)); |
337 #endif | 342 #endif |
338 } | 343 } |
339 | 344 |
340 // static | 345 // static |
341 SSLSessionCacheOpenSSL::Config | |
342 SSLClientSocketOpenSSL::SSLContext::kDefaultSessionCacheConfig = { | |
343 &GetSessionCacheKey, // key_func | |
344 1024, // max_entries | |
345 256, // expiration_check_count | |
346 60 * 60, // timeout_seconds | |
347 }; | |
348 | |
349 // static | |
350 void SSLClientSocket::ClearSessionCache() { | 346 void SSLClientSocket::ClearSessionCache() { |
351 SSLClientSocketOpenSSL::SSLContext* context = | 347 SSLClientSocketOpenSSL::SSLContext* context = |
352 SSLClientSocketOpenSSL::SSLContext::GetInstance(); | 348 SSLClientSocketOpenSSL::SSLContext::GetInstance(); |
353 context->session_cache()->Flush(); | 349 context->session_cache()->Flush(); |
354 } | 350 } |
355 | 351 |
356 // static | 352 // static |
357 uint16 SSLClientSocket::GetMaxSupportedSSLVersion() { | 353 uint16 SSLClientSocket::GetMaxSupportedSSLVersion() { |
358 return SSL_PROTOCOL_VERSION_TLS1_2; | 354 return SSL_PROTOCOL_VERSION_TLS1_2; |
359 } | 355 } |
(...skipping 20 matching lines...) Expand all Loading... | |
380 transport_bio_(NULL), | 376 transport_bio_(NULL), |
381 transport_(transport_socket.Pass()), | 377 transport_(transport_socket.Pass()), |
382 host_and_port_(host_and_port), | 378 host_and_port_(host_and_port), |
383 ssl_config_(ssl_config), | 379 ssl_config_(ssl_config), |
384 ssl_session_cache_shard_(context.ssl_session_cache_shard), | 380 ssl_session_cache_shard_(context.ssl_session_cache_shard), |
385 trying_cached_session_(false), | 381 trying_cached_session_(false), |
386 next_handshake_state_(STATE_NONE), | 382 next_handshake_state_(STATE_NONE), |
387 npn_status_(kNextProtoUnsupported), | 383 npn_status_(kNextProtoUnsupported), |
388 channel_id_xtn_negotiated_(false), | 384 channel_id_xtn_negotiated_(false), |
389 handshake_succeeded_(false), | 385 handshake_succeeded_(false), |
390 marked_session_as_good_(false), | 386 certificate_verified_(false), |
391 transport_security_state_(context.transport_security_state), | 387 transport_security_state_(context.transport_security_state), |
392 policy_enforcer_(context.cert_policy_enforcer), | 388 policy_enforcer_(context.cert_policy_enforcer), |
393 net_log_(transport_->socket()->NetLog()), | 389 net_log_(transport_->socket()->NetLog()), |
394 weak_factory_(this) { | 390 weak_factory_(this) { |
395 } | 391 } |
396 | 392 |
397 SSLClientSocketOpenSSL::~SSLClientSocketOpenSSL() { | 393 SSLClientSocketOpenSSL::~SSLClientSocketOpenSSL() { |
398 Disconnect(); | 394 Disconnect(); |
399 } | 395 } |
400 | 396 |
(...skipping 21 matching lines...) Expand all Loading... | |
422 default: | 418 default: |
423 NOTREACHED(); | 419 NOTREACHED(); |
424 } | 420 } |
425 | 421 |
426 return result; | 422 return result; |
427 } | 423 } |
428 | 424 |
429 bool SSLClientSocketOpenSSL::InSessionCache() const { | 425 bool SSLClientSocketOpenSSL::InSessionCache() const { |
430 SSLContext* context = SSLContext::GetInstance(); | 426 SSLContext* context = SSLContext::GetInstance(); |
431 std::string cache_key = GetSessionCacheKey(); | 427 std::string cache_key = GetSessionCacheKey(); |
432 return context->session_cache()->SSLSessionIsInCache(cache_key); | 428 return context->session_cache()->Lookup(cache_key) != nullptr; |
433 } | 429 } |
434 | 430 |
435 void SSLClientSocketOpenSSL::SetHandshakeCompletionCallback( | 431 void SSLClientSocketOpenSSL::SetHandshakeCompletionCallback( |
436 const base::Closure& callback) { | 432 const base::Closure& callback) { |
437 handshake_completion_callback_ = callback; | 433 handshake_completion_callback_ = callback; |
438 } | 434 } |
439 | 435 |
440 void SSLClientSocketOpenSSL::GetSSLCertRequestInfo( | 436 void SSLClientSocketOpenSSL::GetSSLCertRequestInfo( |
441 SSLCertRequestInfo* cert_request_info) { | 437 SSLCertRequestInfo* cert_request_info) { |
442 cert_request_info->host_and_port = host_and_port_; | 438 cert_request_info->host_and_port = host_and_port_; |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
752 ssl_ = SSL_new(context->ssl_ctx()); | 748 ssl_ = SSL_new(context->ssl_ctx()); |
753 if (!ssl_ || !context->SetClientSocketForSSL(ssl_, this)) | 749 if (!ssl_ || !context->SetClientSocketForSSL(ssl_, this)) |
754 return ERR_UNEXPECTED; | 750 return ERR_UNEXPECTED; |
755 | 751 |
756 if (!SSL_set_tlsext_host_name(ssl_, host_and_port_.host().c_str())) | 752 if (!SSL_set_tlsext_host_name(ssl_, host_and_port_.host().c_str())) |
757 return ERR_UNEXPECTED; | 753 return ERR_UNEXPECTED; |
758 | 754 |
759 // Set an OpenSSL callback to monitor this SSL*'s connection. | 755 // Set an OpenSSL callback to monitor this SSL*'s connection. |
760 SSL_set_info_callback(ssl_, &InfoCallback); | 756 SSL_set_info_callback(ssl_, &InfoCallback); |
761 | 757 |
762 trying_cached_session_ = context->session_cache()->SetSSLSessionWithKey( | 758 SSL_SESSION* session = context->session_cache()->Lookup(GetSessionCacheKey()); |
763 ssl_, GetSessionCacheKey()); | 759 if (session != nullptr) { |
760 SSL_set_session(ssl_, session); | |
761 trying_cached_session_ = true; | |
762 } | |
764 | 763 |
765 send_buffer_ = new GrowableIOBuffer(); | 764 send_buffer_ = new GrowableIOBuffer(); |
766 send_buffer_->SetCapacity(KDefaultOpenSSLBufferSize); | 765 send_buffer_->SetCapacity(KDefaultOpenSSLBufferSize); |
767 recv_buffer_ = new GrowableIOBuffer(); | 766 recv_buffer_ = new GrowableIOBuffer(); |
768 recv_buffer_->SetCapacity(KDefaultOpenSSLBufferSize); | 767 recv_buffer_->SetCapacity(KDefaultOpenSSLBufferSize); |
769 | 768 |
770 BIO* ssl_bio = NULL; | 769 BIO* ssl_bio = NULL; |
771 | 770 |
772 // SSLClientSocketOpenSSL retains ownership of the BIO buffers. | 771 // SSLClientSocketOpenSSL retains ownership of the BIO buffers. |
773 if (!BIO_new_bio_pair_external_buf( | 772 if (!BIO_new_bio_pair_external_buf( |
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1249 server_cert_verify_result_.public_key_hashes, | 1248 server_cert_verify_result_.public_key_hashes, |
1250 &pinning_failure_log_)) { | 1249 &pinning_failure_log_)) { |
1251 result = ERR_SSL_PINNED_KEY_NOT_IN_CERT_CHAIN; | 1250 result = ERR_SSL_PINNED_KEY_NOT_IN_CERT_CHAIN; |
1252 } | 1251 } |
1253 | 1252 |
1254 if (result == OK) { | 1253 if (result == OK) { |
1255 // Only check Certificate Transparency if there were no other errors with | 1254 // Only check Certificate Transparency if there were no other errors with |
1256 // the connection. | 1255 // the connection. |
1257 VerifyCT(); | 1256 VerifyCT(); |
1258 | 1257 |
1259 // TODO(joth): Work out if we need to remember the intermediate CA certs | 1258 DCHECK(!certificate_verified_); |
1260 // when the server sends them to us, and do so here. | 1259 certificate_verified_ = true; |
1261 SSLContext::GetInstance()->session_cache()->MarkSSLSessionAsGood(ssl_); | |
1262 marked_session_as_good_ = true; | |
1263 CheckIfHandshakeFinished(); | 1260 CheckIfHandshakeFinished(); |
1264 } else { | 1261 } else { |
1265 DVLOG(1) << "DoVerifyCertComplete error " << ErrorToString(result) | 1262 DVLOG(1) << "DoVerifyCertComplete error " << ErrorToString(result) |
1266 << " (" << result << ")"; | 1263 << " (" << result << ")"; |
1267 } | 1264 } |
1268 | 1265 |
1269 completed_connect_ = true; | 1266 completed_connect_ = true; |
1270 | 1267 |
1271 // Exit DoHandshakeLoop and return the result to the caller to Connect. | 1268 // Exit DoHandshakeLoop and return the result to the caller to Connect. |
1272 DCHECK_EQ(STATE_NONE, next_handshake_state_); | 1269 DCHECK_EQ(STATE_NONE, next_handshake_state_); |
(...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1996 int type, | 1993 int type, |
1997 int /*val*/) { | 1994 int /*val*/) { |
1998 // TODO(vadimt): Remove ScopedTracker below once crbug.com/424386 is fixed. | 1995 // TODO(vadimt): Remove ScopedTracker below once crbug.com/424386 is fixed. |
1999 tracked_objects::ScopedTracker tracking_profile( | 1996 tracked_objects::ScopedTracker tracking_profile( |
2000 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 1997 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
2001 "424386 SSLClientSocketOpenSSL::InfoCallback")); | 1998 "424386 SSLClientSocketOpenSSL::InfoCallback")); |
2002 | 1999 |
2003 if (type == SSL_CB_HANDSHAKE_DONE) { | 2000 if (type == SSL_CB_HANDSHAKE_DONE) { |
2004 SSLClientSocketOpenSSL* ssl_socket = | 2001 SSLClientSocketOpenSSL* ssl_socket = |
2005 SSLContext::GetInstance()->GetClientSocketFromSSL(ssl); | 2002 SSLContext::GetInstance()->GetClientSocketFromSSL(ssl); |
2006 ssl_socket->handshake_succeeded_ = true; | 2003 if (!ssl_socket->handshake_succeeded_) { |
2007 ssl_socket->CheckIfHandshakeFinished(); | 2004 ssl_socket->handshake_succeeded_ = true; |
2005 ssl_socket->CheckIfHandshakeFinished(); | |
2006 } | |
2008 } | 2007 } |
2009 } | 2008 } |
2010 | 2009 |
2011 // Determines if both the handshake and certificate verification have completed | 2010 // Determines if both the handshake and certificate verification have completed |
2012 // successfully, and calls the handshake completion callback if that is the | 2011 // successfully, and calls the handshake completion callback if that is the |
2013 // case. | 2012 // case. |
2014 // | 2013 // |
2015 // CheckIfHandshakeFinished is called twice per connection: once after | 2014 // CheckIfHandshakeFinished is called twice per connection: once after |
2016 // MarkSSLSessionAsGood, when the certificate has been verified, and | 2015 // MarkSSLSessionAsGood, when the certificate has been verified, and |
2017 // once via an OpenSSL callback when the handshake has completed. On the | 2016 // once via an OpenSSL callback when the handshake has completed. On the |
2018 // second call, when the certificate has been verified and the handshake | 2017 // second call, when the certificate has been verified and the handshake |
2019 // has completed, the connection's handshake completion callback is run. | 2018 // has completed, the connection's handshake completion callback is run. |
2020 void SSLClientSocketOpenSSL::CheckIfHandshakeFinished() { | 2019 void SSLClientSocketOpenSSL::CheckIfHandshakeFinished() { |
2021 if (handshake_succeeded_ && marked_session_as_good_) | 2020 if (handshake_succeeded_ && certificate_verified_) { |
2021 if (!SSL_session_reused(ssl_)) { | |
Ryan Sleevi
2015/03/17 00:50:33
Why is this check needed? Isn't it a nop if it exi
davidben
2015/03/20 22:41:26
I guess it's not strictly needed? MRU is updated o
| |
2022 // Only insert the session into the session cache once both the handshake | |
2023 // has completed and the certificate has been verified. | |
2024 SSLContext::GetInstance()->session_cache()->Insert(GetSessionCacheKey(), | |
2025 SSL_get_session(ssl_)); | |
2026 } | |
2022 OnHandshakeCompletion(); | 2027 OnHandshakeCompletion(); |
2028 } | |
2023 } | 2029 } |
2024 | 2030 |
2025 void SSLClientSocketOpenSSL::AddSCTInfoToSSLInfo(SSLInfo* ssl_info) const { | 2031 void SSLClientSocketOpenSSL::AddSCTInfoToSSLInfo(SSLInfo* ssl_info) const { |
2026 for (ct::SCTList::const_iterator iter = | 2032 for (ct::SCTList::const_iterator iter = |
2027 ct_verify_result_.verified_scts.begin(); | 2033 ct_verify_result_.verified_scts.begin(); |
2028 iter != ct_verify_result_.verified_scts.end(); ++iter) { | 2034 iter != ct_verify_result_.verified_scts.end(); ++iter) { |
2029 ssl_info->signed_certificate_timestamps.push_back( | 2035 ssl_info->signed_certificate_timestamps.push_back( |
2030 SignedCertificateTimestampAndStatus(*iter, ct::SCT_STATUS_OK)); | 2036 SignedCertificateTimestampAndStatus(*iter, ct::SCT_STATUS_OK)); |
2031 } | 2037 } |
2032 for (ct::SCTList::const_iterator iter = | 2038 for (ct::SCTList::const_iterator iter = |
(...skipping 10 matching lines...) Expand all Loading... | |
2043 ct::SCT_STATUS_LOG_UNKNOWN)); | 2049 ct::SCT_STATUS_LOG_UNKNOWN)); |
2044 } | 2050 } |
2045 } | 2051 } |
2046 | 2052 |
2047 scoped_refptr<X509Certificate> | 2053 scoped_refptr<X509Certificate> |
2048 SSLClientSocketOpenSSL::GetUnverifiedServerCertificateChain() const { | 2054 SSLClientSocketOpenSSL::GetUnverifiedServerCertificateChain() const { |
2049 return server_cert_; | 2055 return server_cert_; |
2050 } | 2056 } |
2051 | 2057 |
2052 } // namespace net | 2058 } // namespace net |
OLD | NEW |