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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
//! Error responses
use passkey_crypto::CoseKeyConversionError;
use crate::utils::repr_enum::CodeOutOfRange;
/// Ctap2 error which may or may not be explicitly defined
///
/// <https://fidoalliance.org/specs/fido-v2.1-ps-20210615/fido-client-to-authenticator-protocol-v2.1-ps-errata-20220621.html#error-responses>
#[derive(Debug, PartialEq, Eq)]
pub enum StatusCode {
/// Known error codes
Known(Ctap2Error),
/// last spec reserved number 0xDF
Other(UnknownSpecError),
/// Range 0xE0..=0xEF
Extension(ExtensionError),
/// Range 0xF0..=0xFF
Vendor(VendorError),
}
impl From<u8> for StatusCode {
fn from(value: u8) -> Self {
Ctap2Error::try_from(value)
.map(Self::from)
.or_else(|err| ExtensionError::try_from(err.0).map(Self::from))
.or_else(|err| VendorError::try_from(err.0).map(Self::from))
.or_else(|err| UnknownSpecError::try_from(err.0).map(Self::from))
// SAFETY: this unwrap is safe because at this point we have exhausted all values of a byte.
.unwrap()
}
}
impl From<StatusCode> for u8 {
fn from(src: StatusCode) -> Self {
match src {
StatusCode::Known(known) => known.into(),
StatusCode::Other(other) => other.into(),
StatusCode::Extension(extension) => extension.into(),
StatusCode::Vendor(vendor) => vendor.into(),
}
}
}
repr_enum! {
/// Explicitly defined CTAP2 error variants
Ctap2Error: u8 {
/// Indicates successful response.
Ok : 0x00,
/// The command is not a valid CTAP command.
InvalidCommand : 0x01,
/// The command included an invalid parameter.
InvalidParameter : 0x02,
/// Invalid message or item length.
InvalidLength : 0x03,
/// Invalid message sequencing.
InvalidSequence : 0x04,
/// Message timed out.
Timeout : 0x05,
/// Channel busy. Client SHOULD retry the request after a short delay. Note that the client MAY
/// abort the transaction if the command is no longer relevant.
ChannelBusy : 0x06,
/// Command requires channel lock.
LockRequired : 0x0A,
/// Command not allowed on this cid.
InvalidChannel : 0x0B,
/// Invalid/unexpected CBOR error.
CborUnexpectedType : 0x11,
/// Error when parsing CBOR.
InvalidCbor : 0x12,
/// Missing non-optional parameter.
MissingParameter : 0x14,
/// Limit for number of items exceeded.
LimitExceeded : 0x15,
/// Fingerprint database is full, e.g. during enrollment.
FingerprintDatabaseFull : 0x17,
/// Large blob storage is full. (See [§ 6.10.3 Large, per-credential blobs.][1])
///
/// [1]: https://fidoalliance.org/specs/fido-v2.1-ps-20210615/fido-client-to-authenticator-protocol-v2.1-ps-errata-20220621.html#large-blob
LargeBlobStorageFull : 0x18,
/// Valid credential found in the exclude list.
CredentialExcluded : 0x19,
/// Processing (Lengthy operation is in progress).
Processing : 0x21,
/// Credential not valid for the authenticator.
InvalidCredential : 0x22,
/// Authentication is waiting for user interaction.
UserActionPending : 0x23,
/// Processing, lengthy operation is in progress.
OperationPending : 0x24,
/// No request is pending.
NoOperations : 0x25,
/// Authenticator does not support requested algorithm.
UnsupportedAlgorithm : 0x26,
/// Not authorized for requested operation.
OperationDenied : 0x27,
/// Internal key storage is full.
KeyStoreFull : 0x28,
/// Unsupported option.
UnsupportedOption : 0x2B,
/// Not a valid option for current operation.
InvalidOption : 0x2C,
/// Pending keep alive was cancelled.
KeepAliveCancel : 0x2D,
/// No valid credentials provided.
NoCredentials : 0x2E,
/// A [user action timeout][1] occurred.
///
/// [1]: https://fidoalliance.org/specs/fido-v2.1-ps-20210615/fido-client-to-authenticator-protocol-v2.1-ps-errata-20220621.html#user-action-timeout
UserActionTimeout : 0x2F,
/// Continuation command, such as, authenticatorGetNextAssertion[^1] not allowed.
///
/// [^1]: Coming soon to an MR near you
NotAllowed : 0x30,
/// PIN Invalid.
PinInvalid : 0x31,
/// PIN Blocked.
PinBlocked : 0x32,
/// PIN authentication,pinUvAuthParam, verification failed.
PinAuthInvalid : 0x33,
/// PIN authentication using [pinUvAuthToken] blocked. Requires [power cycle] to reset.
///
/// [pinUvAuthToken]: https://fidoalliance.org/specs/fido-v2.1-ps-20210615/fido-client-to-authenticator-protocol-v2.1-ps-errata-20220621.html#puatoken-pinuvauthtoken
/// [power cycle]: https://fidoalliance.org/specs/fido-v2.1-ps-20210615/fido-client-to-authenticator-protocol-v2.1-ps-errata-20220621.html#authenticator-power-up-configuration
PinAuthBlocked : 0x34,
/// No PIN has been set.
PinNotSet : 0x35,
/// A [pinUvAuthToken] is required for the selected operation. See also the pinUvAuthToken
/// [option ID].
///
/// [pinUvAuthToken]: https://fidoalliance.org/specs/fido-v2.1-ps-20210615/fido-client-to-authenticator-protocol-v2.1-ps-errata-20220621.html#puatoken-pinuvauthtoken
/// [option ID]: https://fidoalliance.org/specs/fido-v2.1-ps-20210615/fido-client-to-authenticator-protocol-v2.1-ps-errata-20220621.html#option-id
PuatRequired : 0x36,
/// PIN policy violation. Currently only enforces minimum length.
PinPolicyViolation : 0x37,
/// Authenticator cannot handle this request due to memory constraints.
RequestTooLarge : 0x39,
/// The current operation has timed out.
ActionTimeout : 0x3A,
/// User presence is required for the requested operation.
UserPresenceRequired : 0x3B,
/// [Built-in user verification][1] is disabled.
///
/// [1]: https://fidoalliance.org/specs/fido-v2.1-ps-20210615/fido-client-to-authenticator-protocol-v2.1-ps-errata-20220621.html#built-in-user-verification-method
UserVerificationBlocked : 0x3C,
/// A checksum did not match.
IntegrityFailure : 0x3D,
/// The requested subcommand is either invalid or not implemented.
InvalidSubcommand : 0x3E,
/// [Built-in user verification][1] unsuccessful. The platform SHOULD retry.
///
/// [1]: https://fidoalliance.org/specs/fido-v2.1-ps-20210615/fido-client-to-authenticator-protocol-v2.1-ps-errata-20220621.html#built-in-user-verification-method
UserVerificationInvalid : 0x3F,
/// The [permissions] parameter contains an unauthorized permission.
///
/// [permissions]: https://fidoalliance.org/specs/fido-v2.1-ps-20210615/fido-client-to-authenticator-protocol-v2.1-ps-errata-20220621.html#perms-param-permissions
UnauthorizedPermission : 0x40,
/// Other unspecified error.
Other : 0x7F,
}
}
impl From<CoseKeyConversionError> for Ctap2Error {
fn from(value: CoseKeyConversionError) -> Self {
match value {
CoseKeyConversionError::UnsupportedAlgorithm => Ctap2Error::UnsupportedAlgorithm,
CoseKeyConversionError::InvalidCredential => Ctap2Error::InvalidCredential,
CoseKeyConversionError::Other(_) => Ctap2Error::Other,
}
}
}
impl From<CoseKeyConversionError> for StatusCode {
fn from(value: CoseKeyConversionError) -> Self {
StatusCode::Known(Ctap2Error::from(value))
}
}
impl From<Ctap2Error> for StatusCode {
fn from(src: Ctap2Error) -> Self {
StatusCode::Known(src)
}
}
/// Error values that are not defined or reserved for future use at the time of writing
#[derive(Debug, PartialEq, Eq)]
pub struct UnknownSpecError(u8);
impl TryFrom<u8> for UnknownSpecError {
type Error = CodeOutOfRange<u8>;
fn try_from(value: u8) -> Result<Self, Self::Error> {
match value {
0x07..=0x09
| 0x0C..=0x10
| 0x13
| 0x16
| 0x1A..=0x20
| 0x29
| 0x2A
| 0x38 // Explicitly marked reserved for future use
| 0x41..=0x7E
| 0x80..=0xDF => Ok(UnknownSpecError(value)),
_ => Err(CodeOutOfRange(value)),
}
}
}
impl From<UnknownSpecError> for u8 {
fn from(src: UnknownSpecError) -> Self {
src.0
}
}
impl From<UnknownSpecError> for StatusCode {
fn from(src: UnknownSpecError) -> Self {
StatusCode::Other(src)
}
}
/// Extension error codes
#[derive(Debug, PartialEq, Eq)]
pub struct ExtensionError(u8);
impl TryFrom<u8> for ExtensionError {
type Error = CodeOutOfRange<u8>;
fn try_from(value: u8) -> Result<Self, Self::Error> {
match value {
0xE0..=0xEF => Ok(Self(value)),
_ => Err(CodeOutOfRange(value)),
}
}
}
impl From<ExtensionError> for u8 {
fn from(src: ExtensionError) -> Self {
src.0
}
}
impl From<ExtensionError> for StatusCode {
fn from(src: ExtensionError) -> Self {
StatusCode::Extension(src)
}
}
/// Vendor specific error codes
#[derive(Debug, PartialEq, Eq)]
pub struct VendorError(u8);
impl TryFrom<u8> for VendorError {
type Error = CodeOutOfRange<u8>;
fn try_from(value: u8) -> Result<Self, Self::Error> {
match value {
0xF0..=0xFF => Ok(Self(value)),
_ => Err(CodeOutOfRange(value)),
}
}
}
impl From<VendorError> for u8 {
fn from(src: VendorError) -> Self {
src.0
}
}
impl From<VendorError> for StatusCode {
fn from(src: VendorError) -> Self {
StatusCode::Vendor(src)
}
}
#[cfg(test)]
mod tests;