1*e1997b9aSAndroid Build Coastguard Worker // Copyright 2020, The Android Open Source Project
2*e1997b9aSAndroid Build Coastguard Worker //
3*e1997b9aSAndroid Build Coastguard Worker // Licensed under the Apache License, Version 2.0 (the "License");
4*e1997b9aSAndroid Build Coastguard Worker // you may not use this file except in compliance with the License.
5*e1997b9aSAndroid Build Coastguard Worker // You may obtain a copy of the License at
6*e1997b9aSAndroid Build Coastguard Worker //
7*e1997b9aSAndroid Build Coastguard Worker // http://www.apache.org/licenses/LICENSE-2.0
8*e1997b9aSAndroid Build Coastguard Worker //
9*e1997b9aSAndroid Build Coastguard Worker // Unless required by applicable law or agreed to in writing, software
10*e1997b9aSAndroid Build Coastguard Worker // distributed under the License is distributed on an "AS IS" BASIS,
11*e1997b9aSAndroid Build Coastguard Worker // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12*e1997b9aSAndroid Build Coastguard Worker // See the License for the specific language governing permissions and
13*e1997b9aSAndroid Build Coastguard Worker // limitations under the License.
14*e1997b9aSAndroid Build Coastguard Worker
15*e1997b9aSAndroid Build Coastguard Worker //! This module implements IKeystoreAuthorization AIDL interface.
16*e1997b9aSAndroid Build Coastguard Worker
17*e1997b9aSAndroid Build Coastguard Worker use crate::error::anyhow_error_to_cstring;
18*e1997b9aSAndroid Build Coastguard Worker use crate::error::Error as KeystoreError;
19*e1997b9aSAndroid Build Coastguard Worker use crate::globals::{DB, ENFORCEMENTS, LEGACY_IMPORTER, SUPER_KEY};
20*e1997b9aSAndroid Build Coastguard Worker use crate::ks_err;
21*e1997b9aSAndroid Build Coastguard Worker use crate::permission::KeystorePerm;
22*e1997b9aSAndroid Build Coastguard Worker use crate::utils::{check_keystore_permission, watchdog as wd};
23*e1997b9aSAndroid Build Coastguard Worker use aconfig_android_hardware_biometrics_rust;
24*e1997b9aSAndroid Build Coastguard Worker use android_hardware_security_keymint::aidl::android::hardware::security::keymint::{
25*e1997b9aSAndroid Build Coastguard Worker HardwareAuthToken::HardwareAuthToken, HardwareAuthenticatorType::HardwareAuthenticatorType,
26*e1997b9aSAndroid Build Coastguard Worker };
27*e1997b9aSAndroid Build Coastguard Worker use android_security_authorization::aidl::android::security::authorization::{
28*e1997b9aSAndroid Build Coastguard Worker AuthorizationTokens::AuthorizationTokens, IKeystoreAuthorization::BnKeystoreAuthorization,
29*e1997b9aSAndroid Build Coastguard Worker IKeystoreAuthorization::IKeystoreAuthorization, ResponseCode::ResponseCode,
30*e1997b9aSAndroid Build Coastguard Worker };
31*e1997b9aSAndroid Build Coastguard Worker use android_security_authorization::binder::{
32*e1997b9aSAndroid Build Coastguard Worker BinderFeatures, ExceptionCode, Interface, Result as BinderResult, Status as BinderStatus,
33*e1997b9aSAndroid Build Coastguard Worker Strong,
34*e1997b9aSAndroid Build Coastguard Worker };
35*e1997b9aSAndroid Build Coastguard Worker use android_system_keystore2::aidl::android::system::keystore2::ResponseCode::ResponseCode as KsResponseCode;
36*e1997b9aSAndroid Build Coastguard Worker use anyhow::{Context, Result};
37*e1997b9aSAndroid Build Coastguard Worker use keystore2_crypto::Password;
38*e1997b9aSAndroid Build Coastguard Worker use keystore2_selinux as selinux;
39*e1997b9aSAndroid Build Coastguard Worker use std::ffi::CString;
40*e1997b9aSAndroid Build Coastguard Worker
41*e1997b9aSAndroid Build Coastguard Worker /// This is the Authorization error type, it wraps binder exceptions and the
42*e1997b9aSAndroid Build Coastguard Worker /// Authorization ResponseCode
43*e1997b9aSAndroid Build Coastguard Worker #[derive(Debug, thiserror::Error, PartialEq, Eq)]
44*e1997b9aSAndroid Build Coastguard Worker pub enum Error {
45*e1997b9aSAndroid Build Coastguard Worker /// Wraps an IKeystoreAuthorization response code as defined by
46*e1997b9aSAndroid Build Coastguard Worker /// android.security.authorization AIDL interface specification.
47*e1997b9aSAndroid Build Coastguard Worker #[error("Error::Rc({0:?})")]
48*e1997b9aSAndroid Build Coastguard Worker Rc(ResponseCode),
49*e1997b9aSAndroid Build Coastguard Worker /// Wraps a Binder exception code other than a service specific exception.
50*e1997b9aSAndroid Build Coastguard Worker #[error("Binder exception code {0:?}, {1:?}")]
51*e1997b9aSAndroid Build Coastguard Worker Binder(ExceptionCode, i32),
52*e1997b9aSAndroid Build Coastguard Worker }
53*e1997b9aSAndroid Build Coastguard Worker
54*e1997b9aSAndroid Build Coastguard Worker /// Translate an error into a service specific exception, logging along the way.
55*e1997b9aSAndroid Build Coastguard Worker ///
56*e1997b9aSAndroid Build Coastguard Worker /// `Error::Rc(x)` variants get mapped onto a service specific error code of `x`.
57*e1997b9aSAndroid Build Coastguard Worker /// Certain response codes may be returned from keystore/ResponseCode.aidl by the keystore2 modules,
58*e1997b9aSAndroid Build Coastguard Worker /// which are then converted to the corresponding response codes of android.security.authorization
59*e1997b9aSAndroid Build Coastguard Worker /// AIDL interface specification.
60*e1997b9aSAndroid Build Coastguard Worker ///
61*e1997b9aSAndroid Build Coastguard Worker /// `selinux::Error::perm()` is mapped on `ResponseCode::PERMISSION_DENIED`.
62*e1997b9aSAndroid Build Coastguard Worker ///
63*e1997b9aSAndroid Build Coastguard Worker /// All non `Error` error conditions get mapped onto ResponseCode::SYSTEM_ERROR`.
into_logged_binder(e: anyhow::Error) -> BinderStatus64*e1997b9aSAndroid Build Coastguard Worker pub fn into_logged_binder(e: anyhow::Error) -> BinderStatus {
65*e1997b9aSAndroid Build Coastguard Worker log::error!("{:#?}", e);
66*e1997b9aSAndroid Build Coastguard Worker let root_cause = e.root_cause();
67*e1997b9aSAndroid Build Coastguard Worker if let Some(KeystoreError::Rc(ks_rcode)) = root_cause.downcast_ref::<KeystoreError>() {
68*e1997b9aSAndroid Build Coastguard Worker let rc = match *ks_rcode {
69*e1997b9aSAndroid Build Coastguard Worker // Although currently keystore2/ResponseCode.aidl and
70*e1997b9aSAndroid Build Coastguard Worker // authorization/ResponseCode.aidl share the same integer values for the
71*e1997b9aSAndroid Build Coastguard Worker // common response codes, this may deviate in the future, hence the
72*e1997b9aSAndroid Build Coastguard Worker // conversion here.
73*e1997b9aSAndroid Build Coastguard Worker KsResponseCode::SYSTEM_ERROR => ResponseCode::SYSTEM_ERROR.0,
74*e1997b9aSAndroid Build Coastguard Worker KsResponseCode::KEY_NOT_FOUND => ResponseCode::KEY_NOT_FOUND.0,
75*e1997b9aSAndroid Build Coastguard Worker KsResponseCode::VALUE_CORRUPTED => ResponseCode::VALUE_CORRUPTED.0,
76*e1997b9aSAndroid Build Coastguard Worker KsResponseCode::INVALID_ARGUMENT => ResponseCode::INVALID_ARGUMENT.0,
77*e1997b9aSAndroid Build Coastguard Worker // If the code paths of IKeystoreAuthorization aidl's methods happen to return
78*e1997b9aSAndroid Build Coastguard Worker // other error codes from KsResponseCode in the future, they should be converted
79*e1997b9aSAndroid Build Coastguard Worker // as well.
80*e1997b9aSAndroid Build Coastguard Worker _ => ResponseCode::SYSTEM_ERROR.0,
81*e1997b9aSAndroid Build Coastguard Worker };
82*e1997b9aSAndroid Build Coastguard Worker BinderStatus::new_service_specific_error(rc, anyhow_error_to_cstring(&e).as_deref())
83*e1997b9aSAndroid Build Coastguard Worker } else {
84*e1997b9aSAndroid Build Coastguard Worker let rc = match root_cause.downcast_ref::<Error>() {
85*e1997b9aSAndroid Build Coastguard Worker Some(Error::Rc(rcode)) => rcode.0,
86*e1997b9aSAndroid Build Coastguard Worker Some(Error::Binder(_, _)) => ResponseCode::SYSTEM_ERROR.0,
87*e1997b9aSAndroid Build Coastguard Worker None => match root_cause.downcast_ref::<selinux::Error>() {
88*e1997b9aSAndroid Build Coastguard Worker Some(selinux::Error::PermissionDenied) => ResponseCode::PERMISSION_DENIED.0,
89*e1997b9aSAndroid Build Coastguard Worker _ => ResponseCode::SYSTEM_ERROR.0,
90*e1997b9aSAndroid Build Coastguard Worker },
91*e1997b9aSAndroid Build Coastguard Worker };
92*e1997b9aSAndroid Build Coastguard Worker BinderStatus::new_service_specific_error(rc, anyhow_error_to_cstring(&e).as_deref())
93*e1997b9aSAndroid Build Coastguard Worker }
94*e1997b9aSAndroid Build Coastguard Worker }
95*e1997b9aSAndroid Build Coastguard Worker
96*e1997b9aSAndroid Build Coastguard Worker /// This struct is defined to implement the aforementioned AIDL interface.
97*e1997b9aSAndroid Build Coastguard Worker /// As of now, it is an empty struct.
98*e1997b9aSAndroid Build Coastguard Worker pub struct AuthorizationManager;
99*e1997b9aSAndroid Build Coastguard Worker
100*e1997b9aSAndroid Build Coastguard Worker impl AuthorizationManager {
101*e1997b9aSAndroid Build Coastguard Worker /// Create a new instance of Keystore Authorization service.
new_native_binder() -> Result<Strong<dyn IKeystoreAuthorization>>102*e1997b9aSAndroid Build Coastguard Worker pub fn new_native_binder() -> Result<Strong<dyn IKeystoreAuthorization>> {
103*e1997b9aSAndroid Build Coastguard Worker Ok(BnKeystoreAuthorization::new_binder(
104*e1997b9aSAndroid Build Coastguard Worker Self,
105*e1997b9aSAndroid Build Coastguard Worker BinderFeatures { set_requesting_sid: true, ..BinderFeatures::default() },
106*e1997b9aSAndroid Build Coastguard Worker ))
107*e1997b9aSAndroid Build Coastguard Worker }
108*e1997b9aSAndroid Build Coastguard Worker
add_auth_token(&self, auth_token: &HardwareAuthToken) -> Result<()>109*e1997b9aSAndroid Build Coastguard Worker fn add_auth_token(&self, auth_token: &HardwareAuthToken) -> Result<()> {
110*e1997b9aSAndroid Build Coastguard Worker // Check keystore permission.
111*e1997b9aSAndroid Build Coastguard Worker check_keystore_permission(KeystorePerm::AddAuth)
112*e1997b9aSAndroid Build Coastguard Worker .context(ks_err!("caller missing AddAuth permissions"))?;
113*e1997b9aSAndroid Build Coastguard Worker
114*e1997b9aSAndroid Build Coastguard Worker log::info!(
115*e1997b9aSAndroid Build Coastguard Worker "add_auth_token(challenge={}, userId={}, authId={}, authType={:#x}, timestamp={}ms)",
116*e1997b9aSAndroid Build Coastguard Worker auth_token.challenge,
117*e1997b9aSAndroid Build Coastguard Worker auth_token.userId,
118*e1997b9aSAndroid Build Coastguard Worker auth_token.authenticatorId,
119*e1997b9aSAndroid Build Coastguard Worker auth_token.authenticatorType.0,
120*e1997b9aSAndroid Build Coastguard Worker auth_token.timestamp.milliSeconds,
121*e1997b9aSAndroid Build Coastguard Worker );
122*e1997b9aSAndroid Build Coastguard Worker
123*e1997b9aSAndroid Build Coastguard Worker ENFORCEMENTS.add_auth_token(auth_token.clone());
124*e1997b9aSAndroid Build Coastguard Worker Ok(())
125*e1997b9aSAndroid Build Coastguard Worker }
126*e1997b9aSAndroid Build Coastguard Worker
on_device_unlocked(&self, user_id: i32, password: Option<Password>) -> Result<()>127*e1997b9aSAndroid Build Coastguard Worker fn on_device_unlocked(&self, user_id: i32, password: Option<Password>) -> Result<()> {
128*e1997b9aSAndroid Build Coastguard Worker log::info!(
129*e1997b9aSAndroid Build Coastguard Worker "on_device_unlocked(user_id={}, password.is_some()={})",
130*e1997b9aSAndroid Build Coastguard Worker user_id,
131*e1997b9aSAndroid Build Coastguard Worker password.is_some(),
132*e1997b9aSAndroid Build Coastguard Worker );
133*e1997b9aSAndroid Build Coastguard Worker check_keystore_permission(KeystorePerm::Unlock)
134*e1997b9aSAndroid Build Coastguard Worker .context(ks_err!("caller missing Unlock permissions"))?;
135*e1997b9aSAndroid Build Coastguard Worker ENFORCEMENTS.set_device_locked(user_id, false);
136*e1997b9aSAndroid Build Coastguard Worker
137*e1997b9aSAndroid Build Coastguard Worker let mut skm = SUPER_KEY.write().unwrap();
138*e1997b9aSAndroid Build Coastguard Worker if let Some(password) = password {
139*e1997b9aSAndroid Build Coastguard Worker DB.with(|db| {
140*e1997b9aSAndroid Build Coastguard Worker skm.unlock_user(&mut db.borrow_mut(), &LEGACY_IMPORTER, user_id as u32, &password)
141*e1997b9aSAndroid Build Coastguard Worker })
142*e1997b9aSAndroid Build Coastguard Worker .context(ks_err!("Unlock with password."))
143*e1997b9aSAndroid Build Coastguard Worker } else {
144*e1997b9aSAndroid Build Coastguard Worker DB.with(|db| skm.try_unlock_user_with_biometric(&mut db.borrow_mut(), user_id as u32))
145*e1997b9aSAndroid Build Coastguard Worker .context(ks_err!("try_unlock_user_with_biometric failed user_id={user_id}"))
146*e1997b9aSAndroid Build Coastguard Worker }
147*e1997b9aSAndroid Build Coastguard Worker }
148*e1997b9aSAndroid Build Coastguard Worker
on_device_locked( &self, user_id: i32, unlocking_sids: &[i64], weak_unlock_enabled: bool, ) -> Result<()>149*e1997b9aSAndroid Build Coastguard Worker fn on_device_locked(
150*e1997b9aSAndroid Build Coastguard Worker &self,
151*e1997b9aSAndroid Build Coastguard Worker user_id: i32,
152*e1997b9aSAndroid Build Coastguard Worker unlocking_sids: &[i64],
153*e1997b9aSAndroid Build Coastguard Worker weak_unlock_enabled: bool,
154*e1997b9aSAndroid Build Coastguard Worker ) -> Result<()> {
155*e1997b9aSAndroid Build Coastguard Worker log::info!(
156*e1997b9aSAndroid Build Coastguard Worker "on_device_locked(user_id={}, unlocking_sids={:?}, weak_unlock_enabled={})",
157*e1997b9aSAndroid Build Coastguard Worker user_id,
158*e1997b9aSAndroid Build Coastguard Worker unlocking_sids,
159*e1997b9aSAndroid Build Coastguard Worker weak_unlock_enabled
160*e1997b9aSAndroid Build Coastguard Worker );
161*e1997b9aSAndroid Build Coastguard Worker check_keystore_permission(KeystorePerm::Lock)
162*e1997b9aSAndroid Build Coastguard Worker .context(ks_err!("caller missing Lock permission"))?;
163*e1997b9aSAndroid Build Coastguard Worker ENFORCEMENTS.set_device_locked(user_id, true);
164*e1997b9aSAndroid Build Coastguard Worker let mut skm = SUPER_KEY.write().unwrap();
165*e1997b9aSAndroid Build Coastguard Worker DB.with(|db| {
166*e1997b9aSAndroid Build Coastguard Worker skm.lock_unlocked_device_required_keys(
167*e1997b9aSAndroid Build Coastguard Worker &mut db.borrow_mut(),
168*e1997b9aSAndroid Build Coastguard Worker user_id as u32,
169*e1997b9aSAndroid Build Coastguard Worker unlocking_sids,
170*e1997b9aSAndroid Build Coastguard Worker weak_unlock_enabled,
171*e1997b9aSAndroid Build Coastguard Worker );
172*e1997b9aSAndroid Build Coastguard Worker });
173*e1997b9aSAndroid Build Coastguard Worker Ok(())
174*e1997b9aSAndroid Build Coastguard Worker }
175*e1997b9aSAndroid Build Coastguard Worker
on_weak_unlock_methods_expired(&self, user_id: i32) -> Result<()>176*e1997b9aSAndroid Build Coastguard Worker fn on_weak_unlock_methods_expired(&self, user_id: i32) -> Result<()> {
177*e1997b9aSAndroid Build Coastguard Worker log::info!("on_weak_unlock_methods_expired(user_id={})", user_id);
178*e1997b9aSAndroid Build Coastguard Worker check_keystore_permission(KeystorePerm::Lock)
179*e1997b9aSAndroid Build Coastguard Worker .context(ks_err!("caller missing Lock permission"))?;
180*e1997b9aSAndroid Build Coastguard Worker SUPER_KEY.write().unwrap().wipe_plaintext_unlocked_device_required_keys(user_id as u32);
181*e1997b9aSAndroid Build Coastguard Worker Ok(())
182*e1997b9aSAndroid Build Coastguard Worker }
183*e1997b9aSAndroid Build Coastguard Worker
on_non_lskf_unlock_methods_expired(&self, user_id: i32) -> Result<()>184*e1997b9aSAndroid Build Coastguard Worker fn on_non_lskf_unlock_methods_expired(&self, user_id: i32) -> Result<()> {
185*e1997b9aSAndroid Build Coastguard Worker log::info!("on_non_lskf_unlock_methods_expired(user_id={})", user_id);
186*e1997b9aSAndroid Build Coastguard Worker check_keystore_permission(KeystorePerm::Lock)
187*e1997b9aSAndroid Build Coastguard Worker .context(ks_err!("caller missing Lock permission"))?;
188*e1997b9aSAndroid Build Coastguard Worker SUPER_KEY.write().unwrap().wipe_all_unlocked_device_required_keys(user_id as u32);
189*e1997b9aSAndroid Build Coastguard Worker Ok(())
190*e1997b9aSAndroid Build Coastguard Worker }
191*e1997b9aSAndroid Build Coastguard Worker
get_auth_tokens_for_credstore( &self, challenge: i64, secure_user_id: i64, auth_token_max_age_millis: i64, ) -> Result<AuthorizationTokens>192*e1997b9aSAndroid Build Coastguard Worker fn get_auth_tokens_for_credstore(
193*e1997b9aSAndroid Build Coastguard Worker &self,
194*e1997b9aSAndroid Build Coastguard Worker challenge: i64,
195*e1997b9aSAndroid Build Coastguard Worker secure_user_id: i64,
196*e1997b9aSAndroid Build Coastguard Worker auth_token_max_age_millis: i64,
197*e1997b9aSAndroid Build Coastguard Worker ) -> Result<AuthorizationTokens> {
198*e1997b9aSAndroid Build Coastguard Worker // Check permission. Function should return if this failed. Therefore having '?' at the end
199*e1997b9aSAndroid Build Coastguard Worker // is very important.
200*e1997b9aSAndroid Build Coastguard Worker check_keystore_permission(KeystorePerm::GetAuthToken)
201*e1997b9aSAndroid Build Coastguard Worker .context(ks_err!("caller missing GetAuthToken permission"))?;
202*e1997b9aSAndroid Build Coastguard Worker
203*e1997b9aSAndroid Build Coastguard Worker // If the challenge is zero, return error
204*e1997b9aSAndroid Build Coastguard Worker if challenge == 0 {
205*e1997b9aSAndroid Build Coastguard Worker return Err(Error::Rc(ResponseCode::INVALID_ARGUMENT))
206*e1997b9aSAndroid Build Coastguard Worker .context(ks_err!("Challenge can not be zero."));
207*e1997b9aSAndroid Build Coastguard Worker }
208*e1997b9aSAndroid Build Coastguard Worker // Obtain the auth token and the timestamp token from the enforcement module.
209*e1997b9aSAndroid Build Coastguard Worker let (auth_token, ts_token) =
210*e1997b9aSAndroid Build Coastguard Worker ENFORCEMENTS.get_auth_tokens(challenge, secure_user_id, auth_token_max_age_millis)?;
211*e1997b9aSAndroid Build Coastguard Worker Ok(AuthorizationTokens { authToken: auth_token, timestampToken: ts_token })
212*e1997b9aSAndroid Build Coastguard Worker }
213*e1997b9aSAndroid Build Coastguard Worker
get_last_auth_time( &self, secure_user_id: i64, auth_types: &[HardwareAuthenticatorType], ) -> Result<i64>214*e1997b9aSAndroid Build Coastguard Worker fn get_last_auth_time(
215*e1997b9aSAndroid Build Coastguard Worker &self,
216*e1997b9aSAndroid Build Coastguard Worker secure_user_id: i64,
217*e1997b9aSAndroid Build Coastguard Worker auth_types: &[HardwareAuthenticatorType],
218*e1997b9aSAndroid Build Coastguard Worker ) -> Result<i64> {
219*e1997b9aSAndroid Build Coastguard Worker // Check keystore permission.
220*e1997b9aSAndroid Build Coastguard Worker check_keystore_permission(KeystorePerm::GetLastAuthTime)
221*e1997b9aSAndroid Build Coastguard Worker .context(ks_err!("caller missing GetLastAuthTime permission"))?;
222*e1997b9aSAndroid Build Coastguard Worker
223*e1997b9aSAndroid Build Coastguard Worker let mut max_time: i64 = -1;
224*e1997b9aSAndroid Build Coastguard Worker for auth_type in auth_types.iter() {
225*e1997b9aSAndroid Build Coastguard Worker if let Some(time) = ENFORCEMENTS.get_last_auth_time(secure_user_id, *auth_type) {
226*e1997b9aSAndroid Build Coastguard Worker if time.milliseconds() > max_time {
227*e1997b9aSAndroid Build Coastguard Worker max_time = time.milliseconds();
228*e1997b9aSAndroid Build Coastguard Worker }
229*e1997b9aSAndroid Build Coastguard Worker }
230*e1997b9aSAndroid Build Coastguard Worker }
231*e1997b9aSAndroid Build Coastguard Worker
232*e1997b9aSAndroid Build Coastguard Worker if max_time >= 0 {
233*e1997b9aSAndroid Build Coastguard Worker Ok(max_time)
234*e1997b9aSAndroid Build Coastguard Worker } else {
235*e1997b9aSAndroid Build Coastguard Worker Err(Error::Rc(ResponseCode::NO_AUTH_TOKEN_FOUND))
236*e1997b9aSAndroid Build Coastguard Worker .context(ks_err!("No auth token found"))
237*e1997b9aSAndroid Build Coastguard Worker }
238*e1997b9aSAndroid Build Coastguard Worker }
239*e1997b9aSAndroid Build Coastguard Worker }
240*e1997b9aSAndroid Build Coastguard Worker
241*e1997b9aSAndroid Build Coastguard Worker impl Interface for AuthorizationManager {}
242*e1997b9aSAndroid Build Coastguard Worker
243*e1997b9aSAndroid Build Coastguard Worker impl IKeystoreAuthorization for AuthorizationManager {
addAuthToken(&self, auth_token: &HardwareAuthToken) -> BinderResult<()>244*e1997b9aSAndroid Build Coastguard Worker fn addAuthToken(&self, auth_token: &HardwareAuthToken) -> BinderResult<()> {
245*e1997b9aSAndroid Build Coastguard Worker let _wp = wd::watch("IKeystoreAuthorization::addAuthToken");
246*e1997b9aSAndroid Build Coastguard Worker self.add_auth_token(auth_token).map_err(into_logged_binder)
247*e1997b9aSAndroid Build Coastguard Worker }
248*e1997b9aSAndroid Build Coastguard Worker
onDeviceUnlocked(&self, user_id: i32, password: Option<&[u8]>) -> BinderResult<()>249*e1997b9aSAndroid Build Coastguard Worker fn onDeviceUnlocked(&self, user_id: i32, password: Option<&[u8]>) -> BinderResult<()> {
250*e1997b9aSAndroid Build Coastguard Worker let _wp = wd::watch("IKeystoreAuthorization::onDeviceUnlocked");
251*e1997b9aSAndroid Build Coastguard Worker self.on_device_unlocked(user_id, password.map(|pw| pw.into())).map_err(into_logged_binder)
252*e1997b9aSAndroid Build Coastguard Worker }
253*e1997b9aSAndroid Build Coastguard Worker
onDeviceLocked( &self, user_id: i32, unlocking_sids: &[i64], weak_unlock_enabled: bool, ) -> BinderResult<()>254*e1997b9aSAndroid Build Coastguard Worker fn onDeviceLocked(
255*e1997b9aSAndroid Build Coastguard Worker &self,
256*e1997b9aSAndroid Build Coastguard Worker user_id: i32,
257*e1997b9aSAndroid Build Coastguard Worker unlocking_sids: &[i64],
258*e1997b9aSAndroid Build Coastguard Worker weak_unlock_enabled: bool,
259*e1997b9aSAndroid Build Coastguard Worker ) -> BinderResult<()> {
260*e1997b9aSAndroid Build Coastguard Worker let _wp = wd::watch("IKeystoreAuthorization::onDeviceLocked");
261*e1997b9aSAndroid Build Coastguard Worker self.on_device_locked(user_id, unlocking_sids, weak_unlock_enabled)
262*e1997b9aSAndroid Build Coastguard Worker .map_err(into_logged_binder)
263*e1997b9aSAndroid Build Coastguard Worker }
264*e1997b9aSAndroid Build Coastguard Worker
onWeakUnlockMethodsExpired(&self, user_id: i32) -> BinderResult<()>265*e1997b9aSAndroid Build Coastguard Worker fn onWeakUnlockMethodsExpired(&self, user_id: i32) -> BinderResult<()> {
266*e1997b9aSAndroid Build Coastguard Worker let _wp = wd::watch("IKeystoreAuthorization::onWeakUnlockMethodsExpired");
267*e1997b9aSAndroid Build Coastguard Worker self.on_weak_unlock_methods_expired(user_id).map_err(into_logged_binder)
268*e1997b9aSAndroid Build Coastguard Worker }
269*e1997b9aSAndroid Build Coastguard Worker
onNonLskfUnlockMethodsExpired(&self, user_id: i32) -> BinderResult<()>270*e1997b9aSAndroid Build Coastguard Worker fn onNonLskfUnlockMethodsExpired(&self, user_id: i32) -> BinderResult<()> {
271*e1997b9aSAndroid Build Coastguard Worker let _wp = wd::watch("IKeystoreAuthorization::onNonLskfUnlockMethodsExpired");
272*e1997b9aSAndroid Build Coastguard Worker self.on_non_lskf_unlock_methods_expired(user_id).map_err(into_logged_binder)
273*e1997b9aSAndroid Build Coastguard Worker }
274*e1997b9aSAndroid Build Coastguard Worker
getAuthTokensForCredStore( &self, challenge: i64, secure_user_id: i64, auth_token_max_age_millis: i64, ) -> binder::Result<AuthorizationTokens>275*e1997b9aSAndroid Build Coastguard Worker fn getAuthTokensForCredStore(
276*e1997b9aSAndroid Build Coastguard Worker &self,
277*e1997b9aSAndroid Build Coastguard Worker challenge: i64,
278*e1997b9aSAndroid Build Coastguard Worker secure_user_id: i64,
279*e1997b9aSAndroid Build Coastguard Worker auth_token_max_age_millis: i64,
280*e1997b9aSAndroid Build Coastguard Worker ) -> binder::Result<AuthorizationTokens> {
281*e1997b9aSAndroid Build Coastguard Worker let _wp = wd::watch("IKeystoreAuthorization::getAuthTokensForCredStore");
282*e1997b9aSAndroid Build Coastguard Worker self.get_auth_tokens_for_credstore(challenge, secure_user_id, auth_token_max_age_millis)
283*e1997b9aSAndroid Build Coastguard Worker .map_err(into_logged_binder)
284*e1997b9aSAndroid Build Coastguard Worker }
285*e1997b9aSAndroid Build Coastguard Worker
getLastAuthTime( &self, secure_user_id: i64, auth_types: &[HardwareAuthenticatorType], ) -> binder::Result<i64>286*e1997b9aSAndroid Build Coastguard Worker fn getLastAuthTime(
287*e1997b9aSAndroid Build Coastguard Worker &self,
288*e1997b9aSAndroid Build Coastguard Worker secure_user_id: i64,
289*e1997b9aSAndroid Build Coastguard Worker auth_types: &[HardwareAuthenticatorType],
290*e1997b9aSAndroid Build Coastguard Worker ) -> binder::Result<i64> {
291*e1997b9aSAndroid Build Coastguard Worker if aconfig_android_hardware_biometrics_rust::last_authentication_time() {
292*e1997b9aSAndroid Build Coastguard Worker self.get_last_auth_time(secure_user_id, auth_types).map_err(into_logged_binder)
293*e1997b9aSAndroid Build Coastguard Worker } else {
294*e1997b9aSAndroid Build Coastguard Worker Err(BinderStatus::new_service_specific_error(
295*e1997b9aSAndroid Build Coastguard Worker ResponseCode::PERMISSION_DENIED.0,
296*e1997b9aSAndroid Build Coastguard Worker Some(CString::new("Feature is not enabled.").unwrap().as_c_str()),
297*e1997b9aSAndroid Build Coastguard Worker ))
298*e1997b9aSAndroid Build Coastguard Worker }
299*e1997b9aSAndroid Build Coastguard Worker }
300*e1997b9aSAndroid Build Coastguard Worker }
301