Skip to content

Commit

Permalink
chore: cherry-pick eac3d9283d11 from chromium
Browse files Browse the repository at this point in the history
  • Loading branch information
ppontes committed Jun 16, 2020
1 parent 2a4aaa9 commit c2cd1d1
Show file tree
Hide file tree
Showing 14 changed files with 327 additions and 69 deletions.
1 change: 1 addition & 0 deletions patches/chromium/.patches
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,4 @@ fix_swap_global_proxies_before_initializing_the_windows_proxies.patch
fix_default_to_ntlm_v2_in_network_service.patch
a11y_allows_klistboxoption_as_an_item_to_kgroup.patch
fix_handling_non_client_pointer_events_from_pen_on_windows_10.patch
cherry-pick-eac3d9283d11.patch
257 changes: 257 additions & 0 deletions patches/chromium/cherry-pick-eac3d9283d11.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,257 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Martin Kreichgauer <martinkr@google.com>
Date: Wed, 3 Jun 2020 21:07:08 +0000
Subject: Revert "fido: add FidoDiscoveryFactory::ResetRequestState()"

This reverts commit 9f151687295d2547bc3d7c1542b80505552f0f87.

Reason for revert: The original change makes an invalid assumptions
about the lifetime of FidoDiscoveryFactory (crbug/1087158). Instances of
FidoDiscoveryFactory generally belong to the
AuthenticatorRequestClientDelegate and as such should outlive the
WebAuthn request. As an exception, instances obtained via
AuthenticatorEnvironmentImpl::GetDiscoveryFactoryOverride() may be
unregistered and freed before the request finishes.

This revert is safe because the caBLE data reset by ResetRequestState
(a) only gets set in the first place if the
WebAuthenticationPhoneSupport flag is on (which is default-off); and (b)
gets set anew for every single request, so it will never be reused
across requests.

Bug: 1087158

Original change's description:
> fido: add FidoDiscoveryFactory::ResetRequestState()
>
> FidoDiscoveryFactory instances generally outlive a WebAuthn request, but
> some of the state is specific to a single request (caBLE pairing and QR
> code generation keys). This is currently not an issue, because
> AuthenticatorCommon explicitly resets all that state at the beginning of
> the request. But I worry that we accidentally break that and leak state
> between requests. To mitigate, introduce an explicit ResetRequestState
> function and call it in AuthenticatorCommon::Cleanup().
>
> Change-Id: I8333a3b14d189d7977cde17cbfe44b4b8dcf6ee2
> Reviewed-on:
> https://chromium-review.googlesource.com/c/chromium/src/+/1793792
> Commit-Queue: Martin Kreichgauer <martinkr@chromium.org>
> Reviewed-by: Nina Satragno <nsatragno@chromium.org>
> Reviewed-by: Adam Langley <agl@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#696593}

