blob: c6a5b688743b7541952582e8285afdf1ae7e135d [file] [log] [blame]
Janis Danisevskisc51dff82021-10-20 09:51:16 -07001// Copyright 2021, 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//! Main entry point for diced, the friendly neighborhood DICE service.
16
Janis Danisevskis99652dc2021-10-20 15:59:33 -070017use diced::{DiceMaintenance, DiceNode, ResidentNode};
18use std::convert::TryInto;
Janis Danisevskisc51dff82021-10-20 09:51:16 -070019use std::panic;
20use std::sync::Arc;
21
Janis Danisevskis99652dc2021-10-20 15:59:33 -070022static DICE_NODE_SERVICE_NAME: &str = "android.security.dice.IDiceNode";
23static DICE_MAINTENANCE_SERVICE_NAME: &str = "android.security.dice.IDiceMaintenance";
Janis Danisevskisc51dff82021-10-20 09:51:16 -070024
25fn main() {
26 android_logger::init_once(
27 android_logger::Config::default().with_tag("diced").with_min_level(log::Level::Debug),
28 );
29 // Redirect panic messages to logcat.
30 panic::set_hook(Box::new(|panic_info| {
31 log::error!("{}", panic_info);
32 }));
33
34 // Saying hi.
35 log::info!("Diced, your friendly neighborhood DICE service, is starting.");
36
Janis Danisevskis99652dc2021-10-20 15:59:33 -070037 let (cdi_attest, cdi_seal, bcc) = diced_sample_inputs::make_sample_bcc_and_cdis()
38 .expect("Failed to create sample dice artifacts.");
39
Janis Danisevskisc51dff82021-10-20 09:51:16 -070040 let node_impl = Arc::new(
Janis Danisevskis99652dc2021-10-20 15:59:33 -070041 ResidentNode::new(
42 cdi_attest[..].try_into().expect("Failed to convert cdi_attest into array ref."),
43 cdi_seal[..].try_into().expect("Failed to convert cdi_seal into array ref."),
44 bcc,
45 )
46 .expect("Failed to construct a resident node."),
Janis Danisevskisc51dff82021-10-20 09:51:16 -070047 );
48
Janis Danisevskis99652dc2021-10-20 15:59:33 -070049 let node = DiceNode::new_as_binder(node_impl.clone())
50 .expect("Failed to create IDiceNode service instance.");
Janis Danisevskisc51dff82021-10-20 09:51:16 -070051
Janis Danisevskis99652dc2021-10-20 15:59:33 -070052 let maintenance = DiceMaintenance::new_as_binder(node_impl)
53 .expect("Failed to create IDiceMaintenance service instance.");
54
55 binder::add_service(DICE_NODE_SERVICE_NAME, node.as_binder())
Janis Danisevskisc51dff82021-10-20 09:51:16 -070056 .expect("Failed to register IDiceNode Service");
57
Janis Danisevskis99652dc2021-10-20 15:59:33 -070058 binder::add_service(DICE_MAINTENANCE_SERVICE_NAME, maintenance.as_binder())
59 .expect("Failed to register IDiceMaintenance Service");
60
Janis Danisevskisc51dff82021-10-20 09:51:16 -070061 log::info!("Joining thread pool now.");
62 binder::ProcessState::join_thread_pool();
63}