1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
|
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_WEBUI_SETTINGS_SETTINGS_SECURITY_KEY_HANDLER_H_
#define CHROME_BROWSER_UI_WEBUI_SETTINGS_SETTINGS_SECURITY_KEY_HANDLER_H_
#include <memory>
#include <optional>
#include <string>
#include "base/memory/weak_ptr.h"
#include "base/values.h"
#include "build/build_config.h"
#include "chrome/browser/ui/webui/settings/settings_page_ui_handler.h"
#include "device/fido/bio/enrollment.h"
#include "device/fido/bio/enrollment_handler.h"
#include "device/fido/credential_management_handler.h"
#include "device/fido/fido_constants.h"
#include "device/fido/fido_discovery_factory.h"
namespace device {
struct AggregatedEnumerateCredentialsResponse;
enum class CredentialManagementStatus;
class SetPINRequestHandler;
class ResetRequestHandler;
} // namespace device
class LocalCredentialManagement;
namespace settings {
// Base class for message handlers on the "Security Keys" settings subpage.
class SecurityKeysHandlerBase : public SettingsPageUIHandler {
public:
SecurityKeysHandlerBase(const SecurityKeysHandlerBase&) = delete;
SecurityKeysHandlerBase& operator=(const SecurityKeysHandlerBase&) = delete;
protected:
SecurityKeysHandlerBase();
explicit SecurityKeysHandlerBase(
std::unique_ptr<device::FidoDiscoveryFactory> discovery_factory);
~SecurityKeysHandlerBase() override;
// Subclasses must implement close to invalidate all pending callbacks.
virtual void Close() = 0;
// Returns the discovery factory to be used for the request.
device::FidoDiscoveryFactory* discovery_factory() {
return discovery_factory_.get();
}
private:
void OnJavascriptAllowed() override;
void OnJavascriptDisallowed() override;
std::unique_ptr<device::FidoDiscoveryFactory> discovery_factory_ =
std::make_unique<device::FidoDiscoveryFactory>();
};
// SecurityKeysPINHandler processes messages from the "Create a PIN" dialog of
// the "Security Keys" settings subpage. An instance of this class is created
// for each settings tab and is destroyed when the tab is closed. See
// SecurityKeysPINBrowserProxy about the interface.
class SecurityKeysPINHandler : public SecurityKeysHandlerBase {
public:
SecurityKeysPINHandler();
~SecurityKeysPINHandler() override;
private:
enum class State {
kNone,
kStartSetPIN,
kGatherNewPIN,
kGatherChangePIN,
kSettingPIN,
};
void RegisterMessages() override;
void Close() override;
void HandleStartSetPIN(const base::Value::List& args);
void OnGatherPIN(uint32_t current_min_pin_length,
uint32_t new_min_pin_length,
std::optional<int64_t> num_retries);
void OnSetPINComplete(device::CtapDeviceResponseCode code);
void HandleSetPIN(const base::Value::List& args);
State state_ = State::kNone;
std::unique_ptr<device::SetPINRequestHandler> set_pin_;
std::string callback_id_;
base::WeakPtrFactory<SecurityKeysPINHandler> weak_factory_{this};
};
// SecurityKeysResetHandler processes messages from the "Reset your Security
// Key" dialog of the "Security Keys" settings subpage. An instance of this
// class is created for each settings tab and is destroyed when the tab is
// closed. See SecurityKeysResetBrowserProxy about the interface.
class SecurityKeysResetHandler : public SecurityKeysHandlerBase {
public:
SecurityKeysResetHandler();
~SecurityKeysResetHandler() override;
private:
enum class State {
kNone,
kStartReset,
kWaitingForResetNoCallbackYet,
kWaitingForResetHaveCallback,
kWaitingForCompleteReset,
};
void RegisterMessages() override;
void Close() override;
void HandleReset(const base::Value::List& args);
void OnResetSent();
void HandleCompleteReset(const base::Value::List& args);
void OnResetFinished(device::CtapDeviceResponseCode result);
State state_ = State::kNone;
std::unique_ptr<device::ResetRequestHandler> reset_;
std::optional<device::CtapDeviceResponseCode> reset_result_;
std::string callback_id_;
base::WeakPtrFactory<SecurityKeysResetHandler> weak_factory_{this};
};
// SecurityKeysCredentialHandler processes messages from the "Manage
// sign-in data" dialog of the "Security Keys" settings subpage. An instance of
// this class is created for each settings tab and is destroyed when the tab is
// closed. See SecurityKeysCredentialBrowserProxy about the interface.
class SecurityKeysCredentialHandler : public SecurityKeysHandlerBase {
public:
SecurityKeysCredentialHandler();
~SecurityKeysCredentialHandler() override;
protected:
explicit SecurityKeysCredentialHandler(
std::unique_ptr<device::FidoDiscoveryFactory> discovery_factory);
void HandleStart(const base::Value::List& args);
void HandlePIN(const base::Value::List& args);
void HandleUpdateUserInformation(const base::Value::List& args);
private:
enum class State {
kNone,
kStart,
kPIN,
kReady,
kGettingCredentials,
kDeletingCredentials,
kUpdatingUserInformation,
};
void RegisterMessages() override;
void Close() override;
void HandleEnumerate(const base::Value::List& args);
void HandleDelete(const base::Value::List& args);
void OnCredentialManagementReady();
void OnHaveCredentials(
device::CtapDeviceResponseCode status,
std::optional<std::vector<device::AggregatedEnumerateCredentialsResponse>>
responses,
std::optional<size_t> remaining_credentials);
void OnGatherPIN(device::CredentialManagementHandler::AuthenticatorProperties
authenticator_properties,
base::OnceCallback<void(std::string)>);
void OnCredentialsDeleted(device::CtapDeviceResponseCode status);
void OnUserInformationUpdated(device::CtapDeviceResponseCode status);
void OnFinished(device::CredentialManagementStatus status);
State state_ = State::kNone;
base::OnceCallback<void(std::string)> credential_management_provide_pin_cb_;
std::unique_ptr<device::CredentialManagementHandler> credential_management_;
std::string callback_id_;
base::WeakPtrFactory<SecurityKeysCredentialHandler> weak_factory_{this};
};
// SecurityKeysBioEnrollmentHandler processes messages from the "Manage
// fingerprints" dialog of the "Security Keys" settings subpage. An instance of
// this class is created for each settings tab and is destroyed when the tab is
// closed. See SecurityKeysBioEnrollProxy about the interface.
class SecurityKeysBioEnrollmentHandler : public SecurityKeysHandlerBase {
public:
SecurityKeysBioEnrollmentHandler();
~SecurityKeysBioEnrollmentHandler() override;
protected:
explicit SecurityKeysBioEnrollmentHandler(
std::unique_ptr<device::FidoDiscoveryFactory> discovery_factory);
void HandleStart(const base::Value::List& args);
void HandleProvidePIN(const base::Value::List& args);
void HandleStartEnrolling(const base::Value::List& args);
private:
enum class State {
kNone,
kStart,
kGatherPIN,
kReady,
kEnumerating,
kEnrolling,
kDeleting,
kRenaming,
};
void RegisterMessages() override;
void Close() override;
void OnReady(device::BioEnrollmentHandler::SensorInfo sensor_info);
void OnError(device::BioEnrollmentHandler::Error error);
void OnGatherPIN(uint32_t min_pin_length,
int64_t num_retries,
base::OnceCallback<void(std::string)>);
void HandleGetSensorInfo(const base::Value::List& args);
void HandleEnumerate(const base::Value::List& args);
void OnHaveEnumeration(
device::CtapDeviceResponseCode,
std::optional<std::map<std::vector<uint8_t>, std::string>>);
void OnEnrollingResponse(device::BioEnrollmentSampleStatus, uint8_t);
void OnEnrollmentFinished(device::CtapDeviceResponseCode,
std::vector<uint8_t> template_id);
void OnHavePostEnrollmentEnumeration(
std::vector<uint8_t> enrolled_template_id,
device::CtapDeviceResponseCode code,
std::optional<std::map<std::vector<uint8_t>, std::string>> enrollments);
void HandleDelete(const base::Value::List& args);
void OnDelete(device::CtapDeviceResponseCode);
void HandleRename(const base::Value::List& args);
void OnRename(device::CtapDeviceResponseCode);
void HandleCancel(const base::Value::List& args);
State state_ = State::kNone;
std::string callback_id_;
base::OnceCallback<void(std::string)> provide_pin_cb_;
std::unique_ptr<device::BioEnrollmentHandler> bio_;
device::BioEnrollmentHandler::SensorInfo sensor_info_;
base::WeakPtrFactory<SecurityKeysBioEnrollmentHandler> weak_factory_{this};
};
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC)
class PasskeysHandler : public SettingsPageUIHandler {
public:
PasskeysHandler();
explicit PasskeysHandler(
std::unique_ptr<LocalCredentialManagement> local_cred_man);
~PasskeysHandler() override;
protected:
void RegisterMessages() override;
void OnJavascriptAllowed() override;
void OnJavascriptDisallowed() override;
void HandleEdit(const base::Value::List& args);
void OnEditComplete(std::string callback_id, bool edit_ok);
void HandleDelete(const base::Value::List& args);
void OnDeleteComplete(std::string callback_id, bool delete_ok);
private:
void HandleHasPasskeys(const base::Value::List& args);
void OnHasPasskeysComplete(std::string callback_id, bool has_passkeys);
void HandleManagePasskeys(const base::Value::List& args);
void HandleEnumerate(const base::Value::List& args);
void DoEnumerate(std::string callback_id);
void OnEnumerateComplete(
std::string callback_id,
std::optional<std::vector<device::DiscoverableCredentialMetadata>>
credentials);
std::unique_ptr<LocalCredentialManagement> local_cred_man_{nullptr};
base::WeakPtrFactory<PasskeysHandler> weak_factory_{this};
};
#endif
} // namespace settings
#endif // CHROME_BROWSER_UI_WEBUI_SETTINGS_SETTINGS_SECURITY_KEY_HANDLER_H_
|