blob: 9925fb56a1ae59a7428aa4f2001c9458ba4e8b16 [file] [log] [blame]
Jun Choi66761162018-07-02 23:03:081// 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 Langleye0e46cdf2018-10-29 19:23:1618#include "components/cbor/values.h"
Jun Choi66761162018-07-02 23:03:0819#include "device/fido/attested_credential_data.h"
20#include "device/fido/authenticator_data.h"
21#include "device/fido/authenticator_supported_options.h"
Martin Kreichgauer90c625742018-10-31 04:24:1522#include "device/fido/ctap_get_assertion_request.h"
23#include "device/fido/ctap_make_credential_request.h"
Jun Choi66761162018-07-02 23:03:0824#include "device/fido/fido_constants.h"
25#include "device/fido/virtual_fido_device.h"
26
27namespace device {
28
29class 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 Langley32f38742019-02-06 18:50:2041 void SetAuthenticatorSupportedOptions(
42 const AuthenticatorSupportedOptions& options);
Jun Choi66761162018-07-02 23:03:0843
44 private:
45 CtapDeviceResponseCode OnMakeCredential(base::span<const uint8_t> request,
46 std::vector<uint8_t>* response);
47
Jun Choi3106cc62018-07-03 18:22:5848 CtapDeviceResponseCode OnGetAssertion(base::span<const uint8_t> request,
49 std::vector<uint8_t>* response);
50
Jun Choi66761162018-07-02 23:03:0851 CtapDeviceResponseCode OnAuthenticatorGetInfo(
52 std::vector<uint8_t>* response) const;
53
54 AuthenticatorData ConstructAuthenticatorData(
55 base::span<const uint8_t, kRpIdHashLength> rp_id_hash,
Adam Langley52f83d82019-02-08 19:35:1756 bool user_verified,
Jun Choi3106cc62018-07-03 18:22:5857 uint32_t current_signature_count,
Adam Langleyd072d4f2018-10-18 16:46:0658 base::Optional<AttestedCredentialData> attested_credential_data,
Adam Langleyb4f12f92018-10-26 21:00:0259 base::Optional<cbor::Value> extensions);
Jun Choi66761162018-07-02 23:03:0860
61 AuthenticatorGetInfoResponse device_info_;
62 base::WeakPtrFactory<FidoDevice> weak_factory_;
63
64 DISALLOW_COPY_AND_ASSIGN(VirtualCtap2Device);
65};
66
Martin Kreichgauer90c625742018-10-31 04:24:1567// 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.
70COMPONENT_EXPORT(DEVICE_FIDO)
71base::Optional<std::pair<CtapMakeCredentialRequest,
72 CtapMakeCredentialRequest::ClientDataHash>>
73ParseCtapMakeCredentialRequest(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.
78COMPONENT_EXPORT(DEVICE_FIDO)
79base::Optional<
80 std::pair<CtapGetAssertionRequest, CtapGetAssertionRequest::ClientDataHash>>
81ParseCtapGetAssertionRequest(base::span<const uint8_t> request_bytes);
82
Jun Choi66761162018-07-02 23:03:0883} // namespace device
84
85#endif // DEVICE_FIDO_VIRTUAL_CTAP2_DEVICE_H_