Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion dstack/tee-simulator/src/nsm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ impl Default for NsmState {
}

impl NsmState {
fn measured() -> Self {
let mut state = Self::default();
for index in 0..=2 {
let digest = Sha384::digest(format!("dstack-tee-simulator/nsm/pcr/{index}").as_bytes());
state.pcrs[index].copy_from_slice(&digest);
}
state
}

fn handle(&mut self, generator: &NsmGenerator, request: Request) -> Response {
match request {
Request::DescribePCR { index } => {
Expand Down Expand Up @@ -376,7 +385,7 @@ pub fn run(config: &TeeSimulatorConfig) -> Result<()> {
.set(Arc::new(NsmGenerator::from_seed(parse_seed(seed)?)?))
.map_err(|_| anyhow::anyhow!("NSM simulator was already initialized"))?;
STATE
.set(Mutex::new(NsmState::default()))
.set(Mutex::new(NsmState::measured()))
.map_err(|_| anyhow::anyhow!("NSM simulator state was already initialized"))?;

let device_name = CString::new("DEVNAME=nsm")?;
Expand Down Expand Up @@ -441,6 +450,17 @@ mod tests {
}
}

#[test]
fn measured_state_models_a_production_enclave() {
let state = NsmState::measured();
assert!(state.pcrs[..=2]
.iter()
.all(|value| value.iter().any(|byte| *byte != 0)));
assert!(state.pcrs[3..]
.iter()
.all(|value| value.iter().all(|byte| *byte == 0)));
}

#[test]
fn pcr_lifecycle_matches_nsm_semantics() {
let generator = NsmGenerator::from_seed([0x51; 32]).unwrap();
Expand Down
10 changes: 10 additions & 0 deletions dstack/tests/e2e/attestation/run-platform.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ elif [[ "$TEE_PLATFORM" == dstack-amd-sev-snp ]]; then
dstack-util attest-json --input "$WORK/snp-fixture.bin" --output "$WORK/snp-fixture.json"
VM_CONFIG=$(jq -c '.config | fromjson' "$WORK/snp-fixture.json")
MR_CONFIG=$(jq -r .mr_config <<<"$VM_CONFIG")
elif [[ "$TEE_PLATFORM" == dstack-nitro-enclave ]]; then
for index in 0 1 2; do
printf 'dstack-tee-simulator/nsm/pcr/%s' "$index" |
sha384sum | cut -d' ' -f1 > "$WORK/pcr$index"
done
OS_IMAGE_HASH=$(
cat "$WORK/pcr0" "$WORK/pcr1" "$WORK/pcr2" |
xxd -r -p | sha256sum | cut -d' ' -f1
)
VM_CONFIG=$(jq -cn --arg os "$OS_IMAGE_HASH" '{os_image_hash:$os}')
elif [[ "$TEE_PLATFORM" == dstack-aws-nitro-tpm ]]; then
ZERO_PCR=$(printf '00%.0s' $(seq 1 48))
printf '%s' "$ZERO_PCR" > "$WORK/pcr4"
Expand Down