1// Copyright 2017 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
5module network.mojom;
6
7import "mojo/public/mojom/base/file.mojom";
8import "mojo/public/mojom/base/file_path.mojom";
9import "mojo/public/mojom/base/memory_pressure_level.mojom";
10import "mojo/public/mojom/base/read_only_buffer.mojom";
11import "mojo/public/mojom/base/string16.mojom";
12import "mojo/public/mojom/base/time.mojom";
13import "mojo/public/mojom/base/unguessable_token.mojom";
14import "mojo/public/mojom/base/values.mojom";
15import "services/network/public/mojom/cookie_manager.mojom";
16import "services/network/public/mojom/host_resolver.mojom";
17import "services/network/public/mojom/http_raw_headers.mojom";
18import "services/network/public/mojom/net_log.mojom";
19import "services/network/public/mojom/network_change_manager.mojom";
20import "services/network/public/mojom/network_context.mojom";
21import "services/network/public/mojom/network_interface.mojom";
22import "services/network/public/mojom/network_param.mojom";
23import "services/network/public/mojom/network_quality_estimator_manager.mojom";
24import "services/network/public/mojom/network_service_test.mojom";
25import "services/network/public/mojom/trust_tokens.mojom";
26import "services/network/public/mojom/url_loader.mojom";
27import "services/network/public/mojom/url_loader_factory.mojom";
28import "services/network/public/mojom/url_response_head.mojom";
29import "url/mojom/origin.mojom";
30import "url/mojom/url.mojom";
31
32[EnableIf=is_android]
33import "mojo/public/mojom/base/application_state.mojom";
34
35struct LoadInfo {
36  int32 process_id;
37  int32 routing_id;
38  string host;
39  uint32 load_state;  // net::LoadState enum
40  mojo_base.mojom.String16 state_param;
41  uint64 upload_position;
42  uint64 upload_size;
43};
44
45// Network service interface to the browser.
46interface NetworkServiceClient {
47  // Called periodically to update the client about progress of the current
48  // loads. To avoid flooding the client, it has to ack the update before it can
49  // receive the next update.
50  OnLoadingStateUpdate(array<LoadInfo> infos) => ();
51
52  // Called on every request completion to update the network traffic annotation
53  // ID, and the total bytes received and sent.
54  // |network_traffic_annotation_id_hash| represents the hash of unique tag that
55  // identifies the annotation of the request.
56  OnDataUseUpdate(int32 network_traffic_annotation_id_hash, int64 recv_bytes,
57                  int64 sent_bytes);
58
59  // Called to send raw header information and information about excluded
60  // cookies. Only called when |devtool_request_id| is available to the
61  // URLLoader.
62  OnRawRequest(
63    int32 process_id,
64    int32 routing_id,
65    string devtool_request_id,
66    array<CookieWithStatus> cookies_with_status,
67    array<HttpRawHeaderPair> headers);
68
69  // Called to send information about the cookies blocked from storage from a
70  // received response. Only called when |devtool_request_id| is available to
71  // the URLLoader.
72  OnRawResponse(
73    int32 process_id,
74    int32 routing_id,
75    string devtool_request_id,
76    array<CookieAndLineWithStatus> cookies_with_status,
77    array<HttpRawHeaderPair> headers,
78    string? raw_response_headers);
79
80  // Called to send the CORS preflight request information. Only called when
81  // |devtool_request_id| is available on the original request.
82  OnCorsPreflightRequest(
83    int32 process_id,
84    int32 render_frame_id,
85    mojo_base.mojom.UnguessableToken devtool_request_id,
86    URLRequest request,
87    url.mojom.Url initiator_url);
88
89  // Called to send the CORS preflight response information. Only called when
90  // |devtool_request_id| is available on the original request.
91  OnCorsPreflightResponse(
92    int32 process_id,
93    int32 render_frame_id,
94    mojo_base.mojom.UnguessableToken devtool_request_id,
95    url.mojom.Url url,
96    URLResponseHead head);
97
98  // Called to send the CORS preflight completion status. Only called when
99  // |devtool_request_id| is available on the original request.
100  OnCorsPreflightRequestCompleted(
101    int32 process_id,
102    int32 render_frame_id,
103    mojo_base.mojom.UnguessableToken devtool_request_id,
104    URLLoaderCompletionStatus status);
105
106  // Called to log a Rappor sample and a UKM event for the
107  // Extensions.CrossOriginFetchFromContentScript3 metric.  See the metric
108  // definition in //tools/metrics/rappor/rappor.xml for more details,
109  // including when this metric should be logged.
110  //
111  // |isolated_world_hostname| is the hostname of the isolated world origin
112  // that has initiated the network request.  See the doc comment for
113  // network.mojom.URLRequest.isolated_world_origin for more details.
114  // In practice, |isolated_world_origin| is the Chrome Extension ID.
115  LogCrossOriginFetchFromContentScript3(string isolated_world_hostname);
116};
117
118// Values for configuring HTTP authentication that can only be set once.
119struct HttpAuthStaticParams {
120  // List of supported auth schemes. Unrecognized schemes are ignored.
121  // The default value of this field (an empty list) does not match default
122  // behavior of NetworkService when no HttpAuthStaticParams is specified.
123  array<string> supported_schemes;
124
125  // File name the GSSAPI library to load. Only supported on platforms where an
126  // external GSSAPI library is necessary for Kerberos/SPNEGO support. See the
127  // |use_external_gssapi| variable definition in //net/BUILD.gn for details on
128  // platforms where this setting is applicable.
129  string gssapi_library_name;
130};
131
132// Values for configurating HTTP authentication that can be changed as needed.
133struct HttpAuthDynamicParams {
134  // Comma / semi-colon delimited allowlist of server origins which the network
135  // service may send the default credentials for NTLM or Negotiate
136  // authentication.
137  string server_allowlist;
138
139  // Comma / semi-colon delimited allowlist of server origins for which Kerberos
140  // delegation is allowed for NTLM or Negotiate authentication.
141  string delegate_allowlist;
142
143  // True if OK-AS-DELEGATE flag from KDC should be used to allow delegation for
144  // Negotiate authentication along with delegate_allowlist;
145  bool delegate_by_kdc_policy = false;
146
147  // True if canonical hostnames should be resolved when using Negotiate.
148  bool negotiate_disable_cname_lookup = false;
149
150  // True if Negotiate SPNs (service principal names) should include ports
151  // when the port isn't a standard port (80 or 443).
152  bool enable_negotiate_port = true;
153
154  // Whether NTLM V2 is enabled on POSIX platforms. No effect elsewhere.
155  bool ntlm_v2_enabled = false;
156
157  // The AccountManager AccountManagerget.AccountsByTypeAndFeatures on Android
158  // when using Negotiate authentication.
159  string android_negotiate_account_type;
160
161  // Indicates whether the GSSAPI library should be loaded. Only supported on
162  // Chrome OS.
163  bool allow_gssapi_library_load = true;
164};
165
166// Values for configuring OSCrypt.
167[EnableIf=needs_crypt_config]
168struct CryptConfig {
169  // Force OSCrypt to use a specific linux password store.
170  string store;
171
172  // The product name to use for permission prompts.
173  string product_name;
174
175  // Controls whether preference on using or ignoring backends is used.
176  bool should_use_preference;
177
178  // Preferences are stored in a separate file in the user data directory.
179  mojo_base.mojom.FilePath user_data_path;
180};
181
182// Represents the value of a single environment variable.
183struct EnvironmentVariable {
184  string name;
185  string value;
186};
187
188// Parameters needed to initialize the network service.
189struct NetworkServiceParams {
190  ConnectionType initial_connection_type = CONNECTION_UNKNOWN;
191  ConnectionSubtype initial_connection_subtype = SUBTYPE_UNKNOWN;
192
193  // A set of environment variables that should be set in the network
194  // service when starting up.
195  array<EnvironmentVariable> environment;
196};
197
198// Information about how logging should be configured.
199// Corresponds to logging::LoggingSettings.
200[EnableIf=is_chromeos]
201struct LoggingSettings {
202  uint32 logging_dest;
203  handle<platform> log_file_descriptor;
204};
205
206// Browser interface to the network service.
207interface NetworkService {
208  // Sets client used by all |NetworkContext|s creating by |NetworkService|.
209  // Pending requests may hang if the |client| pipe is closed before they
210  // complete.
211  SetClient(pending_remote<NetworkServiceClient> client,
212            NetworkServiceParams params);
213
214  // Reinitializes the Network Service's logging with the given settings. This
215  // is needed on Chrome OS, which switches to a log file in the user's home
216  // directory once they log in.
217  [EnableIf=is_chromeos]
218  ReinitializeLogging(LoggingSettings settings);
219
220  // Starts observing the NetLog event stream and writing entries to |file|.
221  // |constants| is a legend used for decoding constant values in the log; it
222  // will be merged with the |GetNetConstants()| dictionary before being passed
223  // through to the FileObserver. (See |FileNetLogObserver::CreateBounded()|
224  // for more details). Most clients will just be adding a dictionary under
225  // the key "clientInfo".
226  StartNetLog(mojo_base.mojom.File file,
227              NetLogCaptureMode capture_mode,
228              mojo_base.mojom.DictionaryValue constants);
229
230  // Attaches an external source of NetLog events. Control events will be sent
231  // to the |proxy_source| pipe indicating when netlogging is active, the
232  // NetLog events should be sent to the |proxy_sink| pipe, and must use a
233  // non-conflicting source id space.
234  AttachNetLogProxy(pending_remote<NetLogProxySource> proxy_source,
235                    pending_receiver<NetLogProxySink> proxy_sink);
236
237  // Starts logging SSL key material to the |file|. This must be called before
238  // any SSL connections are made. (See |SSLClientSocket::SetSSLKeyLogger()|
239  // for more details).
240  SetSSLKeyLogFile(mojo_base.mojom.File file);
241
242  // Creates a new network context with the given parameters.
243  CreateNetworkContext(pending_receiver<NetworkContext> context,
244                       NetworkContextParams params);
245
246  // Configures whether the built-in stub host resolver is used in preference
247  // over getaddrinfo. When enabled, the stub resolver will attempt to use the
248  // system's DNS settings to do DNS lookups itself. See
249  // https://tools.ietf.org/html/rfc1034#section-5.3.1 for definition of a stub
250  // resolver.
251  //
252  // |dns_over_https_servers| is an optional list of DNS over HTTPS servers.
253  // DnsTransactions will by default follow the behavior of |secure_dns_mode|.
254  // In SECURE mode, only DoH lookups will be performed. In AUTOMATIC mode,
255  // DoH lookups to available servers will be performed first, and insecure
256  // lookups will be used as a fallback. In OFF mode, only insecure lookups will
257  // be performed. When insecure lookups are performed, they will be sent by
258  // the async resolver first if |insecure_dns_client_enabled| is true and
259  // then by the system resolver as a fallback.
260  //
261  // DNS over HTTPS will use the primary NetworkContext, so can only be enabled
262  // after the primary network context has been created. Other than that
263  // limitation, this method can be called at any time to change DNS
264  // configuration, though calling it will fail any DNS lookups that have
265  // already been started.
266  ConfigureStubHostResolver(bool insecure_dns_client_enabled,
267                            SecureDnsMode secure_dns_mode,
268                            array<DnsOverHttpsServer>? dns_over_https_servers);
269
270  // Disables QUIC for the NetworkService. Affects all existing NetworkContexts,
271  // and all new ones that are created. Once called, QUIC cannot be re-enabled.
272  DisableQuic();
273
274  // Configures HTTP authentication for all NetworkContexts created using the
275  // NetworkService. May only be called at most once, and may only be called
276  // before any NetworkContexts are created.
277  //
278  // If this method is not invoked, default values will be used (which currently
279  // allow all supported schemes on the current platform).
280  SetUpHttpAuth(HttpAuthStaticParams http_auth_static_params);
281
282  // Sets global auth params. Unlike SetUpAuth(), may be called multiple times,
283  // at any point in time. Affects all NetworkContexts, both already existing
284  // one and subsequently created ones.
285  ConfigureHttpAuthPrefs(HttpAuthDynamicParams http_auth_dynamic_params);
286
287  // Specifies whether requests for raw headers coming through URLLoaderFactory
288  // associated with the specified process will be granted. Only raw headers
289  // for requests with URLs matching a listed origin will be reported (this
290  // permission has no effect on the network request itself).
291  // The list overwrites the list set for given process with a previous call
292  // to this method.
293  // Granting a permission increases risks in case the child process becomes
294  // compromised, so this should be done only in specific cases
295  // (e.g. DevTools attached).
296  SetRawHeadersAccess(int32 process_id, array<url.mojom.Origin> origins);
297
298  // Sets the maximum number of connections for a proxy server.
299  //   * Negative values will set the default proxy connection limit (32)
300  //   * Values larger than 99 will saturate to 99.
301  //   * Values smaller than 6 will saturate to 6.
302  SetMaxConnectionsPerProxy(int32 max_connections);
303
304  // Gets the NetworkChangeManager.
305  GetNetworkChangeManager(
306      pending_receiver<NetworkChangeManager> network_change_manager);
307
308  // Gets the NetworkQualityEstimatorManager.
309  GetNetworkQualityEstimatorManager(
310      pending_receiver<NetworkQualityEstimatorManager> receiver);
311
312  // Gets the DnsConfigChangeManager.
313  GetDnsConfigChangeManager(
314      pending_receiver<DnsConfigChangeManager> receiver);
315
316  // Gets the accumulated network usage since the start/restart of the service.
317  GetTotalNetworkUsages() => (array<NetworkUsage> total_network_usages);
318
319  // Gets list of network interfaces.
320  // The |policy| parameter is a flag that specifies whether to include/exclude
321  // network interfaces. Corresponds to enum net::HostAddressSelectionPolicy.
322  GetNetworkList(uint32 policy) => (array<NetworkInterface>? networks);
323
324  // Updates the CRLSet used in the verification of certificates. CRLSets that
325  // cannot be parsed using net::CRLSet::Parse will be ignored, as will older
326  // CRLSets (where older is determined by the sequence number). All Network
327  // Contexts created by the Network Service, including those created after
328  // this call, will use the same CRLSet.
329  UpdateCRLSet(mojo_base.mojom.ReadOnlyBuffer crl_set) => ();
330
331  // Updates the configuration used for determining if a site should have legacy
332  // TLS warnings suppressed. Configs that cannot be parsed as a
333  // LegacyTLSExperimentConfig (protobuf) will be ignored.
334  UpdateLegacyTLSConfig(mojo_base.mojom.ReadOnlyBuffer config) => ();
335
336  // Notification that the certificate database has been modified.
337  OnCertDBChanged();
338
339  // Sets up OSCrypt for the network service process. Must be called before
340  // encrypted cookies can be read or set.
341  [EnableIf=needs_crypt_config]
342  SetCryptConfig(CryptConfig crypt_config);
343
344  // Send the encryption key to the network service to use for AES encryption.
345  [EnableIf=is_mac]
346  SetEncryptionKey(string encryption_key);
347
348  // Send the encryption key to the network service to use for AES encryption.
349  [EnableIf=is_win]
350  SetEncryptionKey(string encryption_key);
351
352  // Notifies CORB (Cross-Origin Read Blocking) that |process_id| is proxying
353  // requests on behalf of a universal-access plugin and therefore CORB should
354  // stop blocking requests marked as ResourceType::kPluginResource.
355  //
356  // TODO(lukasza, laforge): https://crbug.com/702995: Remove the ...ForPlugin
357  // methods once Flash support is removed from Chromium (probably around 2020
358  // - see https://www.chromium.org/flash-roadmap).
359  AddCorbExceptionForPlugin(int32 process_id);
360
361  // Notifies |request_initiator_site_lock| enforcement code that |process_id|
362  // is proxying requests on behalf of a plugin from
363  // |allowed_request_initiator| origin.
364  //
365  // TODO(lukasza, kmoon): https://crbug.com/702993: Remove the code here once
366  // PDF support doesn't depend on PPAPI anymore.
367  AddAllowedRequestInitiatorForPlugin(
368      int32 process_id,
369      url.mojom.Origin allowed_request_initiator);
370
371  // Reverts AddCorbExceptionForPlugin and AddAllowedRequestInitiatorForPlugin.
372  RemoveSecurityExceptionsForPlugin(int32 process_id);
373
374  // Called when the system is low on memory.
375  OnMemoryPressure(mojo_base.mojom.MemoryPressureLevel memory_pressure_level);
376
377  // Called when there is a change in the current count of peer to peer
378  // connections that may require low latency.
379  OnPeerToPeerConnectionsCountChange(uint32 count);
380
381  // Called on state changes of the Android application.
382  [EnableIf=is_android]
383  OnApplicationStateChange(mojo_base.mojom.ApplicationState state);
384
385  // Sets the given environment variables in the network service's process.
386  // This method won't modify variables that aren't present in the
387  // |environment| array.
388  SetEnvironment(array<EnvironmentVariable> environment);
389
390  // Sets Trust Tokens key commitment state. |commitments| is a map from issuer
391  // origins to key commitment results (each result contains a collection of
392  // keys and some associated metadata).
393  SetTrustTokenKeyCommitments(
394      map<url.mojom.Origin, TrustTokenKeyCommitmentResult> commitments);
395
396  // Calls base::debug::DumpWithoutCrashing for the network process.
397  // TODO(http://crbug.com/934317): Remove this once done debugging renderer
398  // hangs.
399  [EnableIf=is_android]
400  DumpWithoutCrashing(mojo_base.mojom.Time dump_request_time);
401
402  // Binds the test service's testing interface. Available only in some test
403  // environments.
404  BindTestInterface(pending_receiver<NetworkServiceTest> receiver);
405};
406