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
276
277
278
279
280
281
282
use base64urlsafedata::Base64UrlSafeData;
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Clone, Copy, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
#[repr(u8)]
pub enum CredentialProtectionPolicy {
UserVerificationOptional = 0x1,
UserVerificationOptionalWithCredentialIDList = 0x2,
UserVerificationRequired = 0x3,
}
impl TryFrom<u8> for CredentialProtectionPolicy {
type Error = &'static str;
fn try_from(v: u8) -> Result<Self, Self::Error> {
use CredentialProtectionPolicy::*;
match v {
0x1 => Ok(UserVerificationOptional),
0x2 => Ok(UserVerificationOptionalWithCredentialIDList),
0x3 => Ok(UserVerificationRequired),
_ => Err("Invalid policy number"),
}
}
}
#[derive(Debug, Serialize, Clone, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct CredProtect {
pub credential_protection_policy: CredentialProtectionPolicy,
#[serde(skip_serializing_if = "Option::is_none")]
pub enforce_credential_protection_policy: Option<bool>,
}
#[derive(Debug, Serialize, Clone, Deserialize, PartialEq, Eq)]
pub struct CredBlobSet(pub Base64UrlSafeData);
impl From<Vec<u8>> for CredBlobSet {
fn from(bytes: Vec<u8>) -> Self {
CredBlobSet(Base64UrlSafeData(bytes))
}
}
#[derive(Debug, Serialize, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RequestRegistrationExtensions {
#[serde(flatten, skip_serializing_if = "Option::is_none")]
pub cred_protect: Option<CredProtect>,
#[serde(skip_serializing_if = "Option::is_none")]
pub cred_blob: Option<CredBlobSet>,
#[serde(skip_serializing_if = "Option::is_none")]
pub uvm: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub cred_props: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub min_pin_length: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub hmac_create_secret: Option<bool>,
}
impl Default for RequestRegistrationExtensions {
fn default() -> Self {
RequestRegistrationExtensions {
cred_protect: None,
cred_blob: None,
uvm: Some(true),
cred_props: Some(true),
min_pin_length: None,
hmac_create_secret: None,
}
}
}
#[derive(Debug, Serialize, Clone, Deserialize, PartialEq, Eq)]
pub struct CredBlobGet(pub bool);
#[derive(Debug, Serialize, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RequestAuthenticationExtensions {
#[serde(skip_serializing_if = "Option::is_none")]
pub get_cred_blob: Option<CredBlobGet>,
#[serde(skip_serializing_if = "Option::is_none")]
pub appid: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub uvm: Option<bool>,
}
#[derive(Debug, Deserialize, Serialize, Clone, Default)]
pub struct AuthenticationExtensionsClientOutputs {
#[serde(default)]
pub appid: Option<bool>,
pub cred_blob: Option<bool>,
}
#[cfg(feature = "wasm")]
impl From<web_sys::AuthenticationExtensionsClientOutputs>
for AuthenticationExtensionsClientOutputs
{
fn from(
ext: web_sys::AuthenticationExtensionsClientOutputs,
) -> AuthenticationExtensionsClientOutputs {
let appid = js_sys::Reflect::get(&ext, &"appid".into())
.ok()
.and_then(|jv| jv.as_bool());
let cred_blob = js_sys::Reflect::get(&ext, &"credBlob".into())
.ok()
.and_then(|jv| jv.as_bool());
AuthenticationExtensionsClientOutputs { appid, cred_blob }
}
}
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct CredProps {
rk: bool,
}
#[derive(Debug, Deserialize, Serialize, Clone, Default)]
pub struct RegistrationExtensionsClientOutputs {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub appid: Option<bool>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub cred_blob: Option<bool>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub cred_props: Option<CredProps>,
}
#[cfg(feature = "wasm")]
impl From<web_sys::AuthenticationExtensionsClientOutputs> for RegistrationExtensionsClientOutputs {
fn from(
ext: web_sys::AuthenticationExtensionsClientOutputs,
) -> RegistrationExtensionsClientOutputs {
let appid = js_sys::Reflect::get(&ext, &"appid".into())
.ok()
.and_then(|jv| jv.as_bool());
let cred_blob = js_sys::Reflect::get(&ext, &"credBlob".into())
.ok()
.and_then(|jv| jv.as_bool());
let cred_props = js_sys::Reflect::get(&ext, &"credProps".into())
.ok()
.and_then(|cred_props_struct| {
js_sys::Reflect::get(&cred_props_struct, &"rk".into())
.ok()
.and_then(|jv| jv.as_bool())
.map(|rk| CredProps { rk })
});
RegistrationExtensionsClientOutputs {
appid,
cred_blob,
cred_props,
}
}
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum ExtnState<T>
where
T: Clone + std::fmt::Debug,
{
NotRequested,
Ignored,
Set(T),
Unsolicited(T),
Unsigned(T),
}
impl<T> Default for ExtnState<T>
where
T: Clone + std::fmt::Debug,
{
fn default() -> Self {
ExtnState::NotRequested
}
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct RegisteredExtensions {
#[serde(default)]
pub cred_protect: ExtnState<CredentialProtectionPolicy>,
#[serde(default)]
pub hmac_create_secret: ExtnState<bool>,
#[serde(default)]
pub appid: ExtnState<bool>,
#[serde(default)]
pub cred_props: ExtnState<CredProps>,
}
impl RegisteredExtensions {
pub fn none() -> Self {
RegisteredExtensions {
cred_protect: ExtnState::NotRequested,
hmac_create_secret: ExtnState::NotRequested,
appid: ExtnState::NotRequested,
cred_props: ExtnState::NotRequested,
}
}
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct AuthenticationExtensions {}