Skip to content

Commit 82011f8

Browse files
tpm: Add v2 Tcg methods related to PCR banks
1 parent bf74459 commit 82011f8

File tree

2 files changed

+62
-0
lines changed
  • uefi/src/proto/tcg
  • uefi-test-runner/src/proto

2 files changed

+62
-0
lines changed

uefi-test-runner/src/proto/tcg.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,25 @@ pub fn test_tcg_v2(bt: &BootServices) {
197197
assert_eq!(capability.manufacturer_id, 0x4d4249);
198198
assert_eq!(capability.number_of_pcr_banks, 4);
199199
assert_eq!(capability.active_pcr_banks, expected_banks);
200+
201+
// Check the active PCR banks.
202+
assert_eq!(
203+
tcg.get_active_pcr_banks()
204+
.expect("get_active_pcr_banks failed"),
205+
expected_banks,
206+
);
207+
208+
// Set the active PCR banks. This should succeed, but won't have any effect
209+
// since we're not rebooting the system.
210+
tcg.set_active_pcr_banks(HashAlgorithm::SHA256)
211+
.expect("set_active_pcr_banks failed");
212+
213+
// Check that there was no attempt to change the active banks in the
214+
// previous boot.
215+
assert!(tcg
216+
.get_result_of_set_active_pcr_banks()
217+
.expect("get_result_of_set_active_pcr_banks failed")
218+
.is_none());
200219
}
201220

202221
pub fn test(bt: &BootServices) {

uefi/src/proto/tcg/v2.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,47 @@ impl Tcg {
190190
let mut capability = BootServiceCapability::default();
191191
unsafe { (self.get_capability)(self, &mut capability).into_with_val(|| capability) }
192192
}
193+
194+
/// Get a bitmap of the active PCR banks. Each bank corresponds to a hash
195+
/// algorithm.
196+
pub fn get_active_pcr_banks(&mut self) -> Result<HashAlgorithm> {
197+
let mut active_pcr_banks = HashAlgorithm::empty();
198+
199+
let status = unsafe { (self.get_active_pcr_banks)(self, &mut active_pcr_banks) };
200+
201+
status.into_with_val(|| active_pcr_banks)
202+
}
203+
204+
/// Set the active PCR banks. Each bank corresponds to a hash
205+
/// algorithm. This change will not take effect until the system is
206+
/// rebooted twice.
207+
pub fn set_active_pcr_banks(&mut self, active_pcr_banks: HashAlgorithm) -> Result {
208+
unsafe { (self.set_active_pcr_banks)(self, active_pcr_banks) }.into()
209+
}
210+
211+
/// Get the stored result of calling [`Tcg::set_active_pcr_banks`] in a
212+
/// previous boot.
213+
///
214+
/// If there was no attempt to set the active PCR banks in a previous boot,
215+
/// this returns `None`. Otherwise, it returns a numeric response code:
216+
/// * `0x00000000`: Success
217+
/// * `0x00000001..=0x00000FFF`: TPM error code
218+
/// * `0xfffffff0`: The operation was canceled by the user or timed out
219+
/// * `0xfffffff1`: Firmware error
220+
pub fn get_result_of_set_active_pcr_banks(&mut self) -> Result<Option<u32>> {
221+
let mut operation_present = 0;
222+
let mut response = 0;
223+
224+
let status = unsafe {
225+
(self.get_result_of_set_active_pcr_banks)(self, &mut operation_present, &mut response)
226+
};
227+
228+
status.into_with_val(|| {
229+
if operation_present == 0 {
230+
None
231+
} else {
232+
Some(response)
233+
}
234+
})
235+
}
193236
}

0 commit comments

Comments
 (0)