| 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 #ifndef NET_SSL_SSL_CONFIG_SERVICE_H_ | 5 #ifndef NET_SSL_SSL_CONFIG_SERVICE_H_ |
| 6 #define NET_SSL_SSL_CONFIG_SERVICE_H_ | 6 #define NET_SSL_SSL_CONFIG_SERVICE_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | |
| 11 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 12 #include "base/observer_list.h" | 11 #include "base/observer_list.h" |
| 13 #include "base/strings/string_piece.h" | |
| 14 #include "net/base/net_export.h" | 12 #include "net/base/net_export.h" |
| 15 #include "net/cert/cert_status_flags.h" | |
| 16 #include "net/cert/crl_set.h" | 13 #include "net/cert/crl_set.h" |
| 17 #include "net/cert/x509_certificate.h" | 14 #include "net/ssl/ssl_config.h" |
| 18 | 15 |
| 19 namespace net { | 16 namespace net { |
| 20 | 17 |
| 21 // Various TLS/SSL ProtocolVersion values encoded as uint16 | |
| 22 // struct { | |
| 23 // uint8 major; | |
| 24 // uint8 minor; | |
| 25 // } ProtocolVersion; | |
| 26 // The most significant byte is |major|, and the least significant byte | |
| 27 // is |minor|. | |
| 28 enum { | |
| 29 SSL_PROTOCOL_VERSION_SSL3 = 0x0300, | |
| 30 SSL_PROTOCOL_VERSION_TLS1 = 0x0301, | |
| 31 SSL_PROTOCOL_VERSION_TLS1_1 = 0x0302, | |
| 32 SSL_PROTOCOL_VERSION_TLS1_2 = 0x0303, | |
| 33 }; | |
| 34 | |
| 35 // A collection of SSL-related configuration settings. | |
| 36 struct NET_EXPORT SSLConfig { | |
| 37 // Default to revocation checking. | |
| 38 // Default to SSL 3.0 ~ default_version_max() on. | |
| 39 SSLConfig(); | |
| 40 ~SSLConfig(); | |
| 41 | |
| 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 | |
| 44 // be NULL if user doesn't care about the cert status. | |
| 45 bool IsAllowedBadCert(X509Certificate* cert, CertStatus* cert_status) const; | |
| 46 | |
| 47 // Same as above except works with DER encoded certificates instead | |
| 48 // of X509Certificate. | |
| 49 bool IsAllowedBadCert(const base::StringPiece& der_cert, | |
| 50 CertStatus* cert_status) const; | |
| 51 | |
| 52 // rev_checking_enabled is true if online certificate revocation checking is | |
| 53 // enabled (i.e. OCSP and CRL fetching). | |
| 54 // | |
| 55 // Regardless of this flag, CRLSet checking is always enabled and locally | |
| 56 // cached revocation information will be considered. | |
| 57 bool rev_checking_enabled; | |
| 58 | |
| 59 // rev_checking_required_local_anchors is true if revocation checking is | |
| 60 // required to succeed when certificates chain to local trust anchors (that | |
| 61 // is, non-public CAs). If revocation information cannot be obtained, such | |
| 62 // certificates will be treated as revoked ("hard-fail"). | |
| 63 // Note: This is distinct from rev_checking_enabled. If true, it is | |
| 64 // equivalent to also setting rev_checking_enabled, but only when the | |
| 65 // certificate chain chains to a local (non-public) trust anchor. | |
| 66 bool rev_checking_required_local_anchors; | |
| 67 | |
| 68 // The minimum and maximum protocol versions that are enabled. | |
| 69 // SSL 3.0 is 0x0300, TLS 1.0 is 0x0301, TLS 1.1 is 0x0302, and so on. | |
| 70 // (Use the SSL_PROTOCOL_VERSION_xxx enumerators defined above.) | |
| 71 // SSL 2.0 is not supported. If version_max < version_min, it means no | |
| 72 // protocol versions are enabled. | |
| 73 uint16 version_min; | |
| 74 uint16 version_max; | |
| 75 | |
| 76 // Presorted list of cipher suites which should be explicitly prevented from | |
| 77 // being used in addition to those disabled by the net built-in policy. | |
| 78 // | |
| 79 // By default, all cipher suites supported by the underlying SSL | |
| 80 // implementation will be enabled except for: | |
| 81 // - Null encryption cipher suites. | |
| 82 // - Weak cipher suites: < 80 bits of security strength. | |
| 83 // - FORTEZZA cipher suites (obsolete). | |
| 84 // - IDEA cipher suites (RFC 5469 explains why). | |
| 85 // - Anonymous cipher suites. | |
| 86 // - ECDSA cipher suites on platforms that do not support ECDSA signed | |
| 87 // certificates, as servers may use the presence of such ciphersuites as a | |
| 88 // hint to send an ECDSA certificate. | |
| 89 // The ciphers listed in |disabled_cipher_suites| will be removed in addition | |
| 90 // to the above list. | |
| 91 // | |
| 92 // Though cipher suites are sent in TLS as "uint8 CipherSuite[2]", in | |
| 93 // big-endian form, they should be declared in host byte order, with the | |
| 94 // first uint8 occupying the most significant byte. | |
| 95 // Ex: To disable TLS_RSA_WITH_RC4_128_MD5, specify 0x0004, while to | |
| 96 // disable TLS_ECDH_ECDSA_WITH_RC4_128_SHA, specify 0xC002. | |
| 97 std::vector<uint16> disabled_cipher_suites; | |
| 98 | |
| 99 bool channel_id_enabled; // True if TLS channel ID extension is enabled. | |
| 100 bool false_start_enabled; // True if we'll use TLS False Start. | |
| 101 // True if the Certificate Transparency signed_certificate_timestamp | |
| 102 // TLS extension is enabled. | |
| 103 bool signed_cert_timestamps_enabled; | |
| 104 | |
| 105 // require_forward_secrecy, if true, causes only (EC)DHE cipher suites to be | |
| 106 // enabled. NOTE: this only applies to server sockets currently, although | |
| 107 // that could be extended if needed. | |
| 108 bool require_forward_secrecy; | |
| 109 | |
| 110 // TODO(wtc): move the following members to a new SSLParams structure. They | |
| 111 // are not SSL configuration settings. | |
| 112 | |
| 113 struct NET_EXPORT CertAndStatus { | |
| 114 CertAndStatus(); | |
| 115 ~CertAndStatus(); | |
| 116 | |
| 117 std::string der_cert; | |
| 118 CertStatus cert_status; | |
| 119 }; | |
| 120 | |
| 121 // Add any known-bad SSL certificate (with its cert status) to | |
| 122 // |allowed_bad_certs| that should not trigger an ERR_CERT_* error when | |
| 123 // calling SSLClientSocket::Connect. This would normally be done in | |
| 124 // response to the user explicitly accepting the bad certificate. | |
| 125 std::vector<CertAndStatus> allowed_bad_certs; | |
| 126 | |
| 127 // True if we should send client_cert to the server. | |
| 128 bool send_client_cert; | |
| 129 | |
| 130 bool verify_ev_cert; // True if we should verify the certificate for EV. | |
| 131 | |
| 132 bool version_fallback; // True if we are falling back to an older protocol | |
| 133 // version (one still needs to decrement | |
| 134 // version_max). | |
| 135 | |
| 136 // If cert_io_enabled is false, then certificate verification will not | |
| 137 // result in additional HTTP requests. (For example: to fetch missing | |
| 138 // intermediates or to perform OCSP/CRL fetches.) It also implies that online | |
| 139 // revocation checking is disabled. | |
| 140 // NOTE: Only used by NSS. | |
| 141 bool cert_io_enabled; | |
| 142 | |
| 143 // The list of application level protocols supported. If set, this will | |
| 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 | |
| 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 | |
| 148 // requested by the client. | |
| 149 std::vector<std::string> next_protos; | |
| 150 | |
| 151 scoped_refptr<X509Certificate> client_cert; | |
| 152 }; | |
| 153 | |
| 154 // The interface for retrieving the SSL configuration. This interface | 18 // The interface for retrieving the SSL configuration. This interface |
| 155 // does not cover setting the SSL configuration, as on some systems, the | 19 // does not cover setting the SSL configuration, as on some systems, the |
| 156 // SSLConfigService objects may not have direct access to the configuration, or | 20 // SSLConfigService objects may not have direct access to the configuration, or |
| 157 // live longer than the configuration preferences. | 21 // live longer than the configuration preferences. |
| 158 class NET_EXPORT SSLConfigService | 22 class NET_EXPORT SSLConfigService |
| 159 : public base::RefCountedThreadSafe<SSLConfigService> { | 23 : public base::RefCountedThreadSafe<SSLConfigService> { |
| 160 public: | 24 public: |
| 161 // Observer is notified when SSL config settings have changed. | 25 // Observer is notified when SSL config settings have changed. |
| 162 class NET_EXPORT Observer { | 26 class NET_EXPORT Observer { |
| 163 public: | 27 public: |
| (...skipping 15 matching lines...) Expand all Loading... |
| 179 | 43 |
| 180 SSLConfigService(); | 44 SSLConfigService(); |
| 181 | 45 |
| 182 // May not be thread-safe, should only be called on the IO thread. | 46 // May not be thread-safe, should only be called on the IO thread. |
| 183 virtual void GetSSLConfig(SSLConfig* config) = 0; | 47 virtual void GetSSLConfig(SSLConfig* config) = 0; |
| 184 | 48 |
| 185 // Sets and gets the current, global CRL set. | 49 // Sets and gets the current, global CRL set. |
| 186 static void SetCRLSet(scoped_refptr<CRLSet> crl_set); | 50 static void SetCRLSet(scoped_refptr<CRLSet> crl_set); |
| 187 static scoped_refptr<CRLSet> GetCRLSet(); | 51 static scoped_refptr<CRLSet> GetCRLSet(); |
| 188 | 52 |
| 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? | 53 // Is SNI available in this configuration? |
| 196 static bool IsSNIAvailable(SSLConfigService* service); | 54 static bool IsSNIAvailable(SSLConfigService* service); |
| 197 | 55 |
| 198 // Add an observer of this service. | 56 // Add an observer of this service. |
| 199 void AddObserver(Observer* observer); | 57 void AddObserver(Observer* observer); |
| 200 | 58 |
| 201 // Remove an observer of this service. | 59 // Remove an observer of this service. |
| 202 void RemoveObserver(Observer* observer); | 60 void RemoveObserver(Observer* observer); |
| 203 | 61 |
| 204 // Calls the OnSSLConfigChanged method of registered observers. Should only be | 62 // Calls the OnSSLConfigChanged method of registered observers. Should only be |
| 205 // called on the IO thread. | 63 // called on the IO thread. |
| 206 void NotifySSLConfigChange(); | 64 void NotifySSLConfigChange(); |
| 207 | 65 |
| 208 protected: | 66 protected: |
| 209 friend class base::RefCountedThreadSafe<SSLConfigService>; | 67 friend class base::RefCountedThreadSafe<SSLConfigService>; |
| 210 | 68 |
| 211 virtual ~SSLConfigService(); | 69 virtual ~SSLConfigService(); |
| 212 | 70 |
| 213 // Process before/after config update. | 71 // Process before/after config update. |
| 214 void ProcessConfigUpdate(const SSLConfig& orig_config, | 72 void ProcessConfigUpdate(const SSLConfig& orig_config, |
| 215 const SSLConfig& new_config); | 73 const SSLConfig& new_config); |
| 216 | 74 |
| 217 private: | 75 private: |
| 218 ObserverList<Observer> observer_list_; | 76 ObserverList<Observer> observer_list_; |
| 219 }; | 77 }; |
| 220 | 78 |
| 221 } // namespace net | 79 } // namespace net |
| 222 | 80 |
| 223 #endif // NET_SSL_SSL_CONFIG_SERVICE_H_ | 81 #endif // NET_SSL_SSL_CONFIG_SERVICE_H_ |
| OLD | NEW |