-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split policy creation and measured boot PCR scripts as per review
- Loading branch information
1 parent
db408ec
commit 7b15783
Showing
4 changed files
with
67 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
recipes-support/tpm-test-scripts/tpm_check_measured_boot.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/bin/bash | ||
|
||
# Define the PCR index | ||
pcr_index=16 | ||
|
||
#script is located | ||
script_directory="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | ||
|
||
# Define the filename you want to check | ||
file_to_check="measured.pcrvalues" | ||
|
||
# Combine the directory and the filename | ||
file_path="$script_directory/$file_to_check" | ||
|
||
tpm2_pcrread -o pcr16.dat sha256:$pcr_index | ||
|
||
# creating a bin file with the value of zero | ||
dd if=/dev/zero of=pcr_zero.dat bs=32 count=1 | ||
|
||
#comparing the pcr.dat with pcr_zero.dat file, if the values is not extended means then it will terminated the whole process. | ||
cmp_value=$(cmp -s pcr16.dat pcr_zero.dat; echo $?) | ||
|
||
if [ "$cmp_value" -eq 1 ]; then | ||
echo "PCR value is extended we can proceed further" | ||
else | ||
echo "PCR value is all zeros, check whether it is the closed board or not." | ||
rm pcr16.dat | ||
exit 1 | ||
fi | ||
|
||
if [ -e "$file_path" ]; then | ||
echo "File $file_to_check exists in the script's directory." | ||
else | ||
echo "File $file_to_check does not exist in the script's directory, creating measured.pcrvalues file." | ||
cp pcr16.dat measured.pcrvalues | ||
fi | ||
|
||
# Start a policy auth session used when authenticating with a policy. | ||
tpm2_startauthsession --policy-session -S session1.dat | ||
|
||
# Measured boot check using tpm2_policypcr api carried out by comparing current state value with the measured.pcrvalues value; this is done by TPM internally. | ||
if tpm2_policypcr -S session1.dat -l sha256:$pcr_index -f $file_to_check; then | ||
echo "PCR value is extended and Passes the Measure Boot condition." | ||
else | ||
echo "PCR values are not matching, Measure Boot fails" | ||
exit 1 | ||
fi | ||
|