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