2019-11-14 18:01:18 +00:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Jeremy Apthorp <nornagon@nornagon.net>
|
|
|
|
Date: Tue, 12 Nov 2019 11:50:16 -0800
|
|
|
|
Subject: add TrustedAuthClient to URLLoaderFactory
|
|
|
|
|
|
|
|
This allows intercepting authentication requests for the 'net' module.
|
|
|
|
Without this, the 'login' event for electron.net.ClientRequest can't be
|
|
|
|
implemented, because the existing path checks for the presence of a
|
|
|
|
WebContents, and cancels the authentication if there's no WebContents
|
|
|
|
available, which there isn't in the case of the 'net' module.
|
|
|
|
|
|
|
|
diff --git a/services/network/public/mojom/network_context.mojom b/services/network/public/mojom/network_context.mojom
|
2020-03-11 11:15:07 +00:00
|
|
|
index c37432121142472010b767b7fb257e20bc60b3fc..099c94d1db7994a0608864cb05e3686a85b7070d 100644
|
2019-11-14 18:01:18 +00:00
|
|
|
--- a/services/network/public/mojom/network_context.mojom
|
|
|
|
+++ b/services/network/public/mojom/network_context.mojom
|
2020-03-03 21:35:05 +00:00
|
|
|
@@ -193,6 +193,25 @@ struct HttpAuthStaticNetworkContextParams {
|
2019-12-11 00:22:35 +00:00
|
|
|
= DefaultCredentials.ALLOW_DEFAULT_CREDENTIALS;
|
2019-11-14 18:01:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
+interface TrustedAuthClient {
|
|
|
|
+ OnAuthRequired(
|
|
|
|
+ mojo_base.mojom.UnguessableToken? window_id,
|
|
|
|
+ uint32 process_id,
|
|
|
|
+ uint32 routing_id,
|
|
|
|
+ uint32 request_id,
|
|
|
|
+ url.mojom.Url url,
|
|
|
|
+ bool first_auth_attempt,
|
|
|
|
+ AuthChallengeInfo auth_info,
|
|
|
|
+ URLResponseHead? head,
|
|
|
|
+ pending_remote<AuthChallengeResponder> auth_challenge_responder);
|
|
|
|
+};
|
|
|
|
+interface TrustedURLLoaderAuthClient {
|
|
|
|
+ // When a new URLLoader is created, this will be called to pass a
|
|
|
|
+ // corresponding |auth_client|.
|
|
|
|
+ OnLoaderCreated(int32 request_id,
|
|
|
|
+ pending_receiver<TrustedAuthClient> auth_client);
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
interface CertVerifierClient {
|
|
|
|
Verify(
|
|
|
|
int32 default_error,
|
2020-03-03 21:35:05 +00:00
|
|
|
@@ -633,6 +652,8 @@ struct URLLoaderFactoryParams {
|
2019-12-11 00:22:35 +00:00
|
|
|
// interface. This still respects the per-context block lists.
|
|
|
|
CorsOriginAccessPatterns? factory_bound_access_patterns;
|
2019-11-14 18:01:18 +00:00
|
|
|
|
|
|
|
+ pending_remote<TrustedURLLoaderAuthClient>? auth_client;
|
|
|
|
+
|
2019-12-11 00:22:35 +00:00
|
|
|
// Key used to isolate shared network resources like the cache.
|
|
|
|
NetworkIsolationKey? network_isolation_key;
|
|
|
|
|
2019-11-14 18:01:18 +00:00
|
|
|
diff --git a/services/network/url_loader.cc b/services/network/url_loader.cc
|
2020-03-11 11:15:07 +00:00
|
|
|
index 79091a2b010409b27ba54fbe875d108344f8c337..7b6bc5b4d608c78b7ab43f701c86a0d29931df73 100644
|
2019-11-14 18:01:18 +00:00
|
|
|
--- a/services/network/url_loader.cc
|
|
|
|
+++ b/services/network/url_loader.cc
|
2020-03-11 11:15:07 +00:00
|
|
|
@@ -484,6 +484,7 @@ URLLoader::URLLoader(
|
2019-11-14 18:01:18 +00:00
|
|
|
base::WeakPtr<KeepaliveStatisticsRecorder> keepalive_statistics_recorder,
|
|
|
|
base::WeakPtr<NetworkUsageAccumulator> network_usage_accumulator,
|
|
|
|
mojom::TrustedURLLoaderHeaderClient* url_loader_header_client,
|
|
|
|
+ mojom::TrustedURLLoaderAuthClient* url_loader_auth_client,
|
|
|
|
mojom::OriginPolicyManager* origin_policy_manager)
|
|
|
|
: url_request_context_(url_request_context),
|
|
|
|
network_service_client_(network_service_client),
|
2020-03-11 11:15:07 +00:00
|
|
|
@@ -544,6 +545,11 @@ URLLoader::URLLoader(
|
2019-11-14 18:01:18 +00:00
|
|
|
header_client_.set_disconnect_handler(
|
2019-12-11 00:22:35 +00:00
|
|
|
base::BindOnce(&URLLoader::OnMojoDisconnect, base::Unretained(this)));
|
2019-11-14 18:01:18 +00:00
|
|
|
}
|
|
|
|
+ if (url_loader_auth_client) {
|
|
|
|
+ url_loader_auth_client->OnLoaderCreated(request_id_, auth_client_.BindNewPipeAndPassReceiver());
|
|
|
|
+ auth_client_.set_disconnect_handler(
|
2019-12-11 00:22:35 +00:00
|
|
|
+ base::BindOnce(&URLLoader::OnMojoDisconnect, base::Unretained(this)));
|
2019-11-14 18:01:18 +00:00
|
|
|
+ }
|
|
|
|
if (want_raw_headers_) {
|
|
|
|
options_ |= mojom::kURLLoadOptionSendSSLInfoWithResponse |
|
|
|
|
mojom::kURLLoadOptionSendSSLInfoForCertificateError;
|
2020-03-11 11:15:07 +00:00
|
|
|
@@ -982,7 +988,7 @@ void URLLoader::OnReceivedRedirect(net::URLRequest* url_request,
|
2019-11-14 18:01:18 +00:00
|
|
|
|
|
|
|
void URLLoader::OnAuthRequired(net::URLRequest* url_request,
|
|
|
|
const net::AuthChallengeInfo& auth_info) {
|
|
|
|
- if (!network_context_client_) {
|
|
|
|
+ if (!network_context_client_ && !auth_client_) {
|
|
|
|
OnAuthCredentials(base::nullopt);
|
|
|
|
return;
|
|
|
|
}
|
2020-03-11 11:15:07 +00:00
|
|
|
@@ -998,11 +1004,20 @@ void URLLoader::OnAuthRequired(net::URLRequest* url_request,
|
2019-11-14 18:01:18 +00:00
|
|
|
if (url_request->response_headers())
|
2019-12-13 20:13:12 +00:00
|
|
|
head->headers = url_request->response_headers();
|
|
|
|
head->auth_challenge_info = auth_info;
|
2019-11-14 18:01:18 +00:00
|
|
|
- network_context_client_->OnAuthRequired(
|
|
|
|
- fetch_window_id_, factory_params_->process_id, render_frame_id_,
|
2019-12-13 20:13:12 +00:00
|
|
|
- request_id_, url_request_->url(), first_auth_attempt_, auth_info,
|
|
|
|
- std::move(head),
|
2019-11-14 18:01:18 +00:00
|
|
|
- auth_challenge_responder_receiver_.BindNewPipeAndPassRemote());
|
|
|
|
+
|
|
|
|
+ if (auth_client_) {
|
|
|
|
+ auth_client_->OnAuthRequired(
|
|
|
|
+ fetch_window_id_, factory_params_->process_id, render_frame_id_,
|
2019-12-13 20:13:12 +00:00
|
|
|
+ request_id_, url_request_->url(), first_auth_attempt_, auth_info,
|
|
|
|
+ std::move(head),
|
2019-11-14 18:01:18 +00:00
|
|
|
+ auth_challenge_responder_receiver_.BindNewPipeAndPassRemote());
|
|
|
|
+ } else {
|
|
|
|
+ network_context_client_->OnAuthRequired(
|
|
|
|
+ fetch_window_id_, factory_params_->process_id, render_frame_id_,
|
2019-12-13 20:13:12 +00:00
|
|
|
+ request_id_, url_request_->url(), first_auth_attempt_, auth_info,
|
|
|
|
+ std::move(head),
|
2019-11-14 18:01:18 +00:00
|
|
|
+ auth_challenge_responder_receiver_.BindNewPipeAndPassRemote());
|
|
|
|
+ }
|
|
|
|
|
|
|
|
auth_challenge_responder_receiver_.set_disconnect_handler(
|
|
|
|
base::BindOnce(&URLLoader::DeleteSelf, base::Unretained(this)));
|
|
|
|
diff --git a/services/network/url_loader.h b/services/network/url_loader.h
|
2020-03-11 11:15:07 +00:00
|
|
|
index 88c69d29b8a1ffe3293d9985ebb9fbb438f5e84d..f78923a2097ef2679b606ecb61f0b57bf167de41 100644
|
2019-11-14 18:01:18 +00:00
|
|
|
--- a/services/network/url_loader.h
|
|
|
|
+++ b/services/network/url_loader.h
|
2020-03-11 11:15:07 +00:00
|
|
|
@@ -106,6 +106,7 @@ class COMPONENT_EXPORT(NETWORK_SERVICE) URLLoader
|
2019-11-14 18:01:18 +00:00
|
|
|
base::WeakPtr<KeepaliveStatisticsRecorder> keepalive_statistics_recorder,
|
|
|
|
base::WeakPtr<NetworkUsageAccumulator> network_usage_accumulator,
|
|
|
|
mojom::TrustedURLLoaderHeaderClient* url_loader_header_client,
|
|
|
|
+ mojom::TrustedURLLoaderAuthClient* url_loader_auth_client,
|
|
|
|
mojom::OriginPolicyManager* origin_policy_manager);
|
|
|
|
~URLLoader() override;
|
|
|
|
|
2020-03-11 11:15:07 +00:00
|
|
|
@@ -418,6 +419,7 @@ class COMPONENT_EXPORT(NETWORK_SERVICE) URLLoader
|
2019-11-14 18:01:18 +00:00
|
|
|
base::Optional<base::UnguessableToken> fetch_window_id_;
|
|
|
|
|
|
|
|
mojo::Remote<mojom::TrustedHeaderClient> header_client_;
|
|
|
|
+ mojo::Remote<mojom::TrustedAuthClient> auth_client_;
|
|
|
|
|
|
|
|
std::unique_ptr<FileOpenerForUpload> file_opener_for_upload_;
|
|
|
|
|
|
|
|
diff --git a/services/network/url_loader_factory.cc b/services/network/url_loader_factory.cc
|
2020-03-11 11:15:07 +00:00
|
|
|
index f3a9baefc1a18924503d7a6850bc704310e50015..9b3802dbdf7a1ab3f132529b794665a68eeac673 100644
|
2019-11-14 18:01:18 +00:00
|
|
|
--- a/services/network/url_loader_factory.cc
|
|
|
|
+++ b/services/network/url_loader_factory.cc
|
2020-03-11 11:15:07 +00:00
|
|
|
@@ -66,6 +66,7 @@ URLLoaderFactory::URLLoaderFactory(
|
2019-11-14 18:01:18 +00:00
|
|
|
resource_scheduler_client_(std::move(resource_scheduler_client)),
|
|
|
|
header_client_(std::move(params_->header_client)),
|
2020-03-11 11:15:07 +00:00
|
|
|
coep_reporter_(std::move(params_->coep_reporter)),
|
2019-11-14 18:01:18 +00:00
|
|
|
+ auth_client_(std::move(params_->auth_client)),
|
|
|
|
cors_url_loader_factory_(cors_url_loader_factory) {
|
|
|
|
DCHECK(context);
|
|
|
|
DCHECK_NE(mojom::kInvalidProcessId, params_->process_id);
|
2020-03-11 11:15:07 +00:00
|
|
|
@@ -209,6 +210,7 @@ void URLLoaderFactory::CreateLoaderAndStart(
|
|
|
|
std::move(keepalive_statistics_recorder),
|
2019-11-14 18:01:18 +00:00
|
|
|
std::move(network_usage_accumulator),
|
|
|
|
header_client_.is_bound() ? header_client_.get() : nullptr,
|
|
|
|
+ auth_client_.is_bound() ? auth_client_.get() : nullptr,
|
|
|
|
context_->origin_policy_manager());
|
|
|
|
cors_url_loader_factory_->OnLoaderCreated(std::move(loader));
|
|
|
|
}
|
|
|
|
diff --git a/services/network/url_loader_factory.h b/services/network/url_loader_factory.h
|
2020-03-11 11:15:07 +00:00
|
|
|
index 1a623585035487de061ba6476914992ea2f7ac88..caa19dcd4b99296e50f8e22bfc92a70ba14473d1 100644
|
2019-11-14 18:01:18 +00:00
|
|
|
--- a/services/network/url_loader_factory.h
|
|
|
|
+++ b/services/network/url_loader_factory.h
|
2020-03-11 11:15:07 +00:00
|
|
|
@@ -74,6 +74,7 @@ class URLLoaderFactory : public mojom::URLLoaderFactory {
|
2019-11-14 18:01:18 +00:00
|
|
|
scoped_refptr<ResourceSchedulerClient> resource_scheduler_client_;
|
|
|
|
mojo::Remote<mojom::TrustedURLLoaderHeaderClient> header_client_;
|
2020-03-11 11:15:07 +00:00
|
|
|
mojo::Remote<mojom::CrossOriginEmbedderPolicyReporter> coep_reporter_;
|
2019-11-14 18:01:18 +00:00
|
|
|
+ mojo::Remote<mojom::TrustedURLLoaderAuthClient> auth_client_;
|
|
|
|
|
|
|
|
// |cors_url_loader_factory_| owns this.
|
|
|
|
cors::CorsURLLoaderFactory* cors_url_loader_factory_;
|