Skip to content

Commit 6a062f1

Browse files
committed
Lock PCR range
1 parent a8183ca commit 6a062f1

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

fortanix-vme/nsm/src/lib.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pub use serde_bytes::ByteBuf;
44

55
pub struct Nsm(i32);
66

7-
#[derive(Debug)]
7+
#[derive(Debug, PartialEq)]
88
pub enum Error {
99
AttestationError(AttestationError),
1010
BufferTooSmall,
@@ -105,7 +105,6 @@ impl TryFrom<Response> for Pcr {
105105
impl Nsm {
106106
pub fn new() -> Result<Self, Error> {
107107
let fd = nsm_driver::nsm_init();
108-
109108
if fd < 0 {
110109
Err(Error::CannotOpenDriver)
111110
} else {
@@ -151,6 +150,18 @@ impl Nsm {
151150
_ => Err(Error::InvalidResponse),
152151
}
153152
}
153+
154+
/// Lock PlatformConfigurationRegisters at indexes `[0, range)` from further modifications
155+
pub fn lock_pcrs(&self, range: u16) -> Result<(), Error> {
156+
let req = Request::LockPCRs {
157+
range,
158+
};
159+
match nsm_driver::nsm_process_request(self.0, req) {
160+
Response::LockPCRs => Ok(()),
161+
Response::Error(code) => Err(code.into()),
162+
_ => Err(Error::InvalidResponse),
163+
}
164+
}
154165
}
155166

156167
impl Drop for Nsm {

fortanix-vme/tests/nsm-test/src/main.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,10 @@ fn main() {
3838
nsm.lock_pcr(16).unwrap();
3939
println!("pcr16 = {:?}", nsm.describe_pcr(10));
4040
assert_eq!(nsm.describe_pcr(16).unwrap().locked, true);
41+
42+
nsm.lock_pcrs(18).unwrap();
43+
for pcr in 0..=18 {
44+
println!("#pcr{} = {:?}", pcr, nsm.describe_pcr(pcr));
45+
assert_eq!(nsm.describe_pcr(pcr).map(|val| val.locked), Ok(pcr < 18));
46+
}
4147
}

0 commit comments

Comments
 (0)