[email protected] | 94de3e0 | 2014-06-17 00:09:51 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef COMPONENTS_CRONET_URL_REQUEST_CONTEXT_CONFIG_H_ |
| 6 | #define COMPONENTS_CRONET_URL_REQUEST_CONTEXT_CONFIG_H_ |
| 7 | |
dcheng | fe3745e624 | 2016-04-21 23:49:58 | [diff] [blame] | 8 | #include <memory> |
[email protected] | 94de3e0 | 2014-06-17 00:09:51 | [diff] [blame] | 9 | #include <string> |
Donna Wu | 7ea51c2 | 2017-06-20 08:34:52 | [diff] [blame] | 10 | #include <vector> |
[email protected] | 94de3e0 | 2014-06-17 00:09:51 | [diff] [blame] | 11 | |
mef | c71361c | 2014-09-16 14:48:56 | [diff] [blame] | 12 | #include "base/macros.h" |
xunjieli | da7f7702 | 2016-03-28 16:36:36 | [diff] [blame] | 13 | #include "base/memory/ref_counted.h" |
kapishnikov | df5ccab | 2015-12-03 18:38:50 | [diff] [blame] | 14 | #include "base/time/time.h" |
mgersh | cc6ae89 | 2017-06-20 22:33:53 | [diff] [blame] | 15 | #include "base/values.h" |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 16 | #include "net/base/hash_value.h" |
lilyhoughton | 14e2a1f1 | 2017-01-11 14:50:27 | [diff] [blame] | 17 | #include "net/cert/cert_verifier.h" |
[email protected] | 94de3e0 | 2014-06-17 00:09:51 | [diff] [blame] | 18 | |
xunjieli | da7f7702 | 2016-03-28 16:36:36 | [diff] [blame] | 19 | namespace base { |
| 20 | class SequencedTaskRunner; |
| 21 | } // namespace base |
| 22 | |
[email protected] | 94de3e0 | 2014-06-17 00:09:51 | [diff] [blame] | 23 | namespace net { |
xunjieli | 013145f | 2015-10-20 23:20:11 | [diff] [blame] | 24 | class CertVerifier; |
pauljensen | e92c409 | 2015-12-09 19:13:48 | [diff] [blame] | 25 | class NetLog; |
[email protected] | 94de3e0 | 2014-06-17 00:09:51 | [diff] [blame] | 26 | class URLRequestContextBuilder; |
| 27 | } // namespace net |
| 28 | |
| 29 | namespace cronet { |
| 30 | |
| 31 | // Common configuration parameters used by Cronet to configure |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 32 | // URLRequestContext. |
mgersh | cc6ae89 | 2017-06-20 22:33:53 | [diff] [blame] | 33 | // TODO(mgersh): This shouldn't be a struct, and experimental option parsing |
| 34 | // should be kept more separate from applying the configuration. |
[email protected] | 94de3e0 | 2014-06-17 00:09:51 | [diff] [blame] | 35 | struct URLRequestContextConfig { |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 36 | // Type of HTTP cache. |
kapishnikov | aa8f338c | 2016-10-28 16:17:32 | [diff] [blame] | 37 | // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.net.impl |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 38 | enum HttpCacheType { |
| 39 | // No HTTP cache. |
| 40 | DISABLED, |
| 41 | // HTTP cache persisted to disk. |
| 42 | DISK, |
| 43 | // HTTP cache kept in memory. |
| 44 | MEMORY, |
| 45 | }; |
| 46 | |
mef | c71361c | 2014-09-16 14:48:56 | [diff] [blame] | 47 | // App-provided hint that server supports QUIC. |
| 48 | struct QuicHint { |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 49 | QuicHint(const std::string& host, int port, int alternate_port); |
mef | c71361c | 2014-09-16 14:48:56 | [diff] [blame] | 50 | ~QuicHint(); |
| 51 | |
mef | c71361c | 2014-09-16 14:48:56 | [diff] [blame] | 52 | // Host name of the server that supports QUIC. |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 53 | const std::string host; |
mef | c71361c | 2014-09-16 14:48:56 | [diff] [blame] | 54 | // Port of the server that supports QUIC. |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 55 | const int port; |
mef | c71361c | 2014-09-16 14:48:56 | [diff] [blame] | 56 | // Alternate protocol port. |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 57 | const int alternate_port; |
mef | c71361c | 2014-09-16 14:48:56 | [diff] [blame] | 58 | |
| 59 | private: |
| 60 | DISALLOW_COPY_AND_ASSIGN(QuicHint); |
| 61 | }; |
| 62 | |
kapishnikov | df5ccab | 2015-12-03 18:38:50 | [diff] [blame] | 63 | // Public-Key-Pinning configuration structure. |
| 64 | struct Pkp { |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 65 | Pkp(const std::string& host, |
| 66 | bool include_subdomains, |
| 67 | const base::Time& expiration_date); |
kapishnikov | df5ccab | 2015-12-03 18:38:50 | [diff] [blame] | 68 | ~Pkp(); |
| 69 | |
kapishnikov | df5ccab | 2015-12-03 18:38:50 | [diff] [blame] | 70 | // Host name. |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 71 | const std::string host; |
kapishnikov | df5ccab | 2015-12-03 18:38:50 | [diff] [blame] | 72 | // Pin hashes (currently SHA256 only). |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 73 | net::HashValueVector pin_hashes; |
kapishnikov | df5ccab | 2015-12-03 18:38:50 | [diff] [blame] | 74 | // Indicates whether the pinning should apply to the pinned host subdomains. |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 75 | const bool include_subdomains; |
kapishnikov | df5ccab | 2015-12-03 18:38:50 | [diff] [blame] | 76 | // Expiration date for the pins. |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 77 | const base::Time expiration_date; |
kapishnikov | df5ccab | 2015-12-03 18:38:50 | [diff] [blame] | 78 | |
| 79 | private: |
| 80 | DISALLOW_COPY_AND_ASSIGN(Pkp); |
| 81 | }; |
| 82 | |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 83 | URLRequestContextConfig( |
| 84 | // Enable QUIC. |
| 85 | bool enable_quic, |
mef | c5da571 | 2016-02-09 20:14:23 | [diff] [blame] | 86 | // QUIC User Agent ID. |
| 87 | const std::string& quic_user_agent_id, |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 88 | // Enable SPDY. |
| 89 | bool enable_spdy, |
| 90 | // Enable SDCH. |
| 91 | bool enable_sdch, |
xunjieli | 186d2bf | 2017-04-18 13:45:47 | [diff] [blame] | 92 | // Enable Brotli. |
| 93 | bool enable_brotli, |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 94 | // Type of http cache. |
| 95 | HttpCacheType http_cache, |
| 96 | // Max size of http cache in bytes. |
| 97 | int http_cache_max_size, |
| 98 | // Disable caching for HTTP responses. Other information may be stored in |
| 99 | // the cache. |
| 100 | bool load_disable_cache, |
| 101 | // Storage path for http cache and cookie storage. |
| 102 | const std::string& storage_path, |
| 103 | // User-Agent request header field. |
| 104 | const std::string& user_agent, |
| 105 | // JSON encoded experimental options. |
| 106 | const std::string& experimental_options, |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 107 | // MockCertVerifier to use for testing purposes. |
tbansal | 7018e2a | 2016-06-25 00:40:39 | [diff] [blame] | 108 | std::unique_ptr<net::CertVerifier> mock_cert_verifier, |
| 109 | // Enable network quality estimator. |
kapishnikov | 385aa42 | 2016-07-01 20:53:02 | [diff] [blame] | 110 | bool enable_network_quality_estimator, |
| 111 | // Enable bypassing of public key pinning for local trust anchors |
rtenneti | 121f9fa | 2016-07-07 23:49:28 | [diff] [blame] | 112 | bool bypass_public_key_pinning_for_local_trust_anchors, |
| 113 | // Certificate verifier cache data. |
| 114 | const std::string& cert_verifier_data); |
[email protected] | 94de3e0 | 2014-06-17 00:09:51 | [diff] [blame] | 115 | ~URLRequestContextConfig(); |
| 116 | |
xunjieli | d67295e | 2017-03-16 21:05:41 | [diff] [blame] | 117 | // Configures |context_builder| based on |this|. |
[email protected] | 94de3e0 | 2014-06-17 00:09:51 | [diff] [blame] | 118 | void ConfigureURLRequestContextBuilder( |
pauljensen | e92c409 | 2015-12-09 19:13:48 | [diff] [blame] | 119 | net::URLRequestContextBuilder* context_builder, |
xunjieli | da7f7702 | 2016-03-28 16:36:36 | [diff] [blame] | 120 | net::NetLog* net_log, |
| 121 | const scoped_refptr<base::SequencedTaskRunner>& file_task_runner); |
[email protected] | 94de3e0 | 2014-06-17 00:09:51 | [diff] [blame] | 122 | |
[email protected] | 94de3e0 | 2014-06-17 00:09:51 | [diff] [blame] | 123 | // Enable QUIC. |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 124 | const bool enable_quic; |
mef | c5da571 | 2016-02-09 20:14:23 | [diff] [blame] | 125 | // QUIC User Agent ID. |
| 126 | const std::string quic_user_agent_id; |
[email protected] | 94de3e0 | 2014-06-17 00:09:51 | [diff] [blame] | 127 | // Enable SPDY. |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 128 | const bool enable_spdy; |
xunjieli | b8a6d56f | 2015-04-29 17:36:14 | [diff] [blame] | 129 | // Enable SDCH. |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 130 | const bool enable_sdch; |
xunjieli | 186d2bf | 2017-04-18 13:45:47 | [diff] [blame] | 131 | // Enable Brotli. |
| 132 | const bool enable_brotli; |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 133 | // Type of http cache. |
| 134 | const HttpCacheType http_cache; |
[email protected] | 94de3e0 | 2014-06-17 00:09:51 | [diff] [blame] | 135 | // Max size of http cache in bytes. |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 136 | const int http_cache_max_size; |
mef | bb4f45c | 2015-01-12 18:03:25 | [diff] [blame] | 137 | // Disable caching for HTTP responses. Other information may be stored in |
| 138 | // the cache. |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 139 | const bool load_disable_cache; |
[email protected] | 94de3e0 | 2014-06-17 00:09:51 | [diff] [blame] | 140 | // Storage path for http cache and cookie storage. |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 141 | const std::string storage_path; |
mef | d190710 | 2014-11-07 17:46:48 | [diff] [blame] | 142 | // User-Agent request header field. |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 143 | const std::string user_agent; |
xunjieli | 61b1eaa | 2015-11-17 22:44:55 | [diff] [blame] | 144 | // Experimental options encoded as a string in a JSON format containing |
| 145 | // experiments and their corresponding configuration options. The format |
| 146 | // is a JSON object with the name of the experiment as the key, and the |
| 147 | // configuration options as the value. An example: |
| 148 | // {"experiment1": {"option1": "option_value1", "option2": "option_value2", |
| 149 | // ...}, "experiment2: {"option3", "option_value3", ...}, ...} |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 150 | const std::string experimental_options; |
mef | c71361c | 2014-09-16 14:48:56 | [diff] [blame] | 151 | |
xunjieli | 013145f | 2015-10-20 23:20:11 | [diff] [blame] | 152 | // Certificate verifier for testing. |
dcheng | fe3745e624 | 2016-04-21 23:49:58 | [diff] [blame] | 153 | std::unique_ptr<net::CertVerifier> mock_cert_verifier; |
xunjieli | 013145f | 2015-10-20 23:20:11 | [diff] [blame] | 154 | |
tbansal | 7018e2a | 2016-06-25 00:40:39 | [diff] [blame] | 155 | // Enable network quality estimator. |
| 156 | const bool enable_network_quality_estimator; |
| 157 | |
kapishnikov | 385aa42 | 2016-07-01 20:53:02 | [diff] [blame] | 158 | // Enable public key pinning bypass for local trust anchors. |
| 159 | const bool bypass_public_key_pinning_for_local_trust_anchors; |
| 160 | |
rtenneti | 121f9fa | 2016-07-07 23:49:28 | [diff] [blame] | 161 | // Data to populte CertVerifierCache. |
| 162 | const std::string cert_verifier_data; |
| 163 | |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 164 | // App-provided list of servers that support QUIC. |
Donna Wu | 7ea51c2 | 2017-06-20 08:34:52 | [diff] [blame] | 165 | std::vector<std::unique_ptr<QuicHint>> quic_hints; |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 166 | |
| 167 | // The list of public key pins. |
Donna Wu | 7ea51c2 | 2017-06-20 08:34:52 | [diff] [blame] | 168 | std::vector<std::unique_ptr<Pkp>> pkp_list; |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 169 | |
mgersh | ac5f75a | 2017-06-28 16:53:08 | [diff] [blame^] | 170 | // Enable DNS cache persistence. |
| 171 | bool enable_host_cache_persistence = false; |
| 172 | |
| 173 | // Minimum time in milliseconds between writing the HostCache contents to |
| 174 | // prefs. Only relevant when |enable_host_cache_persistence| is true. |
| 175 | int host_cache_persistence_delay_ms = 60000; |
| 176 | |
xunjieli | d67295e | 2017-03-16 21:05:41 | [diff] [blame] | 177 | // Experimental options that are recognized by the config parser. |
mgersh | cc6ae89 | 2017-06-20 22:33:53 | [diff] [blame] | 178 | std::unique_ptr<base::DictionaryValue> effective_experimental_options = |
| 179 | nullptr; |
xunjieli | d67295e | 2017-03-16 21:05:41 | [diff] [blame] | 180 | |
mef | c71361c | 2014-09-16 14:48:56 | [diff] [blame] | 181 | private: |
mgersh | cc6ae89 | 2017-06-20 22:33:53 | [diff] [blame] | 182 | // Parses experimental options and makes appropriate changes to settings in |
| 183 | // the URLRequestContextConfig and URLRequestContextBuilder. |
| 184 | void ParseAndSetExperimentalOptions( |
| 185 | net::URLRequestContextBuilder* context_builder, |
| 186 | net::NetLog* net_log, |
| 187 | const scoped_refptr<base::SequencedTaskRunner>& file_task_runner); |
| 188 | |
mef | c71361c | 2014-09-16 14:48:56 | [diff] [blame] | 189 | DISALLOW_COPY_AND_ASSIGN(URLRequestContextConfig); |
[email protected] | 94de3e0 | 2014-06-17 00:09:51 | [diff] [blame] | 190 | }; |
| 191 | |
lilyhoughton | 14e2a1f1 | 2017-01-11 14:50:27 | [diff] [blame] | 192 | // Stores intermediate state for URLRequestContextConfig. Initializes with |
| 193 | // (mostly) sane defaults, then the appropriate member variables can be |
| 194 | // modified, and it can be finalized with Build(). |
| 195 | struct URLRequestContextConfigBuilder { |
| 196 | URLRequestContextConfigBuilder(); |
| 197 | ~URLRequestContextConfigBuilder(); |
| 198 | |
| 199 | // Finalize state into a URLRequestContextConfig. Must only be called once, |
| 200 | // as once |mock_cert_verifier| is moved into a URLRequestContextConfig, it |
| 201 | // cannot be used again. |
| 202 | std::unique_ptr<URLRequestContextConfig> Build(); |
| 203 | |
| 204 | // Enable QUIC. |
| 205 | bool enable_quic = false; |
| 206 | // QUIC User Agent ID. |
| 207 | std::string quic_user_agent_id = ""; |
| 208 | // Enable SPDY. |
| 209 | bool enable_spdy = true; |
| 210 | // Enable SDCH. |
| 211 | bool enable_sdch = false; |
xunjieli | 186d2bf | 2017-04-18 13:45:47 | [diff] [blame] | 212 | // Enable Brotli. |
| 213 | bool enable_brotli = false; |
lilyhoughton | 14e2a1f1 | 2017-01-11 14:50:27 | [diff] [blame] | 214 | // Type of http cache. |
| 215 | URLRequestContextConfig::HttpCacheType http_cache = |
| 216 | URLRequestContextConfig::DISABLED; |
| 217 | // Max size of http cache in bytes. |
| 218 | int http_cache_max_size = 0; |
| 219 | // Disable caching for HTTP responses. Other information may be stored in |
| 220 | // the cache. |
| 221 | bool load_disable_cache = false; |
| 222 | // Storage path for http cache and cookie storage. |
| 223 | std::string storage_path = ""; |
| 224 | // User-Agent request header field. |
| 225 | std::string user_agent = ""; |
| 226 | // Experimental options encoded as a string in a JSON format containing |
| 227 | // experiments and their corresponding configuration options. The format |
| 228 | // is a JSON object with the name of the experiment as the key, and the |
| 229 | // configuration options as the value. An example: |
| 230 | // {"experiment1": {"option1": "option_value1", "option2": "option_value2", |
| 231 | // ...}, "experiment2: {"option3", "option_value3", ...}, ...} |
| 232 | std::string experimental_options = "{}"; |
lilyhoughton | 14e2a1f1 | 2017-01-11 14:50:27 | [diff] [blame] | 233 | |
| 234 | // Certificate verifier for testing. |
| 235 | std::unique_ptr<net::CertVerifier> mock_cert_verifier = nullptr; |
| 236 | |
| 237 | // Enable network quality estimator. |
| 238 | bool enable_network_quality_estimator = false; |
| 239 | |
| 240 | // Enable public key pinning bypass for local trust anchors. |
| 241 | bool bypass_public_key_pinning_for_local_trust_anchors = true; |
| 242 | |
| 243 | // Data to populate CertVerifierCache. |
| 244 | std::string cert_verifier_data = ""; |
| 245 | |
| 246 | private: |
| 247 | DISALLOW_COPY_AND_ASSIGN(URLRequestContextConfigBuilder); |
| 248 | }; |
| 249 | |
[email protected] | 94de3e0 | 2014-06-17 00:09:51 | [diff] [blame] | 250 | } // namespace cronet |
| 251 | |
| 252 | #endif // COMPONENTS_CRONET_URL_REQUEST_CONTEXT_CONFIG_H_ |