• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 use diced_open_dice_cbor as dice;
16 use diced_sample_inputs;
17 use diced_utils;
18 use std::convert::TryInto;
19 
20 mod utils;
21 use utils::with_connection;
22 
23 // This test calls derive with an empty argument vector, then demotes the HAL using
24 // a set of three input values, and then calls derive with empty argument vector again.
25 // It then performs the same three derivation steps on the result of the former and compares
26 // the result to the result of the latter.
27 #[test]
demote_test()28 fn demote_test() {
29     with_connection(|device| {
30         let input_values = diced_sample_inputs::get_input_values_vector();
31         let former = device.derive(&[]).expect("Trying to call derive.");
32         device
33             .demote(&input_values)
34             .expect("Trying to call demote with input values.");
35 
36         let latter = device
37             .derive(&[])
38             .expect("Trying to call derive after demote.");
39 
40         let artifacts = diced_utils::ResidentArtifacts::new(
41             former.cdiAttest[..].try_into().unwrap(),
42             former.cdiSeal[..].try_into().unwrap(),
43             &former.bcc.data,
44         )
45         .unwrap();
46 
47         let input_values: Vec<diced_utils::InputValues> = input_values
48             .iter()
49             .map(|v| v.into())
50             .collect();
51 
52         let artifacts = artifacts
53             .execute_steps(input_values.iter().map(|v| v as &dyn dice::InputValues))
54             .unwrap();
55         let (cdi_attest, cdi_seal, bcc) = artifacts.into_tuple();
56         let from_former = diced_utils::make_bcc_handover(
57             cdi_attest[..].try_into().unwrap(),
58             cdi_seal[..].try_into().unwrap(),
59             &bcc,
60         )
61         .unwrap();
62         // TODO b/204938506 when we have a parser/verifier, check equivalence rather
63         // than bit by bit equality.
64         assert_eq!(latter, from_former);
65         Ok(())
66     })
67 }
68