@@ -40,45 +40,7 @@ impl super::BiometricsTrait for Biometrics {
40
40
}
41
41
}
42
42
43
- fn get_decryption_key ( challenge_b64 : Option < & str > ) -> Result < [ String ; 2 ] > {
44
- static KEY_NAME : & HSTRING = h ! ( "ProtonPass" ) ;
45
-
46
- let challenge: [ u8 ; 16 ] = match challenge_b64 {
47
- Some ( str) => base64_engine
48
- . decode ( str) ?
49
- . try_into ( )
50
- . map_err ( |_e| anyhow ! ( "Invalid challenge" ) ) ?,
51
- None => random_challenge ( ) ,
52
- } ;
53
-
54
- let open_result =
55
- KeyCredentialManager :: RequestCreateAsync ( KEY_NAME , KeyCredentialCreationOption :: FailIfExists ) ?. get ( ) ?;
56
-
57
- let retreive_result = match open_result. Status ( ) ? {
58
- KeyCredentialStatus :: CredentialAlreadyExists => KeyCredentialManager :: OpenAsync ( KEY_NAME ) ?. get ( ) ?,
59
- KeyCredentialStatus :: Success => open_result,
60
- _ => return Err ( anyhow ! ( "Failed to create key credential" ) ) ,
61
- } ;
62
-
63
- let credential = retreive_result. Credential ( ) ?;
64
- let challenge_buffer = CryptographicBuffer :: CreateFromByteArray ( & challenge) ?;
65
- let signature_result = credential. RequestSignAsync ( & challenge_buffer) ?. get ( ) ?;
66
- ensure ! (
67
- signature_result. Status ( ) ? == KeyCredentialStatus :: Success ,
68
- "Failed to sign data"
69
- ) ;
70
-
71
- let signature_buffer = signature_result. Result ( ) ?;
72
- let mut signature_value = Array :: < u8 > :: with_len ( signature_buffer. Length ( ) ? as usize ) ;
73
- CryptographicBuffer :: CopyToByteArray ( & signature_buffer, & mut signature_value) ?;
74
-
75
- let key = Sha256 :: digest ( & * signature_value) ;
76
- let key_b64 = base64_engine. encode ( key) ;
77
- let iv_b64 = base64_engine. encode ( challenge) ;
78
- Ok ( [ key_b64, iv_b64] )
79
- }
80
-
81
- fn check_presence ( handle : Vec < u8 > , reason : String ) -> Result < bool > {
43
+ fn check_presence ( handle : Vec < u8 > , reason : String ) -> Result < ( ) > {
82
44
let h = isize:: from_le_bytes ( handle. clone ( ) . try_into ( ) . unwrap ( ) ) ;
83
45
let window = HWND ( h) ;
84
46
@@ -88,8 +50,14 @@ impl super::BiometricsTrait for Biometrics {
88
50
let result = operation. get ( ) ?;
89
51
90
52
match result {
91
- UserConsentVerificationResult :: Verified => Ok ( true ) ,
92
- _ => Ok ( false ) ,
53
+ UserConsentVerificationResult :: Verified => Ok ( ) ,
54
+ UserConsentVerificationResult :: DeviceBusy => Err ( "Authentication device is busy." ) ,
55
+ UserConsentVerificationResult :: DeviceNotPresent => Err ( "No authentication device found." ) ,
56
+ UserConsentVerificationResult :: DisabledByPolicy => Err ( "Authentication device is disabled by policy." ) ,
57
+ UserConsentVerificationResult :: NotConfiguredForUser => Err ( "No authentication device configured." ) ,
58
+ UserConsentVerificationResult :: Canceled => Err ( "Authentication cancelled." ) ,
59
+ UserConsentVerificationResult :: RetriesExhausted => Err ( "There have been too many failed attempts." ) ,
60
+ _ => Err ( "Biometric authentication failed." ) ,
93
61
}
94
62
}
95
63
0 commit comments