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
3 // found in the LICENSE file.
5 #ifndef NET_BASE_SSL_CONFIG_SERVICE_H_
6 #define NET_BASE_SSL_CONFIG_SERVICE_H_
11 #include "base/basictypes.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/observer_list.h"
14 #include "base/string_piece.h"
15 #include "net/base/cert_status_flags.h"
16 #include "net/base/crl_set.h"
17 #include "net/base/net_export.h"
18 #include "net/base/x509_certificate.h"
22 // Various TLS/SSL ProtocolVersion values encoded as uint16
27 // The most significant byte is |major|, and the least significant byte
30 SSL_PROTOCOL_VERSION_SSL3
= 0x0300,
31 SSL_PROTOCOL_VERSION_TLS1
= 0x0301,
32 SSL_PROTOCOL_VERSION_TLS1_1
= 0x0302,
33 SSL_PROTOCOL_VERSION_TLS1_2
= 0x0303,
36 // A collection of SSL-related configuration settings.
37 struct NET_EXPORT SSLConfig
{
38 // Default to revocation checking.
39 // Default to SSL 3.0 ~ default_version_max() on.
43 // Returns true if |cert| is one of the certs in |allowed_bad_certs|.
44 // The expected cert status is written to |cert_status|. |*cert_status| can
45 // be NULL if user doesn't care about the cert status.
46 bool IsAllowedBadCert(X509Certificate
* cert
, CertStatus
* cert_status
) const;
48 // Same as above except works with DER encoded certificates instead
49 // of X509Certificate.
50 bool IsAllowedBadCert(const base::StringPiece
& der_cert
,
51 CertStatus
* cert_status
) const;
53 // rev_checking_enabled is true if online certificate revocation checking is
54 // enabled (i.e. OCSP and CRL fetching).
56 // Regardless of this flag, CRLSet checking is always enabled and locally
57 // cached revocation information will be considered.
58 bool rev_checking_enabled
;
60 // The minimum and maximum protocol versions that are enabled.
61 // SSL 3.0 is 0x0300, TLS 1.0 is 0x0301, TLS 1.1 is 0x0302, and so on.
62 // (Use the SSL_PROTOCOL_VERSION_xxx enumerators defined above.)
63 // SSL 2.0 is not supported. If version_max < version_min, it means no
64 // protocol versions are enabled.
68 // Presorted list of cipher suites which should be explicitly prevented from
69 // being used in addition to those disabled by the net built-in policy.
71 // By default, all cipher suites supported by the underlying SSL
72 // implementation will be enabled except for:
73 // - Null encryption cipher suites.
74 // - Weak cipher suites: < 80 bits of security strength.
75 // - FORTEZZA cipher suites (obsolete).
76 // - IDEA cipher suites (RFC 5469 explains why).
77 // - Anonymous cipher suites.
78 // The ciphers listed in |disabled_cipher_suites| will be removed in addition
81 // Though cipher suites are sent in TLS as "uint8 CipherSuite[2]", in
82 // big-endian form, they should be declared in host byte order, with the
83 // first uint8 occupying the most significant byte.
84 // Ex: To disable TLS_RSA_WITH_RC4_128_MD5, specify 0x0004, while to
85 // disable TLS_ECDH_ECDSA_WITH_RC4_128_SHA, specify 0xC002.
87 // Note: Not implemented when using Schannel/SSLClientSocketWin.
88 std::vector
<uint16
> disabled_cipher_suites
;
90 bool cached_info_enabled
; // True if TLS cached info extension is enabled.
91 bool channel_id_enabled
; // True if TLS channel ID extension is enabled.
92 bool false_start_enabled
; // True if we'll use TLS False Start.
94 // TODO(wtc): move the following members to a new SSLParams structure. They
95 // are not SSL configuration settings.
97 struct NET_EXPORT CertAndStatus
{
101 std::string der_cert
;
102 CertStatus cert_status
;
105 // Add any known-bad SSL certificate (with its cert status) to
106 // |allowed_bad_certs| that should not trigger an ERR_CERT_* error when
107 // calling SSLClientSocket::Connect. This would normally be done in
108 // response to the user explicitly accepting the bad certificate.
109 std::vector
<CertAndStatus
> allowed_bad_certs
;
111 // True if we should send client_cert to the server.
112 bool send_client_cert
;
114 bool verify_ev_cert
; // True if we should verify the certificate for EV.
116 bool version_fallback
; // True if we are falling back to an older protocol
117 // version (one still needs to decrement
120 // If cert_io_enabled is false, then certificate verification will not
121 // result in additional HTTP requests. (For example: to fetch missing
122 // intermediates or to perform OCSP/CRL fetches.) It also implies that online
123 // revocation checking is disabled.
124 // NOTE: currently only effective on Linux
125 bool cert_io_enabled
;
127 // The list of application level protocols supported. If set, this will
128 // enable Next Protocol Negotiation (if supported). The order of the
129 // protocols doesn't matter expect for one case: if the server supports Next
130 // Protocol Negotiation, but there is no overlap between the server's and
131 // client's protocol sets, then the first protocol in this list will be
132 // requested by the client.
133 std::vector
<std::string
> next_protos
;
135 scoped_refptr
<X509Certificate
> client_cert
;
138 // The interface for retrieving the SSL configuration. This interface
139 // does not cover setting the SSL configuration, as on some systems, the
140 // SSLConfigService objects may not have direct access to the configuration, or
141 // live longer than the configuration preferences.
142 class NET_EXPORT SSLConfigService
143 : public base::RefCountedThreadSafe
<SSLConfigService
> {
145 // Observer is notified when SSL config settings have changed.
146 class NET_EXPORT Observer
{
148 // Notify observers if SSL settings have changed. We don't check all of the
149 // data in SSLConfig, just those that qualify as a user config change.
150 // The following settings are considered user changes:
151 // rev_checking_enabled
154 // disabled_cipher_suites
155 // channel_id_enabled
156 // false_start_enabled
157 virtual void OnSSLConfigChanged() = 0;
160 virtual ~Observer() {}
165 // May not be thread-safe, should only be called on the IO thread.
166 virtual void GetSSLConfig(SSLConfig
* config
) = 0;
168 // Sets and gets the current, global CRL set.
169 static void SetCRLSet(scoped_refptr
<CRLSet
> crl_set
);
170 static scoped_refptr
<CRLSet
> GetCRLSet();
172 // Enables the TLS cached info extension, which allows the server to send
173 // just a digest of its certificate chain.
174 static void EnableCachedInfo();
175 static bool cached_info_enabled();
177 // Gets the default minimum protocol version.
178 static uint16
default_version_min();
180 // Sets and gets the default maximum protocol version.
181 static void SetDefaultVersionMax(uint16 version_max
);
182 static uint16
default_version_max();
184 // Force channel ID support to be enabled.
185 static void EnableChannelIDTrial();
187 // Is SNI available in this configuration?
188 static bool IsSNIAvailable(SSLConfigService
* service
);
190 // Add an observer of this service.
191 void AddObserver(Observer
* observer
);
193 // Remove an observer of this service.
194 void RemoveObserver(Observer
* observer
);
197 friend class base::RefCountedThreadSafe
<SSLConfigService
>;
199 virtual ~SSLConfigService();
201 // SetFlags sets the values of several flags based on global configuration.
202 static void SetSSLConfigFlags(SSLConfig
* ssl_config
);
204 // Process before/after config update.
205 void ProcessConfigUpdate(const SSLConfig
& orig_config
,
206 const SSLConfig
& new_config
);
209 ObserverList
<Observer
> observer_list_
;
214 #endif // NET_BASE_SSL_CONFIG_SERVICE_H_