Alan Stokes | 71cc11e | 2022-01-17 10:39:05 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2022 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 | |
Alan Stokes | c33d292 | 2022-01-18 14:17:00 +0000 | [diff] [blame] | 17 | //! Handles the use of DICE (via diced / IDiceNode) for accessing our VM's unique secret. |
Alan Stokes | 71cc11e | 2022-01-17 10:39:05 +0000 | [diff] [blame] | 18 | |
| 19 | use android_security_dice::aidl::android::security::dice::IDiceNode::IDiceNode; |
| 20 | use android_security_dice::binder::{wait_for_interface, Strong}; |
| 21 | use anyhow::{Context, Result}; |
| 22 | |
| 23 | pub struct Dice { |
| 24 | node: Strong<dyn IDiceNode>, |
| 25 | } |
| 26 | |
| 27 | impl Dice { |
| 28 | pub fn new() -> Result<Self> { |
| 29 | let dice_service = wait_for_interface::<dyn IDiceNode>("android.security.dice.IDiceNode") |
| 30 | .context("No IDiceNode service")?; |
| 31 | Ok(Self { node: dice_service }) |
| 32 | } |
| 33 | |
Alan Stokes | c33d292 | 2022-01-18 14:17:00 +0000 | [diff] [blame] | 34 | pub fn get_sealing_cdi(&self) -> Result<Vec<u8>> { |
| 35 | let input_values = []; |
| 36 | let bcc_handover = self.node.derive(&input_values).context("Failed to retrieve CDI")?; |
| 37 | Ok(bcc_handover.cdiSeal.to_vec()) |
| 38 | } |
Alan Stokes | 71cc11e | 2022-01-17 10:39:05 +0000 | [diff] [blame] | 39 | } |