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/ssl/ssl_config_service.h" | 5 #include "net/ssl/ssl_config_service.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "base/memory/ref_counted.h" | |
9 #include "base/synchronization/lock.h" | 8 #include "base/synchronization/lock.h" |
10 #include "net/cert/crl_set.h" | |
11 #include "net/ssl/ssl_config_service_defaults.h" | 9 #include "net/ssl/ssl_config_service_defaults.h" |
12 | 10 |
13 #if defined(USE_OPENSSL) | |
14 #include <openssl/ssl.h> | |
15 #endif | |
16 | |
17 namespace net { | 11 namespace net { |
18 | 12 |
19 static uint16 g_default_version_min = SSL_PROTOCOL_VERSION_SSL3; | |
20 | |
21 static uint16 g_default_version_max = | |
22 #if defined(USE_OPENSSL) | |
23 #if defined(SSL_OP_NO_TLSv1_2) | |
24 SSL_PROTOCOL_VERSION_TLS1_2; | |
25 #elif defined(SSL_OP_NO_TLSv1_1) | |
26 SSL_PROTOCOL_VERSION_TLS1_1; | |
27 #else | |
28 SSL_PROTOCOL_VERSION_TLS1; | |
29 #endif | |
30 #else | |
31 SSL_PROTOCOL_VERSION_TLS1_2; | |
32 #endif | |
33 | |
34 SSLConfig::CertAndStatus::CertAndStatus() : cert_status(0) {} | |
35 | |
36 SSLConfig::CertAndStatus::~CertAndStatus() {} | |
37 | |
38 SSLConfig::SSLConfig() | |
39 : rev_checking_enabled(false), | |
40 rev_checking_required_local_anchors(false), | |
41 version_min(g_default_version_min), | |
42 version_max(g_default_version_max), | |
43 channel_id_enabled(true), | |
44 false_start_enabled(true), | |
45 signed_cert_timestamps_enabled(true), | |
46 require_forward_secrecy(false), | |
47 send_client_cert(false), | |
48 verify_ev_cert(false), | |
49 version_fallback(false), | |
50 cert_io_enabled(true) { | |
51 } | |
52 | |
53 SSLConfig::~SSLConfig() { | |
54 } | |
55 | |
56 bool SSLConfig::IsAllowedBadCert(X509Certificate* cert, | |
57 CertStatus* cert_status) const { | |
58 std::string der_cert; | |
59 if (!X509Certificate::GetDEREncoded(cert->os_cert_handle(), &der_cert)) | |
60 return false; | |
61 return IsAllowedBadCert(der_cert, cert_status); | |
62 } | |
63 | |
64 bool SSLConfig::IsAllowedBadCert(const base::StringPiece& der_cert, | |
65 CertStatus* cert_status) const { | |
66 for (size_t i = 0; i < allowed_bad_certs.size(); ++i) { | |
67 if (der_cert == allowed_bad_certs[i].der_cert) { | |
68 if (cert_status) | |
69 *cert_status = allowed_bad_certs[i].cert_status; | |
70 return true; | |
71 } | |
72 } | |
73 return false; | |
74 } | |
75 | |
76 SSLConfigService::SSLConfigService() | 13 SSLConfigService::SSLConfigService() |
77 : observer_list_(ObserverList<Observer>::NOTIFY_EXISTING_ONLY) { | 14 : observer_list_(ObserverList<Observer>::NOTIFY_EXISTING_ONLY) { |
78 } | 15 } |
79 | 16 |
80 // GlobalCRLSet holds a reference to the global CRLSet. It simply wraps a lock | 17 // GlobalCRLSet holds a reference to the global CRLSet. It simply wraps a lock |
81 // around a scoped_refptr so that getting a reference doesn't race with | 18 // around a scoped_refptr so that getting a reference doesn't race with |
82 // updating the CRLSet. | 19 // updating the CRLSet. |
83 class GlobalCRLSet { | 20 class GlobalCRLSet { |
84 public: | 21 public: |
85 void Set(const scoped_refptr<CRLSet>& new_crl_set) { | 22 void Set(const scoped_refptr<CRLSet>& new_crl_set) { |
(...skipping 17 matching lines...) Expand all Loading... |
103 void SSLConfigService::SetCRLSet(scoped_refptr<CRLSet> crl_set) { | 40 void SSLConfigService::SetCRLSet(scoped_refptr<CRLSet> crl_set) { |
104 // Note: this can be called concurently with GetCRLSet(). | 41 // Note: this can be called concurently with GetCRLSet(). |
105 g_crl_set.Get().Set(crl_set); | 42 g_crl_set.Get().Set(crl_set); |
106 } | 43 } |
107 | 44 |
108 // static | 45 // static |
109 scoped_refptr<CRLSet> SSLConfigService::GetCRLSet() { | 46 scoped_refptr<CRLSet> SSLConfigService::GetCRLSet() { |
110 return g_crl_set.Get().Get(); | 47 return g_crl_set.Get().Get(); |
111 } | 48 } |
112 | 49 |
113 // static | |
114 uint16 SSLConfigService::default_version_min() { | |
115 return g_default_version_min; | |
116 } | |
117 | |
118 // static | |
119 uint16 SSLConfigService::default_version_max() { | |
120 return g_default_version_max; | |
121 } | |
122 | |
123 void SSLConfigService::AddObserver(Observer* observer) { | 50 void SSLConfigService::AddObserver(Observer* observer) { |
124 observer_list_.AddObserver(observer); | 51 observer_list_.AddObserver(observer); |
125 } | 52 } |
126 | 53 |
127 void SSLConfigService::RemoveObserver(Observer* observer) { | 54 void SSLConfigService::RemoveObserver(Observer* observer) { |
128 observer_list_.RemoveObserver(observer); | 55 observer_list_.RemoveObserver(observer); |
129 } | 56 } |
130 | 57 |
131 void SSLConfigService::NotifySSLConfigChange() { | 58 void SSLConfigService::NotifySSLConfigChange() { |
132 FOR_EACH_OBSERVER(Observer, observer_list_, OnSSLConfigChanged()); | 59 FOR_EACH_OBSERVER(Observer, observer_list_, OnSSLConfigChanged()); |
(...skipping 25 matching lines...) Expand all Loading... |
158 bool SSLConfigService::IsSNIAvailable(SSLConfigService* service) { | 85 bool SSLConfigService::IsSNIAvailable(SSLConfigService* service) { |
159 if (!service) | 86 if (!service) |
160 return false; | 87 return false; |
161 | 88 |
162 SSLConfig ssl_config; | 89 SSLConfig ssl_config; |
163 service->GetSSLConfig(&ssl_config); | 90 service->GetSSLConfig(&ssl_config); |
164 return ssl_config.version_max >= SSL_PROTOCOL_VERSION_TLS1; | 91 return ssl_config.version_max >= SSL_PROTOCOL_VERSION_TLS1; |
165 } | 92 } |
166 | 93 |
167 } // namespace net | 94 } // namespace net |
OLD | NEW |