-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract stage1 attestation logic so it can be used for integration tests
Change-Id: If4bf0e66afbb508b9bbe7fcaf47f768673baa28c
- Loading branch information
Showing
11 changed files
with
168 additions
and
72 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# | ||
# Copyright 2024 The Project Oak Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
load("@rules_rust//rust:defs.bzl", "rust_library") | ||
|
||
package( | ||
default_visibility = ["//:internal"], | ||
licenses = ["notice"], | ||
) | ||
|
||
rust_library( | ||
name = "stage1_dice", | ||
srcs = glob( | ||
["src/**"], | ||
), | ||
crate_name = "oak_containers_stage1_dice", | ||
deps = [ | ||
"//oak_attestation", | ||
"//oak_dice", | ||
"//oak_proto_rust", | ||
"@oak_crates_index//:anyhow", | ||
"@oak_crates_index//:ciborium", | ||
"@oak_crates_index//:coset", | ||
"@oak_crates_index//:prost", | ||
"@oak_crates_index//:prost-types", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[package] | ||
name = "oak_containers_stage1_dice" | ||
version = "0.1.0" | ||
edition = "2021" | ||
authors = ["Andri Saar <andrisaar@google.com>"] | ||
license = "Apache-2.0" | ||
|
||
[dependencies] | ||
anyhow = "*" | ||
ciborium = { version = "*", default-features = false } | ||
coset = { version = "*", features = ["std"] } | ||
oak_attestation = { workspace = true } | ||
oak_dice = { workspace = true } | ||
oak_proto_rust = { workspace = true } | ||
prost = { workspace = true } | ||
prost-types = "*" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// | ||
// Copyright 2023 The Project Oak Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
#![feature(iterator_try_collect)] | ||
#![feature(never_type)] | ||
|
||
use ciborium::Value; | ||
use coset::cwt::ClaimName; | ||
use oak_dice::cert::{LAYER_2_CODE_MEASUREMENT_ID, SHA2_256_ID, SYSTEM_IMAGE_LAYER_ID}; | ||
use oak_proto_rust::oak::{ | ||
attestation::v1::{DiceData, Event, SystemLayerData}, | ||
RawDigest, | ||
}; | ||
use prost::Message; | ||
|
||
pub fn stage0_dice_data_into_dice_attester( | ||
stage0_dice_data: oak_dice::evidence::Stage0DiceData, | ||
eventlog: oak_proto_rust::oak::attestation::v1::EventLog, | ||
) -> anyhow::Result<oak_attestation::dice::DiceAttester> { | ||
let dice_data: DiceData = | ||
oak_attestation::dice::stage0_dice_data_and_event_log_to_proto(stage0_dice_data, eventlog)?; | ||
dice_data.try_into() | ||
} | ||
|
||
pub fn get_layer_data(system_image: &[u8]) -> oak_attestation::dice::LayerData { | ||
let digest = oak_attestation::dice::MeasureDigest::measure_digest(&system_image); | ||
let event = Event { | ||
tag: "stage1".to_string(), | ||
event: Some(prost_types::Any { | ||
type_url: "type.googleapis.com/oak.attestation.v1.SystemLayerData".to_string(), | ||
value: SystemLayerData { system_image: Some(digest.clone()) }.encode_to_vec(), | ||
}), | ||
}; | ||
let encoded_event = event.encode_to_vec(); | ||
let event_digest = | ||
oak_attestation::dice::MeasureDigest::measure_digest(&encoded_event.as_slice()); | ||
oak_attestation::dice::LayerData { | ||
additional_claims: vec![ | ||
( | ||
ClaimName::PrivateUse(SYSTEM_IMAGE_LAYER_ID), | ||
Value::Map(vec![( | ||
Value::Integer(LAYER_2_CODE_MEASUREMENT_ID.into()), | ||
Value::Map(vec![( | ||
Value::Integer(SHA2_256_ID.into()), | ||
Value::Bytes(digest.sha2_256.clone()), | ||
)]), | ||
)]), | ||
), | ||
( | ||
ClaimName::PrivateUse(oak_dice::cert::EVENT_ID), | ||
Value::Map(vec![( | ||
Value::Integer(SHA2_256_ID.into()), | ||
Value::Bytes(event_digest.sha2_256), | ||
)]), | ||
), | ||
], | ||
encoded_event, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters