Skip to content

Commit e4edad0

Browse files
committed
Makes NV context methods fail fast when missing session.
- Makes some of the context methods that deal with NV memory fail fast if a session has not been provided. Because according to the ESAPI specification some of the NV functions requires it. Signed-off-by: Jesper Brynolf <[email protected]>
1 parent 3956ae4 commit e4edad0

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

tss-esapi/src/context/tpm_commands/non_volatile_storage.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ impl Context {
2222
/// This method will instruct the TPM to reserve space for an NV index
2323
/// with the attributes defined in the provided parameters.
2424
///
25+
/// Please beware
26+
/// that this method requires an authorization session handle to be present.
27+
///
2528
/// # Arguments
2629
/// * `nv_auth` - The [Provision] used for authorization.
2730
/// * `auth` - The authorization value.
@@ -106,7 +109,7 @@ impl Context {
106109
Esys_NV_DefineSpace(
107110
self.mut_context(),
108111
AuthHandle::from(nv_auth).into(),
109-
self.optional_session_1(),
112+
self.required_session_1()?,
110113
self.optional_session_2(),
111114
self.optional_session_3(),
112115
&auth.unwrap_or_default().into(),
@@ -130,6 +133,9 @@ impl Context {
130133
/// The method will instruct the TPM to remove a
131134
/// nv index.
132135
///
136+
/// Please beware that this method requires an authorization
137+
/// session handle to be present.
138+
///
133139
/// # Arguments
134140
/// * `nv_auth` - The [Provision] used for authorization.
135141
/// * `nv_index_handle`- The [NvIndexHandle] associated with
@@ -207,7 +213,7 @@ impl Context {
207213
self.mut_context(),
208214
AuthHandle::from(nv_auth).into(),
209215
nv_index_handle.into(),
210-
self.optional_session_1(),
216+
self.required_session_1()?,
211217
self.optional_session_2(),
212218
self.optional_session_3(),
213219
)
@@ -339,6 +345,9 @@ impl Context {
339345
/// This method is used to write a value to
340346
/// the nv memory in the TPM.
341347
///
348+
/// Please beware that this method requires an authorization
349+
/// session handle to be present.
350+
///
342351
/// # Arguments
343352
/// * `auth_handle` - Handle indicating the source of authorization value.
344353
/// * `nv_index_handle` - The [NvIndexHandle] associated with NV memory
@@ -432,7 +441,7 @@ impl Context {
432441
self.mut_context(),
433442
AuthHandle::from(auth_handle).into(),
434443
nv_index_handle.into(),
435-
self.optional_session_1(),
444+
self.required_session_1()?,
436445
self.optional_session_2(),
437446
self.optional_session_3(),
438447
&data.into(),
@@ -451,6 +460,9 @@ impl Context {
451460
/// This method is used to increment monotonic counter
452461
/// in the TPM.
453462
///
463+
/// Please beware that this method requires an authorization
464+
/// session handle to be present.
465+
///
454466
/// # Arguments
455467
/// * `auth_handle` - Handle indicating the source of authorization value.
456468
/// * `nv_index_handle` - The [NvIndexHandle] associated with NV memory
@@ -535,7 +547,7 @@ impl Context {
535547
self.mut_context(),
536548
AuthHandle::from(auth_handle).into(),
537549
nv_index_handle.into(),
538-
self.optional_session_1(),
550+
self.required_session_1()?,
539551
self.optional_session_2(),
540552
self.optional_session_3(),
541553
)
@@ -555,6 +567,9 @@ impl Context {
555567
/// This method is used to read a value from an area in
556568
/// NV memory of the TPM.
557569
///
570+
/// Please beware that this method requires an authorization
571+
/// session handle to be present.
572+
///
558573
/// # Arguments
559574
/// * `auth_handle` - Handle indicating the source of authorization value.
560575
/// * `nv_index_handle` - The [NvIndexHandle] associated with NV memory
@@ -656,7 +671,7 @@ impl Context {
656671
self.mut_context(),
657672
AuthHandle::from(auth_handle).into(),
658673
nv_index_handle.into(),
659-
self.optional_session_1(),
674+
self.required_session_1()?,
660675
self.optional_session_2(),
661676
self.optional_session_3(),
662677
size,

0 commit comments

Comments
 (0)