Shikha Panwar | eb223ba | 2023-10-19 14:54:06 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2023 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
David Drysdale | 8898d2e | 2023-11-07 15:20:15 +0000 | [diff] [blame] | 17 | //! Non-secure implementation of the Secretkeeper HAL. |
| 18 | |
Shikha Panwar | 2759df0 | 2023-11-27 22:00:42 +0000 | [diff] [blame] | 19 | use log::{error, info, Level}; |
David Drysdale | 8898d2e | 2023-11-07 15:20:15 +0000 | [diff] [blame] | 20 | use secretkeeper_hal::SecretkeeperService; |
David Drysdale | c3aa442 | 2023-12-18 16:29:18 +0000 | [diff] [blame] | 21 | use secretkeeper_nonsecure::{AuthGraphChannel, SecretkeeperChannel, LocalTa}; |
| 22 | use std::sync::{Arc, Mutex}; |
Shikha Panwar | eb223ba | 2023-10-19 14:54:06 +0000 | [diff] [blame] | 23 | use android_hardware_security_secretkeeper::aidl::android::hardware::security::secretkeeper::ISecretkeeper::{ |
Shikha Panwar | 2759df0 | 2023-11-27 22:00:42 +0000 | [diff] [blame] | 24 | BpSecretkeeper, ISecretkeeper, |
Shikha Panwar | eb223ba | 2023-10-19 14:54:06 +0000 | [diff] [blame] | 25 | }; |
Shikha Panwar | eb223ba | 2023-10-19 14:54:06 +0000 | [diff] [blame] | 26 | |
| 27 | fn main() { |
| 28 | // Initialize Android logging. |
| 29 | android_logger::init_once( |
| 30 | android_logger::Config::default() |
| 31 | .with_tag("NonSecureSecretkeeper") |
| 32 | .with_min_level(Level::Info) |
| 33 | .with_log_id(android_logger::LogId::System), |
| 34 | ); |
| 35 | // Redirect panic messages to logcat. |
| 36 | std::panic::set_hook(Box::new(|panic_info| { |
| 37 | error!("{}", panic_info); |
| 38 | })); |
| 39 | |
David Drysdale | 8898d2e | 2023-11-07 15:20:15 +0000 | [diff] [blame] | 40 | let ta = Arc::new(Mutex::new(LocalTa::new())); |
| 41 | let ag_channel = AuthGraphChannel(ta.clone()); |
| 42 | let sk_channel = SecretkeeperChannel(ta.clone()); |
| 43 | |
| 44 | let service = SecretkeeperService::new_as_binder(sk_channel, ag_channel); |
Shikha Panwar | eb223ba | 2023-10-19 14:54:06 +0000 | [diff] [blame] | 45 | let service_name = format!( |
| 46 | "{}/nonsecure", |
| 47 | <BpSecretkeeper as ISecretkeeper>::get_descriptor() |
| 48 | ); |
David Drysdale | 8898d2e | 2023-11-07 15:20:15 +0000 | [diff] [blame] | 49 | binder::add_service(&service_name, service.as_binder()).unwrap_or_else(|e| { |
| 50 | panic!("Failed to register service {service_name} because of {e:?}.",); |
Shikha Panwar | eb223ba | 2023-10-19 14:54:06 +0000 | [diff] [blame] | 51 | }); |
| 52 | info!("Registered Binder service, joining threadpool."); |
| 53 | binder::ProcessState::join_thread_pool(); |
| 54 | } |