blob: 436f9a78497ba0ae24742af4b83eccd2a65f2285 [file] [log] [blame]
Shikha Panwareb223ba2023-10-19 14:54:06 +00001/*
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 Drysdale8898d2e2023-11-07 15:20:15 +000017//! Non-secure implementation of the Secretkeeper HAL.
18
Shikha Panwar2759df02023-11-27 22:00:42 +000019use log::{error, info, Level};
David Drysdale8898d2e2023-11-07 15:20:15 +000020use secretkeeper_hal::SecretkeeperService;
David Drysdalec3aa4422023-12-18 16:29:18 +000021use secretkeeper_nonsecure::{AuthGraphChannel, SecretkeeperChannel, LocalTa};
22use std::sync::{Arc, Mutex};
Shikha Panwareb223ba2023-10-19 14:54:06 +000023use android_hardware_security_secretkeeper::aidl::android::hardware::security::secretkeeper::ISecretkeeper::{
Shikha Panwar2759df02023-11-27 22:00:42 +000024 BpSecretkeeper, ISecretkeeper,
Shikha Panwareb223ba2023-10-19 14:54:06 +000025};
Shikha Panwareb223ba2023-10-19 14:54:06 +000026
27fn 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 Drysdale8898d2e2023-11-07 15:20:15 +000040 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 Panwareb223ba2023-10-19 14:54:06 +000045 let service_name = format!(
46 "{}/nonsecure",
47 <BpSecretkeeper as ISecretkeeper>::get_descriptor()
48 );
David Drysdale8898d2e2023-11-07 15:20:15 +000049 binder::add_service(&service_name, service.as_binder()).unwrap_or_else(|e| {
50 panic!("Failed to register service {service_name} because of {e:?}.",);
Shikha Panwareb223ba2023-10-19 14:54:06 +000051 });
52 info!("Registered Binder service, joining threadpool.");
53 binder::ProcessState::join_thread_pool();
54}