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