| 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" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 38 #include "net/url_request/url_request_context.h" | 39 #include "net/url_request/url_request_context.h" |
| 39 | 40 |
| 40 namespace net { | 41 namespace net { |
| 41 | 42 |
| 42 namespace { | 43 namespace { |
| 43 | 44 |
| 44 // Protects |g_request_context|. | 45 // Protects |g_request_context|. |
| 45 pthread_mutex_t g_request_context_lock = PTHREAD_MUTEX_INITIALIZER; | 46 pthread_mutex_t g_request_context_lock = PTHREAD_MUTEX_INITIALIZER; |
| 46 URLRequestContext* g_request_context = NULL; | 47 URLRequestContext* g_request_context = NULL; |
| 47 | 48 |
| 49 // The default timeout for network fetches in NSS is 60 seconds. Choose a |
| 50 // saner upper limit for OCSP/CRL/AIA fetches. |
| 51 const int kNetworkFetchTimeoutInSecs = 15; |
| 52 |
| 48 class OCSPRequestSession; | 53 class OCSPRequestSession; |
| 49 | 54 |
| 50 class OCSPIOLoop { | 55 class OCSPIOLoop { |
| 51 public: | 56 public: |
| 52 void StartUsing() { | 57 void StartUsing() { |
| 53 base::AutoLock autolock(lock_); | 58 base::AutoLock autolock(lock_); |
| 54 used_ = true; | 59 used_ = true; |
| 55 io_loop_ = MessageLoopForIO::current(); | 60 io_loop_ = MessageLoopForIO::current(); |
| 56 DCHECK(io_loop_); | 61 DCHECK(io_loop_); |
| 57 } | 62 } |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 return NULL; | 440 return NULL; |
| 436 } | 441 } |
| 437 | 442 |
| 438 std::string url_string(base::StringPrintf( | 443 std::string url_string(base::StringPrintf( |
| 439 "%s://%s%s", | 444 "%s://%s%s", |
| 440 http_protocol_variant, | 445 http_protocol_variant, |
| 441 host_and_port_.ToString().c_str(), | 446 host_and_port_.ToString().c_str(), |
| 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 HostPortPair host_and_port_; | 462 HostPortPair host_and_port_; |
| 453 | 463 |
| 454 DISALLOW_COPY_AND_ASSIGN(OCSPServerSession); | 464 DISALLOW_COPY_AND_ASSIGN(OCSPServerSession); |
| 455 }; | 465 }; |
| 456 | 466 |
| 457 OCSPIOLoop::OCSPIOLoop() | 467 OCSPIOLoop::OCSPIOLoop() |
| (...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 928 void SetURLRequestContextForNSSHttpIO(URLRequestContext* request_context) { | 938 void SetURLRequestContextForNSSHttpIO(URLRequestContext* request_context) { |
| 929 pthread_mutex_lock(&g_request_context_lock); | 939 pthread_mutex_lock(&g_request_context_lock); |
| 930 if (request_context) { | 940 if (request_context) { |
| 931 DCHECK(!g_request_context); | 941 DCHECK(!g_request_context); |
| 932 } | 942 } |
| 933 g_request_context = request_context; | 943 g_request_context = request_context; |
| 934 pthread_mutex_unlock(&g_request_context_lock); | 944 pthread_mutex_unlock(&g_request_context_lock); |
| 935 } | 945 } |
| 936 | 946 |
| 937 } // namespace net | 947 } // namespace net |
| OLD | NEW |