forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
credential_management.h
225 lines (187 loc) · 7.8 KB
/
credential_management.h
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
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef DEVICE_FIDO_CREDENTIAL_MANAGEMENT_H_
#define DEVICE_FIDO_CREDENTIAL_MANAGEMENT_H_
#include "base/component_export.h"
#include "base/optional.h"
#include "device/fido/fido_constants.h"
#include "device/fido/pin.h"
#include "device/fido/public_key_credential_descriptor.h"
#include "device/fido/public_key_credential_rp_entity.h"
#include "device/fido/public_key_credential_user_entity.h"
namespace cbor {
class Value;
}
namespace device {
namespace pin {
struct EmptyResponse;
}
// https://drafts.fidoalliance.org/fido-2/latest/fido-client-to-authenticator-protocol-v2.0-wd-20190409.html#authenticatorCredentialManagement
enum class CredentialManagementRequestKey : uint8_t {
kSubCommand = 0x01,
kSubCommandParams = 0x02,
kPinProtocol = 0x03,
kPinAuth = 0x04,
};
enum class CredentialManagementRequestParamKey : uint8_t {
kRPIDHash = 0x01,
kCredentialID = 0x02,
};
enum class CredentialManagementResponseKey : uint8_t {
kExistingResidentCredentialsCount = 0x01,
kMaxPossibleRemainingResidentCredentialsCount = 0x02,
kRP = 0x03,
kRPIDHash = 0x04,
kTotalRPs = 0x05,
kUser = 0x06,
kCredentialID = 0x07,
kPublicKey = 0x08,
kTotalCredentials = 0x09,
kCredProtect = 0x0a,
};
enum class CredentialManagementSubCommand : uint8_t {
kGetCredsMetadata = 0x01,
kEnumerateRPsBegin = 0x02,
kEnumerateRPsGetNextRP = 0x03,
kEnumerateCredentialsBegin = 0x04,
kEnumerateCredentialsGetNextCredential = 0x05,
kDeleteCredential = 0x06,
};
// CredentialManagementPreviewRequestAdapter wraps any credential management
// request struct in order to replace the authenticatorCredentialManagement
// command byte returned by the static EncodeAsCBOR() method (0x0a) with its
// vendor-specific preview equivalent (0x41).
template <class T>
class CredentialManagementPreviewRequestAdapter {
public:
static std::pair<CtapRequestCommand, base::Optional<cbor::Value>>
EncodeAsCBOR(const CredentialManagementPreviewRequestAdapter<T>& request) {
auto result = T::EncodeAsCBOR(request.wrapped_request_);
DCHECK_EQ(result.first,
CtapRequestCommand::kAuthenticatorCredentialManagement);
result.first =
CtapRequestCommand::kAuthenticatorCredentialManagementPreview;
return result;
}
CredentialManagementPreviewRequestAdapter(T request)
: wrapped_request_(std::move(request)) {}
private:
T wrapped_request_;
};
// CredentialManagementRequest is an authenticatorCredentialManagement(0x0a)
// CTAP2 request. Instances can be obtained via one of the subcommand-specific
// static factory methods.
struct CredentialManagementRequest {
static std::pair<CtapRequestCommand, base::Optional<cbor::Value>>
EncodeAsCBOR(const CredentialManagementRequest&);
enum Version {
kDefault,
kPreview,
};
static CredentialManagementRequest ForGetCredsMetadata(
Version version,
const pin::TokenResponse& token);
static CredentialManagementRequest ForEnumerateRPsBegin(
Version version,
const pin::TokenResponse& token);
static CredentialManagementRequest ForEnumerateRPsGetNext(Version version);
static CredentialManagementRequest ForEnumerateCredentialsBegin(
Version version,
const pin::TokenResponse& token,
std::array<uint8_t, kRpIdHashLength> rp_id_hash);
static CredentialManagementRequest ForEnumerateCredentialsGetNext(
Version version);
static CredentialManagementRequest ForDeleteCredential(
Version version,
const pin::TokenResponse& token,
const PublicKeyCredentialDescriptor& credential_id);
CredentialManagementRequest(Version version,
CredentialManagementSubCommand subcommand,
base::Optional<cbor::Value::MapValue> params);
CredentialManagementRequest(CredentialManagementRequest&&);
CredentialManagementRequest& operator=(CredentialManagementRequest&&);
CredentialManagementRequest(const CredentialManagementRequest&) = delete;
CredentialManagementRequest& operator=(const CredentialManagementRequest&) =
delete;
~CredentialManagementRequest();
Version version;
CredentialManagementSubCommand subcommand;
base::Optional<cbor::Value::MapValue> params;
base::Optional<PINUVAuthProtocol> pin_protocol;
base::Optional<std::vector<uint8_t>> pin_auth;
};
struct CredentialsMetadataResponse {
static base::Optional<CredentialsMetadataResponse> Parse(
const base::Optional<cbor::Value>& cbor_response);
size_t num_existing_credentials;
size_t num_estimated_remaining_credentials;
private:
CredentialsMetadataResponse() = default;
};
struct EnumerateRPsResponse {
static base::Optional<EnumerateRPsResponse> Parse(
bool expect_rp_count,
const base::Optional<cbor::Value>& cbor_response);
// StringFixupPredicate indicates which fields of an EnumerateRPsResponse may
// contain truncated UTF-8 strings. See
// |Ctap2DeviceOperation::CBORPathPredicate|.
static bool StringFixupPredicate(const std::vector<const cbor::Value*>& path);
EnumerateRPsResponse(EnumerateRPsResponse&&);
EnumerateRPsResponse& operator=(EnumerateRPsResponse&&);
~EnumerateRPsResponse();
base::Optional<PublicKeyCredentialRpEntity> rp;
base::Optional<std::array<uint8_t, kRpIdHashLength>> rp_id_hash;
size_t rp_count;
private:
EnumerateRPsResponse(
base::Optional<PublicKeyCredentialRpEntity> rp,
base::Optional<std::array<uint8_t, kRpIdHashLength>> rp_id_hash,
size_t rp_count);
EnumerateRPsResponse(const EnumerateRPsResponse&) = delete;
EnumerateRPsResponse& operator=(const EnumerateRPsResponse&) = delete;
};
struct EnumerateCredentialsResponse {
static base::Optional<EnumerateCredentialsResponse> Parse(
bool expect_credential_count,
const base::Optional<cbor::Value>& cbor_response);
// StringFixupPredicate indicates which fields of an
// EnumerateCredentialsResponse may contain truncated UTF-8 strings. See
// |Ctap2DeviceOperation::CBORPathPredicate|.
static bool StringFixupPredicate(const std::vector<const cbor::Value*>& path);
EnumerateCredentialsResponse(EnumerateCredentialsResponse&&);
EnumerateCredentialsResponse& operator=(EnumerateCredentialsResponse&&);
~EnumerateCredentialsResponse();
PublicKeyCredentialUserEntity user;
PublicKeyCredentialDescriptor credential_id;
// For convenience, also return the serialized |credential_id| so that the UI
// doesn't have to do CBOR serialization. (It only cares about the opaque byte
// string.)
std::vector<uint8_t> credential_id_cbor_bytes;
size_t credential_count;
private:
EnumerateCredentialsResponse(PublicKeyCredentialUserEntity user,
PublicKeyCredentialDescriptor credential_id,
size_t credential_count);
EnumerateCredentialsResponse(const EnumerateCredentialsResponse&) = delete;
EnumerateCredentialsResponse& operator=(EnumerateCredentialsResponse&) =
delete;
};
struct COMPONENT_EXPORT(DEVICE_FIDO) AggregatedEnumerateCredentialsResponse {
AggregatedEnumerateCredentialsResponse(PublicKeyCredentialRpEntity rp);
AggregatedEnumerateCredentialsResponse(
AggregatedEnumerateCredentialsResponse&&);
AggregatedEnumerateCredentialsResponse& operator=(
AggregatedEnumerateCredentialsResponse&&);
~AggregatedEnumerateCredentialsResponse();
PublicKeyCredentialRpEntity rp;
std::vector<EnumerateCredentialsResponse> credentials;
private:
AggregatedEnumerateCredentialsResponse(
const AggregatedEnumerateCredentialsResponse&) = delete;
};
using DeleteCredentialResponse = pin::EmptyResponse;
std::pair<CtapRequestCommand, base::Optional<cbor::Value>>
AsCTAPRequestValuePair(const CredentialManagementRequest&);
} // namespace device
#endif // DEVICE_FIDO_CREDENTIAL_MANAGEMENT_H_