123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361 |
- # SPDX-License-Identifier: BSD-3-Clause
- source helpers.sh
- cleanup() {
- rm -f \
- prim.ctx signing_key.ctx signing_key.pub signing_key.priv \
- att.data att.sig cp.hash rp.hash cphash.bin rphash.bin zero.bin
- if [ "${1}" != "no-shutdown" ]; then
- shut_down
- fi
- }
- trap cleanup EXIT
- start_up
- cleanup "no-shutdown"
- #
- # Get audit digest for a TPM command TPM2_GetRandom using and audit session
- #
- tpm2 clear
- tpm2 createprimary -Q -C e -c prim.ctx
- tpm2 create -Q -C prim.ctx -c signing_key.ctx -u signing_key.pub \
- -r signing_key.priv
- tpm2 startauthsession -S session.ctx --audit-session
- tpm2 getrandom 8 -S session.ctx --cphash cp.hash --rphash rp.hash
- tpm2 getsessionauditdigest -c signing_key.ctx -m att.data -s att.sig \
- -S session.ctx
- tpm2 flushcontext session.ctx
- dd if=/dev/zero bs=1 count=32 status=none of=zero.bin
- dd if=cp.hash skip=2 bs=1 count=32 status=none of=cphash.bin
- dd if=rp.hash skip=2 bs=1 count=32 status=none of=rphash.bin
- diff \
- <( cat zero.bin cphash.bin rphash.bin | openssl dgst -sha256 -binary ) \
- <( tail -c 32 att.data )
- #
- # Get audit digest for a TPM command TPM2_CC_Create in an audit session
- #
- tpm2 clear
- tpm2 createprimary -Q -C e -c prim.ctx
- tpm2 create -Q -C prim.ctx -c signing_key.ctx -u signing_key.pub \
- -r signing_key.priv
- tpm2 startauthsession -S session.ctx --audit-session
- tpm2 create -Q -C prim.ctx -u key.pub -r key.priv --cphash cp.hash \
- --rphash rp.hash -S session.ctx
- tpm2 getsessionauditdigest -c signing_key.ctx -m att.data -s att.sig \
- -S session.ctx
- dd if=/dev/zero bs=1 count=32 status=none of=zero.bin
- dd if=cp.hash skip=2 bs=1 count=32 status=none of=cphash.bin
- dd if=rp.hash skip=2 bs=1 count=32 status=none of=rphash.bin
- diff \
- <( cat zero.bin cphash.bin rphash.bin | openssl dgst -sha256 -binary ) \
- <( tail -c 32 att.data )
- #
- # Get audit digest for a TPM command TPM2_CC_Create in an audit session
- #
- tpm2 clear
- tpm2 createprimary -Q -C e -c prim.ctx
- tpm2 create -Q -C prim.ctx -c signing_key.ctx -u signing_key.pub \
- -r signing_key.priv
- tpm2 createprimary -C o -c prim.ctx -G rsa
- tpm2 readpublic -c prim.ctx -o prim.pub
- tpm2 create -C prim.ctx -u key.pub -r key.priv -c key.ctx
- tpm2 readpublic -c key.ctx -n key.name
- echo "plaintext" > plain.txt
- tpm2 makecredential -u prim.pub -s plain.txt -n `xxd -p -c 34 key.name` \
- -o cred.secret
- tpm2 startauthsession -S session.ctx --audit-session
- tpm2 activatecredential -c key.ctx -C prim.ctx -i cred.secret \
- -o act_cred.secret -S session.ctx --cphash cp.hash --rphash rp.hash
- tpm2 getsessionauditdigest -c signing_key.ctx -m att.data -s att.sig \
- -S session.ctx
- dd if=/dev/zero bs=1 count=32 status=none of=zero.bin
- dd if=cp.hash skip=2 bs=1 count=32 status=none of=cphash.bin
- dd if=rp.hash skip=2 bs=1 count=32 status=none of=rphash.bin
- diff \
- <( cat zero.bin cphash.bin rphash.bin | openssl dgst -sha256 -binary ) \
- <( tail -c 32 att.data )
- #
- # Get audit digest for a TPM command TPM2_CC_Certify in an audit session
- #
- tpm2 clear -Q
- tpm2 createprimary -Q -C e -g sha256 -G rsa -c primary.ctx
- tpm2 create -Q -C primary.ctx -c signing_key.ctx -u signing_key.pub \
- -r signing_key.priv
- tpm2 create -Q -g sha256 -G rsa -u certify.pub -r certify.priv -C primary.ctx
- tpm2 load -Q -C primary.ctx -u certify.pub -r certify.priv -n certify.name \
- -c certify.ctx
- tpm2 startauthsession -S session.ctx --audit-session
- tpm2 certify -Q -c primary.ctx -C certify.ctx -g sha256 -o attest.out -s sig.out \
- --cphash cp.hash --rphash rp.hash -S session.ctx
- tpm2 getsessionauditdigest -c signing_key.ctx -m att.data -s att.sig \
- -S session.ctx
- dd if=/dev/zero bs=1 count=32 status=none of=zero.bin
- dd if=cp.hash skip=2 bs=1 count=32 status=none of=cphash.bin
- dd if=rp.hash skip=2 bs=1 count=32 status=none of=rphash.bin
- diff \
- <( cat zero.bin cphash.bin rphash.bin | openssl dgst -sha256 -binary ) \
- <( tail -c 32 att.data )
- #
- # Get audit digest for a TPM command TPM2_CC_CertifyCreation in an audit session
- #
- tpm2 clear -Q
- tpm2 createprimary -Q -C e -g sha256 -G rsa -c prim.ctx \
- -d create.dig -t create.ticket
- tpm2 create -Q -C prim.ctx -c signing_key.ctx -u signing_key.pub \
- -r signing_key.priv
- tpm2 create -G rsa -u rsa.pub -r rsa.priv -C prim.ctx -c certsigningkey.ctx
- tpm2 startauthsession -S session.ctx --audit-session
- tpm2 certifycreation -C certsigningkey.ctx -c prim.ctx -d create.dig \
- -t create.ticket -g sha256 -f plain -s rsassa \
- --cphash cp.hash --rphash rp.hash -S session.ctx
- tpm2 getsessionauditdigest -c signing_key.ctx -m att.data -s att.sig \
- -S session.ctx
- dd if=/dev/zero bs=1 count=32 status=none of=zero.bin
- dd if=cp.hash skip=2 bs=1 count=32 status=none of=cphash.bin
- dd if=rp.hash skip=2 bs=1 count=32 status=none of=rphash.bin
- diff \
- <( cat zero.bin cphash.bin rphash.bin | openssl dgst -sha256 -binary ) \
- <( tail -c 32 att.data )
- #
- # Get audit digest: TPM command TPM2_CC_HierarchyChangeauth in an audit session
- #
- tpm2 clear -Q
- tpm2 createprimary -Q -C e -g sha256 -G rsa -c prim.ctx \
- -d create.dig -t create.ticket
- tpm2 create -Q -C prim.ctx -c signing_key.ctx -u signing_key.pub \
- -r signing_key.priv
- tpm2 startauthsession -S session.ctx --audit-session
- tpm2 changeauth -c o ownerpassword --cphash cp.hash --rphash rp.hash \
- -S session.ctx
- tpm2 getsessionauditdigest -c signing_key.ctx -m att.data -s att.sig \
- -S session.ctx
- dd if=/dev/zero bs=1 count=32 status=none of=zero.bin
- dd if=cp.hash skip=2 bs=1 count=32 status=none of=cphash.bin
- dd if=rp.hash skip=2 bs=1 count=32 status=none of=rphash.bin
- diff \
- <( cat zero.bin cphash.bin rphash.bin | openssl dgst -sha256 -binary ) \
- <( tail -c 32 att.data )
- #
- # Get audit digest: TPM command TPM2_CC_ObjectChangeauth in an audit session
- #
- tpm2 clear -Q
- tpm2 createprimary -Q -C e -g sha256 -G rsa -c prim.ctx \
- -d create.dig -t create.ticket
- tpm2 create -Q -C prim.ctx -c signing_key.ctx -u signing_key.pub \
- -r signing_key.priv
- tpm2 create -Q -C prim.ctx -p foo -u key.pub -r key.priv -c key.ctx
- tpm2 startauthsession -S session.ctx --audit-session
- tpm2 changeauth -C prim.ctx -p foo -c key.ctx -r new.priv bar \
- --cphash cp.hash --rphash rp.hash -S session.ctx
- tpm2 getsessionauditdigest -c signing_key.ctx -m att.data -s att.sig \
- -S session.ctx
- dd if=/dev/zero bs=1 count=32 status=none of=zero.bin
- dd if=cp.hash skip=2 bs=1 count=32 status=none of=cphash.bin
- dd if=rp.hash skip=2 bs=1 count=32 status=none of=rphash.bin
- diff \
- <( cat zero.bin cphash.bin rphash.bin | openssl dgst -sha256 -binary ) \
- <( tail -c 32 att.data )
- #
- # Get audit digest: TPM command TPM2_CC_ChangeEPS in an audit session
- #
- tpm2 clear -Q
- tpm2 startauthsession -S session.ctx --audit-session
- tpm2 changeeps --cphash cp.hash --rphash rp.hash -S session.ctx
- tpm2 createprimary -Q -C e -g sha256 -G rsa -c prim.ctx
- tpm2 create -Q -C prim.ctx -c signing_key.ctx -u signing_key.pub \
- -r signing_key.priv
- tpm2 getsessionauditdigest -c signing_key.ctx -m att.data -s att.sig \
- -S session.ctx
- dd if=/dev/zero bs=1 count=32 status=none of=zero.bin
- dd if=cp.hash skip=2 bs=1 count=32 status=none of=cphash.bin
- dd if=rp.hash skip=2 bs=1 count=32 status=none of=rphash.bin
- diff \
- <( cat zero.bin cphash.bin rphash.bin | openssl dgst -sha256 -binary ) \
- <( tail -c 32 att.data )
- #
- # Get audit digest: TPM command TPM2_CC_ChangePPS in an audit session
- #
- tpm2 clear -Q
- tpm2 startauthsession -S session.ctx --audit-session
- tpm2 changepps --cphash cp.hash --rphash rp.hash -S session.ctx
- tpm2 createprimary -Q -C e -g sha256 -G rsa -c prim.ctx
- tpm2 create -Q -C prim.ctx -c signing_key.ctx -u signing_key.pub \
- -r signing_key.priv
- tpm2 getsessionauditdigest -c signing_key.ctx -m att.data -s att.sig \
- -S session.ctx
- dd if=/dev/zero bs=1 count=32 status=none of=zero.bin
- dd if=cp.hash skip=2 bs=1 count=32 status=none of=cphash.bin
- dd if=rp.hash skip=2 bs=1 count=32 status=none of=rphash.bin
- diff \
- <( cat zero.bin cphash.bin rphash.bin | openssl dgst -sha256 -binary ) \
- <( tail -c 32 att.data )
- #
- # Get audit digest: TPM command TPM2_CC_NV_Define in an audit session
- #
- tpm2 clear -Q
- tpm2 startauthsession -S session.ctx --audit-session
- tpm2 nvdefine 0x1500016 -C o -s 32 -a "ownerread|ownerwrite" \
- --cphash cp.hash --rphash rp.hash -S session.ctx
- tpm2 createprimary -Q -C e -g sha256 -G rsa -c prim.ctx
- tpm2 create -Q -C prim.ctx -c signing_key.ctx -u signing_key.pub \
- -r signing_key.priv
- tpm2 getsessionauditdigest -c signing_key.ctx -m att.data -s att.sig \
- -S session.ctx
- dd if=/dev/zero bs=1 count=32 status=none of=zero.bin
- dd if=cp.hash skip=2 bs=1 count=32 status=none of=cphash.bin
- dd if=rp.hash skip=2 bs=1 count=32 status=none of=rphash.bin
- diff \
- <( cat zero.bin cphash.bin rphash.bin | openssl dgst -sha256 -binary ) \
- <( tail -c 32 att.data )
- #
- # Get audit digest: TPM command TPM2_CC_NV_Extend in an audit session
- #
- tpm2 clear -Q
- tpm2 nvdefine -C o -a "nt=extend|ownerread|policywrite|ownerwrite|writedefine" 1
- tpm2 startauthsession -S session.ctx --audit-session
- echo 'my data' | tpm2 nvextend -C o -i- 1 -S session.ctx \
- --cphash cp.hash --rphash rp.hash
- tpm2 createprimary -Q -C e -g sha256 -G rsa -c prim.ctx
- tpm2 create -Q -C prim.ctx -c signing_key.ctx -u signing_key.pub \
- -r signing_key.priv
- tpm2 getsessionauditdigest -c signing_key.ctx -m att.data -s att.sig \
- -S session.ctx
- dd if=/dev/zero bs=1 count=32 status=none of=zero.bin
- dd if=cp.hash skip=2 bs=1 count=32 status=none of=cphash.bin
- dd if=rp.hash skip=2 bs=1 count=32 status=none of=rphash.bin
- diff \
- <( cat zero.bin cphash.bin rphash.bin | openssl dgst -sha256 -binary ) \
- <( tail -c 32 att.data )
- #
- # Get audit digest: TPM command TPM2_CC_Unseal in an audit session
- #
- tpm2 clear -Q
- tpm2 createprimary -Q -C e -g sha256 -G rsa -c prim.ctx
- tpm2 create -Q -C prim.ctx -c signing_key.ctx -u signing_key.pub \
- -r signing_key.priv
- echo "plaintext" | \
- tpm2 create -C prim.ctx -c key.ctx -u key.pub -r key.priv -i-
- tpm2 startauthsession -S session.ctx --audit-session
- tpm2 unseal -c key.ctx --cphash cp.hash --rphash rp.hash -S session.ctx
- tpm2 getsessionauditdigest -c signing_key.ctx -m att.data -s att.sig \
- -S session.ctx
- dd if=/dev/zero bs=1 count=32 status=none of=zero.bin
- dd if=cp.hash skip=2 bs=1 count=32 status=none of=cphash.bin
- dd if=rp.hash skip=2 bs=1 count=32 status=none of=rphash.bin
- diff \
- <( cat zero.bin cphash.bin rphash.bin | openssl dgst -sha256 -binary ) \
- <( tail -c 32 att.data )
- #
- # End
- #
- exit 0
|