Hasini Gunasinghe | 3410f79 | 2020-09-14 17:55: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 | |
| 15 | //TODO: remove this after implementing the methods. |
| 16 | #![allow(dead_code)] |
| 17 | |
| 18 | //! This is the Keystore 2.0 Enforcements module. |
| 19 | // TODO: more description to follow. |
| 20 | use android_hardware_security_keymint::aidl::android::hardware::security::keymint::HardwareAuthToken::HardwareAuthToken; |
| 21 | use std::collections::{HashMap, HashSet}; |
| 22 | use std::sync::Mutex; |
| 23 | |
| 24 | /// Enforcements data structure |
| 25 | pub struct Enforcements { |
| 26 | // This hash set contains the user ids for whom the device is currently unlocked. If a user id |
| 27 | // is not in the set, it implies that the device is locked for the user. |
| 28 | device_unlocked_set: Mutex<HashSet<i32>>, |
| 29 | // This maps the operation challenge to an optional auth token, to maintain op-auth tokens |
| 30 | // in-memory, until they are picked up and given to the operation by authorise_update_finish(). |
| 31 | op_auth_map: Mutex<HashMap<i64, Option<HardwareAuthToken>>>, |
| 32 | } |
| 33 | |
| 34 | impl Enforcements { |
| 35 | /// Creates an enforcement object with the two data structures it holds. |
| 36 | pub fn new() -> Self { |
| 37 | Enforcements { |
| 38 | device_unlocked_set: Mutex::new(HashSet::new()), |
| 39 | op_auth_map: Mutex::new(HashMap::new()), |
| 40 | } |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | impl Default for Enforcements { |
| 45 | fn default() -> Self { |
| 46 | Self::new() |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | //TODO: Add tests to enforcement module (b/175578618). |