Change-Id: I3b1ea46b9b1d5912cbc7ab9a82851e5132335ea8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2228136
Reviewed-by: Nina Satragno <nsatragno@chromium.org>
Reviewed-by: Adam Langley <agl@chromium.org>
Commit-Queue: Martin Kreichgauer <martinkr@google.com>
Cr-Commit-Position: refs/heads/master@{#774784}

diff --git a/content/browser/webauth/authenticator_common.cc b/content/browser/webauth/authenticator_common.cc
index cea81abea6f8059ff09de9c9a55c305446a0b661..7721eac960bd69351bd6963871f9f1bb96756915 100644
--- a/content/browser/webauth/authenticator_common.cc
+++ b/content/browser/webauth/authenticator_common.cc
@@ -579,13 +579,12 @@ AuthenticatorCommon::CreateRequestDelegate(std::string relying_party_id) {

void AuthenticatorCommon::StartMakeCredentialRequest(
bool allow_skipping_pin_touch) {
- discovery_factory_ =
+ device::FidoDiscoveryFactory* discovery_factory =
AuthenticatorEnvironmentImpl::GetInstance()->GetDiscoveryFactoryOverride(
static_cast<RenderFrameHostImpl*>(render_frame_host_)
->frame_tree_node());
- if (!discovery_factory_) {
- discovery_factory_ = request_delegate_->GetDiscoveryFactory();
- }
+ if (!discovery_factory)
+ discovery_factory = request_delegate_->GetDiscoveryFactory();

if (base::FeatureList::IsEnabled(device::kWebAuthPhoneSupport)) {
std::vector<device::CableDiscoveryData> cable_pairings =
@@ -597,13 +596,13 @@ void AuthenticatorCommon::StartMakeCredentialRequest(
if (request_delegate_->SetCableTransportInfo(
/*cable_extension_provided=*/false, have_paired_phones,
qr_generator_key)) {
- discovery_factory_->set_cable_data(cable_pairings,
- std::move(qr_generator_key));
+ discovery_factory->set_cable_data(cable_pairings,
+ std::move(qr_generator_key));
}
}

request_ = std::make_unique<device::MakeCredentialRequestHandler>(
- connector_, discovery_factory_,
+ connector_, discovery_factory,
GetTransports(caller_origin_, transports_),
*ctap_make_credential_request_, *authenticator_selection_criteria_,
allow_skipping_pin_touch,
@@ -634,13 +633,12 @@ void AuthenticatorCommon::StartMakeCredentialRequest(

void AuthenticatorCommon::StartGetAssertionRequest(
bool allow_skipping_pin_touch) {
- discovery_factory_ =
+ device::FidoDiscoveryFactory* discovery_factory =
AuthenticatorEnvironmentImpl::GetInstance()->GetDiscoveryFactoryOverride(
static_cast<RenderFrameHostImpl*>(render_frame_host_)
->frame_tree_node());
- if (!discovery_factory_) {
- discovery_factory_ = request_delegate_->GetDiscoveryFactory();
- }
+ if (!discovery_factory)
+ discovery_factory = request_delegate_->GetDiscoveryFactory();

std::vector<device::CableDiscoveryData> cable_pairings;
bool have_cable_extension = false;
@@ -664,12 +662,12 @@ void AuthenticatorCommon::StartGetAssertionRequest(
if ((!cable_pairings.empty() || qr_generator_key.has_value()) &&
request_delegate_->SetCableTransportInfo(
have_cable_extension, have_paired_phones, qr_generator_key)) {
- discovery_factory_->set_cable_data(std::move(cable_pairings),
- std::move(qr_generator_key));
+ discovery_factory->set_cable_data(std::move(cable_pairings),
+ std::move(qr_generator_key));
}

request_ = std::make_unique<device::GetAssertionRequestHandler>(
- connector_, discovery_factory_,
+ connector_, discovery_factory,
GetTransports(caller_origin_, transports_), *ctap_get_assertion_request_,
allow_skipping_pin_touch,
base::BindOnce(&AuthenticatorCommon::OnSignResponse,
@@ -1528,15 +1526,6 @@ void AuthenticatorCommon::Cleanup() {

timer_->Stop();
request_.reset();
- if (discovery_factory_) {
- // The FidoDiscoveryFactory instance may have been obtained via
- // AuthenticatorEnvironmentImpl::GetDiscoveryFactoryOverride() (in unit
- // tests or when WebDriver injected a virtual authenticator), in which case
- // it may be long-lived and handle more than one request. Hence, we need to
- // reset all per-request state before deleting its pointer.
- discovery_factory_->ResetRequestState();
- discovery_factory_ = nullptr;
- }
request_delegate_.reset();
make_credential_response_callback_.Reset();
get_assertion_response_callback_.Reset();
diff --git a/content/browser/webauth/authenticator_common.h b/content/browser/webauth/authenticator_common.h
index a7879a77f337e9d31afb954c2fc397cedb74256f..bd241cc8fc34ce9d831ce5fcfb97fbd6997237f0 100644
--- a/content/browser/webauth/authenticator_common.h
+++ b/content/browser/webauth/authenticator_common.h
@@ -194,7 +194,6 @@ class CONTENT_EXPORT AuthenticatorCommon {
RenderFrameHost* const render_frame_host_;
service_manager::Connector* connector_ = nullptr;
base::flat_set<device::FidoTransportProtocol> transports_;
- device::FidoDiscoveryFactory* discovery_factory_ = nullptr;
std::unique_ptr<device::FidoRequestHandlerBase> request_;
blink::mojom::Authenticator::MakeCredentialCallback
make_credential_response_callback_;
diff --git a/device/fido/fido_discovery_factory.cc b/device/fido/fido_discovery_factory.cc
index 05d5f211b17021ac3397fd79b7f210bdf6681def..dc404ba31c2158887c3f946aecba33fb672189f0 100644
--- a/device/fido/fido_discovery_factory.cc
+++ b/device/fido/fido_discovery_factory.cc
@@ -46,10 +46,6 @@ std::unique_ptr<FidoDiscoveryBase> CreateUsbFidoDiscovery(
FidoDiscoveryFactory::FidoDiscoveryFactory() = default;
FidoDiscoveryFactory::~FidoDiscoveryFactory() = default;

-void FidoDiscoveryFactory::ResetRequestState() {
- request_state_ = {};
-}
-
std::unique_ptr<FidoDiscoveryBase> FidoDiscoveryFactory::Create(
FidoTransportProtocol transport,
service_manager::Connector* connector) {
@@ -59,13 +55,10 @@ std::unique_ptr<FidoDiscoveryBase> FidoDiscoveryFactory::Create(
case FidoTransportProtocol::kBluetoothLowEnergy:
return std::make_unique<FidoBleDiscovery>();
case FidoTransportProtocol::kCloudAssistedBluetoothLowEnergy:
- if (request_state_.cable_data_.has_value() ||
- request_state_.qr_generator_key_.has_value()) {
+ if (cable_data_.has_value() || qr_generator_key_.has_value()) {
return std::make_unique<FidoCableDiscovery>(
- request_state_.cable_data_.value_or(
- std::vector<CableDiscoveryData>()),
- request_state_.qr_generator_key_,
- request_state_.cable_pairing_callback_);
+ cable_data_.value_or(std::vector<CableDiscoveryData>()),
+ qr_generator_key_, cable_pairing_callback_);
}
return nullptr;
case FidoTransportProtocol::kNearFieldCommunication:
@@ -88,14 +81,14 @@ std::unique_ptr<FidoDiscoveryBase> FidoDiscoveryFactory::Create(
void FidoDiscoveryFactory::set_cable_data(
std::vector<CableDiscoveryData> cable_data,
base::Optional<QRGeneratorKey> qr_generator_key) {
- request_state_.cable_data_ = std::move(cable_data);
- request_state_.qr_generator_key_ = std::move(qr_generator_key);
+ cable_data_ = std::move(cable_data);
+ qr_generator_key_ = std::move(qr_generator_key);
}

void FidoDiscoveryFactory::set_cable_pairing_callback(
base::RepeatingCallback<void(std::unique_ptr<CableDiscoveryData>)>
pairing_callback) {
- request_state_.cable_pairing_callback_.emplace(std::move(pairing_callback));
+ cable_pairing_callback_.emplace(std::move(pairing_callback));
}

#if defined(OS_WIN)
@@ -121,7 +114,4 @@ FidoDiscoveryFactory::MaybeCreateWinWebAuthnApiDiscovery() {
}
#endif // defined(OS_WIN)

-FidoDiscoveryFactory::RequestState::RequestState() = default;
-FidoDiscoveryFactory::RequestState::~RequestState() = default;
-
} // namespace device
diff --git a/device/fido/fido_discovery_factory.h b/device/fido/fido_discovery_factory.h
index 63133e7dc2bca9dc763881d74ca1e017f5799df7..3723225f316e4766d96b24f135980321bb0e5308 100644
--- a/device/fido/fido_discovery_factory.h
+++ b/device/fido/fido_discovery_factory.h
@@ -38,18 +38,6 @@ class COMPONENT_EXPORT(DEVICE_FIDO) FidoDiscoveryFactory {
FidoDiscoveryFactory();
virtual ~FidoDiscoveryFactory();

- // Resets all fields that are only meaningful for the duration of a single
- // request to a safe default.
- //
- // The "regular" FidoDiscoveryFactory is owned by the
- // AuthenticatorClientRequestDelegate and lives only for a single request.
- // Instances returned from
- // AuthenticatorEnvironmentImpl::GetDiscoveryFactoryOverride(), which are
- // used in unit tests or by the WebDriver virtual authenticators, are
- // long-lived and may handle multiple WebAuthn requests. Hence, they will be
- // reset at the beginning of each new request.
- void ResetRequestState();
-
// Instantiates a FidoDiscoveryBase for the given transport.
//
// FidoTransportProtocol::kUsbHumanInterfaceDevice requires specifying a
@@ -89,22 +77,14 @@ class COMPONENT_EXPORT(DEVICE_FIDO) FidoDiscoveryFactory {
#endif // defined(OS_WIN)

private:
- // RequestState holds configuration data that is only meaningful for a
- // single WebAuthn request.
- struct RequestState {
- RequestState();
- ~RequestState();
- base::Optional<std::vector<CableDiscoveryData>> cable_data_;
- base::Optional<QRGeneratorKey> qr_generator_key_;
- base::Optional<
- base::RepeatingCallback<void(std::unique_ptr<CableDiscoveryData>)>>
- cable_pairing_callback_;
- };
-
- RequestState request_state_;
#if defined(OS_MACOSX)
base::Optional<fido::mac::AuthenticatorConfig> mac_touch_id_config_;
#endif // defined(OS_MACOSX)
+ base::Optional<std::vector<CableDiscoveryData>> cable_data_;
+ base::Optional<QRGeneratorKey> qr_generator_key_;
+ base::Optional<
+ base::RepeatingCallback<void(std::unique_ptr<CableDiscoveryData>)>>
+ cable_pairing_callback_;
#if defined(OS_WIN)
WinWebAuthnApi* win_webauthn_api_ = nullptr;
#endif // defined(OS_WIN)
2 changes: 1 addition & 1 deletion patches/chromium/command-ismediakey.patch
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ index 85378bb565de617b1bd611d28c8714361747a357..36de4c0b0353be2418dacd388e92d7c3
}
return VKEY_UNKNOWN;
}
@@ -192,7 +198,10 @@ CGEventRef MediaKeysListenerImpl::EventTapCallback(CGEventTapProxy proxy,
@@ -192,7 +198,10 @@ static CGEventRef EventTapCallback(CGEventTapProxy proxy,
int key_code = (data1 & 0xFFFF0000) >> 16;
if (key_code != NX_KEYTYPE_PLAY && key_code != NX_KEYTYPE_NEXT &&
key_code != NX_KEYTYPE_PREVIOUS && key_code != NX_KEYTYPE_FAST &&
Expand Down
2 changes: 1 addition & 1 deletion patches/chromium/disable_compositor_recycling.patch
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ diff --git a/content/browser/renderer_host/render_widget_host_view_mac.mm b/cont
index 5bec9c5d258c06fe338c8abe3e233e0b9b937234..92d2fa2343d1272dcadfa37c07ed368d18488ef8 100644
--- a/content/browser/renderer_host/render_widget_host_view_mac.mm
+++ b/content/browser/renderer_host/render_widget_host_view_mac.mm
@@ -477,7 +477,11 @@ void RenderWidgetHostViewMac::WasOccluded() {
@@ -477,7 +477,11 @@
return;

host()->WasHidden();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ diff --git a/chrome/browser/extensions/global_shortcut_listener_mac.mm b/chrome/
index befe726af9c10b1563a7fc0bb77cc55f65943d5c..bac51f33f35f96fe4ecc764cf5ca887176642f74 100644
--- a/chrome/browser/extensions/global_shortcut_listener_mac.mm
+++ b/chrome/browser/extensions/global_shortcut_listener_mac.mm
@@ -39,7 +39,7 @@ GlobalShortcutListenerMac::GlobalShortcutListenerMac()
@@ -39,7 +39,7 @@
// global MediaKeysListener to receive media keys.
if (!content::MediaKeysListenerManager::IsMediaKeysListenerManagerEnabled()) {
media_keys_listener_ = ui::MediaKeysListener::Create(
Expand Down
6 changes: 3 additions & 3 deletions patches/chromium/mas-cfisobjc.patch
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ diff --git a/base/mac/foundation_util.mm b/base/mac/foundation_util.mm
index 2a83d4d8158422c1056725679309c6ced1e531bd..f52934712f8de78193127c426d02982b36e9d422 100644
--- a/base/mac/foundation_util.mm
+++ b/base/mac/foundation_util.mm
@@ -27,7 +27,6 @@ CFTypeID SecKeyGetTypeID();
@@ -27,7 +27,6 @@
#if !defined(OS_IOS)
CFTypeID SecACLGetTypeID();
CFTypeID SecTrustedApplicationGetTypeID();
-Boolean _CFIsObjC(CFTypeID typeID, CFTypeRef obj);
#endif
} // extern "C"

@@ -316,8 +315,7 @@ NSFont* CFToNSCast(CTFontRef cf_val) {
@@ -316,8 +315,7 @@ void SetBaseBundleID(const char* new_base_bundle_id) {
const_cast<NSFont*>(reinterpret_cast<const NSFont*>(cf_val));
DCHECK(!cf_val ||
CTFontGetTypeID() == CFGetTypeID(cf_val) ||
Expand All @@ -27,7 +27,7 @@ index 2a83d4d8158422c1056725679309c6ced1e531bd..f52934712f8de78193127c426d02982b
return ns_val;
}

@@ -385,9 +383,6 @@ CFCast<CTFontRef>(const CFTypeRef& cf_val) {
@@ -385,9 +383,6 @@ CTFontRef NSToCFCast(NSFont* ns_val) {
return (CTFontRef)(cf_val);
}

Expand Down
6 changes: 3 additions & 3 deletions patches/chromium/mas_blink_no_private_api.patch
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ index 94afefcee81b87c05bf9b1199d90d3d4b5ea84a6..2ec7f04c71824b47de1ddbf1f0e8625d
extern "C" {

// Kill ring calls. Would be better to use NSKillRing.h, but that's not
@@ -39,38 +40,53 @@ NSString* _NSYankFromKillRing();
@@ -39,38 +40,53 @@
void _NSNewKillRingSequence();
void _NSSetKillRingToYankedState();
}
Expand Down Expand Up @@ -92,7 +92,7 @@ index 8f4ae94bc1d8188d041654c50511f3346eee79de..fa06f47abbff3dcda937bf0b794f616e

namespace blink {

@@ -95,10 +97,12 @@ bool ThemePainterMac::PaintTextField(const Node* node,
@@ -95,10 +97,12 @@ void _NSDrawCarbonThemeListBox(NSRect frame,
// behavior change while remaining a fragile solution.
// https://bugs.chromium.org/p/chromium/issues/detail?id=658085#c3
if (!use_ns_text_field_cell) {
Expand All @@ -105,7 +105,7 @@ index 8f4ae94bc1d8188d041654c50511f3346eee79de..fa06f47abbff3dcda937bf0b794f616e
return false;
}

@@ -186,10 +190,12 @@ bool ThemePainterMac::PaintTextArea(const Node* node,
@@ -186,10 +190,12 @@ void _NSDrawCarbonThemeListBox(NSRect frame,
const IntRect& r) {
ScopedColorSchemeAppearance appearance(style.UsedColorScheme());
LocalCurrentGraphicsContext local_context(paint_info.context, r);
Expand Down

0 comments on commit c2cd1d1

Please sign in to comment.