| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_session_cache_openssl.h" | 5 #include "net/socket/ssl_session_cache_openssl.h" |
| 6 | 6 |
| 7 #include <list> | 7 #include <list> |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include <openssl/rand.h> | 10 #include <openssl/rand.h> |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 return false; // Session has not yet been marked good. Treat as a miss. | 229 return false; // Session has not yet been marked good. Treat as a miss. |
| 230 | 230 |
| 231 // Move to front of MRU list. | 231 // Move to front of MRU list. |
| 232 ordering_.push_front(session); | 232 ordering_.push_front(session); |
| 233 ordering_.erase(it->second); | 233 ordering_.erase(it->second); |
| 234 it->second = ordering_.begin(); | 234 it->second = ordering_.begin(); |
| 235 | 235 |
| 236 return SSL_set_session(ssl, session) == 1; | 236 return SSL_set_session(ssl, session) == 1; |
| 237 } | 237 } |
| 238 | 238 |
| 239 bool SSLSessionIsInCache(const std::string& cache_key) const { |
| 240 base::AutoLock locked(lock_); |
| 241 KeyIndex::const_iterator it = key_index_.find(cache_key); |
| 242 if (it == key_index_.end()) |
| 243 return false; |
| 244 return true; |
| 245 } |
| 246 |
| 239 void MarkSSLSessionAsGood(SSL* ssl) { | 247 void MarkSSLSessionAsGood(SSL* ssl) { |
| 240 SSL_SESSION* session = SSL_get_session(ssl); | 248 SSL_SESSION* session = SSL_get_session(ssl); |
| 241 if (!session) | 249 if (!session) |
| 242 return; | 250 return; |
| 243 | 251 |
| 244 // Mark the session as good, allowing it to be used for future connections. | 252 // Mark the session as good, allowing it to be used for future connections. |
| 245 SSL_SESSION_set_ex_data( | 253 SSL_SESSION_set_ex_data( |
| 246 session, GetSSLSessionExIndex(), reinterpret_cast<void*>(1)); | 254 session, GetSSLSessionExIndex(), reinterpret_cast<void*>(1)); |
| 247 } | 255 } |
| 248 | 256 |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 DLOG(ERROR) << "Couldn't generate unique session ID of " << id_len | 470 DLOG(ERROR) << "Couldn't generate unique session ID of " << id_len |
| 463 << "bytes after " << kMaxTries << " tries."; | 471 << "bytes after " << kMaxTries << " tries."; |
| 464 return false; | 472 return false; |
| 465 } | 473 } |
| 466 | 474 |
| 467 SSL_CTX* ctx_; | 475 SSL_CTX* ctx_; |
| 468 SSLSessionCacheOpenSSL::Config config_; | 476 SSLSessionCacheOpenSSL::Config config_; |
| 469 | 477 |
| 470 // method to get the index which can later be used with SSL_CTX_get_ex_data() | 478 // method to get the index which can later be used with SSL_CTX_get_ex_data() |
| 471 // or SSL_CTX_set_ex_data(). | 479 // or SSL_CTX_set_ex_data(). |
| 472 base::Lock lock_; // Protects access to containers below. | 480 mutable base::Lock lock_; // Protects access to containers below. |
| 473 | 481 |
| 474 MRUSessionList ordering_; | 482 MRUSessionList ordering_; |
| 475 KeyIndex key_index_; | 483 KeyIndex key_index_; |
| 476 SessionIdIndex id_index_; | 484 SessionIdIndex id_index_; |
| 477 | 485 |
| 478 size_t expiration_check_; | 486 size_t expiration_check_; |
| 479 }; | 487 }; |
| 480 | 488 |
| 481 SSLSessionCacheOpenSSL::~SSLSessionCacheOpenSSL() { delete impl_; } | 489 SSLSessionCacheOpenSSL::~SSLSessionCacheOpenSSL() { delete impl_; } |
| 482 | 490 |
| 483 size_t SSLSessionCacheOpenSSL::size() const { return impl_->size(); } | 491 size_t SSLSessionCacheOpenSSL::size() const { return impl_->size(); } |
| 484 | 492 |
| 485 void SSLSessionCacheOpenSSL::Reset(SSL_CTX* ctx, const Config& config) { | 493 void SSLSessionCacheOpenSSL::Reset(SSL_CTX* ctx, const Config& config) { |
| 486 if (impl_) | 494 if (impl_) |
| 487 delete impl_; | 495 delete impl_; |
| 488 | 496 |
| 489 impl_ = new SSLSessionCacheOpenSSLImpl(ctx, config); | 497 impl_ = new SSLSessionCacheOpenSSLImpl(ctx, config); |
| 490 } | 498 } |
| 491 | 499 |
| 492 bool SSLSessionCacheOpenSSL::SetSSLSession(SSL* ssl) { | 500 bool SSLSessionCacheOpenSSL::SetSSLSession(SSL* ssl) { |
| 493 return impl_->SetSSLSession(ssl); | 501 return impl_->SetSSLSession(ssl); |
| 494 } | 502 } |
| 495 | 503 |
| 496 bool SSLSessionCacheOpenSSL::SetSSLSessionWithKey( | 504 bool SSLSessionCacheOpenSSL::SetSSLSessionWithKey( |
| 497 SSL* ssl, | 505 SSL* ssl, |
| 498 const std::string& cache_key) { | 506 const std::string& cache_key) { |
| 499 return impl_->SetSSLSessionWithKey(ssl, cache_key); | 507 return impl_->SetSSLSessionWithKey(ssl, cache_key); |
| 500 } | 508 } |
| 501 | 509 |
| 510 bool SSLSessionCacheOpenSSL::SSLSessionIsInCache( |
| 511 const std::string& cache_key) const { |
| 512 return impl_->SSLSessionIsInCache(cache_key); |
| 513 } |
| 514 |
| 502 void SSLSessionCacheOpenSSL::MarkSSLSessionAsGood(SSL* ssl) { | 515 void SSLSessionCacheOpenSSL::MarkSSLSessionAsGood(SSL* ssl) { |
| 503 return impl_->MarkSSLSessionAsGood(ssl); | 516 return impl_->MarkSSLSessionAsGood(ssl); |
| 504 } | 517 } |
| 505 | 518 |
| 506 void SSLSessionCacheOpenSSL::Flush() { impl_->Flush(); } | 519 void SSLSessionCacheOpenSSL::Flush() { impl_->Flush(); } |
| 507 | 520 |
| 508 } // namespace net | 521 } // namespace net |
| OLD | NEW |