Last active
February 18, 2022 14:26
-
-
Save grigorig/dec727e84524e59401f5d82d91566c4a to your computer and use it in GitHub Desktop.
Software TPM setup with swtpm plus initialization
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
#!/usr/bin/bash | |
modprobe tpm_vtpm_proxy | |
rm -rf /tmp/vtpm.state /tmp/vtpm.* | |
mkdir -p /tmp/vtpm.state | |
swtpm chardev --vtpm-proxy --tpmstate dir=/tmp/vtpm.state --tpm2 --ctrl type=tcp,port=2322 --log file=/tmp/vtpm.log,level=2 >/tmp/vtpm.out & | |
trap "kill %%" SIGINT EXIT | |
for i in {1..5}; do | |
[[ -s /tmp/vtpm.out ]] && break | |
echo "waiting for swtpm to be ready" | |
sleep 1 | |
done | |
line=$(</tmp/vtpm.out) | |
pat='/dev/tpm([0-9]+)' | |
if [[ $line =~ $pat ]]; then | |
idx="${BASH_REMATCH[1]}" | |
echo "swtpm ready with device index $idx" | |
else | |
echo "vtpm not ready!" | |
kill %% | |
wait -f | |
exit 1 | |
fi | |
echo "setting up vtpm" | |
export TPM2TOOLS_TCTI="device:/dev/tpmrm$idx" | |
tpm2_pcrextend 7:sha256=b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c | |
wait -f |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment