reset_request_handler.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright 2019 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. #ifndef DEVICE_FIDO_RESET_REQUEST_HANDLER_H_
  5. #define DEVICE_FIDO_RESET_REQUEST_HANDLER_H_
  6. #include <memory>
  7. #include "base/callback.h"
  8. #include "base/component_export.h"
  9. #include "base/containers/flat_set.h"
  10. #include "base/memory/weak_ptr.h"
  11. #include "base/sequence_checker.h"
  12. #include "device/fido/fido_discovery_factory.h"
  13. #include "device/fido/fido_request_handler_base.h"
  14. #include "device/fido/fido_transport_protocol.h"
  15. namespace device {
  16. class FidoAuthenticator;
  17. namespace pin {
  18. struct EmptyResponse;
  19. }
  20. // ResetRequestHandler is a simple state machine that gets a touch from an
  21. // authenticator and then sends a CTAP2 reset request. This is expected to be
  22. // driven by Settings UI for users to manually reset authenticators.
  23. class COMPONENT_EXPORT(DEVICE_FIDO) ResetRequestHandler
  24. : public FidoRequestHandlerBase {
  25. public:
  26. // ResetSentCallback will be run once an authenticator has been touched and a
  27. // reset command has been sent to it. This will always occur before
  28. // |FinishedCallback|.
  29. using ResetSentCallback = base::OnceCallback<void()>;
  30. // FinishedCallback will be called once this process has completed. If the
  31. // status is |kCtap1ErrInvalidCommand| then the user may have selected a non-
  32. // CTAP2 authenticator, in which case no reset command was ever sent.
  33. // Otherwise the status is the result of the reset command.
  34. using FinishedCallback = base::OnceCallback<void(CtapDeviceResponseCode)>;
  35. ResetRequestHandler(
  36. const base::flat_set<FidoTransportProtocol>& supported_transports,
  37. ResetSentCallback reset_sent_callback,
  38. FinishedCallback finished_callback,
  39. std::unique_ptr<FidoDiscoveryFactory> fido_discovery_factory =
  40. std::make_unique<FidoDiscoveryFactory>());
  41. ResetRequestHandler(const ResetRequestHandler&) = delete;
  42. ResetRequestHandler& operator=(const ResetRequestHandler&) = delete;
  43. ~ResetRequestHandler() override;
  44. private:
  45. // FidoRequestHandlerBase:
  46. void DispatchRequest(FidoAuthenticator* authenticator) override;
  47. void OnTouch(FidoAuthenticator* authenticator);
  48. void OnResetComplete(CtapDeviceResponseCode status,
  49. absl::optional<pin::EmptyResponse> response);
  50. ResetSentCallback reset_sent_callback_;
  51. FinishedCallback finished_callback_;
  52. bool processed_touch_ = false;
  53. std::unique_ptr<FidoDiscoveryFactory> fido_discovery_factory_;
  54. SEQUENCE_CHECKER(my_sequence_checker_);
  55. base::WeakPtrFactory<ResetRequestHandler> weak_factory_{this};
  56. };
  57. } // namespace device
  58. #endif // DEVICE_FIDO_RESET_REQUEST_HANDLER_H_