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/ocsp/nss_ocsp.h" | 5 #include "net/ocsp/nss_ocsp.h" |
| 6 | 6 |
| 7 #include <certt.h> | 7 #include <certt.h> |
| 8 #include <certdb.h> | 8 #include <certdb.h> |
| 9 #include <ocsp.h> | 9 #include <ocsp.h> |
| 10 #include <nspr.h> | 10 #include <nspr.h> |
| 11 #include <nss.h> | 11 #include <nss.h> |
| 12 #include <pthread.h> | 12 #include <pthread.h> |
| 13 #include <secerr.h> | 13 #include <secerr.h> |
| 14 | 14 |
| 15 #include <algorithm> | |
| 15 #include <string> | 16 #include <string> |
| 16 | 17 |
| 17 #include "base/basictypes.h" | 18 #include "base/basictypes.h" |
| 18 #include "base/callback.h" | 19 #include "base/callback.h" |
| 19 #include "base/compiler_specific.h" | 20 #include "base/compiler_specific.h" |
| 20 #include "base/lazy_instance.h" | 21 #include "base/lazy_instance.h" |
| 21 #include "base/logging.h" | 22 #include "base/logging.h" |
| 22 #include "base/message_loop.h" | 23 #include "base/message_loop.h" |
| 23 #include "base/metrics/histogram.h" | 24 #include "base/metrics/histogram.h" |
| 24 #include "base/stl_util.h" | 25 #include "base/stl_util.h" |
| 25 #include "base/string_util.h" | 26 #include "base/string_util.h" |
| 26 #include "base/stringprintf.h" | 27 #include "base/stringprintf.h" |
| 27 #include "base/synchronization/condition_variable.h" | 28 #include "base/synchronization/condition_variable.h" |
| 28 #include "base/synchronization/lock.h" | 29 #include "base/synchronization/lock.h" |
| 29 #include "base/threading/thread_checker.h" | 30 #include "base/threading/thread_checker.h" |
| 30 #include "base/time.h" | 31 #include "base/time.h" |
| 31 #include "googleurl/src/gurl.h" | 32 #include "googleurl/src/gurl.h" |
| 32 #include "net/base/io_buffer.h" | 33 #include "net/base/io_buffer.h" |
| 33 #include "net/base/load_flags.h" | 34 #include "net/base/load_flags.h" |
| 34 #include "net/http/http_request_headers.h" | 35 #include "net/http/http_request_headers.h" |
| 35 #include "net/http/http_response_headers.h" | 36 #include "net/http/http_response_headers.h" |
| 36 #include "net/url_request/url_request.h" | 37 #include "net/url_request/url_request.h" |
| 37 #include "net/url_request/url_request_context.h" | 38 #include "net/url_request/url_request_context.h" |
| 38 | 39 |
| 39 namespace { | 40 namespace { |
| 40 | 41 |
| 41 // Protects |g_request_context|. | 42 // Protects |g_request_context|. |
| 42 pthread_mutex_t g_request_context_lock = PTHREAD_MUTEX_INITIALIZER; | 43 pthread_mutex_t g_request_context_lock = PTHREAD_MUTEX_INITIALIZER; |
| 43 static net::URLRequestContext* g_request_context = NULL; | 44 net::URLRequestContext* g_request_context = NULL; |
| 45 | |
| 46 // The default timeout for network fetches in NSS is 60 seconds. Choose a | |
| 47 // saner upper limit for OCSP/CRL/AIA fetches. | |
|
wtc
2012/08/24 23:51:52
Nit: OCSP responder location is also listed in the
| |
| 48 const int kNetworkFetchTimeoutInSecs = 15; | |
| 44 | 49 |
| 45 class OCSPRequestSession; | 50 class OCSPRequestSession; |
| 46 | 51 |
| 47 class OCSPIOLoop { | 52 class OCSPIOLoop { |
| 48 public: | 53 public: |
| 49 void StartUsing() { | 54 void StartUsing() { |
| 50 base::AutoLock autolock(lock_); | 55 base::AutoLock autolock(lock_); |
| 51 used_ = true; | 56 used_ = true; |
| 52 io_loop_ = MessageLoopForIO::current(); | 57 io_loop_ = MessageLoopForIO::current(); |
| 53 DCHECK(io_loop_); | 58 DCHECK(io_loop_); |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 435 | 440 |
| 436 // TODO(ukai): If |host| is an IPv6 literal, we need to quote it with | 441 // TODO(ukai): If |host| is an IPv6 literal, we need to quote it with |
| 437 // square brackets []. | 442 // square brackets []. |
| 438 std::string url_string(base::StringPrintf("%s://%s:%d%s", | 443 std::string url_string(base::StringPrintf("%s://%s:%d%s", |
| 439 http_protocol_variant, | 444 http_protocol_variant, |
| 440 host_.c_str(), | 445 host_.c_str(), |
| 441 port_, | 446 port_, |
| 442 path_and_query_string)); | 447 path_and_query_string)); |
| 443 VLOG(1) << "URL [" << url_string << "]"; | 448 VLOG(1) << "URL [" << url_string << "]"; |
| 444 GURL url(url_string); | 449 GURL url(url_string); |
| 445 return new OCSPRequestSession( | 450 |
| 446 url, http_request_method, | 451 // NSS does not expose public functions to adjust the fetch timeout when |
| 452 // using libpkix, so hardcode the upper limit for network fetches. | |
| 453 base::TimeDelta actual_timeout = std::min( | |
| 454 base::TimeDelta::FromSeconds(kNetworkFetchTimeoutInSecs), | |
| 447 base::TimeDelta::FromMilliseconds(PR_IntervalToMilliseconds(timeout))); | 455 base::TimeDelta::FromMilliseconds(PR_IntervalToMilliseconds(timeout))); |
| 456 | |
| 457 return new OCSPRequestSession(url, http_request_method, actual_timeout); | |
| 448 } | 458 } |
| 449 | 459 |
| 450 | 460 |
| 451 private: | 461 private: |
| 452 std::string host_; | 462 std::string host_; |
| 453 int port_; | 463 int port_; |
| 454 | 464 |
| 455 DISALLOW_COPY_AND_ASSIGN(OCSPServerSession); | 465 DISALLOW_COPY_AND_ASSIGN(OCSPServerSession); |
| 456 }; | 466 }; |
| 457 | 467 |
| (...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 931 void SetURLRequestContextForNSSHttpIO(URLRequestContext* request_context) { | 941 void SetURLRequestContextForNSSHttpIO(URLRequestContext* request_context) { |
| 932 pthread_mutex_lock(&g_request_context_lock); | 942 pthread_mutex_lock(&g_request_context_lock); |
| 933 if (request_context) { | 943 if (request_context) { |
| 934 DCHECK(!g_request_context); | 944 DCHECK(!g_request_context); |
| 935 } | 945 } |
| 936 g_request_context = request_context; | 946 g_request_context = request_context; |
| 937 pthread_mutex_unlock(&g_request_context_lock); | 947 pthread_mutex_unlock(&g_request_context_lock); |
| 938 } | 948 } |
| 939 | 949 |
| 940 } // namespace net | 950 } // namespace net |
| OLD | NEW |