@@ -28,6 +28,7 @@ use crate::api::crypto::sha256::Sha256;
28
28
use crate :: api:: customization:: Customization ;
29
29
use crate :: api:: key_store:: KeyStore ;
30
30
use crate :: api:: persist:: Persist ;
31
+ use crate :: ctap:: status_code:: CtapResult ;
31
32
use crate :: ctap:: storage;
32
33
#[ cfg( test) ]
33
34
use crate :: env:: EcdhSk ;
@@ -65,7 +66,7 @@ const PIN_PADDED_LENGTH: usize = 64;
65
66
fn decrypt_pin < E : Env > (
66
67
shared_secret : & SharedSecret < E > ,
67
68
new_pin_enc : Vec < u8 > ,
68
- ) -> Result < Secret < [ u8 ] > , Ctap2StatusCode > {
69
+ ) -> CtapResult < Secret < [ u8 ] > > {
69
70
let decrypted_pin = shared_secret. decrypt ( & new_pin_enc) ?;
70
71
if decrypted_pin. len ( ) != PIN_PADDED_LENGTH {
71
72
return Err ( Ctap2StatusCode :: CTAP1_ERR_INVALID_PARAMETER ) ;
@@ -91,7 +92,7 @@ fn check_and_store_new_pin<E: Env>(
91
92
env : & mut E ,
92
93
shared_secret : & SharedSecret < E > ,
93
94
new_pin_enc : Vec < u8 > ,
94
- ) -> Result < ( ) , Ctap2StatusCode > {
95
+ ) -> CtapResult < ( ) > {
95
96
let pin = decrypt_pin ( shared_secret, new_pin_enc) ?;
96
97
let min_pin_length = storage:: min_pin_length ( env) ? as usize ;
97
98
let pin_length = str:: from_utf8 ( & pin) . unwrap_or ( "" ) . chars ( ) . count ( ) ;
@@ -168,7 +169,7 @@ impl<E: Env> ClientPin<E> {
168
169
& self ,
169
170
pin_uv_auth_protocol : PinUvAuthProtocol ,
170
171
key_agreement : CoseKey ,
171
- ) -> Result < SharedSecret < E > , Ctap2StatusCode > {
172
+ ) -> CtapResult < SharedSecret < E > > {
172
173
self . get_pin_protocol ( pin_uv_auth_protocol)
173
174
. decapsulate ( key_agreement, pin_uv_auth_protocol)
174
175
}
@@ -184,7 +185,7 @@ impl<E: Env> ClientPin<E> {
184
185
pin_uv_auth_protocol : PinUvAuthProtocol ,
185
186
shared_secret : & SharedSecret < E > ,
186
187
pin_hash_enc : Vec < u8 > ,
187
- ) -> Result < ( ) , Ctap2StatusCode > {
188
+ ) -> CtapResult < ( ) > {
188
189
match env. persist ( ) . pin_hash ( ) ? {
189
190
Some ( pin_hash) => {
190
191
if self . consecutive_pin_mismatches >= 3 {
@@ -217,10 +218,7 @@ impl<E: Env> ClientPin<E> {
217
218
Ok ( ( ) )
218
219
}
219
220
220
- fn process_get_pin_retries (
221
- & self ,
222
- env : & mut E ,
223
- ) -> Result < AuthenticatorClientPinResponse , Ctap2StatusCode > {
221
+ fn process_get_pin_retries ( & self , env : & mut E ) -> CtapResult < AuthenticatorClientPinResponse > {
224
222
Ok ( AuthenticatorClientPinResponse {
225
223
key_agreement : None ,
226
224
pin_uv_auth_token : None ,
@@ -232,7 +230,7 @@ impl<E: Env> ClientPin<E> {
232
230
fn process_get_key_agreement (
233
231
& self ,
234
232
client_pin_params : AuthenticatorClientPinParameters ,
235
- ) -> Result < AuthenticatorClientPinResponse , Ctap2StatusCode > {
233
+ ) -> CtapResult < AuthenticatorClientPinResponse > {
236
234
let key_agreement = Some (
237
235
self . get_pin_protocol ( client_pin_params. pin_uv_auth_protocol )
238
236
. get_public_key ( ) ,
@@ -249,7 +247,7 @@ impl<E: Env> ClientPin<E> {
249
247
& mut self ,
250
248
env : & mut E ,
251
249
client_pin_params : AuthenticatorClientPinParameters ,
252
- ) -> Result < ( ) , Ctap2StatusCode > {
250
+ ) -> CtapResult < ( ) > {
253
251
let AuthenticatorClientPinParameters {
254
252
pin_uv_auth_protocol,
255
253
key_agreement,
@@ -276,7 +274,7 @@ impl<E: Env> ClientPin<E> {
276
274
& mut self ,
277
275
env : & mut E ,
278
276
client_pin_params : AuthenticatorClientPinParameters ,
279
- ) -> Result < ( ) , Ctap2StatusCode > {
277
+ ) -> CtapResult < ( ) > {
280
278
let AuthenticatorClientPinParameters {
281
279
pin_uv_auth_protocol,
282
280
key_agreement,
@@ -309,7 +307,7 @@ impl<E: Env> ClientPin<E> {
309
307
& mut self ,
310
308
env : & mut E ,
311
309
client_pin_params : AuthenticatorClientPinParameters ,
312
- ) -> Result < AuthenticatorClientPinResponse , Ctap2StatusCode > {
310
+ ) -> CtapResult < AuthenticatorClientPinResponse > {
313
311
let AuthenticatorClientPinParameters {
314
312
pin_uv_auth_protocol,
315
313
key_agreement,
@@ -357,12 +355,12 @@ impl<E: Env> ClientPin<E> {
357
355
// If you want to support local user verification, implement this function.
358
356
// Lacking a fingerprint reader, this subcommand is currently unsupported.
359
357
_client_pin_params : AuthenticatorClientPinParameters ,
360
- ) -> Result < AuthenticatorClientPinResponse , Ctap2StatusCode > {
358
+ ) -> CtapResult < AuthenticatorClientPinResponse > {
361
359
// User verification is only supported through PIN currently.
362
360
Err ( Ctap2StatusCode :: CTAP2_ERR_INVALID_SUBCOMMAND )
363
361
}
364
362
365
- fn process_get_uv_retries ( & self ) -> Result < AuthenticatorClientPinResponse , Ctap2StatusCode > {
363
+ fn process_get_uv_retries ( & self ) -> CtapResult < AuthenticatorClientPinResponse > {
366
364
// User verification is only supported through PIN currently.
367
365
Err ( Ctap2StatusCode :: CTAP2_ERR_INVALID_SUBCOMMAND )
368
366
}
@@ -371,7 +369,7 @@ impl<E: Env> ClientPin<E> {
371
369
& mut self ,
372
370
env : & mut E ,
373
371
mut client_pin_params : AuthenticatorClientPinParameters ,
374
- ) -> Result < AuthenticatorClientPinResponse , Ctap2StatusCode > {
372
+ ) -> CtapResult < AuthenticatorClientPinResponse > {
375
373
// Mutating client_pin_params is just an optimization to move it into
376
374
// process_get_pin_token, without cloning permissions_rp_id here.
377
375
// getPinToken requires permissions* to be None.
@@ -399,7 +397,7 @@ impl<E: Env> ClientPin<E> {
399
397
& mut self ,
400
398
env : & mut E ,
401
399
client_pin_params : AuthenticatorClientPinParameters ,
402
- ) -> Result < ResponseData , Ctap2StatusCode > {
400
+ ) -> CtapResult < ResponseData > {
403
401
if !env. customization ( ) . allows_pin_protocol_v1 ( )
404
402
&& client_pin_params. pin_uv_auth_protocol == PinUvAuthProtocol :: V1
405
403
{
@@ -441,7 +439,7 @@ impl<E: Env> ClientPin<E> {
441
439
hmac_contents : & [ u8 ] ,
442
440
pin_uv_auth_param : & [ u8 ] ,
443
441
pin_uv_auth_protocol : PinUvAuthProtocol ,
444
- ) -> Result < ( ) , Ctap2StatusCode > {
442
+ ) -> CtapResult < ( ) > {
445
443
if !self . pin_uv_auth_token_state . is_in_use ( ) {
446
444
return Err ( Ctap2StatusCode :: CTAP2_ERR_PIN_AUTH_INVALID ) ;
447
445
}
@@ -477,7 +475,7 @@ impl<E: Env> ClientPin<E> {
477
475
env : & mut E ,
478
476
hmac_secret_input : GetAssertionHmacSecretInput ,
479
477
cred_random : & [ u8 ; 32 ] ,
480
- ) -> Result < Vec < u8 > , Ctap2StatusCode > {
478
+ ) -> CtapResult < Vec < u8 > > {
481
479
let GetAssertionHmacSecretInput {
482
480
key_agreement,
483
481
salt_enc,
@@ -523,7 +521,7 @@ impl<E: Env> ClientPin<E> {
523
521
}
524
522
525
523
/// Checks if user verification is cached for use of the pinUvAuthToken.
526
- pub fn check_user_verified_flag ( & mut self ) -> Result < ( ) , Ctap2StatusCode > {
524
+ pub fn check_user_verified_flag ( & mut self ) -> CtapResult < ( ) > {
527
525
if self . pin_uv_auth_token_state . get_user_verified_flag_value ( ) {
528
526
Ok ( ( ) )
529
527
} else {
@@ -532,27 +530,24 @@ impl<E: Env> ClientPin<E> {
532
530
}
533
531
534
532
/// Check if the required command's token permission is granted.
535
- pub fn has_permission ( & self , permission : PinPermission ) -> Result < ( ) , Ctap2StatusCode > {
533
+ pub fn has_permission ( & self , permission : PinPermission ) -> CtapResult < ( ) > {
536
534
self . pin_uv_auth_token_state . has_permission ( permission)
537
535
}
538
536
539
537
/// Check if no RP ID is associated with the token permission.
540
- pub fn has_no_rp_id_permission ( & self ) -> Result < ( ) , Ctap2StatusCode > {
538
+ pub fn has_no_rp_id_permission ( & self ) -> CtapResult < ( ) > {
541
539
self . pin_uv_auth_token_state . has_no_permissions_rp_id ( )
542
540
}
543
541
544
542
/// Check if no or the passed RP ID is associated with the token permission.
545
- pub fn has_no_or_rp_id_permission ( & mut self , rp_id : & str ) -> Result < ( ) , Ctap2StatusCode > {
543
+ pub fn has_no_or_rp_id_permission ( & mut self , rp_id : & str ) -> CtapResult < ( ) > {
546
544
self . pin_uv_auth_token_state
547
545
. has_no_permissions_rp_id ( )
548
546
. or_else ( |_| self . pin_uv_auth_token_state . has_permissions_rp_id ( rp_id) )
549
547
}
550
548
551
549
/// Check if no RP ID is associated with the token permission, or it matches the hash.
552
- pub fn has_no_or_rp_id_hash_permission (
553
- & self ,
554
- rp_id_hash : & [ u8 ] ,
555
- ) -> Result < ( ) , Ctap2StatusCode > {
550
+ pub fn has_no_or_rp_id_hash_permission ( & self , rp_id_hash : & [ u8 ] ) -> CtapResult < ( ) > {
556
551
self . pin_uv_auth_token_state
557
552
. has_no_permissions_rp_id ( )
558
553
. or_else ( |_| {
@@ -564,7 +559,7 @@ impl<E: Env> ClientPin<E> {
564
559
/// Check if the passed RP ID is associated with the token permission.
565
560
///
566
561
/// If no RP ID is associated, associate the passed RP ID as a side effect.
567
- pub fn ensure_rp_id_permission ( & mut self , rp_id : & str ) -> Result < ( ) , Ctap2StatusCode > {
562
+ pub fn ensure_rp_id_permission ( & mut self , rp_id : & str ) -> CtapResult < ( ) > {
568
563
if self
569
564
. pin_uv_auth_token_state
570
565
. has_no_permissions_rp_id ( )
@@ -1277,7 +1272,7 @@ mod test {
1277
1272
pin_uv_auth_protocol : PinUvAuthProtocol ,
1278
1273
cred_random : & [ u8 ; 32 ] ,
1279
1274
salt : Vec < u8 > ,
1280
- ) -> Result < Vec < u8 > , Ctap2StatusCode > {
1275
+ ) -> CtapResult < Vec < u8 > > {
1281
1276
let mut env = TestEnv :: default ( ) ;
1282
1277
let ( client_pin, shared_secret) = create_client_pin_and_shared_secret ( pin_uv_auth_protocol) ;
1283
1278
0 commit comments