Skip to content
Merged
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
49 changes: 31 additions & 18 deletions keylime/src/tpm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use thiserror::Error;
use tss_esapi::handles::SessionHandle;
use tss_esapi::interface_types::session_handles::PolicySession;
use tss_esapi::structures::{DigestList, SymmetricDefinition};

use openssl::{
hash::{Hasher, MessageDigest},
Expand Down Expand Up @@ -54,13 +53,14 @@
structure_tags::AttestationType,
},
structures::{
Attest, AttestInfo, Auth, CapabilityData, Data, Digest, DigestValues,
EccParameter, EccPoint, EccScheme, EncryptedSecret, HashScheme,
IdObject, KeyDerivationFunctionScheme, Name, PcrSelectionList,
PcrSelectionListBuilder, PcrSlot, Private as TssPrivate,
Public as TssPublic, PublicBuilder, PublicEccParametersBuilder,
PublicKeyRsa, PublicRsaParametersBuilder, RsaExponent, RsaScheme,
Signature, SignatureScheme, SymmetricDefinitionObject, Ticket,
Attest, AttestInfo, Auth, CapabilityData, Data, Digest, DigestList,
DigestValues, EccParameter, EccPoint, EccScheme, EncryptedSecret,
HashScheme, IdObject, KeyDerivationFunctionScheme, Name,
PcrSelectionList, PcrSelectionListBuilder, PcrSlot,
Private as TssPrivate, Public as TssPublic, PublicBuilder,
PublicEccParametersBuilder, PublicKeyRsa, PublicRsaParametersBuilder,
RsaExponent, RsaScheme, Signature, SignatureScheme,
SymmetricDefinition, SymmetricDefinitionObject, Ticket,
VerifiedTicket,
},
tcti_ldr::TctiNameConf,
Expand Down Expand Up @@ -1665,28 +1665,41 @@
&mut self,
expected_hash_algorithm: HashAlgorithm,
) -> Result<Vec<u32>> {
let mut selected_pcr_numbers: Vec<u32> = Vec::new();
let hashing_algorithm = crate::algorithms::hash_to_hashing_algorithm(
expected_hash_algorithm,
);
let pcr_selection_list =
self.get_pcr_selection_list(hashing_algorithm)?;
let pcrs_to_select: Vec<PcrSlot> = (0..24)
.map(|i| PcrSlot::try_from(1 << i))
.filter_map(|result| result.ok())
.collect();

Check warning on line 1674 in keylime/src/tpm.rs

View check run for this annotation

Codecov / codecov/patch

keylime/src/tpm.rs#L1674

Added line #L1674 was not covered by tests

let pcr_selection_list = PcrSelectionListBuilder::new()
.with_selection(hashing_algorithm, &pcrs_to_select)
.build()
.map_err(|e| TpmError::TSSPCRSelectionBuildError { source: e })?;

Check warning on line 1679 in keylime/src/tpm.rs

View check run for this annotation

Codecov / codecov/patch

keylime/src/tpm.rs#L1678-L1679

Added lines #L1678 - L1679 were not covered by tests

let mut selected_pcr_numbers: Vec<u32> = Vec::new();

for selection in pcr_selection_list.get_selections() {
if selection.hashing_algorithm() == hashing_algorithm {
let selected_slots = selection.selected();
for pcr_slot in selected_slots {
let pcr_mask_value: u32 = pcr_slot.into();
if pcr_mask_value > 0 {
let pcr_index = pcr_mask_value.trailing_zeros();
selected_pcr_numbers.push(pcr_index);
for i in 0..24 {
if (pcr_mask_value >> i) & 1 == 1 {
selected_pcr_numbers.push(i);
}

Check warning on line 1691 in keylime/src/tpm.rs

View check run for this annotation

Codecov / codecov/patch

keylime/src/tpm.rs#L1691

Added line #L1691 was not covered by tests
}
}
let mut sorted_pcr_numbers: Vec<u32> =
selected_pcr_numbers.into_iter().collect();
sorted_pcr_numbers.sort_unstable();
return Ok(sorted_pcr_numbers);
}
}

if !selected_pcr_numbers.is_empty() {
selected_pcr_numbers.sort_unstable();
selected_pcr_numbers.dedup();
return Ok(selected_pcr_numbers);
}

Check warning on line 1701 in keylime/src/tpm.rs

View check run for this annotation

Codecov / codecov/patch

keylime/src/tpm.rs#L1701

Added line #L1701 was not covered by tests

Err(TpmError::TSSPCRSelectionBuildError {
source: tss_esapi::Error::WrapperError(
tss_esapi::WrapperErrorKind::InvalidParam,
Expand Down