get_assertion_task.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // Copyright 2018 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_GET_ASSERTION_TASK_H_
  5. #define DEVICE_FIDO_GET_ASSERTION_TASK_H_
  6. #include <stdint.h>
  7. #include <memory>
  8. #include <vector>
  9. #include "base/callback.h"
  10. #include "base/component_export.h"
  11. #include "base/memory/weak_ptr.h"
  12. #include "device/fido/ctap_get_assertion_request.h"
  13. #include "device/fido/ctap_make_credential_request.h"
  14. #include "device/fido/device_operation.h"
  15. #include "device/fido/fido_constants.h"
  16. #include "device/fido/fido_task.h"
  17. #include "device/fido/pin.h"
  18. #include "third_party/abseil-cpp/absl/types/optional.h"
  19. namespace cbor {
  20. class Value;
  21. }
  22. namespace device {
  23. class AuthenticatorGetAssertionResponse;
  24. class AuthenticatorMakeCredentialResponse;
  25. // Represents per device sign operation on CTAP1/CTAP2 devices.
  26. // https://fidoalliance.org/specs/fido-v2.0-rd-20161004/fido-client-to-authenticator-protocol-v2.0-rd-20161004.html#authenticatorgetassertion
  27. class COMPONENT_EXPORT(DEVICE_FIDO) GetAssertionTask : public FidoTask {
  28. public:
  29. using GetAssertionTaskCallback = base::OnceCallback<void(
  30. CtapDeviceResponseCode,
  31. absl::optional<AuthenticatorGetAssertionResponse>)>;
  32. using SignOperation = DeviceOperation<CtapGetAssertionRequest,
  33. AuthenticatorGetAssertionResponse>;
  34. using RegisterOperation =
  35. DeviceOperation<CtapMakeCredentialRequest,
  36. AuthenticatorMakeCredentialResponse>;
  37. GetAssertionTask(FidoDevice* device,
  38. CtapGetAssertionRequest request,
  39. CtapGetAssertionOptions options,
  40. GetAssertionTaskCallback callback);
  41. GetAssertionTask(const GetAssertionTask&) = delete;
  42. GetAssertionTask& operator=(const GetAssertionTask&) = delete;
  43. ~GetAssertionTask() override;
  44. // FidoTask:
  45. void Cancel() override;
  46. // StringFixupPredicate indicates which fields of a GetAssertion
  47. // response may contain truncated UTF-8 strings. See
  48. // |Ctap2DeviceOperation::CBORPathPredicate|.
  49. static bool StringFixupPredicate(const std::vector<const cbor::Value*>& path);
  50. private:
  51. // FidoTask:
  52. void StartTask() override;
  53. void GetAssertion();
  54. void U2fSign();
  55. CtapGetAssertionRequest NextSilentRequest();
  56. // HandleResponse is the callback to a CTAP2 assertion request that requested
  57. // user-presence.
  58. void HandleResponse(
  59. std::vector<PublicKeyCredentialDescriptor> allow_list,
  60. CtapDeviceResponseCode response_code,
  61. absl::optional<AuthenticatorGetAssertionResponse> response_data);
  62. // HandleResponseToSilentRequest is a callback to a request without user-
  63. // presence requested used to silently probe credentials from the allow list.
  64. void HandleResponseToSilentRequest(
  65. CtapDeviceResponseCode response_code,
  66. absl::optional<AuthenticatorGetAssertionResponse> response_data);
  67. // HandleDummyMakeCredentialComplete is the callback for the dummy credential
  68. // creation request that will be triggered, if needed, to get a touch.
  69. void HandleDummyMakeCredentialComplete(
  70. CtapDeviceResponseCode response_code,
  71. absl::optional<AuthenticatorMakeCredentialResponse> response_data);
  72. void MaybeSetPRFParameters(
  73. CtapGetAssertionRequest* request,
  74. const CtapGetAssertionOptions::PRFInput* maybe_inputs);
  75. void MaybeRevertU2fFallbackAndInvokeCallback(
  76. CtapDeviceResponseCode status,
  77. absl::optional<AuthenticatorGetAssertionResponse> response);
  78. CtapGetAssertionRequest request_;
  79. CtapGetAssertionOptions options_;
  80. std::vector<std::vector<PublicKeyCredentialDescriptor>> allow_list_batches_;
  81. size_t current_allow_list_batch_ = 0;
  82. std::unique_ptr<SignOperation> sign_operation_;
  83. std::unique_ptr<RegisterOperation> dummy_register_operation_;
  84. GetAssertionTaskCallback callback_;
  85. std::unique_ptr<pin::HMACSecretRequest> hmac_secret_request_;
  86. bool canceled_ = false;
  87. base::WeakPtrFactory<GetAssertionTask> weak_factory_{this};
  88. };
  89. } // namespace device
  90. #endif // DEVICE_FIDO_GET_ASSERTION_TASK_H_