Jun Choi | 6676116 | 2018-07-02 23:03:08 | [diff] [blame] | 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 | |
| 5 | #ifndef DEVICE_FIDO_VIRTUAL_CTAP2_DEVICE_H_ |
| 6 | #define DEVICE_FIDO_VIRTUAL_CTAP2_DEVICE_H_ |
| 7 | |
| 8 | #include <stdint.h> |
| 9 | |
| 10 | #include <memory> |
| 11 | #include <vector> |
| 12 | |
| 13 | #include "base/component_export.h" |
| 14 | #include "base/containers/span.h" |
| 15 | #include "base/macros.h" |
| 16 | #include "base/memory/scoped_refptr.h" |
| 17 | #include "base/optional.h" |
Adam Langley | e0e46cdf | 2018-10-29 19:23:16 | [diff] [blame] | 18 | #include "components/cbor/values.h" |
Jun Choi | 6676116 | 2018-07-02 23:03:08 | [diff] [blame] | 19 | #include "device/fido/attested_credential_data.h" |
| 20 | #include "device/fido/authenticator_data.h" |
| 21 | #include "device/fido/authenticator_supported_options.h" |
Martin Kreichgauer | 90c62574 | 2018-10-31 04:24:15 | [diff] [blame] | 22 | #include "device/fido/ctap_get_assertion_request.h" |
| 23 | #include "device/fido/ctap_make_credential_request.h" |
Jun Choi | 6676116 | 2018-07-02 23:03:08 | [diff] [blame] | 24 | #include "device/fido/fido_constants.h" |
| 25 | #include "device/fido/virtual_fido_device.h" |
| 26 | |
| 27 | namespace device { |
| 28 | |
| 29 | class COMPONENT_EXPORT(DEVICE_FIDO) VirtualCtap2Device |
| 30 | : public VirtualFidoDevice { |
| 31 | public: |
| 32 | VirtualCtap2Device(); |
| 33 | explicit VirtualCtap2Device(scoped_refptr<State> state); |
| 34 | ~VirtualCtap2Device() override; |
| 35 | |
| 36 | // FidoDevice: |
| 37 | void Cancel() override; |
| 38 | void DeviceTransact(std::vector<uint8_t> command, DeviceCallback cb) override; |
| 39 | base::WeakPtr<FidoDevice> GetWeakPtr() override; |
| 40 | |
Adam Langley | 32f3874 | 2019-02-06 18:50:20 | [diff] [blame] | 41 | void SetAuthenticatorSupportedOptions( |
| 42 | const AuthenticatorSupportedOptions& options); |
Jun Choi | 6676116 | 2018-07-02 23:03:08 | [diff] [blame] | 43 | |
| 44 | private: |
| 45 | CtapDeviceResponseCode OnMakeCredential(base::span<const uint8_t> request, |
| 46 | std::vector<uint8_t>* response); |
| 47 | |
Jun Choi | 3106cc6 | 2018-07-03 18:22:58 | [diff] [blame] | 48 | CtapDeviceResponseCode OnGetAssertion(base::span<const uint8_t> request, |
| 49 | std::vector<uint8_t>* response); |
| 50 | |
Jun Choi | 6676116 | 2018-07-02 23:03:08 | [diff] [blame] | 51 | CtapDeviceResponseCode OnAuthenticatorGetInfo( |
| 52 | std::vector<uint8_t>* response) const; |
| 53 | |
| 54 | AuthenticatorData ConstructAuthenticatorData( |
| 55 | base::span<const uint8_t, kRpIdHashLength> rp_id_hash, |
Adam Langley | 52f83d8 | 2019-02-08 19:35:17 | [diff] [blame] | 56 | bool user_verified, |
Jun Choi | 3106cc6 | 2018-07-03 18:22:58 | [diff] [blame] | 57 | uint32_t current_signature_count, |
Adam Langley | d072d4f | 2018-10-18 16:46:06 | [diff] [blame] | 58 | base::Optional<AttestedCredentialData> attested_credential_data, |
Adam Langley | b4f12f9 | 2018-10-26 21:00:02 | [diff] [blame] | 59 | base::Optional<cbor::Value> extensions); |
Jun Choi | 6676116 | 2018-07-02 23:03:08 | [diff] [blame] | 60 | |
| 61 | AuthenticatorGetInfoResponse device_info_; |
| 62 | base::WeakPtrFactory<FidoDevice> weak_factory_; |
| 63 | |
| 64 | DISALLOW_COPY_AND_ASSIGN(VirtualCtap2Device); |
| 65 | }; |
| 66 | |
Martin Kreichgauer | 90c62574 | 2018-10-31 04:24:15 | [diff] [blame] | 67 | // Decodes a CBOR-encoded CTAP2 authenticatorMakeCredential request message. The |
| 68 | // request's client_data_json() value will be empty, and the hashed client data |
| 69 | // is returned separately. |
| 70 | COMPONENT_EXPORT(DEVICE_FIDO) |
| 71 | base::Optional<std::pair<CtapMakeCredentialRequest, |
| 72 | CtapMakeCredentialRequest::ClientDataHash>> |
| 73 | ParseCtapMakeCredentialRequest(base::span<const uint8_t> request_bytes); |
| 74 | |
| 75 | // Decodes a CBOR-encoded CTAP2 authenticatorGetAssertion request message. The |
| 76 | // request's client_data_json() value will be empty, and the hashed client data |
| 77 | // is returned separately. |
| 78 | COMPONENT_EXPORT(DEVICE_FIDO) |
| 79 | base::Optional< |
| 80 | std::pair<CtapGetAssertionRequest, CtapGetAssertionRequest::ClientDataHash>> |
| 81 | ParseCtapGetAssertionRequest(base::span<const uint8_t> request_bytes); |
| 82 | |
Jun Choi | 6676116 | 2018-07-02 23:03:08 | [diff] [blame] | 83 | } // namespace device |
| 84 | |
| 85 | #endif // DEVICE_FIDO_VIRTUAL_CTAP2_DEVICE_H_ |