blob: bc6e762daa900d6ef709decfcb48f09a57229e79 [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
17use diced::dice::CDI_SIZE;
18use diced::DiceNode;
19use diced::ResidentNode;
20use std::panic;
21use std::sync::Arc;
22
23static DICE_SERVICE_NAME: &str = "android.security.dice";
24
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
37 let node_impl = Arc::new(
38 ResidentNode::new(&[0u8; CDI_SIZE], &[1u8; CDI_SIZE], vec![])
39 .expect("Failed to construct a resident node."),
40 );
41
42 let node =
43 DiceNode::new_as_binder(node_impl).expect("Failed to create IDiceNode service instance.");
44
45 binder::add_service(DICE_SERVICE_NAME, node.as_binder())
46 .expect("Failed to register IDiceNode Service");
47
48 log::info!("Joining thread pool now.");
49 binder::ProcessState::join_thread_pool();
50}