File: setclock.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 (38 lines) | stat: -rw-r--r-- 812 bytes parent folder | download | duplicates (3)
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
# SPDX-License-Identifier: BSD-3-Clause

source helpers.sh

get_new_clock() {
    tpm2 readclock > clock.yaml
    local clock=$(yaml_get_kv clock.yaml clock_info clock)

    # the magic number is enough time where where setting the clock to a point
    # in the future from where we read it.
    clock=$(($clock + 100000))
    echo -n $clock
}

cleanup() {
	tpm2 changeauth -c o -p newowner 2>/dev/null || true
	tpm2 changeauth -c p -p newplatform 2>/dev/null || true

	rm -f clock.yaml

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

start_up

tpm2 setclock $(get_new_clock)

# validate hierarchies and passwords
tpm2 changeauth -c o newowner
tpm2 changeauth -c p newplatform

tpm2 setclock -c o -p newowner $(get_new_clock)
tpm2 setclock -c p -p newplatform $(get_new_clock)

exit 0