File: flushcontext.sh

package info (click to toggle)
tpm2-tools 5.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,988 kB
  • sloc: ansic: 45,737; sh: 14,915; xml: 8,342; makefile: 610; python: 51
file content (50 lines) | stat: -rw-r--r-- 1,249 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# SPDX-License-Identifier: BSD-3-Clause

source helpers.sh

start_up

cleanup() {
    rm -f saved_session.ctx

    if [ "$1" != "no-shut-down" ]; then
          shut_down
    fi
}
trap cleanup EXIT

cleanup "no-shut-down"
tpm2 clear

## Check cpHash output
tpm2 startauthsession -S session.ctx
Param_flushHandle="$(tpm2 sessionconfig session.ctx  | \
grep 'Session-Handle' | cut -d' ' -f2-2)"
tpm2 flushcontext $Param_flushHandle --cphash cp.hash
TPM2_CC_flushContext="00000165"

echo -ne $TPM2_CC_flushContext$Param_flushHandle | xxd -r -p | \
openssl dgst -sha256 -binary -out test.bin
cmp cp.hash test.bin 2

# Test for flushing the specified handle
tpm2 createprimary -Q -C o -g sha256 -G rsa
# tpm2-abrmd may save the transient object and restore it when using
res=`tpm2 getcap handles-transient`
if [ -n "$res" ]; then
    tpm2 flushcontext -Q -c 0x80000000
fi

# Test for flushing a transient object
tpm2 createprimary -Q -C o -g sha256 -G rsa
# make sure multiple options don't overflow
# bug: https://github.com/tpm2-software/tpm2-tools/issues/3035
tpm2 flushcontext -Q -ttttttttttt

# Test for flushing a loaded session
tpm2 createpolicy -Q --policy-session --policy-pcr -l sha256:0
tpm2 flushcontext -Q -l

cleanup "no-shut-down"

exit 0