-
Notifications
You must be signed in to change notification settings - Fork 0
/
tpm-state-control.sh
69 lines (59 loc) · 1.8 KB
/
tpm-state-control.sh
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
# Copyright (C) 2022 Toni Blåfield
#
# edge-image-tools is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# edge-image-tools is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with edge-image-tools. If not, see <http://www.gnu.org/licenses/>.
set -e
export TPM_PATH=/tmp/vtpm
[ -z "${1}" ] && echo "${0} [rm(clear)/cp(backup&exit)/cprm(backup&clear)/rst(restore)]"
if [[ ${1} == "rst" ]]; then
echo "restore backed up tpm state"
rm -vrf ${TPM_PATH}
cp -vr vtpm_bak ${TPM_PATH}
chmod -vR 0640 ${TPM_PATH}
chmod -v 0755 ${TPM_PATH}
elif [[ $1 == "cp" ]]; then
echo "backup tpm state"
rm -vrf vtpm_bak
cp -vrp ${TPM_PATH} vtpm_bak
exit 0
elif [[ $1 == "cprm" ]]; then
echo "backup & clear tpm state"
rm -vrf vtpm_bak
cp -vrp ${TPM_PATH} vtpm_bak
rm -vrf ${TPM_PATH}
elif [[ $1 == "rm" ]]; then
echo "clear tpm state"
rm -vrf ${TPM_PATH}
else
echo "${0} [rm(clear)/cp(backup&exit)/cprm(backup&clear)/rst(restore)]"
fi
# ensure dir exists
mkdir -vp ${TPM_PATH}
pkill swtpm || true
pkill tpm2-abrmd || true
sleep 1
swtpm socket \
--daemon \
--server type=tcp,port=2321,disconnect \
--ctrl type=tcp,port=2322 \
--tpmstate dir=${TPM_PATH} \
--tpm2 \
--flags not-need-init,startup-clear \
--runas 0 \
--log file=logtpm.log,truncate
sleep 1
echo "Swtpm daemon started"
tpm2-abrmd -o --tcti "swtpm" &
sleep 1
echo "tpm2 resource manager daemon started"