Skip to content

Commit ebb69b8

Browse files
committed
Add NV index reader (for reading AK certificate)
1 parent cfbeab0 commit ebb69b8

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ tracing = "0.1.41"
3535
tracing-subscriber = { version = "0.3.20", features = ["env-filter", "json"] }
3636
parity-scale-codec = "3.7.5"
3737
openssl = "0.10.75"
38+
tss-esapi = "7.6.0"
3839

3940
[dev-dependencies]
4041
rcgen = "0.14.5"

src/attestation/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
pub mod azure;
22
pub mod dcap;
33
pub mod measurements;
4+
pub mod nv_index;
45

56
use measurements::{MeasurementRecord, Measurements};
67
use parity_scale_codec::{Decode, Encode};

src/attestation/nv_index.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
use tss_esapi::{
2+
handles::NvIndexHandle,
3+
interface_types::{resource_handles::NvAuth, session_handles::AuthSession},
4+
structures::MaxNvBuffer,
5+
tcti_ldr::{DeviceConfig, TctiNameConf},
6+
Context,
7+
};
8+
9+
pub fn get_session_context() -> Result<Context, tss_esapi::Error> {
10+
let conf: TctiNameConf = TctiNameConf::Device(DeviceConfig::default());
11+
let mut context = Context::new(conf)?;
12+
let auth_session = AuthSession::Password;
13+
context.set_sessions((Some(auth_session), None, None));
14+
Ok(context)
15+
}
16+
17+
pub fn read_nv_index(ctx: &mut Context, index: u32) -> Result<Vec<u8>, anyhow::Error> {
18+
let handle = NvIndexHandle::from(index);
19+
let size = ctx
20+
.nv_read_public(handle.into())?
21+
.0
22+
.data_size()
23+
.try_into()
24+
.unwrap_or(0u16);
25+
26+
let data: MaxNvBuffer = ctx.nv_read(NvAuth::Owner, handle, size, 0)?;
27+
Ok(data.to_vec())
28+
}

0 commit comments

Comments
 (0)