Janis Danisevskis | c51dff8 | 2021-10-20 09:51:16 -0700 | [diff] [blame] | 1 | // 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 Danisevskis | 99652dc | 2021-10-20 15:59:33 -0700 | [diff] [blame] | 17 | use diced::{DiceMaintenance, DiceNode, ResidentNode}; |
| 18 | use std::convert::TryInto; |
Janis Danisevskis | c51dff8 | 2021-10-20 09:51:16 -0700 | [diff] [blame] | 19 | use std::panic; |
| 20 | use std::sync::Arc; |
| 21 | |
Janis Danisevskis | 99652dc | 2021-10-20 15:59:33 -0700 | [diff] [blame] | 22 | static DICE_NODE_SERVICE_NAME: &str = "android.security.dice.IDiceNode"; |
| 23 | static DICE_MAINTENANCE_SERVICE_NAME: &str = "android.security.dice.IDiceMaintenance"; |
Janis Danisevskis | c51dff8 | 2021-10-20 09:51:16 -0700 | [diff] [blame] | 24 | |
| 25 | fn 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 Danisevskis | 99652dc | 2021-10-20 15:59:33 -0700 | [diff] [blame] | 37 | let (cdi_attest, cdi_seal, bcc) = diced_sample_inputs::make_sample_bcc_and_cdis() |
| 38 | .expect("Failed to create sample dice artifacts."); |
| 39 | |
Janis Danisevskis | c51dff8 | 2021-10-20 09:51:16 -0700 | [diff] [blame] | 40 | let node_impl = Arc::new( |
Janis Danisevskis | 99652dc | 2021-10-20 15:59:33 -0700 | [diff] [blame] | 41 | 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 Danisevskis | c51dff8 | 2021-10-20 09:51:16 -0700 | [diff] [blame] | 47 | ); |
| 48 | |
Janis Danisevskis | 99652dc | 2021-10-20 15:59:33 -0700 | [diff] [blame] | 49 | let node = DiceNode::new_as_binder(node_impl.clone()) |
| 50 | .expect("Failed to create IDiceNode service instance."); |
Janis Danisevskis | c51dff8 | 2021-10-20 09:51:16 -0700 | [diff] [blame] | 51 | |
Janis Danisevskis | 99652dc | 2021-10-20 15:59:33 -0700 | [diff] [blame] | 52 | 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 Danisevskis | c51dff8 | 2021-10-20 09:51:16 -0700 | [diff] [blame] | 56 | .expect("Failed to register IDiceNode Service"); |
| 57 | |
Janis Danisevskis | 99652dc | 2021-10-20 15:59:33 -0700 | [diff] [blame] | 58 | binder::add_service(DICE_MAINTENANCE_SERVICE_NAME, maintenance.as_binder()) |
| 59 | .expect("Failed to register IDiceMaintenance Service"); |
| 60 | |
Janis Danisevskis | c51dff8 | 2021-10-20 09:51:16 -0700 | [diff] [blame] | 61 | log::info!("Joining thread pool now."); |
| 62 | binder::ProcessState::join_thread_pool(); |
| 63 | } |