| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef NET_SSL_SSL_CONFIG_SERVICE_H_ | 5 #ifndef NET_SSL_SSL_CONFIG_H_ |
| 6 #define NET_SSL_SSL_CONFIG_SERVICE_H_ | 6 #define NET_SSL_SSL_CONFIG_H_ |
| 7 | |
| 8 #include <vector> | |
| 9 | 7 |
| 10 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 11 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 12 #include "base/observer_list.h" | |
| 13 #include "base/strings/string_piece.h" | |
| 14 #include "net/base/net_export.h" | 10 #include "net/base/net_export.h" |
| 15 #include "net/cert/cert_status_flags.h" | |
| 16 #include "net/cert/crl_set.h" | |
| 17 #include "net/cert/x509_certificate.h" | 11 #include "net/cert/x509_certificate.h" |
| 18 | 12 |
| 19 namespace net { | 13 namespace net { |
| 20 | 14 |
| 21 // Various TLS/SSL ProtocolVersion values encoded as uint16 | 15 // Various TLS/SSL ProtocolVersion values encoded as uint16 |
| 22 // struct { | 16 // struct { |
| 23 // uint8 major; | 17 // uint8 major; |
| 24 // uint8 minor; | 18 // uint8 minor; |
| 25 // } ProtocolVersion; | 19 // } ProtocolVersion; |
| 26 // The most significant byte is |major|, and the least significant byte | 20 // The most significant byte is |major|, and the least significant byte |
| 27 // is |minor|. | 21 // is |minor|. |
| 28 enum { | 22 enum { |
| 29 SSL_PROTOCOL_VERSION_SSL3 = 0x0300, | 23 SSL_PROTOCOL_VERSION_SSL3 = 0x0300, |
| 30 SSL_PROTOCOL_VERSION_TLS1 = 0x0301, | 24 SSL_PROTOCOL_VERSION_TLS1 = 0x0301, |
| 31 SSL_PROTOCOL_VERSION_TLS1_1 = 0x0302, | 25 SSL_PROTOCOL_VERSION_TLS1_1 = 0x0302, |
| 32 SSL_PROTOCOL_VERSION_TLS1_2 = 0x0303, | 26 SSL_PROTOCOL_VERSION_TLS1_2 = 0x0303, |
| 33 }; | 27 }; |
| 34 | 28 |
| 29 // Default minimum protocol version. |
| 30 NET_EXPORT extern const uint16 kDefaultSSLVersionMin; |
| 31 |
| 32 // Default maximum protocol version. |
| 33 NET_EXPORT extern const uint16 kDefaultSSLVersionMax; |
| 34 |
| 35 // A collection of SSL-related configuration settings. | 35 // A collection of SSL-related configuration settings. |
| 36 struct NET_EXPORT SSLConfig { | 36 struct NET_EXPORT SSLConfig { |
| 37 // Default to revocation checking. | 37 // Default to revocation checking. |
| 38 // Default to SSL 3.0 ~ default_version_max() on. | 38 // Default to SSL 3.0 ~ default_version_max() on. |
| 39 SSLConfig(); | 39 SSLConfig(); |
| 40 ~SSLConfig(); | 40 ~SSLConfig(); |
| 41 | 41 |
| 42 // Returns true if |cert| is one of the certs in |allowed_bad_certs|. | 42 // Returns true if |cert| is one of the certs in |allowed_bad_certs|. |
| 43 // The expected cert status is written to |cert_status|. |*cert_status| can | 43 // The expected cert status is written to |cert_status|. |*cert_status| can |
| 44 // be NULL if user doesn't care about the cert status. | 44 // be NULL if user doesn't care about the cert status. |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 // enable Next Protocol Negotiation (if supported). The order of the | 144 // enable Next Protocol Negotiation (if supported). The order of the |
| 145 // protocols doesn't matter expect for one case: if the server supports Next | 145 // protocols doesn't matter expect for one case: if the server supports Next |
| 146 // Protocol Negotiation, but there is no overlap between the server's and | 146 // Protocol Negotiation, but there is no overlap between the server's and |
| 147 // client's protocol sets, then the first protocol in this list will be | 147 // client's protocol sets, then the first protocol in this list will be |
| 148 // requested by the client. | 148 // requested by the client. |
| 149 std::vector<std::string> next_protos; | 149 std::vector<std::string> next_protos; |
| 150 | 150 |
| 151 scoped_refptr<X509Certificate> client_cert; | 151 scoped_refptr<X509Certificate> client_cert; |
| 152 }; | 152 }; |
| 153 | 153 |
| 154 // The interface for retrieving the SSL configuration. This interface | |
| 155 // does not cover setting the SSL configuration, as on some systems, the | |
| 156 // SSLConfigService objects may not have direct access to the configuration, or | |
| 157 // live longer than the configuration preferences. | |
| 158 class NET_EXPORT SSLConfigService | |
| 159 : public base::RefCountedThreadSafe<SSLConfigService> { | |
| 160 public: | |
| 161 // Observer is notified when SSL config settings have changed. | |
| 162 class NET_EXPORT Observer { | |
| 163 public: | |
| 164 // Notify observers if SSL settings have changed. We don't check all of the | |
| 165 // data in SSLConfig, just those that qualify as a user config change. | |
| 166 // The following settings are considered user changes: | |
| 167 // rev_checking_enabled | |
| 168 // version_min | |
| 169 // version_max | |
| 170 // disabled_cipher_suites | |
| 171 // channel_id_enabled | |
| 172 // false_start_enabled | |
| 173 // require_forward_secrecy | |
| 174 virtual void OnSSLConfigChanged() = 0; | |
| 175 | |
| 176 protected: | |
| 177 virtual ~Observer() {} | |
| 178 }; | |
| 179 | |
| 180 SSLConfigService(); | |
| 181 | |
| 182 // May not be thread-safe, should only be called on the IO thread. | |
| 183 virtual void GetSSLConfig(SSLConfig* config) = 0; | |
| 184 | |
| 185 // Sets and gets the current, global CRL set. | |
| 186 static void SetCRLSet(scoped_refptr<CRLSet> crl_set); | |
| 187 static scoped_refptr<CRLSet> GetCRLSet(); | |
| 188 | |
| 189 // Gets the default minimum protocol version. | |
| 190 static uint16 default_version_min(); | |
| 191 | |
| 192 // Gets the default maximum protocol version. | |
| 193 static uint16 default_version_max(); | |
| 194 | |
| 195 // Is SNI available in this configuration? | |
| 196 static bool IsSNIAvailable(SSLConfigService* service); | |
| 197 | |
| 198 // Add an observer of this service. | |
| 199 void AddObserver(Observer* observer); | |
| 200 | |
| 201 // Remove an observer of this service. | |
| 202 void RemoveObserver(Observer* observer); | |
| 203 | |
| 204 // Calls the OnSSLConfigChanged method of registered observers. Should only be | |
| 205 // called on the IO thread. | |
| 206 void NotifySSLConfigChange(); | |
| 207 | |
| 208 protected: | |
| 209 friend class base::RefCountedThreadSafe<SSLConfigService>; | |
| 210 | |
| 211 virtual ~SSLConfigService(); | |
| 212 | |
| 213 // Process before/after config update. | |
| 214 void ProcessConfigUpdate(const SSLConfig& orig_config, | |
| 215 const SSLConfig& new_config); | |
| 216 | |
| 217 private: | |
| 218 ObserverList<Observer> observer_list_; | |
| 219 }; | |
| 220 | |
| 221 } // namespace net | 154 } // namespace net |
| 222 | 155 |
| 223 #endif // NET_SSL_SSL_CONFIG_SERVICE_H_ | 156 #endif // NET_SSL_SSL_CONFIG_H_ |
| OLD | NEW |